How can I change spinner background color?
this black color from style .
How can I change style color for spinner pop up?
I want to change background color white in place of black. How can I change?
spinnner
<Spinner
android:id="@+id/spinner"
android:layout_width="100dp"
android:layout_marginTop="1dp"
android:layout_height="wrap_content"
android:background="@drawable/spinner_bg"
android:layout_marginLeft="1dp"/>
spinnerbg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/InputBg1" />
</item>
<item android:gravity="center_vertical|right" android:right="8dp">
<layer-list>
<item android:width="12dp" android:height="12dp" android:background="#fff" android:gravity="center" android:bottom="10dp">
<rotate
android:fromDegrees="45"
android:toDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
<stroke android:color="#ffffff" android:width="1dp"/>
</shape>
</rotate>
</item>
<item android:width="20dp" android:height="10dp" android:bottom="21dp" android:background="#fff" android:gravity="center">
<shape android:shape="rectangle">
<solid android:color="@color/InputBg1"/>
</shape>
</item>
</layer-list>
</item>
</layer-list>
Couple of things need to do with customization spinner as per below :-
spinner_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/InputBg1" />
</item>
<item android:gravity="center_vertical|right" android:right="8dp">
<layer-list>
<item android:width="12dp" android:height="12dp" android:gravity="center" android:bottom="10dp">
<rotate
android:fromDegrees="45"
android:toDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
<stroke android:color="#ffffff" android:width="1dp"/>
</shape>
</rotate>
</item>
<item android:width="20dp" android:height="10dp" android:bottom="21dp" android:gravity="center">
<shape android:shape="rectangle">
<solid android:color="@color/InputBg1"/>
</shape>
</item>
</layer-list>
</item>
</layer-list>
spinner_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="@style/spinnerItemStyle"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:ellipsize="marquee"
android:textAlignment="inherit"/>
spinner_dropdown_item.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="@style/spinnerItemStyle"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:ellipsize="marquee"/>
spinner
<Spinner
android:id="@+id/spinner"
android:layout_width="100dp"
android:popupBackground="#ffffff"
android:layout_marginBottom="1dp"
android:layout_height="wrap_content"
android:textColor="#ffff"
style="@style/spinnerItemStyle"
android:background="@drawable/spinner_bg"
android:layout_marginLeft="1dp" />
style.xml
<style name="spinnerItemStyle" parent="@android:style/Widget.Holo.DropDownItem.Spinner">
<item name="android:textColor">#000000</item>
</style>
Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);