title: Attach custom CardView style to theme
body: <p>In my app, I have two themes (light and dark), and I want all of my <code>CardView</code>s to change their background color depending on which theme is selected.</p>
  
  <p>What I <strong>don't</strong> want is:</p>
  
  <pre><code>&lt;android.support.v7.widget.CardView
      style="@style/CardView.MyBlue"
      android:layout_width="200dp"
      android:layout_height="100dp"
      android:layout_gravity="center_horizontal"&gt;
  </code></pre>
  
  <p>The above code is not dynamic. I need my two styles to automatically be applied depending on if a light or a dark theme is selected.</p>
  
  <hr>
  
  <p>What I have right now doesn't work:</p>
  
  <pre><code>&lt;style name="AppTheme.Light" parent="Theme.AppCompat.Light"&gt;
     ...
     &lt;item name="cardViewStyle"&gt;@style/CardViewStyle.Light&lt;/item&gt;
  &lt;/style&gt;
  &lt;style name="AppTheme.Dark" parent="Theme.AppCompat"&gt;
     ...
     &lt;item name="cardViewStyle"&gt;@style/CardViewStyle.Dark&lt;/item&gt;
  &lt;/style&gt;
  
  &lt;style name="CardViewStyle.Light" parent="CardView"&gt;
      &lt;item name="cardBackgroundColor"&gt;@color/cardview_dark_background&lt;/item&gt;
  &lt;/style&gt;
  
  &lt;style name="CardViewStyle.Dark" parent="CardView"&gt;
          &lt;item name="cardBackgroundColor"&gt;@color/cardview_light_background&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p>I read somewhere that you can define a <code>styleable.xml</code> file in <code>/res/values/</code> to key the word <code>cardViewStyle</code>, so I did that:</p>
  
  <p><code>styleable.xml:</code></p>
  
  <pre><code>&lt;resources&gt;
      &lt;declare-styleable name="AppTheme"&gt;
          &lt;attr name="cardViewStyle" format="reference" /&gt;
      &lt;/declare-styleable&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <h2>Update</h2>
  
  <p>Similar question <a href="https://stackoverflow.com/questions/29914671/how-to-add-cardview-attributes-to-app-theme">here</a> with no answer either.</p>