1

I am using a custom spinner. It is almost similar to default, except that I need to set padding at left of each item ( in the drop down padding in each row before text). I am able to do that. But I also want to show the selected item in a different color when list of values are displayed to user as dropdown.

I have used text view as drop down item.

Can someone please suggest if it can be done. I have tired to achieve this with xml, but I couldn't find any option.

Thanks in advance.

EDIT : Text of selected item in Blue color.

user2702700
  • 639
  • 2
  • 11
  • 26

3 Answers3

3

You could specify android:dropDownSelector="@color/spinner_selector" for the spinner element and define the spinner_selector color to #800000FF, for example.

See http://developer.android.com/reference/android/widget/Spinner.html#attr_android:dropDownSelector

aleb
  • 2,490
  • 1
  • 28
  • 46
1

You Can Do it by following code.

Just apply style to your textview as background.



// TextStyle is xml file which contain following code.

<item android:state_selected="false"
    android:drawable="@android:color/white" />

<item android:state_selected="true"
    android:drawable="android:drawable="@android:color/blue"" />

Vickyexpert
  • 3,147
  • 5
  • 21
  • 34
0

You have to change color of textview at runtime by using spinner's method setOnItemSelectedListener. For Example,

  spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            TextView tv = (TextView) view.findViewById(R.id.tv );
            tv.setTextColor(R.color.green);
        }
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
Vishal Vaishnav
  • 3,346
  • 3
  • 26
  • 57