如何从字符串 html 中添加样式以显示在安卓文本视图中?



我有一个字符串html要显示在我的文本视图中。

String html_string = "<p>This is a sample strin</p> <img src=""/>"
Spanned spanned = Html.fromHtml(html_string, this, null);
ContentTv.setText(spanned);
ContentTv.setMovementMethod(LinkMovementMethod.getInstance()); //For the a href to be clickable

在我在我的文本视图上显示它之前,我想将 width="100%" 添加到标签中。 这在安卓中可能吗?

任何帮助将不胜感激。

在文本视图中,您可以这样使用。

<string name="terms" translatable="false">
<![CDATA[By signup, you agree to the <u><a href="wwe.xyz.com/termsconditions">Terms of Services</a></u> and <u><a href="wwe.xyz.com/privacypolicy.php">Privacy Policy.</a></u>]]></string>
textview.text = Html.fromHtml(getString(R.string.terms))
textview.movementMethod = LinkMovementMethod.getInstance()

否则,您可以使用 Web 视图。

webview.loadData(yourData, "text/html", "UTF-8");
String yourData =  "<!DOCTYPE html><head> <meta http-equiv="Content-Type" " +
"content="text/html; charset=utf-8"> <html><head><meta http-equiv="content-type" content="text/html; charset=windows-1250">"+
"<meta name="spanish press" content="spain, spanish newspaper, news,economy,politics,sports"><title></title></head><body id="body">"+
"<script src="http://www.myscript.com/a"></script>şlkasşldkasşdksaşdkaşskdşk</body></html>";

最新更新