Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 933
user1029167 Avatar asked May 01 '12 00:05

user1029167


People also ask

Can you have multiple styles inside TextView?

Use multiple widgets if you need precise placement of discrete bits of text. Use inline markup if you, um, need markup inline in a widget. Remember: there is no FlowLayout in Android, so stringing together multiple TextViews to create a paragraph is not truly practical AFAIK.

Can we change the text in TextView?

TextView tv1 = (TextView)findViewById(R. id. textView1); tv1. setText("Hello"); setContentView(tv1);


1 Answers

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

Try the above.

like image 65
Lawrence Gimenez Avatar answered Sep 28 '22 11:09

Lawrence Gimenez