问题
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>
回答1:
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>
- similar ques
- How to put a CardView attribute in a style?
来源:https://stackoverflow.com/questions/31221911/how-to-set-cardview-attributes-in-style-xml-file-in-android