创建对话框时如何设置模糊背景?
我只找到了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);
试试这个
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>
并检查此警报对话框与模糊背景在位置中心的位置