Search code examples
androidtextview

Single TextView with multiple colored text


As the title says, I want to know is it possible to achieve two different colored characters in a single textview element.


Solution

  • yes, if you format the String with html's font-color property then pass it to the method Html.fromHtml(your text here)

    String text = "<font color=#cc0029>First Color</font> <font color=#ffcc00>Second Color</font>";
    yourtextview.setText(Html.fromHtml(text));