Reputation: 2741
Spinner xml:
<Spinner
android:id="@+id/sort_by_spinner"
android:layout_marginLeft="40dip"
android:layout_marginRight="40dip"
android:layout_marginBottom="10dip"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/title_bar"
android:drawSelectorOnTop="true"
android:dropDownSelector="@drawable/spinner_selector"
/>
I've tried using android:background=...
buy itself, with dropDownSelector
, with and without listSelector=...;
with and without listItemDropDownSelector=...
and all permutations with drawSelectorOnTop
spinner_selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/app_tint"/>
</shape>
</item>
<item
android:state_selected="true">
<shape android:shape="rectangle">
<solid android:color="@color/app_tint"/>
</shape>
</item>
</selector>
I always get the default orange color. I've read numerous posts on this; just can't get it to happen. I have to support v10 and up. What's missing?
Upvotes: 3
Views: 8607
Reputation: 1279
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/audio_selector"/>
<item android:drawable="@drawable/launcher" />
</selector>
easy to use selector place this file in drawable folder you also have image in drawable folder
Upvotes: 0
Reputation: 7259
try it as:
<Spinner
android:id="@+id/sort_by_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="@dimen/space"
android:background="@drawable/selection_normal"
android:dropDownSelector="@drawable/list_item_selector"
android:spinnerMode="dropdown" />
and the list_item_selector as
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_selected="true" android:drawable="@color/app_tint"></item>
<item android:state_pressed="true" android:drawable="@color/app_tint"></item>
<item android:drawable="@color/white"></item>
</selector>
selection_normal is any image for the spinner, you can ignore it if not needed.
[EDIT]
In order to set highlight the list row of the item touched / clicked do the following:
in the getDropDownView
instead of getView
method in the spinner's adapter set the selector using the code:
view.setBackgroundResource(R.drawable.list_item_selector)
or using the setBackground
method of the view.
Upvotes: 2