【问题标题】:Bold a text and have it in next line for a particular string in Strings.xml加粗文本并将其放在 Strings.xml 中特定字符串的下一行
【发布时间】:2014-08-30 02:45:47
【问题描述】:

我正在尝试将存储在 strings.xml 中的字符串中的特定单词加粗:

这是我想要的:

将来时:示例:我将在上午 9:00 到那里

我关注了这个:Bold words in a string of strings.xml in Android - 但没有得到结果。

所以我在 strings.xml 中有如下文本:

<string name="futureText">Future tense: <b>Example:</b> I will be there at 9:00AM</string>

Spanned text = Html.fromHtml(res.getString(R.string.futureText));
questionText.setText (text);

“示例:”我没有得到任何粗体。

另外如何将“示例:我将在上午 9:00 到”文本添加到下一行?我知道字符串 \n 转到下一个 html 格式怎么样?

这里有什么问题?

【问题讨论】:

    标签: android xml string


    【解决方案1】:

    您无法真正读取 string.xml 中的 html 标签,因为它是 xml 中的默认标签,因此当您以编程方式读取它时,它不会读取标签,而只会读取没有标签的文本。

    解决方案:

    您需要将其包装在&lt;![CDATA[ ...raw html... ]]&gt; 中,以使您能够阅读文本中的 html 标记。

    样本:

    <string name="futureText">Future tense: <![CDATA[<b>Example:</b>]]> I will be there at 9:00AM</string>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-31
      • 2022-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-08
      • 2015-05-07
      相关资源
      最近更新 更多