title: Transparent background for custom AlertDialog
body: <p>Strangely, this was working fine, this is how it looks on my app released on Google Play:</p>
  
  <p><a href="https://i.stack.imgur.com/2nxFC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2nxFC.jpg" alt="enter image description here"></a></p>
  
  <p>And this is how it looks now:</p>
  
  <p><a href="https://i.stack.imgur.com/2GCTg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2GCTg.jpg" alt="enter image description here"></a></p>
  
  <p>All I did was migrate to AndroidX.</p>
  
  <p>Here is my dialog layout:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/dialogLinear"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:padding="10dp"&gt;
  
      &lt;FrameLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginBottom="10dp"
          android:background="@drawable/rounded_corners"&gt;
  
          &lt;Button
              android:id="@+id/btnAdd2"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="?android:attr/selectableItemBackground"
              android:text="@string/import_video"
              android:textColor="@color/dark_text" /&gt;
  
      &lt;/FrameLayout&gt;
  
      &lt;FrameLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@drawable/rounded_corners"&gt;
  
          &lt;Button
              android:id="@+id/btnAdd1"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="?android:attr/selectableItemBackground"
              android:text="@string/add_student"
              android:textColor="@color/dark_text" /&gt;
  
      &lt;/FrameLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and here is how I inflate it:</p>
  
  <pre><code>View dialogView = View.inflate(getApplicationContext(), R.layout.dialog_main, null);
  LinearLayout dialogLinear = dialogView.findViewById(R.id.dialogLinear);
  //Here is where is set the background to transparent
  dialogLinear.setBackgroundColor(0x00000000);
  
  final AlertDialog alertD = new AlertDialog.Builder(this).create();
  Button btnAdd1 = dialogView.findViewById(R.id.btnAdd1);
  Button btnAdd2 = dialogView.findViewById(R.id.btnAdd2);
  btnAdd1.setTypeface(mCustom_font_Bold);
  btnAdd2.setTypeface(mCustom_font_Bold);           
  
  btnAdd1.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
          //Do stuff
      }
  });
  
  btnAdd2.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
          //Do stuff
      }
  });
  
  alertD.setView(dialogView);
  if (alertD.getWindow() != null) {
      alertD.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
  }
  alertD.show();
  </code></pre>
  
  <p>I searched and couldn't find why this would be happening. Can someone please give me some advise?</p>
  
  <hr>
  
  <p>I have tried setting it in in the layout itself.</p>
  
  <hr>
  
  <p>Edit 1:</p>
  
  <p>After trying the answer below, it now looks like this, instead of above:</p>
  
  <p><a href="https://i.stack.imgur.com/WFIQ1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WFIQ1.jpg" alt="enter image description here"></a></p>
  
  <hr>
  
  <p><strong>I resolved it</strong> by adding the following styles:</p>
  
  <pre><code>&lt;style name="NewDialog"&gt;
      &lt;item name="android:windowIsFloating"&gt;true&lt;/item&gt;
      &lt;item name="android:windowAnimationStyle"&gt;@android:style/Animation.Dialog&lt;/item&gt;
      &lt;item name="android:backgroundDimEnabled"&gt;true&lt;/item&gt;
      &lt;item name="android:background"&gt;@android:color/transparent&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p>Setting the style like this:</p>
  
  <pre><code>final AlertDialog alertD = new AlertDialog.Builder(this, R.style.NewDialog).create();
  </code></pre>
  
  <p>And to fix what happened in Edit 1, i changed my <code>LinearLayout</code> to a <code>RelativeLayout</code></p>