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

前端 未结 2 1604
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-12 03:28

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(

相关标签:
2条回答
  • 2021-01-12 04:10

    getWindow() is a method of the dialog class, not of the dialog builder. Your code should rather look 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);
    

    Note though that the FLAG_BLUR_BEHIND constant is deprecated now, blurring behind windows is no longer supported. So your code might break in the future.

    0 讨论(0)
  • 2021-01-12 04:17

    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);
    
    0 讨论(0)
提交回复
热议问题