title: Android: Layer drawable loses information
body: <p>I am messing around with creating my own dialog class, but I've run into an interesting issue.  I use a layer-list drawable for the dialog's close button, but for some reason, the shadow layer disappears after the first time I show the dialog.  You can see in the image below:</p>
  
  <p><img src="https://i.stack.imgur.com/aEGBe.png" alt="enter image description here"></p>
  
  <p>I really have absolutely no idea what could be causing this.  I've tried debugging, but I wasn't able to find any leads.  Does anyone have any ideas?  My code is below.</p>
  
  <p><em>TwoColorDialog.java</em></p>
  
  <pre><code>public class TwoColorDialog extends DialogFragment {
      private static final String TAG = "TwoColorDialog";
  
      private ViewGroup _root;
  
      private TextView _textTitle;
      private ImageView _buttonClose;
      private Button _button1;
      private Button _button2;
  
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          final Dialog dialog = new Dialog(getActivity());
          _root = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.two_color_dialog, null);
  
          _textTitle   =  (TextView) _root.findViewById(R.id.dialog_title);
          _buttonClose = (ImageView) _root.findViewById(R.id.dialog_close_button);
          _button1     =    (Button) _root.findViewById(R.id.dialog_button1);
          _button2     =    (Button) _root.findViewById(R.id.dialog_button2);
  
          dialog.requestWindowFeature(STYLE_NO_TITLE);
          View decorView = dialog.getWindow().getDecorView();
          decorView.setBackgroundResource(getResources().getColor(android.R.color.transparent));
  
          dialog.setContentView(_root);
  
          _buttonClose.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  dialog.cancel();
              }
          });
          _button1.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Log.d(TAG, "Button 1 pressed");
              }
          });
          _button2.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Log.d(TAG, "Button 2 pressed");
              }
          });
  
          return dialog;
      }
  }
  </code></pre>
  
  <p><em>two_color_dialog.xml</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"&gt;
  
      &lt;LinearLayout android:id="@+id/dialog_background"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          android:background="@drawable/dialog_background"&gt;
  
          &lt;LinearLayout android:id="@+id/dialog_title_spacing"
              android:layout_width="match_parent"
              android:layout_height="24dp"
              android:orientation="horizontal" /&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="center"
              android:orientation="horizontal"&gt;
  
              &lt;Button android:id="@+id/dialog_button1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_margin="6dp"
                  android:background="@drawable/button"
                  android:text="Button1" /&gt;
  
              &lt;Button android:id="@+id/dialog_button2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_margin="6dp"
                  android:background="@drawable/button"
                  android:text="Button2" /&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;TextView android:id="@+id/dialog_title"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center|top"
          android:layout_marginTop="6dp"
          android:background="@drawable/dialog_title_box"
          android:textAppearance="@android:style/TextAppearance.Large"
          android:text="TITLE" /&gt;
  
      &lt;ImageView android:id="@+id/dialog_close_button"
          android:layout_width="42dp"
          android:layout_height="44dp"
          android:layout_marginTop="5dp"
          android:layout_marginRight="5dp"
          android:layout_gravity="top|right"
          android:src="@drawable/dialog_close_button"/&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p><em>dialog_title_box.xml</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item&gt;
          &lt;shape android:shape="rectangle"&gt;
              &lt;solid android:color="#88888888" /&gt;
              &lt;corners android:radius="1dp" /&gt;
              &lt;padding
                  android:left="1dp"
                  android:top="0dp"
                  android:right="1dp"
                  android:bottom="3dp" /&gt;
          &lt;/shape&gt;
      &lt;/item&gt;
  
      &lt;item&gt;
          &lt;shape android:shape="rectangle"&gt;
              &lt;solid android:color="@color/white" /&gt;
              &lt;corners android:radius="1dp" /&gt;
              &lt;padding
                  android:left="15dp"
                  android:top="5dp"
                  android:right="15dp"
                  android:bottom="5dp" /&gt;
          &lt;/shape&gt;
      &lt;/item&gt;
  &lt;/layer-list&gt;
  </code></pre>
  
  <p><em>dialog_close_button.xml</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item&gt;
          &lt;shape android:shape="oval"&gt;
              &lt;solid android:color="#88888888" /&gt;
              &lt;padding
                  android:left="1dp"
                  android:top="0dp"
                  android:right="1dp"
                  android:bottom="4dp" /&gt;
          &lt;/shape&gt;
      &lt;/item&gt;
  
      &lt;item&gt;
          &lt;shape android:shape="oval"&gt;
              &lt;solid android:color="@color/white" /&gt;
          &lt;/shape&gt;
      &lt;/item&gt;
  
      &lt;item android:drawable="@drawable/ic_close" /&gt;
  &lt;/layer-list&gt;
  </code></pre>