I have implemented a custom dialog for my application. I want to implement that when the user clicks outside the dialog, the dialog will be dismissed.
What do I have to do for this?
I have implemented a custom dialog for my application. I want to implement that
Share
You can use
dialog.setCanceledOnTouchOutside(true);which will close the dialog if you touch outside of the dialog.Something like,
Or if your Dialog in non-model then,
1 – Set the flag-
FLAG_NOT_TOUCH_MODALfor your dialog’s window attribute2 – Add another flag to windows properties,,
FLAG_WATCH_OUTSIDE_TOUCH– this one is for dialog to receive touch event outside its visible region.3 – Override
onTouchEvent()of dialog and check for action type. if the action type is‘
MotionEvent.ACTION_OUTSIDE‘ means, user is interacting outside the dialog region. So in this case, you can dimiss your dialog or decide what you wanted to perform.view plainprint?
For more info look at How to dismiss a custom dialog based on touch points? and
How to dismiss your non-modal dialog, when touched outside dialog region