I create my theme to use with the app and the parent of the theme is Theme.AppCompat.Light.NoActionBar
by the way, I want white background and black text.
And this is adapter code
val adapter = ArrayAdapter.createFromResource(activity,
R.array.email_type_array, android.R.layout.simple_spinner_item)
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
child.spinner.adapter = adapter
Is there any easy way to change Spinner dropdown color in Android?
yes. You can use following attribute fro spinner inside your xml
android:popupBackground="YOUR_HEX_COLOR_CODE"
to change textcolor etc Make a custom XML file for your spinner item.
spin_item.xml:
Then provide it your desired color and sizes :
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textColor="#000000"
android:padding="4dp"
/>
And then use it like this:
val adapter = ArrayAdapter.createFromResource(activity,
R.array.email_type_array, android.R.layout.simple_spinner_item)
adapter.setDropDownViewResource(R.layout.spin_item)
To change the dropdown background color use android:popupBackground="@color/aColor"
on the xml file for your Spinner
widget:
<Spinner
android:id="@+id/my_spinner"
android:layout_width="100dp"
android:layout_height="match_parent"
android:popupBackground="@color/aColor" />
When playing with a light theme on your styles.xml
file the spinner dropdown icon color will be black, but pay attention that if you are using <item name="android:textColorSecondary">@color/aColor</item>
the dropdown icon will pick that color:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorSecondary">@color/aColor</item>
Even your question is about to change the dropdown background color I came here because I was trying to understand why my spinner dropdown icon color was with a different color until I discover that (android:textColorSecondary
) - So hope that helps someone else too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With