Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <code>dialog.setCanceledOnTouchOutside(true);</code> which will close the dialog if you touch outside of the dialog.</p> <p>Something like,</p> <pre><code> Dialog dialog = new Dialog(context) dialog.setCanceledOnTouchOutside(true); </code></pre> <p>Or if your Dialog in non-model then,</p> <p>1 - Set the flag-<code>FLAG_NOT_TOUCH_MODAL</code> for your dialog's window attribute</p> <pre><code>Window window = this.getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); </code></pre> <p>2 - Add another flag to windows properties,, <code>FLAG_WATCH_OUTSIDE_TOUCH</code> - this one is for dialog to receive touch event outside its visible region.</p> <p>3 - Override <code>onTouchEvent()</code> of dialog and check for action type. if the action type is '<code>MotionEvent.ACTION_OUTSIDE</code>' 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?</p> <pre><code>public boolean onTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_OUTSIDE){ System.out.println("TOuch outside the dialog ******************** "); this.dismiss(); } return false; } </code></pre> <p>For more info look at <a href="http://iserveandroid.blogspot.com/2010/11/how-to-dismiss-custom-dialog-based-on.html" rel="noreferrer">How to dismiss a custom dialog based on touch points?</a> and <a href="http://iserveandroid.blogspot.com/2011/04/how-to-dismiss-your-non-modal-dialog.html" rel="noreferrer">How to dismiss your non-modal dialog, when touched outside dialog region</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload