I want to change my spinner item background (not the spinner background) when the item is selected.
I want it like this:
I want to change my spinner item background (not the spinner background) when the item is selected.
I want it like this:
First create a drawable
under drawable folder
named
my_click_changer
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/your_new_Color" android:state_pressed="true" />
<item android:drawable="@color/your_default_Color" android:state_pressed="false" />
</selector>
EDIT this is for changing the text color
create another drawable
text_color_changer
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/black" android:state_checked="true" />
<item android:color="@android:color/white" />
</selector>
then create a individual layout for each Spinner
item,
your_xml_name.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@drawable/my_click_changer"
android:ellipsize="marquee"
android:gravity="center"
android:padding="10dp"
android:singleLine="true"
android:textAlignment="inherit"
android:textSize="15sp"
android:textColor="@drawable/text_color_changer"
android:textStyle="bold" />
And in the code create
Adapter
by
final ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(getContext(), R.layout.your_xml_name, yourList);