title: Dismiss DialogFragment(not Dialog) onTouchOutside
body: <p>I have searched through all the answers about dismissing a Dialog <strong>onTouchOutside</strong>, however, I am using <strong>DialogFragment</strong> in my application. How can I achieve dismissing the <strong>DialogFragment</strong> when user clicks outside the <strong>DialogFragment's</strong> region.</p>
  
  <p>I have examined <strong>Dialog</strong>'s <a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.1_r2/android/app/Dialog.java#Dialog.isOutOfBounds%28android.view.MotionEvent%29" rel="noreferrer">source code</a> for <strong>setCanceledOnTouchOutside</strong></p>
  
  <pre><code>public void setCanceledOnTouchOutside(boolean cancel) {
      if (cancel &amp;&amp; !mCancelable) {
          mCancelable = true;
      }
  
      mCanceledOnTouchOutside = cancel;
  }
  </code></pre>
  
  <p>There's another function which may be interesting which is <strong>isOutOfBounds</strong></p>
  
  <pre><code>private boolean isOutOfBounds(MotionEvent event) {
      final int x = (int) event.getX();
      final int y = (int) event.getY();
      final int slop = ViewConfiguration.get(mContext).getScaledWindowTouchSlop();
      final View decorView = getWindow().getDecorView();
      return (x &lt; -slop) || (y &lt; -slop)
      || (x &gt; (decorView.getWidth()+slop))
      || (y &gt; (decorView.getHeight()+slop));
  }
  </code></pre>
  
  <p>but I couldn't figure out a way to make use of these for <strong>DialogFragment</strong></p>
  
  <p>In addition to these I have examined the state of the application with <a href="http://developer.android.com/guide/developing/tools/hierarchy-viewer.html" rel="noreferrer">hierarchyviewer</a>
  and as I understand it, I can only see the region of the dialog and not the outsied part of it (I mean the remaining part of the screen after the <strong>DialogFragment</strong>).</p>
  
  <p><em>Can you suggest a way of implementing this <strong>setCanceledOnTouchOutside</strong> for <strong>DialogFragment</strong> and if possible with a sample code?</em></p>