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

Exception or error:

In one textview I’m trying to separate text stylings on different words.

So far I have:

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

Basically, I’m saying I want "Competitor ID:" to be italic, small, and grey.

And I want that string compID to be normal sized, not italic, and green.

The italic and small portions of the code work perfectly, but for some reason, the entire text view has grey text, rather than just "Competitor ID:".

Any ideas?

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

Try the above.


Try using one of these grey hex code values instead.

gray1 #030303   
gray2 #050505  
gray3 #080808     
gray4 #0A0A0A   
gray5 #0D0D0D 

. Also try to control the text color inside the xml textview properties using the above codes. Hope this helps

Leave a Reply

Your email address will not be published. Required fields are marked *