I'd like to close a dialog window in my android app by simply touching the screen.. is this possible? If so, how?
I've looked into setting some "onClickEven" on the dialog, but it doesnt exist.
How would this be possible?
I'd like to close a dialog window in my android app by simply touching the screen.. is this possible? If so, how?
I've looked into setting some "onClickEven" on the dialog, but it doesnt exist.
How would this be possible?
You can extend
Dialog
class and overridedispatchTouchEvent()
method.EDIT: Also you can implement
Window.Callback
interface and set it as dialog's window callback usingdialog.getWindow().setCallback()
. This implementation should call corresponding dialog's methods or handle events in its own way.And you are done!
If someone still searching for a solution to dismiss a Dialog by onTouch Event, here is a snippet of code:
You can use
dialog.setCanceledOnTouchOutside(true);
which will close the dialog if you touch u=outside the dialog.If your dialog contains any view try to get the touch events in that view and dismiss your dialog when user touch on that view. For example if your dialog has any Image then your code should be like this.