简体   繁体   中英

Cannot change color in TextView android

I want to change particular text in textview ,i tried like this,

xml file

<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 file

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();
}

what the wrong with this,the text color not changed.give any suggestion.

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

 android:textAllCaps="true"  

 runtime u have to set Allcaps="true";

this is the easiest way to change text color:

your_textview.setTextColor(0xFF000000);

you can change the color with many ways:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM