【问题标题】:How to set Blur background when dialog create创建对话框时如何设置模糊背景
【发布时间】:2018-01-29 20:04:00
【问题描述】:

对话框创建时如何设置模糊背景?

我只找到了DialogFragmentAlertDialog,但我想在活动中设置Dialog

如何创建或图书馆推荐什么?

final Dialog dialog = new Dialog(this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        Window window = dialog.getWindow();
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setLayout(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        dialog.setContentView(R.layout.register_policy_dialog);

【问题讨论】:

    标签: java android dialog blur


    【解决方案1】:

    试试这个

    dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); 
    

    或者试试这个,您可以像这样将自定义主题应用到您的对话框中

    Dialog customDialog= new Dialog(MainActivity.this,R.style.mytheme); 
    Window window = customDialog.getWindow();
    window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
    window.setGravity(Gravity.CENTER);
    

    现在创建这样的主题

    <style name="mytheme" 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>
    

    并检查此AlertDialog with Blur background in possition center

    【讨论】:

      猜你喜欢
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多