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?

1

2 Answers 2

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

Try the above.

Sign up to request clarification or add additional context in comments.

3 Comments

@userIsAMonkey +1 great work but why are you using escape sequences in font color if it is in html
For peoples having issues; using color names doesn't work, I think you have to use color codes. wrong:<font color=\"#white\"> right :<font color=\"#f1f1f1\">
@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.
-9

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.