Search code examples
androidandroid-layoutandroid-spinnerandroid-theme

Is there any easy way to change Spinner dropdown color in Android?


enter image description here

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?


Solution

  • 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)