Android: html.fromHtml () method - strange problem

I have a strange problem:

My source line 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 extracted from json response

Now, when I show it using setText as follows:

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

but the output I see is as follows:

enter image description here

Why does this give me italic text instead of bold?

+4
source share
1 answer

This may be a LIMITATION , as described here :

the Html.fromHtml () method in Android, which creates a SpannedString from an HTML source, inverts the <em> and <strong> , tags , so what you could use to highlight in bold turns into italic and tick -versa. This should only be a problem if you display the generated HTML in a TextView. In particular, WebView should behave more normally.

+8
source

Source: https://habr.com/ru/post/1383011/


All Articles