How do I fire an event when click occurs outside a dialog
It Works For me,,
Window window = dialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.show();
See this http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_NOT_TOUCH_MODAL
When dialog.setCanceledOnTouchOutside(true);
then you just override onCancel()
like this:
dialog.setOnCancelListener(
new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
//When you touch outside of dialog bounds,
//the dialog gets canceled and this method executes.
}
}
);
Type your code inside the onCancel()
method so it runs when the dialog gets canceled.
In DialogFragment
you can use AlertDialog
and the answer of @silverTech:
override fun onDismiss(dialog: DialogInterface) {
yourMethod()
super.onDismiss(dialog)
}
or
override fun onCancel(dialog: DialogInterface) {
yourMethod()
super.onCancel(dialog)
}