Animate CardView background color with TransitionDrawable
suggest changepublic void setCardColorTran(CardView card) {
ColorDrawable[] color = {new ColorDrawable(Color.BLUE), new ColorDrawable(Color.RED)};
TransitionDrawable trans = new TransitionDrawable(color);
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
card.setBackground(trans);
} else {
card.setBackgroundDrawable(trans);
}
trans.startTransition(5000);
}
CardView.setBackground replaces the drawable that draws the rounded corners and shadow. setCardBackgroundColor keeps that drawable, but it does not accept a TransitionDrawable, so this sample uses setBackground only to run the cross-fade.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents