CardView setCardBackgroundColor won't work

Change

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

to

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.


I'm getting a more reliable color overriding with this line:

setBackgroundTintList(ColorStateList.valueOf(color));

instead of:

setCardBackgroundColor(color).