Home » Android » android – HTML tags in string for TextView

android – HTML tags in string for TextView

Posted by: admin June 15, 2020 Leave a comment


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?

How to&Answers:

You have to use Html#fromHtml

String input = "<b>bold</b>";