title: Cardview corner background not transparent
body: <p>I have a custom implementation of a CardView support widget but I can't seem to get the background for the corners transparent when I include it in my layout-file. However, if I simply place the CardView support widget in my layout-file it suddenly works. How can I get the corners transparent for my custom component?</p>
  
  <p><a href="https://i.stack.imgur.com/4SLAf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/4SLAf.png" alt="example"></a></p>
  
  <p>This is the layout file for my custom implementation of the CardView:</p>
  
  <p>view_card.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/view_card"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      style="@style/Custom.Widget.CardView"&gt;
  
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:padding="@dimen/default_padding"&gt;
  
      &lt;TextView
          android:id="@+id/view_mainText"
          style="@style/Custom.Widget.TextView.Header"
          android:textColor="@color/instruction_balloon_text"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/view_subText"
          android:textSize="@dimen/text_size_medium"
          android:textColor="@color/instruction_balloon_text"
          android:singleLine="false"
          android:text="Please remove white corners :-("
          android:textIsSelectable="true"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>styles.xml</p>
  
  <pre><code>&lt;style name="Custom.Widget.CardView" parent="CardView"&gt;
      &lt;item name="cardBackgroundColor"&gt;@color/card_backgroundColor&lt;/item&gt;
      &lt;item name="cardCornerRadius"&gt;12dp&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p>And this is my layout file that includes the two CardViews. The first one with the white corners and the second one that's basically the same layout as view_card.xml but without the white corners (transparent).</p>
  
  <p>example.xml</p>
  
  <pre><code>&lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"&gt;
  
      &lt;some.private.namespace.CardView
          android:id="@+id/custom_card_view"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="@dimen/default_margin" /&gt;
  
      &lt;android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/view_card"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="@dimen/default_margin"
          style="@style/Custom.Widget.CardView"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"
              android:padding="@dimen/default_padding"&gt;
  
              &lt;TextView
                  android:id="@+id/view_mainText"
                  style="@style/Custom.Widget.TextView.Header"
                  android:textColor="@color/instruction_balloon_text"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" /&gt;
  
              &lt;TextView
                  android:id="@+id/view_subText"
                  android:textSize="@dimen/text_size_medium"
                  android:textColor="@color/instruction_balloon_text"
                  android:singleLine="false"
                  android:text="I have no white corners :-)"
                  android:textIsSelectable="true"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/android.support.v7.widget.CardView&gt;
      ... some other views
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Update 1</strong></p>
  
  <p>I tried Just89's solution, however it results in a crash on lower Android versions.</p>
  
  <pre><code> android.graphics.drawable.ColorDrawable cannot be cast to android.support.v7.widget.RoundRectDrawableWithShadow
  </code></pre>
  
  <p>After a quick search I found the following post.
  <a href="https://stackoverflow.com/questions/26399670/android-graphics-drawable-colordrawable-cannot-be-cast-to-android-support-v7-wid">android.graphics.drawable.ColorDrawable cannot be cast to android.support.v7.widget.RoundRectDrawableWithShadow</a></p>
  
  <p>The answer suggests to set the background color using:<code>setCardBackgroundColor</code>.
  However this will bring back the white corners. </p>
  
  <p><strong>Update 2</strong></p>
  
  <p>The accepted answer will solve this problem, however it's not the preferred solution. I made a mistake when creating the custom CardView component that was causing these white corners. Check <a href="https://stackoverflow.com/a/48925557/2212770">this</a> answer to see what I did wrong.</p>