gpt4 book ai didi

java - CardView 不支持 TransitionDrawable?

转载 作者:太空狗 更新时间:2023-10-29 13:08:25 25 4
gpt4 key购买 nike

我试图在 CardView 背景上设置一个 switch-color 的动画,但我得到了这个:

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

如果CardView不支持TransitionDrawable,那么我们如何实现这样的东西呢?

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);
}

最佳答案

你试过了吗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);
}

关于java - CardView 不支持 TransitionDrawable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44460100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com