Android Background of Spinner Dialog

1

I have the following spinner

           <android.support.v7.widget.AppCompatSpinner
            android:id="@+id/origin_account"
            android:layout_width="match_parent"
            android:spinnerMode="dialog"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_height="wrap_content"
            android:paddingTop="5dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:popupBackground="#E6E6E6"
            android:textColor="@color/light_grey"/>

the Java code is as follows

 final  ArrayAdapter<Account> dataAdapter2 = new ArrayAdapter<Account>(TransferOwnAccountActivityStep1.this,R.layout.spinner_custom,R.id.text1,Destino);
            dataAdapter2.setDropDownViewResource(R.layout.spinner_custom);
            spinner_ocupaciones.setAdapter(dataAdapter2);

The Cumstom Spinner is

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textAlignment="textStart"
android:background="@drawable/redondo"
android:drawableEnd="@drawable/flechaabajooo"/>

and the round.xml is

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="200dp"
    android:height="30dp"></size>
<corners android:radius="5dp"></corners>
<solid android:color="#E6E6E6"></solid>

the issue is that pressing the spinner in DIALOG mode appears like this

I would like to be able to change the white background to the color that I want, and to probe with

 android:popupBackground="#E6E6E6"
    
asked by Bruno Sosa Fast Tag 11.09.2017 в 14:48
source

1 answer

2

Add the following resource in your colors.xml file:

 <color name="fondo_dialogo">#E6E6E6</color>

After displaying the dialog, you can change the background color using this option:

AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
AlertDialog alert = alertDialog.create();
...
...
//Muestra diálogo.
alert.show(); 

//Define color a fondo de diálogo.
alert.getWindow().setBackgroundDrawableResource(R.color.fondo_dialogo);

This is an example of a AlertDialog with a green background:

    
answered by 11.09.2017 / 16:13
source