2

I want to show a string for ex "RedBlueGray" in a single text view like Red should appear with red font color, Blue with blue font and Gray with Gray font.Is it possible? if so, What is the best way to achieve. Note the string I want to display will change dynamically but not colors.

Ganesh K
  • 2,623
  • 9
  • 51
  • 78

3 Answers3

5

You can use something like below for this :

actualStringToDisplay="<font COLOR=\"RED\"><b>" + yourString + "</b></font>";

textDisplayedBottom.setText(Html.fromHtml(actualStringToDisplay));

Hope this helps.

Etaoin
  • 8,444
  • 2
  • 28
  • 44
Deva
  • 3,919
  • 1
  • 27
  • 38
1

Simplest way to do this define a html string:

String text="<FONT COLOR="#RED">red</FONT><FONT COLOR="#GREEN">green</FONT><FONT COLOR="#BLUE">blue/FONT>";

set this string to textView by

TextView.setText(Html.fromHtml(text));
jeet
  • 29,001
  • 6
  • 52
  • 53