android显示Html文本

来源:互联网 发布:pp越狱助手 for mac 编辑:程序博客网 时间:2024/05/04 03:09

开发遇到显示带格式文本,使用HTML标记实现。

1、textview

TextView tView = (TextView) findViewById(R.id.web_textview_html_text);
Spanned html = Html.fromHtml(htmlText);
tView.setMovementMethod(ScrollingMovementMethod.getInstance());// 滚动
tView.setText(html);


2、webview

textview是无法渲染样式,因此应用style等样式需要使用webview完成。

WebView tView = (WebView) findViewById(R.id.web_webView_html);
String htmlText = "<html><head><title>" + title + "</title></head><body>" + body + "</body></html>";

tView.getSettings().setDefaultTextEncodingName("UTF -8");//设置默认为utf-8
tView.loadData(htmlText, "text/html; charset=UTF-8", null);//中文解码  

0 0