Single TextView with multiple colored text

Andro Selva picture Andro Selva · May 23, 2011 · Viewed 124.9k times · Source

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

Answer

2red13 picture 2red13 · May 23, 2011

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