Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Html.fromHtml() method weird issue

I am facing a weird issue:

My source string for Html.fromHtml() is as follows:

<strong>Terrible experience with Nikko hotel</strong><br />It was not easy to cancel booking. I called to cancel books, but they still chraged us two full days. A reason was we were late ten minutes in calling to cancel. They explained us very kindly that I can only cancel the first day. But they charged after then.\nSick."

which is retrieved from a json response

Now, when I display it using setText as follows:

commentbox.setText(Html.fromHtml(cmnt.getString("cmnt")));

but the output which i see is as follows:

enter image description here

Why is it giving me italic text instead of bold?

like image 378
Pratik Bhat Avatar asked Feb 22 '23 07:02

Pratik Bhat


1 Answers

This can be a LIMITATION as described here:

the Html.fromHtml() method in Android that creates a SpannedString from HTML source flips <em> and <strong> tags, so what you might be used to seeing in boldface turns into italics and vice-versa. This should only be an issue if you are displayng the generated HTML in a TextView — WebView in particular should behave more normally.

like image 73
Hanry Avatar answered Mar 08 '23 16:03

Hanry