【发布时间】:2020-09-26 21:32:42
【问题描述】:
我有一个对话框,当我点击它外部时我想将其关闭。但是,我不希望它接收按键事件,因为它是一个音量对话框,我希望活动能够接收按键音量上下事件。于是我设置了FLAG_NOT_FOCUSABLE,如下图:
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.MyDialogTheme);
AlertDialog alert = builder.create();
Window window = alert.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
alert.setView(view);
问题是,有了这个标志,我也不能让对话框在外部触摸发生时关闭。
How to dismiss the dialog with click on outside of the dialog? 上的所有解决方案(如 dialog.setCanceledOnTouchOutside(true);)在这种情况下都不起作用。
【问题讨论】: