如何更改String数组或String数组元素的颜色

时间:2015-10-26 04:35:58

标签: android arrays string

    I want to change the color of each array element or whole array given bellow.so how
    can i achieve this?
            String[] title = {
                    "Abundance",
                    "Anxiety",
                    "Bruxism",
                    "Discipline",
                    "Drug Addiction"
                }
         is there any way that 
        title.setColor or 
        title[0].setColor

这将直接改变String值的颜色。我发现很多,但所有答案都是针对字符串数组资源的。

1 个答案:

答案 0 :(得分:0)

试试这个,

您的字符串项目如下,

<string-array name="menu_items" >
            <item >Abundance</item>
            <item >Anxiety</item>
            <item >Bruxism</item>
            <item >Discipline</item>
            <item >Drug Addiction</item>
</string-array>

<string-array name="menu_items_labels" >
            <item ><FONT COLOR="#006600"><b>Abundance</b></FONT></item>
            <item ><FONT COLOR="#006600"><b>Anxiety</b></FONT></item>
            <item ><FONT COLOR="#006600"><b>Bruxism</b></FONT></item>
            <item ><FONT COLOR="#006600"><b>Discipline</b></FONT></item>
            <item ><FONT COLOR="#006600"><b>Drug Addiction</b></FONT></item>
</string-array>

在您的微调器中,尝试使用以下内容

// 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格式),

strTemp = getResources().getStringArray(R.array.menu_items)[spinner.getSelectedItemPosition()];