繁体   English   中英

在Android TextView中插入HTML格式的字符串(不是资源)

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM