title: closing dialog on clicking outside
body: <p>What I want is a dialog without any button, and closing that dialog when I click outside the dialog body. Is it possible?</p>
  
  <pre><code>public class MainActivity extends Activity{
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          openCredit();
      }
  
     //THIS IS ONE CUSTOM DIALOG
      public void openCredit(){ 
          AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
          LayoutInflater inflater = MainActivity.this.getLayoutInflater();
          builder.setView(inflater.inflate(R.layout.activity_splash, null));
          builder.show();
      }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> I have search and found two functions setCanceledOnTouchOutside() and setCancelable(). First one is not working with my method of AlertDialog, giving error of "The method setCanceledOnTouchOutside(boolean) is undefined for the type AlertDialog.Builder". And 2nd one is just for pressing back button.</p>
  
  <p>So, I change my code like below and it is now working. Thanks.</p>
  
  <pre><code>public void openCredit(){
          AlertDialog builder = new AlertDialog.Builder(this).create();
          LayoutInflater inflater = MainActivity.this.getLayoutInflater();
          builder.setView(inflater.inflate(R.layout.activity_splash, null));
          builder.setCancelable(true);
          builder.show();
          builder.setCanceledOnTouchOutside(true);
      }
  </code></pre>