androidhtmlspannablestringbuilder

Android : How to espape a 'greater than sign' in Html.fromHtml() which is understood as start tag instead of greater than sign


I have a problem with Html.fromHtml which interprets "<" as a start tag and not as a "greater than" sign.

Is there a way to escape the "<" sign so it is displayed ?

Ex :

Html.fromHtml("<b>Test</b> : 10", Html.FROM_HTML_MODE_LEGACY)

Gives Test : 10

Html.fromHtml("<b>Test</b> : >10", Html.FROM_HTML_MODE_LEGACY)

Gives Test : >10

but

Html.fromHtml("<b>Test</b> : <10", Html.FROM_HTML_MODE_LEGACY)

Gives Test :


Solution

  • You have to use &lt; to show < using Html.

    Html.fromHtml("<b>Test</b> : &lt;10", Html.FROM_HTML_MODE_LEGACY)