安卓:HTML中的strings.xml [英] Android: html in strings.xml

查看:111
本文介绍了安卓:HTML中的strings.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示例如这个网站code:

I would like display for example this html code:

<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 。我该怎么办呢?

推荐答案

添加HTML源$ C ​​$ C中的strings.xml最好的方法是使用&LT;![CDATA [HTML源代码code]]&GT; 。下面是一个例子:

The best way to add html source code in strings.xml is to use <![CDATA[html source code]]>. Here is an example:

<string name="html"><![CDATA[<p>Text<p>]]></string> 

然后就可以使用显示这个网站的TextView的:

Then you can display this html in TextView using:

myTextView.setText(Html.fromHtml(getString(R.string.html)));

如果你在你的HTML链接,你想他们是点击,使用此方法:

If you have links in your html and you want them to be clickable, use this method:

myTextView.setMovementMethod(LinkMovementMethod.getInstance());

这篇关于安卓:HTML中的strings.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆