[英]How can i add style from the string html to display in android textview?
我有一个字符串 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
在我的 textview 上显示这个之前,我想在标签中添加 width="100%"。 这在android中可能吗?
任何帮助将非常感激。
在文本视图中,您可以像这样使用。
<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()
否则,您可以使用 webview。
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>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.