The method getWindow() is undefined for the type AlertDialog.Builder

13,170

eula is the Builder, not the dialog itself. Try:

final AlertDialog eulaDialog = eula.create();
eulaDialog.show();
WindowManager.LayoutParams lp = eulaDialog.getWindow().getAttributes();
lp.dimAmount = 0.0F;
eulaDialog.getWindow().setAttributes(lp);
eulaDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Share:
13,170
Bill Mote
Author by

Bill Mote

I have made a very healthy career out of architecting, implementing and maintaining servers, networks, firewalls, databases, workstations, etc, etc, etc. But, at the end of the day; when I turn on my personal laptop: I code. I got serious about coding with the release of the Android handsets. Serious by my standards meant inquisitive or intrigued ... I have always written code in one form or another, but I really, really long for a development job. I grew up when id Software was in its infancy and writing games was the coolest thing you could do. I started through Head First Java. It's a great book. I also purchased and started watching O'Reilly's Developing Android Apps with Java video series. Also good. The problem is I don't learn in that way. I learn by doing, but I really had nothing to do. I was approached out of the blue in January 2011 by a Realtor based in NY. He wanted an application that would allow him to send a large number of people an SMS message. Direct Marketing. Ugh. I hadn't touched Android or Java in almost a year. But thanks to Stuttering John Smith here I am. Almost 1 month into the release of my own app I have 1,500 downloads with 500 active installations. Thank you John for giving me something to do.

Updated on July 29, 2022

Comments

  • Bill Mote
    Bill Mote almost 2 years

    Idea taken from Android: Blurring and dimming background windows from dialog. I'm having trouble getting the content under my dialog to blur. When calling eula.getWindow() I receive this error:

    The method getWindow() is undefined for the type AlertDialog.Builder

    The eula is displayed with this bit of code from the main activity:

        EulaHelper.showEula(false, this);
    

    Any help is greatly appreciated.

        public static void showEula(final boolean accepted, final FragmentActivity activity) {
        AlertDialog.Builder eula = new AlertDialog.Builder(activity)
                .setTitle(R.string.eula_title)
                .setIcon(android.R.drawable.ic_dialog_info)
                    .setMessage(activity.getString(R.raw.eula))
                .setCancelable(accepted);
    
        if (accepted) {
            // If they've accepted the EULA allow, show an OK to dismiss.
            eula.setPositiveButton(android.R.string.ok,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
        } else {
            // If they haven't accepted the EULA allow, show accept/decline buttons and exit on
            // decline.
            eula
                    .setPositiveButton(R.string.accept,
                            new android.content.DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    setAcceptedEula(activity);
                                    dialog.dismiss();
                                }
                            })
                    .setNegativeButton(R.string.decline,
                            new android.content.DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.cancel();
                                    activity.finish();
                                }
                            });
        }
        eula.show();
        WindowManager.LayoutParams lp = eula.getWindow().getAttributes();
        lp.dimAmount = 0.0F;
        eula.getWindow().setAttributes(lp);
        eula.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
    
    }