2

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>   
2
  • 1
    Where do you want to change them? In the IDE or in your app? Commented Oct 14, 2014 at 12:09
  • in my app where they are shown in listview,i.e, i want that they appear white. Commented Oct 14, 2014 at 12:10

2 Answers 2

3

Have your string items as :

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

To retrieve the String value (Without HTML Formatting),

strTemp = getResources().getStringArray(R.array.menu_items)[spinner.getSelectedItemPosition()];
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.