title: Disable Interaction with Background When Dialog Is Opened
body: <p>I am trying to make it so that when the "delete" button is clicked and the Alert Dialog pops up, the user would be unable to interact with everything in the background. I tried to disable interaction by setting:</p>
  
  <pre><code>getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
  WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
  </code></pre>
  
  <p>and allow interaction once the user selects either the cancel or keep ticket:</p>
  
  <pre><code>getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
  </code></pre>
  
  <p>None of this seem to work. </p>
  
  <p>Also, is there a way to make the Alert Dialog's width smaller? I've tried to decrease it in the login_dialog.xml but nothing seems to work.</p>
  
  <p>MainActivity.kt </p>
  
  <pre><code>    import android.app.AlertDialog
      import android.content.Intent
      import android.graphics.Color
      import android.net.Uri
      import android.os.Bundle
      import android.support.v7.app.AppCompatActivity
      import android.view.Gravity
      import android.view.LayoutInflater
      import android.view.WindowManager
      import android.view.animation.AnimationUtils
      import android.widget.TextView
      import kotlinx.android.synthetic.main.activity_main.*
      import kotlinx.android.synthetic.main.login_dialog.view.*
  
  
      class MainActivity : AppCompatActivity() {
  
          override fun onCreate(savedInstanceState: Bundle?) {
              super.onCreate(savedInstanceState)
              setContentView(R.layout.activity_main)
  
      //button click to show dialog
              btn_align_delete.setOnClickListener {
  
              getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
              WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
  
                  val Customtitle = TextView(this)
  
                  Customtitle.setText("WARNING")
                  Customtitle.setBackgroundColor(Color.WHITE)
                  Customtitle.setPadding(10, 30, 10, 0)
                  Customtitle.setGravity(Gravity.CENTER)
                  Customtitle.setTextColor(Color.BLACK)
                  Customtitle.setTextSize(18F)
  
                  //Inflate the dialog with custom view
                  val mDialogView = LayoutInflater.from(this).inflate(R.layout.login_dialog, null)
                  //AlertDialogBuilder
                  val mBuilder = AlertDialog.Builder(this)
                      .setView(mDialogView)
                      .setCustomTitle(Customtitle)
  
                  //show dialog
                  val  mAlertDialog = mBuilder.show()
                  //login button click of custom layout
                  mDialogView.keepTicketBtn.setOnClickListener {
                      //dismiss dialog
                  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
  
                      mAlertDialog.dismiss()
                      //get text from EditTexts of custom layout
  
                      val password = mDialogView.dialogPasswEt.text.toString()
  
                  }
                  //cancel button click of custom layout
                  mDialogView.dialogCancelBtn.setOnClickListener {
                      //dismiss dialog
                  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
  
                      mAlertDialog.dismiss()
                  }
              }
  
          }
      }
  </code></pre>
  
  <p>main_activity.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context=".MainActivity"&gt;
  
      &lt;Button
              android:id="@+id/btn_align_delete"
              style="@style/Widget.AppCompat.Button.Borderless"
              android:layout_width="40dp"
              android:layout_height="40dp"
              android:layout_alignParentEnd="true"
              android:drawableEnd="@drawable/ticketdelete"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintHorizontal_bias="0.0" /&gt;
  
  
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>login_dialog.xml</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  
      &lt;LinearLayout
              xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"
              android:gravity="center"
              android:background="@drawable/alert_dialog"
              android:padding="10dp"&gt;
  
          &lt;TextView
                  android:id="@+id/dialogPasswEt"
                  android:layout_marginTop="0dp"
                  android:layout_width="230dp"
                  android:layout_marginStart="60dp"
                  android:layout_marginEnd="60dp"
                  android:textColor="@color/colorBorder"
                  android:layout_height="wrap_content"
                  android:fontFamily="@font/mlight"
                  android:gravity="center_horizontal"
                  android:text="You will no longer be able to add time to your stay."
                  android:textSize="12sp" /&gt;
  
          &lt;TextView
                  android:id="@+id/dialogPasswE2t"
                  android:layout_width="210dp"
                  android:layout_marginStart="60dp"
                  android:layout_marginEnd="60dp"
                  android:textColor="@color/colorBorder"
                  android:layout_height="wrap_content"
                  android:fontFamily="@font/mlight"
                  android:layout_marginTop="15dp"
                  android:text="This action CANNOT BE UNDONE."
                  android:textSize="12sp" /&gt;
  
          &lt;LinearLayout
                  android:layout_width="250dp"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal"
                  android:layout_marginTop="15dp"
                  android:gravity="center"&gt;
  
              &lt;Button
  
                      android:id="@+id/keepTicketBtn"
                      android:layout_width="125dp"
                      android:layout_height="wrap_content"
                      android:color="@color/colorBorder"
                      android:background="@drawable/btn_align"
                      android:text="Keep Ticket"
  
                      android:textColor="@color/blueOrigin" /&gt;
  
              &lt;Button
                      android:id="@+id/dialogCancelBtn"
                      android:layout_width="125dp"
                      android:color="@color/colorBorder"
                      android:layout_height="wrap_content"
                      android:background="@drawable/btn_align"
                      android:text="DELETE"
                      android:textColor="@color/error_color_material_light" /&gt;
  
  
          &lt;/LinearLayout&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>