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

Idea taken from Android: blurring and dimming background windows from a dialog box . I'm having trouble getting the contents in my dialog box to blur. When calling eula.getWindow (), I get this error:

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

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

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); } 
+7
source share
2 answers

getWindow() is a dialog class method, not a dialog builder. Your code should look something like this:

 AlertDialog dlg = eula.show(); WindowManager.LayoutParams lp = dlg.getWindow().getAttributes(); lp.dimAmount = 0.0F; dlg.getWindow().setAttributes(lp); dlg.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); 

Please note that the constant FLAG_BLUR_BEHIND now deprecated, blurring outside the windows is no longer supported . Thus, your code may break in the future.

+12
source

eula is a 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); 
+5
source

All Articles