0

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

<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*);
4

1 回答 1

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);

请参阅这篇文章以在 xml 中编写标签。

于 2013-07-01T14:49:52.013 回答