1. Set the font color directly in the configuration xml file under the layout file, and change the color by adding android: textcolor = "# FFFFFF"
However, this effect only allows the font to display one color.
2. in the activity, use TextView TV = new TextView (this); to instantiate a textview, use setContentView (TV); to load it to the current activity, set the content to be displayed String str = "content to be displayed"; use the following code to change some text fonts. The numbers in the parameters indicate the start position and end position. This method is complex.Copy codeThe Code is as follows: SpannableStringBuilder style = new SpannableStringBuilder (str );
// SpannableStringBuilder implements the 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 TV
3. Use html tags to change the text colorCopy codeThe Code is as follows: TV. setText (Html. fromHtml ("I am <font color = blue> danyijiangnan </font> "));
The Html tag can be used in the string through the html. fromHtml () method, and the font tag can be used to change the font format.