cerealspiller cerealspiller - 1 year ago 88
Android Question

Change text color of one word in a TextView

I am looking for a way to change the color of a text of a single word in a

from within an

For example, with this:

String first = "This word is ";
String next = "red"
TextView t = (TextView) findViewById(R.id.textbox);
t.setText(first + next);

How would I change the color of the
text to red?

Dan Dan
Answer Source

Easiest way I know is to just use html.

String first = "This word is ";
String next = "<font color='#EE0000'>red</font>";
t.setText(Html.fromHtml(first + next));

But this will require you to rebuild the TextView when (if?) you want to change the color, which could cause a hassle.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download