21

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?

Derlin
  • 9,572
  • 2
  • 32
  • 53
user1029167
  • 349
  • 1
  • 4
  • 15

2 Answers2

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

Try the above.

Lawrence Gimenez
  • 2,662
  • 4
  • 34
  • 52
  • @userIsAMonkey +1 great work but why are you using escape sequences in **font color** if it is in html – Muhammad Babar Apr 17 '13 at 09:48
  • 2
    For peoples having issues; using color names doesn't work, I think you have to use color codes. wrong: right : – Evren Ozturk May 02 '16 at 07:25
  • 1
    @MuhammadBabar the escape is because this is Java source code. To include a `"` in a Java String you have to escape it. After Java compiles this it'll look like normal HTML code and will be parsed as such by `fromHtml`. – TWiStErRob Sep 21 '16 at 09:51
-8

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

aizaz
  • 3,056
  • 9
  • 25
  • 57
lastshadowrider
  • 103
  • 1
  • 9