如何在对话框创建时设置模糊背景?
我只找到DialogFragment
和AlertDialog
,但我想在活动中设置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);
答案 0 :(得分:3)
试试这个
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>