xml 中的 Android 粗体文本不起作用

标签 android xml string

我正在制作一个应用程序,在该应用程序中我想制作一些部分粗体部分正常的文本,如下所示:

蛋糕试试这个用胡萝卜做的美味蛋糕。

在我的 main.xml 中,我输入了这个:

<LinearLayout
        android:id="@+id/itemone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="20"
        android:padding="3dp" >

        <ImageView
            android:layout_width="110dp"
            android:layout_height="85dp"
            android:src="@drawable/cake" />

        <TextView
            android:id="@+id/TextView01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cake"
            android:textAppearance="?android:attr/textAppearanceSmall" />

    </LinearLayout>

在我的 strings.xml 中我输入了这个:

<string name="cake"><b>Cake</b>\n Try this delicious cake made with carrots.</string>

结果不是我除的。我得到的只是“蛋糕”这个词,而且它不是粗体。

最佳答案

textAppearanceSmall 搞砸了这件事。

它以此为风格,忽略其他。不要包括它。

还有一些东西搞砸了,标签“<”和“>”应该被替换,因为有特殊的 xml 字符。搜索 html 转义字符或小数字符,< 应该如下所示:& l t ; (一个字)

如果你觉得无聊,你可以在 xml 中搜索 CDATA。有一种方法可以在 xml 中包含纯文本。

无需动态设置TextView的文本。

关于xml 中的 Android 粗体文本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11334129/

相关文章:

javascript - 如何在 JavaScript 中获取字符串与给定替换的所有组合?

java - 如何从字符串中提取子字符串(Android)?

android - 查看 Recycler 的模型查看项目

java.text.ParseException : Unparseable number: “2,3456” (at offset 5)

Python读取大型xml文件并保存到csv文件

java - 如何在解析 SOAP 正文时从 NodeList 对象中提取属性值

python - 如何在 Python 中针对 DTD 文件验证 xml

android - 如何验证 APK 未被篡改?

android - 使用 String 类型的 Switch 语句

c - 使 char* 指向另一个字符串文字泄漏内存吗?