我有一个字符串html显示在我的textview中。

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()


否则,您可以使用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>";

10-07 19:31
查看更多