Stack Overflow archive
15 scoreaccepted

CardView setCardBackgroundColor won't work

score
15
question views
10.7K
license
CC BY-SA 3.0

Change

java
cardViewHolder.card_view.setCardBackgroundColor(inc_cards.get(i).inc_status);

to

java
int colorId = inc_cards.get(i).inc_status;
int color = cardViewHolder.card_view.getContext().getResources().getColor(colorId);
cardViewHolder.card_view.setCardBackgroundColor(color);

You are using the value from R.color instead of the value you set in your XML.

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.