【问题标题】:Android string with HTML failed带有 HTML 的 Android 字符串失败
【发布时间】:2015-05-27 13:34:54
【问题描述】:

在我的 strings.xml 中:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="informations_links">Read these <b><a href=\"com.android.mobile://ReaderActivity\">general informations</a></b> and <a href=\"com.android.mobile://ReaderActivity\">this main note</a> from this box.</string>
</resources>

那我就这样用了:

mTextView.setText(Html.fromHtml(getString(R.string.informations_links)));

它不起作用。我的文本没有格式化。

但如果我直接写这个并且它可以工作(它是 same 字符串):

mTextView.setText(Html.fromHtml("Read these <b><a href=\"com.android.mobile://ReaderActivity\">general informations</a></b> and <a href=\"com.android.mobile://ReaderActivity\">this main note</a> from this box."));

那么,我的 strings.xml 中最好的写法是什么?

【问题讨论】:

    标签: android html textview


    【解决方案1】:

    你必须将字符串内容包装成&lt;Data&gt;&lt;/Data&gt;

    <string name="my_string"><Data><![CDATA[<p>This is a paragraph!</p>]]> </Data></string>
    

    android string.xml reading html tags problem

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-18
      • 1970-01-01
      • 2013-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多