如何更改段落中的string.xml颜色?

时间:2013-07-01 14:44:08

标签: java android colors

我想更改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*);

1 个答案:

答案 0 :(得分: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.