这是因为material:1.1.0以后,部分Material控件需要MaterialComponents包下的theme才支持,而新建项目默认使用的还是Theme.AppCompat包,我们手动改成Theme.MaterialComponents即可。
第二种解决办法:
加上这一句
<com.google.android.material.card.MaterialCardView
android:id="@+id/title_right_num_bg"
android:layout_width="@dimen/base20dp"
android:layout_height="@dimen/base20dp"
app:cardBackgroundColor="@color/colorAccent"
android:layout_marginStart="@dimen/base13dp"
android:visibility="gone"
android:theme="@style/Theme.MaterialComponents.NoActionBar"
android:layout_marginTop="@dimen/base5dp"
app:cardCornerRadius="@dimen/base10dp"
app:cardElevation="0dp">
</com.google.android.material.card.MaterialCardView>