Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Android

Hiển thị HTML trong TextView trên Android

Dùng HtmlCompat.fromHtml() (API 24+) để parse HTML string thành Spanned rồi set vào TextView.

String htmlText = "

What is Android?

Android is an open source...

"; TextView htmlToTextView = findViewById(R.id.htmlToTextView); htmlToTextView.setText(HtmlCompat.fromHtml(htmlText, 0));

Flag 0 = FROM_HTML_MODE_LEGACY. Kết quả: TextView render thẻ <h2>, <b>, <i>, <p>...