Using Multiple Text Colors in Android's Textview [ HTML.Fromhtml() ]

Using multiple text colors in Android's textview [ Html.fromhtml() ]

textview.setText(Html.fromHtml("<i><small><font color=\"#c5c5c5\">" + "Competitor ID: " + "</font></small></i>" + "<font color=\"#47a842\">" + compID + "</font>"));

Try the above.

Highlighting Text Color using Html.fromHtml() in Android?

Or far simpler than dealing with Spannables manually, since you didn't say that you want the background highlighted, just the text:

String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);

Setting color using Html.fromHtml to TextView in Android is not working

Try this

title = title + "<font color=#2bb1ff> .... read more</font>";

Cannot Set Multi Text color for text view using Html.fromText in 24

No need for HTML, just use spans.

Spannable text = new SpannableString("hello");
text.setSpan(new ForegroundColorSpan(Color.RED), 0, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
mTextView.setText(text);

If you're using appcompat, you probably want to new AppCompatTextView(context) rather than just new TextView(context).

adding multiple colors to a text view in android

Seems like the html has some error or maybe its not supported by Html.fromHtml().

Try loading it on a webview

WebView webview = new Webview(this);
webview.loadHtml(fidscription);

Hope this helps.

Android: unable to change color of part of the text in textview

Try like this. The below code is perfectly working for me, i have tested it.

TextView ttt = (TextView) findViewById(R.id.textView11);
String styledText = "This is <font color='red'>simple</font>.";
ttt.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);

and here is output.

Sample Image

Single TextView with multiple colored text

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


Related Topics



Leave a reply



Submit