Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change background color of Spinner popup

I need to change the color of the spinner popup. Here is what I have attempted till now: java code:

ArrayAdapter<Integer> adapter_year = new ArrayAdapter<Integer>(this, R.drawable.custom_spinner_holidays, year);
adapter_year.setDropDownViewResource(R.layout.customize_spinner);

custom_spinner_holidays.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="@drawable/custom_spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:textColor="@android:color/white" />

customize_spinner.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/spinnertext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#0193DE"
        android:textColor="#FFFFFF"
        android:textSize="18sp" />

</LinearLayout>

But it doesn't work. I get error when I click on the spinner.

like image 344
Veronika Gilbert Avatar asked Apr 14 '15 10:04

Veronika Gilbert


1 Answers

You are making things complicated! Just add this to your main spinner xml

android:popupBackground="#yourcolor"

and change your java code as:

adapter_year.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
like image 55
Anjali Avatar answered Oct 08 '22 19:10

Anjali