Animate CardView background color with TransitionDrawable

suggest change
public 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents