简体   繁体   English

Android中动作栏的Transition Drawable

[英]Transition Drawable for actionbar in Android

Is it possible to use transition drawable for Actionbar and how? 是否可以在Actionbar中使用过渡可绘制,如何使用? I should use an xml like: 我应该使用像这样的xml:

 <xml version="1.0" encoding="utf-8"/>
 <transition xmlns:android="http://schemas.android.com/apk/res/android"/>
 <item android:drawable="@drawable/first_image"/>
 <item android:drawable="@drawable/second_image"/>
 </transition>

but how I continue from here? 但是我如何从这里继续?

Yes, it is possible. 对的,这是可能的。 You can do it without XML, just create a TransitionDrawable in your code: 您可以在不使用XML的情况下进行操作,只需在您的代码中创建一个TransitionDrawable

Drawable firstImage = getDrawable(R.drawable.first_image);
Drawable secondImage = getDrawable(R.drawable.secondImage);
TransitionDrawable transition = new TransitionDrawable(new Drawable[] {
        firstImage, secondImage});

After that set this transition as background to your ActionBar: 之后,将此过渡设置为ActionBar的背景:

getSupportActionBar().setBackgroundDrawable(transition);

And start the transition: 并开始过渡:

transition.startTransition(1000);

Also you can set this transition as background to Toolbar. 您也可以将此过渡设置为工具栏的背景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM