我正在尝试使用 TransitionDrawable 在操作栏上制作一些彩色动画。
我尝试的代码非常简单,在 onCreate 期间,我将转换可绘制对象作为操作栏背景:
Drawable d = getResources().getDrawable(R.drawable.actionbar);
actionbarDrawable = new TransitionDrawable(new Drawable[] { d, d });
getActionBar().setBackgroundDrawable(actionbarDrawable);
然后在事件中我替换了 TransitionDrawable 的第二个可绘制对象并要求为其设置动画。
actionbarDrawable.setDrawableByLayerId(1, d);
actionbarDrawable.startTransition(666);
我已经在我的 Activity 的 RelativeLayout 上尝试了相同的代码,它似乎工作正常,知道为什么 ActionBar 不想合作以及如何让它工作吗?
谢谢。
最佳答案
试一试:
在值/字符串中:
<color name="blue">#FF4682B4</color>
<color name="red">#FFC30F0F</color>
在你的类里面:
ColorDrawable blue = new ColorDrawable(getResources().getColor(R.color.blue));
ColorDrawable red = new ColorDrawable(getResources().getColor(R.color.red));
ColorDrawable[] color = {blue, red};
TransitionDrawable trans = new TransitionDrawable(color);
actionBar.setBackgroundDrawable(trans);
trans.startTransition(500);
关于android - 是否可以在 ActionBar 上使用 TransitionDrawable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12912956/