0

I have recently begun work on an existing android app and noticed that one of the modals displays as a white blank square. I did some research and someone suggested that supplying a theme should fix it. I tried this and it does fix the issue but i don't understand why this was working without it and now its not. The code we use to initialize the AlertDialog looks like this

            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setItems(R.array.media_resume_options, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                    //handle selection logic here
                    //......
            }
        });

        builder.create().show();

I can fix it by changing the instantiation line to

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_DARK );

I don't see any changes to this part of the code that might have caused it. Could it be affected by something else? whats the potential risk that it might affect other dialogs?

Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
Ryan Burnham
  • 573
  • 6
  • 15
  • If you pass theme parameter, it will override some attribute of default dialog, such as background, text color, .... – Alex Hong Jun 16 '16 at 02:10
  • Can this also be override in some other way? IE an app level theme? Or a better question, why would the default theme be showing a white box? – Ryan Burnham Jun 16 '16 at 02:23
  • Maybe your text is white with your current activity/application theme, re-check it. – NamNH Jun 16 '16 at 02:48
  • It based on the context you create the builder, if theme is not provided, it will use context's theme. If you want to define custom, try to use `style`. because custom programmatically is complicated – Alex Hong Jun 16 '16 at 02:50
  • white box because context's theme defined the background of dialog is white @RyanBurnham – Alex Hong Jun 16 '16 at 02:51

1 Answers1

0

It can't be blank,the textcolor and background color both are white that's why you think it is blank.

How to change default text color of dialogbox is explained here

Change dialog text color on 5.0+

Community
  • 1
  • 1
Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
  • Thanks, a combination of your answer and the comments helped me to understand what is going on. It seems like there was some other styles being inherited from the context. There was a white font colour set but no background. – Ryan Burnham Jun 16 '16 at 04:57