【问题标题】:how to change string.xml color in paragraph?如何更改段落中的 string.xml 颜色?
【发布时间】:2013-07-01 14:44:07
【问题描述】:

我想更改value/string.xml 中的数组中的文本颜色,而不是Layout,但也不是所有文本,而是其中的一部分 示例:

<string-array name="list">'

           // like Cafe in example i want it red and bold but not other text.`
             <item>Welcome to Cafe</item>'
            // and shop to be purple
            <item>The new online Shop!</item>'



 //in java i would set 
    welcome.setText(*and one of the array item*);

【问题讨论】:

    标签: java android colors


    【解决方案1】:

    您可以在您的 string.xml 中编写 html 以使它们看起来更漂亮。

           // like Cafe in example i want it red and bold but not other text.`
             <item>Welcome to <b>Cafe</b></item>'
            // and shop to be purple
            <item>The new online <span style="...">Shop!</span></item>'
            // FOR EXAMPLE ONLY, use XML CDATA in the link provided.
    
    textView.setText(Html.fromHtml(YOUR_STRING_FROM_XML), TextView.BufferType.SPANNABLE);
    

    this post for writing tags in xml.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-05
      • 2013-03-04
      • 2013-07-05
      • 2019-05-24
      • 2010-12-11
      相关资源
      最近更新 更多