[英]CardView Background Color Change
I have a CardView
that changes function once clicked. 我有一个
CardView
,一旦点击CardView
改变功能。 To confirm this change, I have a TextView
within the CardView
that changes from Start to Stop. 为了确认这一变化,我在
CardView
中有一个TextView
,它从Start到Stop变化。 I thought I could change the BG color from green to red by the same way I change the text, but it is not working. 我想我可以通过改变文本的方式将BG颜色从绿色变为红色,但它不起作用。
Does anybody know how I could change the background color from GREEN to RED once clicked? 有没有人知道如果点击后我可以将背景颜色从GREEN更改为RED? It is currently green.
它目前是绿色的。 I have tried using the
onPressed
attribute in XML however the color does not remain RED once the CardView
is clicked. 我已尝试在XML中使用
onPressed
属性,但单击CardView
颜色不会保持为红色。
I will post the code below. 我将在下面发布代码。 Help greatly appreciated.
非常感谢。
以编程方式更改cardView背景颜色
your_card_view.setCardBackgroundColor(getResources().getColor(R.color.Primary));
values-Color
值彩
<resources>
<color name="colorPrimary">#009688</color>
<color name="colorPrimaryDark">#00796B</color>
<color name="colorAccent">#d7d6d4</color>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.