Android 如何覆盖应用程序中每个CardView的材质设计样式?

Android 如何覆盖应用程序中每个CardView的材质设计样式?,android,kotlin,material-design,themes,cardview,Android,Kotlin,Material Design,Themes,Cardview,我在我的项目中使用“com.google.android.material:material:1.3.0”。根据Big Nerd Ranch的书,我试图覆盖整个项目的CardView样式,以避免为每个CardView设置样式属性。 我的舱单: android:theme="@style/Theme.MyProject" My themes.xml: <style name="Theme.MyProject" parent="Theme.M

我在我的项目中使用“com.google.android.material:material:1.3.0”。根据Big Nerd Ranch的书,我试图覆盖整个项目的CardView样式,以避免为每个CardView设置样式属性。 我的舱单:

android:theme="@style/Theme.MyProject"
My themes.xml:

<style name="Theme.MyProject" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    ...
    <item name="materialCardViewStyle">@style/MyDesignCardView</item>
</style>

<style name="MyDesignCardView" parent="Widget.MaterialComponents.CardView">
    <item name="cardBackgroundColor">@color/cardViewBackground</item>
    <item name="cardCornerRadius">5dp</item>
    <item name="cardElevation">8dp</item>
</style>

...
@样式/MyDesignCardView
@颜色/卡片视图背景
5dp
8dp
我的名片视图:

<androidx.cardview.widget.CardView
    android:id="@+id/card_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>


您应该使用
com.google.android.material.card.MaterialCardView
而不是
androidx.cardview.widget.cardview

有什么问题吗?