在我的应用程序中,我想在 TextView
中显示一些文本,并且我从 server 获取此 text。
我应该在 XML 布局中只使用一个 textView
,并且我应该为这个 Texts 设置 color。
我的 XML:
<TextView
android:id="@+id/rowExplore_userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/size3"
android:layout_marginTop="@dimen/padding8"
android:layout_toRightOf="@+id/rowExplore_imageCard"
android:fontFamily="sans-serif"
android:gravity="left|center_vertical"
android:text="Adam"
android:textColor="@color/colorPrimary"
android:textSize="@dimen/font14" />
JSON:
"name": "Adam Sandel",
"info": "liked",
"movieName": "SpiderMan",
Java 代码:
rowExplore_userName.setText(response.getName() + response.getInfo() + response.getMovieName() );
我怎么可以呢?请帮助我
最佳答案
你可以使用 HTML
String text = "<font color=#cc0029>First Color</font> <font color=#ffcc00>Second Color</font>";
yourtextview.setText(Html.fromHtml(text));
关于java - 如何在 Android 中为 TextView 动态设置颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46565158/