CardView doesn't support TransitionDrawable?

I tried to animate the switch color in the background CardView

, but I get this:

Cannot resolve method setCardBackgroundColor (android.graphics.drawable.TransitionDrawable) '

If CardView

not TransitionDrawable

, how can we achieve something like this?

public void setCardBackground(CardView cardView) {
    ColorDrawable[] color = {new ColorDrawable(Color.BLUE), new ColorDrawable(Color.RED)};
    TransitionDrawable trans = new TransitionDrawable(color);
     //cardView.setCardBackgroundColor(trans);
    trans.startTransition(5000);
}

      

+3
java android android-cardview android-animation transitiondrawable


source to share


1 answer


Have you tried View#setBackground()

?



public void setCardBackground(CardView cardView) {
    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) {
        cardView.setBackground(trans);
    } else {
        cardView.setBackgroundDrawable(trans);
    }
    trans.startTransition(5000);
}

      

+2


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics