改变CardView的背景色编程 [英] Change the background color of CardView programmatically
本文介绍了改变CardView的背景色编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
借助 CardView 有一个属性 card_view: cardBackgroundColor
来定义背景色。
此属性正常工作。
The CardView has an attribute card_view:cardBackgroundColor
to define the background color.
This attribute works fine.
同时没有一个方法来动态改变颜色。
At the same time there isn't a method to change the color dynamically.
我只是试图解决方案,如:
I've just tried solutions like:
mCardView.setBackgroundColor(...);
或使用cardView内布局
or using a Layout inside the 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。
These solutions don't work because the card has a cardCornerRadius.
推荐答案
您正在寻找的是:
CardView card = ...
card.setCardBackgroundColor(color);
这篇关于改变CardView的背景色编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文