![](/img/trans.png)
[英]Set TextView text from html-formatted string resource in XML
[英]Inserting HTML formatted (not a resource) string in android TextView
我需要将HTML格式的字符串插入TextView
。 我正在从数据库中检索文本,并在使用此代码插入文本时
WebView webview = (WebView) view.findViewById(R.id.webView);
text = "<html><body>" + {text retrieved form database} + "</body></html>"
webview.loadData(text, "text/html", "utf-8");
可以,但是这段代码
TextView output = (TextView) view.findViewById(R.id.simple_text);
output.setText(Html.fromHtml(text));
去除所有HTML格式。
什么是正确的方法?
从摆脱<html><body>
和</body></html>
部分开始,因为Html.fromHtml()
不使用它们。
然后,将HTML限制为使用Html.fromHtml()
支持的标签 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.