我想显示例如这个html代码:
<body>
<p><b>Hello World</b></p>
<p>This is a test of the URL <a href="http://www.example.com"> Example</a></p>
<p><b>This text is bold</b></p>
<p><em>This text is emphasized</em></p>
<p><code>This is computer output</code></p>
<p>This is<sub> subscript</sub> and <sup>superscript</sup></p>
</body>
我想通过在资源中声明 html 将其显示在对话框上strings.xml
。我该怎么做?
在 strings.xml 中添加 html 源代码的最佳方法是使用<![CDATA[html source code]]>
。这是一个例子:
<string name="html"><![CDATA[<p>Text</p>]]></string>
然后你可以使用以下命令在 TextView 中显示此 html:
myTextView.setText(Html.fromHtml(getString(R.string.html)));
如果您的 html 中有链接并且希望它们可点击,请使用以下方法:
myTextView.setMovementMethod(LinkMovementMethod.getInstance());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)