August 13, 2021

How to display HTML in TextView?

By lj007

Display HTML in TextView

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                tvContent.text = Html.fromHtml("#HTML_STRING", HtmlCompat.FROM_HTML_MODE_LEGACY)
            } else {
                tvContent.text = Html.fromHtml("#HTML_STRING")
            }


Above code is for displaying html string in TextView. #HTML_STRING with your own string and all will works fine. If your html content is too large you need to wrap your TextView in ScrollView. That means you need to add ScrollView as parent layout of your TextView.