Is it possible to use TransitionDrawable on the ActionBar?

*爱你&永不变心* 提交于 2020-01-02 07:28:08

问题


I'm trying to do some color animation on the action bar by using a TransitionDrawable.

The code I'm trying is pretty simple, during onCreate, I put the transition drawable as the actionbar background:

Drawable d = getResources().getDrawable(R.drawable.actionbar);
actionbarDrawable = new TransitionDrawable(new Drawable[] { d, d });
getActionBar().setBackgroundDrawable(actionbarDrawable);

then on the event I replace the second drawable of the TransitionDrawable and ask to animate it.

    actionbarDrawable.setDrawableByLayerId(1, d);
    actionbarDrawable.startTransition(666);

I've tried the same code on a RelativeLayout on my activity and it seems to work fine, any ideas why the ActionBar doesn't want to cooperate and how to make it work?

thanks.


回答1:


Try it:

In values/string:

<color name="blue">#FF4682B4</color>
<color name="red">#FFC30F0F</color>

In your class:

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


来源:https://stackoverflow.com/questions/12912956/is-it-possible-to-use-transitiondrawable-on-the-actionbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!