Search code examples
androidandroid-spinner

Setting spinner popup background color


I can set the background of the popup menu of a spinner using:

<Spinner
   android:popupBackground="@color/darkThemeBackgroundColor"/>

But how do I set the background text color of it?

enter image description here


Solution

  • This solution is more simpler, you only need add this code to styles.xml

    <style name="spinnerTheme">
        <item name="android:background">@color/colorDark</item>
        <item name="android:textColor">@android:color/white</item>
        
        <!-- this is for api 19 text color -->
        <item name="android:color">@android:color/white</item>
    </style>
    

    And this is how use in your layout file

     <Spinner
        android:id="@+id/spinner"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:padding="8dp"
        android:entries="@array/aves"
        android:theme="@style/spinnerTheme"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    

    That is the result:

    This is the result

    I hope this solution helps you, greetings.