gordonwd
gordonwd

Reputation: 4587

HTML tags in string for TextView

If I put simple HTML formatting tags, such as <b>...</b> into a string resource and display the string in a TextView, the expected formatting is applied. But how can I do this if I build up my own String and display it? If I do something like String str = "This is <b>bold</b>";, the actual tags get displayed -- not the expected bolding.

Do I have to run the string through some other method to cause the tags to be recognized as tags?

Upvotes: 8

Views: 13408

Answers (1)

RoflcoptrException
RoflcoptrException

Reputation: 52229

You have to use Html#fromHtml

String input = "<b>bold</b>";
myTextView.setText(Html.fromHtml(input));

Upvotes: 21

Related Questions