title: How to dismiss Android Dialog when click outside (using FLAG_NOT_FOCUSABLE)
body: <p>I have a dialog that I want to be dismissed when I click outside it. However, I don't want it to receive key events, because it's a volume dialog, and I want the activity to be able to receive the key volume up and down events. So I setted <code>FLAG_NOT_FOCUSABLE</code>, as you see below:</p>
  
  <pre><code>    AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.MyDialogTheme);
      AlertDialog alert = builder.create();
      Window window = alert.getWindow();
      window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
      alert.setView(view);
  </code></pre>
  
  <p>the problem is that, with this flag, I also can't make the dialog dismiss when a touch outside it happens. </p>
  
  <p>All the solutions on <a href="https://stackoverflow.com/questions/8384067/how-to-dismiss-the-dialog-with-click-on-outside-of-the-dialog">How to dismiss the dialog with click on outside of the dialog?</a> like <code>dialog.setCanceledOnTouchOutside(true);</code> wont work in this case. </p>