Android hamburger arrow transition on new fragment / activity

983 views Asked by At

I have an activity A and on that activity, I want to create a new Activity B (or fragment if needs be). On A, I have a hamburger icon and on B, I have left arrow icon. When I created B from A, B is created with left arrow icon but there is no animation. I want to turn hamburger icon to left arrow icon animated as below when creating new activity.

Image

It should work like android gmail application. In Gmail app, when you are in inbox menu, there is a hamburger icon in toolbar and if you click and open one of your mails in inbox list, hamburger icon turns to left arrow animated. When you click to left arrow or back button, the left arrow turns to hamburger icon also animated. Any help?

1

There are 1 answers

0
Samvid Mistry On

I can see 2 ways of implementing it. The right way to do this is to use the Toolbar or ActionBar as a shared element between activities and change the state of ActionBarToggle when activity is started and when you return from that activity. But that will not work in pre-lollipop devices. But if you really badly want that to work on older devices, you can start the animation in the Toolbar inside Activity B after the activity B starts, it will not look as smooth as shared element transition, but that is the most straightforward way I see to implement it on older devices.