6

I have set a style for my CardView in style.xml file but its giving me error on compile time for app:cardCornerRadius, app:cardElevation, app:cardPreventCornerOverlap and app:contentPadding attributes. What is the correct way to set style for a CardView in Android?

Below is some of my code:

<style name="CardViewStyle" parent="CardView">
    <item name="android:layout_marginBottom">@dimen/cardMarginVertical</item>
    <item name="android:layout_marginTop">@dimen/cardMarginVertical</item>
    <item name="android:layout_marginLeft">@dimen/cardMarginHorizontal</item>
    <item name="android:layout_marginRight">@dimen/cardMarginHorizontal</item>
    <item name="app:cardCornerRadius">2dp</item>
    <item name="app:cardElevation">2dp</item>
    <item name="app:cardPreventCornerOverlap">false</item>
    <item name="app:contentPadding">0dp</item>
    <item name="android:layout_width">match_parent</item>
</style>
Farbod Salamat-Zadeh
  • 18,923
  • 18
  • 69
  • 122
user3391170
  • 91
  • 2
  • 7

1 Answers1

15

Set parent attribute to CardView. You don't even have to add

  • app: qualifier
  • xmlns:card_view="http://schemas.android.com/apk/res-auto". is not required

Working snippet of code:

<style name="CardViewStyle" parent="CardView">
 <item name="cardCornerRadius">4dp</item>
 <item name="cardElevation">4dp</item>
</style>
Community
  • 1
  • 1
Abhishek
  • 2,210
  • 2
  • 16
  • 35