我试图在RecylerView的BindView holder中动态更改Cardview的背景颜色,就像这样。
holder.cardView.setCardBackgroundColor(R.color.LightCyan);
奇怪的是,背景应用的颜色(#E0FFFF-LightCyan)几乎与所应用的颜色(1F0000-几乎黑色)相反。
我在这里验证了几种颜色(链接),结果相同。
但是如果我设置成这样:
holder.cardView.setCardBackgroundColor(ContextCompat.getColor(this.mContext, R.color.LightCyan));
它完美地运作了。(是的,这是正确的设置方式)。
CardView XML:
<android.support.v7.widget.CardView
android:id="@+id/cv"
android:foreground="?selectableItemBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content">
操作系统:Android 6.0 HTC
但这里存在哪些理解障碍呢?