Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change AppCompatSpinner popup background color

I tried to make Spinner with white text as my theme but when Spinner popup show then it has default white background so my text isn't visible there. I also tried to set with both android:popupBackground and app:popupBackground but it doesn't reflect there.

Screenshots of Spinner :

Spinner 1

enter image description here

Spinner Popup 2

![Spinner Popup 2

XML for spinner

<android.support.v7.widget.AppCompatSpinner
    android:id="@+id/spinLocation"
    style="@style/Base.Widget.AppCompat.Spinner.Underlined"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:popupBackground=""
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="20dp"
    app:backgroundTint="@color/white" />

XML for Spinner Item

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/txtValue"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:maxLines="1"
    android:paddingBottom="7dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="7dp"
    android:text=""
    android:textColor="@color/white"
    android:textSize="@dimen/_12sdp" />

I know it is because of item textColor but if I do not define it then it showing in popup but not proper in Spinner. So suggest me a best approach for this and also suggest for header if appCompatSpinner supports it. Thanks.

like image 272
Kinjal Android Avatar asked Sep 15 '25 06:09

Kinjal Android


1 Answers

You need to set themes, or create a custom one.

Here is a sample code:

 <android.support.v7.widget.AppCompatSpinner
                style="@style/Base.Widget.AppCompat.Spinner"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:entries="@array/array_radius"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:theme="@style/ThemeOverlay.AppCompat.Light" />
like image 61
Niraj Sanghani Avatar answered Sep 16 '25 23:09

Niraj Sanghani