I have String with ul and li in it. And I am trying to show them in HTML formatting in textview. textView.setText(Html.fromHtml(myHtmlText));
But tex
A really easy way to make things work for API level M (23) and lower From your HTML string you can use the following:
private fun String.formattedHtml(): String {
// Work around for API Versions lower than N, Html.fromHtml does not render list items correctly
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
this.replace("", "")
.replace("
", "")
.replace("- ", "
• ")
.replace("
", "")
} else {
this
}
}
Then, you can use:
Html.fromHtml("- test
".formattedHtml())
No need for TagHandler for API N and up, as mentioned in https://stackoverflow.com/a/40524835, android.text.Html supports li and ul tags.