Search code examples
androiduser-interfacetexttextviewuicolor

android text color


Is it possible to have different colored texts within the same text view?

I've been trying to use the Spannable class to style my texts but the documentation is completely useless on how to style text with it.


Solution

  • Use Html.fromHtml, the font tag and the color attribute...

    String s = "<font color='#FF0000'>I'm read</font> <font color='#0000FF'>and I'm blue</font>";
    textView.setText(Html.fromHtml(s));