1. Set the font color directly in the configuration XML file in the layout file to change the color by adding android:textcolor= "#FFFFFF"
But this effect only allows the font to display a color
2. In the activity by TextView Tv=new TextView (this); Instantiate a TextView through Setcontentview (TV); load it into the current activity, set the content string to display Str= "What you want to show"; The following code can be used to change the font of some text, the number in the parameter indicates the starting position and the end position, this method is more complicated
Copy Code code as follows:
Spannablestringbuilder style=new Spannablestringbuilder (str);
Spannablestringbuilder Implement Charsequence interface
Style.setspan (New Foregroundcolorspan (color.red), 0, 2,spannable.span_exclusive_exclusive);
Style.setspan (New Foregroundcolorspan (Color.yellow), 2, 4,spannable.span_exclusive_exclusive);
Style.setspan (New Foregroundcolorspan (Color.green), 4, 6,spannable.span_exclusive_exclusive);
Tv.settext (style);//Add it to the TV
3. Change text color through HTML tags
Copy Code code as follows:
Tv.settext (html.fromhtml ("I am <font color=blue>danyijiangnan</font>"));
The Html.fromhtml () method allows you to use HTML tags in a string that can change the format of a font