Skip to content Skip to sidebar Skip to footer

How To Change The Color Of String Array Resources In Android

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 ite

Solution 1:

Have your string items as :

<string-arrayname="menu_items" ><item >Demo Mode</item><item >Inbox</item><item >Sent Items</item><item >Filing History</item></string-array><string-arrayname="menu_items_labels" ><item ><FONTCOLOR="#006600"><b>Demo Mode</b></FONT></item><item ><FONTCOLOR="#006600"><b>Inbox</b></FONT></item><item ><FONTCOLOR="#006600"><b>Sent Items</b></FONT></item><item ><FONTCOLOR="#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 whiteSpinnerspinner= (Spinner) findViewById(R.id.my_spinner);
spinner.setAdapter(
      newArrayAdapter<CharSequence>(this, 
         R.layout.multiline_spinner_dropdown_item, 
        myActivity.this.getResources().getTextArray(R.array.menu_items_labels)));

To retrieve the String value (Without HTML Formatting),

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

Solution 2:

You can not directly tell the (array) resource which color it should have. You either can define an app-wide theme/style to use for list items or create an Adapter with custom view, in your case an ArrayAdapter will fit best.

Hot to create an ArrayAdapter with a custom view.

Post a Comment for "How To Change The Color Of String Array Resources In Android"