简体   繁体   English

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

[英]how to change string.xml color in paragraph?

i want to change a text color in an array in the value/string.xml not in the Layout but also not all the text but some part of it example: 我想在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*);

You can write html in your string.xml to have them fancy looking. 您可以在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);

See this post for writing tags in xml. 有关在xml中编写标签的信息,请参见这篇文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM