我想在這樣的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