我想在这样的RecylerView的Bindview持有者中动态地更改Cardview背景颜色。Cardview设置背景颜色
holder.cardView.setCardBackgroundColor(R.color.LightCyan);
奇怪的是后台应用几乎相反的应用的颜色。(#E0FFFF-浅青绿),以1F0000 -Almost黑色)
我曾在这里验证几种颜色here,其结果是相同。
但如果我这样设置
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">
OS:在Android 6.0 HTC
但是,在这里认识差距?
[这是你的差距(http://developer.android.com/intl/es/reference/android/support/v4/content/ContextCompat.html) – Aks4125