So this has been bothering me for the past couple of hours.
I have a dialog which extends, you guessed it, Dialog
. I do not want to close the dialog when the user click outside of the dialog. That's rather easy, since I can simply use this line: dialog.setCanceledOnTouchOutside(false)
. However, I do want to perform certain actions when the user touches outside of the dialog. That the dialog does not close is easy too (How to cancel an Dialog themed like Activity when touched outside the window?):
getWindow().setFlags(LayoutParams.FLAG_NOT_TOUCH_MODAL, LayoutParams.FLAG_NOT_TOUCH_MODAL);
getWindow().setFlags(LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
And then implementing a custom onTouchEvent(MotionEvent event)
.
However, this does not only not dismiss the dialog, but also performs actions to underlying, say, buttons and such. I've tried some of the other potential answers (empty, false returning onTouchListener on root view, checking whether or not a touch was inside the dialog, etc.) in the post as well, but to no avail.
Now my question is: How can I create a Dialog
that does not close on outside click, nor does it perform actions on buttons and such on the underlying layout/activity, but does inform me/catches an event when the user clicks outside the dialog?