I have a dialog that I want to be dismissed when I click outside it. However, I don't want it to receive key events, because it's a volume dialog, and I want the activity to be able to receive the key volume up and down events. So I setted FLAG_NOT_FOCUSABLE
, as you see below:
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);
the problem is that, with this flag, I also can't make the dialog dismiss when a touch outside it happens.
All the solutions on How to dismiss the dialog with click on outside of the dialog? like dialog.setCanceledOnTouchOutside(true);
wont work in this case.