I have created an AlertDialog with a textviews, button and SPINNER, the problem is that the drop-down list has a color that does not allow me to see the options and I do not know which parameter to modify.
Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rlDatos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/text_size_24pt">
<TextView
android:id="@+id/tvInfoUbicacion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:focusable="true"
android:layout_margin="@dimen/spacing_normal"
android:inputType="text"
android:focusableInTouchMode="true"
android:textColorHint="@color/white"/>
<TextView
android:id="@+id/tvSeleccioneUbicacion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_below="@+id/tvInfoUbicacion"
android:focusable="true"
android:layout_margin="@dimen/spacing_normal"
android:inputType="text"
android:focusableInTouchMode="true" />
<LinearLayout
android:id="@+id/layoutUbicaciones"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/spacing_normal"
android:layout_below="@+id/tvSeleccioneUbicacion"
android:layout_marginEnd="@dimen/spacing_normal"
android:background="@android:color/white"
android:gravity="center"
android:orientation="vertical">
<Spinner
android:id="@+id/spinnerUbicaciones2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:backgroundTint="@color/v2col_lama_dark"
android:padding="0dp"
tools:backgroundTint="@color/white"
tools:listitem="@layout/spinner_item" />
</LinearLayout>
<Button
android:id="@+id/btnAceptar"
style="@style/MyButtonBorderless"
android:layout_margin="@dimen/spacing_normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/gray_light"
android:layout_below="@+id/layoutUbicaciones"
android:layout_alignParentEnd="true"
android:text="@string/text_acept"
android:textColor="@color/color_text_1" />
</RelativeLayout>
</LinearLayout>
public class ClinicInfoUbicacionDialog extends AlertDialog {
@Nullable
protected TextView tvInfoUbicacion;
@Nullable
protected TextView tvSeleccioneUbicacion;
protected Spinner spinnerUbicaciones;
protected final List<Building> SubUbicaciones = new ArrayList<>();
@Nullable
protected Button btnAceptar;
@Nullable
protected WeakReference<IEmptyBaseActivity> activityWeakReference;
//List<String> ubicaciones;
public List<String> ubicaciones= new ArrayList<>();
public List<Building> ubicaciones2= new ArrayList<>();
protected SpinnerBuildingsAdapter spUbicacionesAdapter;
@NonNull
protected String nombreUbicacion;
@NonNull
public Context context;
public IEmptyBaseActivity activity;
public ClinicInfoUbicacionDialog(Context context, IEmptyBaseActivity activity) {
super(context);
this.context=context;
this.activity=activity;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.clinic_info_ubicacion_dialog);
ClinicInventarioInteractor interactor = new ClinicInventarioInteractor();
tvInfoUbicacion=findViewById(R.id.tvInfoUbicacion);
//INFORMAMOS DE EN QUE UBICACION SE ENCUENTRA ACTUALMENTE
tvSeleccioneUbicacion=findViewById(R.id.tvSeleccioneUbicacion);
tvSeleccioneUbicacion.setText("Seleccione la sala: ");
spinnerUbicaciones=findViewById(R.id.spinnerUbicaciones2);
spinnerUbicaciones.setOnItemSelectedListener(onItemUbicacionSelected);
spUbicacionesAdapter= new SpinnerBuildingsAdapter(context,R.layout.custom_spinner_dropdown_item,ubicaciones2, null);
spinnerUbicaciones.setAdapter(spUbicacionesAdapter);
interactor.wsObtenerListaUbicacionesUsuario(context,activity, new OnResponseTaskSingle() {
@Override
public void OnResponse(@NonNull Notif notif) {
List<ClinicInventarioInteractor.wsUbicacion> list = (List<ClinicInventarioInteractor.wsUbicacion>) notif.getObject();
SharedPreferencesUtils sharedPreferencesUtils = SharedPreferencesUtils.createSharedPreferencesUtils(context);
String ubicacionActual = sharedPreferencesUtils.getString(R.string.sp_saved_ubication_clinic, "No encontrado");
//tvInfoUbicacion.setText(getString(R.string.str_ubicacion, ubicacionActual));
tvInfoUbicacion.setText("Usted se encuentra en la sala: " + ubicacionActual);
for(var item: list){
ubicaciones.add(0,item.Texto);
}
spinnerUbicaciones.setAdapter(new ArrayAdapter<String>(context, R.layout.custom_spinner_dropdown_item, ubicaciones));
}
});
btnAceptar = findViewById(R.id.btnAceptar);
btnAceptar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//nombreUbicacion= ubicaciones.get(position).getName();
//Guardar valor de la opcion seleccionada en SharedPreferences.
SharedPreferencesUtils sharedPreferencesUtils = SharedPreferencesUtils.createSharedPreferencesUtils(context);
sharedPreferencesUtils.putString(R.string.sp_saved_name_ubication, nombreUbicacion);
ClinicInfoUbicacionDialog.this.hide();
}
});
}
private final AdapterView.OnItemSelectedListener onItemUbicacionSelected = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
//onCompanyChanged(position, true);
/* BaseInteractor bi = new BaseInteractor();
if(bi.getReportingDeviceInfoFromSharedPreferences(context)!=null){
spinnerUbicaciones.setSelection(4);
}*/
nombreUbicacion= ubicaciones.get(position);
SharedPreferencesUtils sharedPreferencesUtils = SharedPreferencesUtils.createSharedPreferencesUtils(context);
sharedPreferencesUtils.putString(R.string.sp_saved_name_ubication, nombreUbicacion);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
};
}
Tried changing alertdialog background color and style in spinner layout.
spinner_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:layout_marginTop="@dimen/text_size_14pt"
android:textColor="@color/v2col_lama_dark"
android:textAlignment="inherit" />
custom_spinner_dropdown_item.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:gravity="start"
android:ellipsize="end"
android:maxLines="1"
tools:text="Dipole asasdasd asd asdasd asd asdasda sda sda sda dasda sda sd"
android:textSize="@dimen/text_size_32pt"
android:textStyle="bold"
android:textColor="@color/v2col_lama_dark"
android:padding="8dip" />
I suppose there will be many ways to do it, but the one I have used that is very fast and simple is applying the parameter android:popupBackground="@color/white"
on the spinner.
<Spinner
android:id="@+id/spinnerUbicaciones2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:backgroundTint="@color/v2col_lama_dark"
android:padding="0dp"
android:popupBackground="@color/white"
tools:listitem="@layout/spinner_item" />