无法在 TextView 中更改颜色 android

Cannot change color in TextView android

我想更改 textview 中的特定文本,我试过这样,

xml 文件

<TextView
    android:id="@+id/txt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:paddingRight="30dp"
    android:textAllCaps="true"
    android:textSize="8sp"
    android:textStyle="bold" />

Java 文件

try {
   String first_text = "<font color='#ffcc33'><b>"+"ANDROID"+ "</b></font>";
   String second_text = "<font color='#33689C'>"+"MARSHAMLLOW"+ "</font>";
   Tv_text.setText(Html.fromHtml(first_text+second_text));
} catch (Exception e) {
   e.printStackTrace();
}

这有什么问题,文本颜色不是 changed.give 任何建议。

 if you use modifiers below  like this make sure it false state :

 android:textAllCaps="true"  

 runtime u have to set Allcaps="true";

这是更改文本颜色的最简单方法:

your_textview.setTextColor(0xFF000000);

您可以通过多种方式更改颜色:

your_textview.setTextColor(Color.BLACK);
your_textview.setTextColor(Color.parseColor("#000000"));
your_textview.setTextColor(Color.rgb(0,0,0));