0

I am trying to do a very basic alertdialog to show some options to select - am trying it as shown but the text for the options is white on a white background. Is there a simple way to change it without making a bunch of xml files? Maybe make a single style?

 CharSequence[] array = {"Red", "Blue", "Yellow"};
        new AlertDialog.Builder( new ContextThemeWrapper( getActivity(), R.style.Theme_AppCompat_DayNight_Dialog_Alert))
                .setSingleChoiceItems(array, 0, null)
                .setTitle(R.string.selectweightclass)
                .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                        int selectedPosition = ((AlertDialog)dialog).getListView().getCheckedItemPosition();
                        Log.d(TAG, "selectedPosition= "+selectedPosition);

                        // Do something useful withe the position of the selected radio button
                    }
                })
                .show();

enter image description here

PS: Turns out R.style.Theme_AppCompat_Dialog_Alert is good enough for now. Those DayNight themes were messing me up.

lost baby
  • 3,178
  • 4
  • 32
  • 53
  • The problem is the theme you choosed for your AlertDialog – MatPag Jun 19 '17 at 18:01
  • I was thinking that maybe one of my styles was conflicting with it but I changed them around and the text stayed white. What style should I choose? Is there a guide to selecting these styles? It is pretty much hit and miss for me. – lost baby Jun 19 '17 at 18:07
  • 1
    If you are already using a Theme like this `Theme.AppCompat.Light.DarkActionBar` for your application, you could simply remove the style from the AlertDialog and create the builder in this way `new AlertDialog.Builder(context)`. If you need a custom style for the AlertDialog, you should create a new style inheriting from `Theme.AppCompat.Light.Dialog.Alert` or something similar and then apply it to the Dialog as you already did. [Read here for an help on this](https://stackoverflow.com/a/30975075/2910520) – MatPag Jun 19 '17 at 18:31
  • Thanks, Turns out R.style.Theme_AppCompat_Dialog_Alert is good enough for now. – lost baby Jun 19 '17 at 19:58

0 Answers0