CardView背景颜色始终为白色 [英] CardView background color always white
问题描述
我正在将RecyclerView与GridLayoutManager一起使用,并且每个项目都作为CardView.
I am using RecyclerView with GridLayoutManager and I have each item as CardView.
不幸的是,这里的CardView似乎没有改变其背景颜色.我尝试了布局和程序设计,但是似乎没有任何尝试.
Unfortunately, the CardView here does not seem to change its background color. I tried in layout and programmatically as well but I have tried nothing seems to work.
我已经挣扎了很长一段时间.如果有人可以帮助我解决此问题,我将不胜感激.
I Have been struggling for quite a while. I appreciate if someone could help me out with this issue.
推荐答案
如果要更改卡片背景色,请使用:
If you want to change the card background color, use:
app:cardBackgroundColor="@somecolor"
像这样:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/white">
</android.support.v7.widget.CardView>
修改: 正如@imposible指出的那样,您需要添加
As pointed by @imposible, you need to include
xmlns:app="http://schemas.android.com/apk/res-auto"
在您的根XML标记中,以使此代码段起作用
in your root XML tag in order to make this snippet function
这篇关于CardView背景颜色始终为白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!