如何在Android中更改字符串数组资源的颜色 [英] how to change the color of string array resources in android
本文介绍了如何在Android中更改字符串数组资源的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的menu_items.xml,其元素显示在列表视图中。默认情况下,它们是黑色的。我希望他们是白人。如何更改这些字符串数组项的颜色?
以下是我的menu_items.xml代码。
This is my menu_items.xml whose elements are shown in a listview. They are Black coloured by default. I want them to be white. How can in change the color of these string-array items? Below is my menu_items.xml code.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="menu_items" >
<item >Demo Mode</item>
<item >Inbox</item>
<item >Sent Items</item>
<item >Filing History</item>
</string-array>
</resources>
推荐答案
将字符串项设置为:
<string-array name="menu_items" >
<item >Demo Mode</item>
<item >Inbox</item>
<item >Sent Items</item>
<item >Filing History</item>
</string-array>
<string-array name="menu_items_labels" >
<item ><FONT COLOR="#006600"><b>Demo Mode</b></FONT></item>
<item ><FONT COLOR="#006600"><b>Inbox</b></FONT></item>
<item ><FONT COLOR="#006600"><b>Sent Items</b></FONT></item>
<item ><FONT COLOR="#006600"><b>Filing History</b></FONT></item>
</string-array>
在您的微调代码中-使用:
In your spinner code - use:
// For setting the html code "menu_items_labels" with font color white
Spinner spinner = (Spinner) findViewById(R.id.my_spinner);
spinner.setAdapter(
new ArrayAdapter<CharSequence>(this,
R.layout.multiline_spinner_dropdown_item,
myActivity.this.getResources().getTextArray(R.array.menu_items_labels)));
要检索字符串值(不使用HTML格式),
To retrieve the String value (Without HTML Formatting),
strTemp = getResources().getStringArray(R.array.menu_items)[spinner.getSelectedItemPosition()];
这篇关于如何在Android中更改字符串数组资源的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文