Android CardView 报错:Error inflat
2020-08-07 本文已影响0人
水天滑稽天照八野滑稽石
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginBottom="40dp"
app:cardElevation="3dp" />
很标准的用法,但就是报错

这个时候需要加上这个属性
app:cardBackgroundColor 定义背景阴影色的
如
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginBottom="40dp"
app:cardBackgroundColor="@android:color/white"
app:cardElevation="3dp" />
然后就正常了