Wednesday, September 25, 2019

android - How to display HTML in TextView?




I have simple HTML:



Title


description here




I want to display HTML styled text it in TextView. How to do this?


Answer



You need to use Html.fromHtml() to use HTML in your XML Strings. Simply referencing a String with HTML in your layout XML will not work.




This is what you should do:



if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
textView.setText(Html.fromHtml("

Title


Description here

", Html.FROM_HTML_MODE_COMPACT));
} else {
textView.setText(Html.fromHtml("

Title


Description here

"));
}

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...