简体   繁体   中英

How to change the color of String array or String array elements

    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

Which will change the color of String value directly.i found a lot but all answers were for string-array resource.

Try this,

Your string items are as below,

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

In your spinner, try to use of the following,

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

To retrieve the values of string (Without HTML Formatting),

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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