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

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

问题描述

我想显示例如这个 html 代码:

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>

我想通过在资源 strings.xml 中声明 html 来在对话框上显示它.我该怎么做?

I want to display it on a Dialog by declaring html in resources strings.xml. How can I do it?

推荐答案

在strings.xml中添加html源代码最好的方式是使用.下面是一个例子:

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 中显示此 html:

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

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

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