【问题标题】:HTML Formatting in TextViewTextView 中的 HTML 格式
【发布时间】:2012-04-29 14:51:52
【问题描述】:

全部,

我的字符串资源 xml 文件中有以下内容。

<?xml version="1.0" encoding="utf-8"?> <resources>

<string name="hello">Hello World, ProDroid_Android!</string>
<string name="app_name">ProDroid_Android-CH3-Resources</string>

<plurals name ="eggs_in_A_basket">
    <item quantity ="one"> There is 1 egg</item>
    <item quantity = "other"> There are %d eggs</item>

</plurals>
<string name="simple_string">simple string</string>
<string name="quoted_string">"Quoted String 'xyz' string"</string>
<string name="double_quoted_string">\"Double Quoted String\""\";</string>
<string name="java_format_string">Hello %2$s Java format String. %1$s again.</string>

<string name="tagged_string">Hello <b><i> Slanted Android.</i></b>, You are bold</string>

当我将 tagged_string 放入具有 HTML 格式的 TextView 时,它不会以它的格式显示。但是,如果我剪切并粘贴 Hello Slanted Android.,你是粗体 并手动将其放入 .setText 中,或者如果我在我的布局 xml 文件中静态设置它。但是使用下面的 Java 代码不起作用(您看到的只是未格式化的文本):

//HTML
        TextView t6 = (TextView) findViewById(R.id.textView6);

        t6.setText(Html.fromHtml(ProDroid_Android.this.getString(R.string.tagged_string)));

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: android html textview


    【解决方案1】:

    如果您以 XML 格式设置文本,则无需使用 Html.formatHtml(...)

    试试这个:

    t6.setText(getString(R.string.tagged_string);
    

    编辑: 嗯...这种方式对我很有效,我尝试完全你的字符串。 也许您的项目需要清理(项目>清理...)

    如果这没有帮助: 我找到了另一个question。也许那里的答案可以解决你的问题

    【讨论】:

    • 不,这并没有这样做。还有其他想法吗?我正在运行 API 10。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-03
    • 1970-01-01
    • 2017-04-28
    • 2012-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多