Text view with multiple text colors android [duplicate]
Question
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.
Solution
You can use something like below for this :
actualStringToDisplay="<font COLOR=\"RED\"><b>" + yourString + "</b></font>";
textDisplayedBottom.setText(Html.fromHtml(actualStringToDisplay));
Hope this helps.
OTHER TIPS
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));
See SpannedString & SpannedStringBuilder & ColorSpan
http://developer.android.com/reference/android/text/style/ForegroundColorSpan.html
http://developer.android.com/reference/android/text/SpannedString.html
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow