Transition Drawable for actionbar in Android

314 Views Asked by At

Is it possible to use transition drawable for Actionbar and how? I should use an xml like:

 <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?

1

There are 1 best solutions below

0
tikhonos On

Yes, it is possible. You can do it without XML, just create a TransitionDrawable in your code:

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:

getSupportActionBar().setBackgroundDrawable(transition);

And start the transition:

transition.startTransition(1000);

Also you can set this transition as background to Toolbar.