Sunday 8 December 2019

java - How do i parse HTML text with tags that i retrieve from firebaseDB in a TextView? No WebView

There are two options :



First is to use Html.fromHtml(htmlString)



if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
textView.setText(Html.fromHtml(htmlString,Html.FROM_HTML_MODE_LEGACY));
} else {
textView.setText(Html.fromHtml(htmlString));
}



The tags allowed in this approach are :
, ,

,
, ,
, ,

,

,

,

,

,

, ,

,
, , , , ,



Source




Another option is to use CDATA



Define a string resource like



%1$s]]>


Then call it like textView.setText(res.getString(R.string.stringName, htmlString));

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...