CardView具有属性card_view:cardBackgroundColor
来定义背景颜色。该属性正常工作。
同时,没有动态更改颜色的方法。
我刚刚尝试了一些解决方案:
mCardView.setBackgroundColor(...);
或者在cardView内使用布局
<android.support.v7.widget.CardView>
<LinearLayout
android:id="@+id/inside_layout">
</android.support.v7.widget.CardView>
View insideLayout = mCardView.findViewById(R.id.inside_layout);
cardLayout.setBackgroundColor(XXXX);
这些解决方案行不通,因为该卡片拥有一个cardCornerRadius。
card_view:cardBackgroundColor="@android:color/white"
。 - Mavamaartencard_view
命名空间对我无效,我必须使用app
代替。 - rsicarellixmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
- Bryan Bryce