0

I am using 3 spinners in my application and populating the values in 2nd spinner on behalf of 1st. I am getting the values correctly but not text color of items in spinner. Only 1st spinner is showing the simple black color but other spinner is showing white color which is not properly visible.

ArrayAdapter<String> a1= new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_spinner_item,list1);
a1.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);

Kindly suggest me the easiest way to just change the color of all spinner items in rest two spinners.

Regards, Dheeraj

Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
  • You can create a custom xml file for your text as is shown [here][1] [1]: http://stackoverflow.com/questions/9476665/how-to-change-spinner-text-size-and-text-color – yassine__ Jul 14 '14 at 10:05

2 Answers2

0

I think that the easiest way would be to create your own XML copied from android.R.layout.simple_list_item_single_choice and change the color there.

Once you have changed the color, use your new XML.

zozelfelfo
  • 3,776
  • 2
  • 21
  • 35
0

A complete answer for me would be something like:

public class ee extends Activity{
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ww);
addListenerOnSpinnerItemSelection();

}
public void addListenerOnSpinnerItemSelection(){

    ArrayList<String> array = new ArrayList<String>();
    array.add("item0");
    Spinner spinner1;
    ArrayAdapter<String> mAdapter;
    spinner1= (Spinner) findViewById(R.id.spinner2);
    mAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, array);
    spinner1.setAdapter(mAdapter);

}  
}

and in xml res/layout add new xml file:

(in spinner_item.xml)

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="top"
    android:singleLine="true"
    android:textColor="#00f0ff" />

Note: Here you can change the HTML code to change the text color to different one.

Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
  • Dear what is setContentView(R.layout.ww); in the code. and where i can find the android.R.layout.simple_list_item_single_choice.xml file to copy its content. Regards, Dheeraj – user3300589 Jul 16 '14 at 10:55
  • @Dheeraj `setContentView(R.layout.ww);` is the layout you are going to show on the sceen, And `android.R.layout.simple_list_item_single_choice.xml` is in built xml file which is present in android.R.layout package – Shailendra Madda Jul 16 '14 at 13:22