我正在尝试以编程方式更改 CardView 颜色。
这是我的卡片视图:
<android.support.v7.widget.CardView
android:id="@+id/createsub_card"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
这就是我设置背景颜色的方法:
CardView card = (CardView) findViewById(R.id.createsub_card);
card.setCardBackgroundColor(sub.getColor());
where sub.getColor()
在这种特定情况下返回这种颜色:
<color name="color_black">#000000</color>
应该是漆黑的。我的 CardView 仍然是这样的:
知道为什么会发生这种情况以及如何解决它吗?
我假设问题源于子.getColor()。首先正确返回颜色 code .
你可以尝试用这个
cardView.setCardBackgroundColor(Color.parseColor("#000000"));
Or
cardView.setCardBackgroundColor(getResources().getColor(R.color.color_black));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)