Background blur while using dialog box

前端 未结 2 1597
灰色年华
灰色年华 2021-01-06 12:12

I want the background behind the dialog box to be blurry. I used this code but it black outs the whole background instead of blur

dialog = new Dialog(contex         


        
相关标签:
2条回答
  • 2021-01-06 12:23

    Try it like this instead:

    WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
    lp.dimAmount=0.0f;
    dialog.getWindow().setAttributes(lp);
    dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
    
    0 讨论(0)
  • 2021-01-06 12:44

    I think you need to create styles.xml with custom style under res - values folder.

     <style name="Theme.D1NoTitleDim" parent="android:style/Theme.Translucent">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:backgroundDimEnabled">true</item>
        <item name="android:background">@android:color/transparent</item>        
    </style>
    

    and then use this style with your dialog

    dialog = new Dialog(context,style); 
    
    0 讨论(0)
提交回复
热议问题