Question Detail

How to consume HTML tags on TextView Android

6 years ago Views 1442 Visit Post Reply

In my app I am using web services for real-time data on my app in some case I am getting some HTML tag in my JSON Result how can I consume HTML in my Java code, How can i display HTML styled in my TextView b
like "Hello, <b>Rony</b>,<br>How are you?"

Thread Reply


- 6 years ago

For example (< Android Nougat):

textView.setText(Html.fromHtml("Hello, <b>Rony</b>,<br>How are you?"));

For example (>= Android Nougat):

myTextView.setText(Html.fromHtml("Hello, <b>Rony</b>,<br>How are you????????", Html.FROM_HTML_MODE_COMPACT));

To distinguish between Android versions use Build.VERSION.SDK_INT >= Build.VERSION_CODES.N.