0

No, its not a re asked question I've searched so well. but nowhere found how to do this. I want to change the hamburger icon to back icon by calling a method from my activity. I can do it with Drawer.. but I wanna do it without opening drawer.. for example, when a fragment is shown.. the hamburger will turn into back arrow(with animation) then clicking the back arrow will hide fragment and turn the arrow back into hamburger.

I want the animation while doing this.. is there any way to do that? or its only possible while opening/closing drawer

Thanks in advance

dhir
  • 187
  • 2
  • 15

2 Answers2

2

I did it by Calling

onDrawerSlide(View v, float f);

where float value from 0.0f to 1.0f defines the progress of transforming from hamburger to back arrow.

Then I used object animator to call this method 100 times each time float value 0.1 increased and the magic happened. Thank you @gauravsarma for showing me the way.

Gaurav Sarma
  • 2,248
  • 2
  • 24
  • 45
dhir
  • 187
  • 2
  • 15
0

Do the following

ActionBarDrawerToggle toolbarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout,        
        toolbar, R.string.drawer_open, R.string.drawer_close) {

    public void onDrawerClosed(View view) {
        super.onDrawerClosed(view);
        invalidateOptionsMenu();
    }

    public void onDrawerOpened(View view) {
        super.onDrawerOpened(view);
        invalidateOptionsMenu();
    }
};
drawerLayout.setDrawerListener(toolbarDrawerToggle);
toolbarDrawerToggle.syncState();
Gaurav Sarma
  • 2,248
  • 2
  • 24
  • 45
  • Thank you .But it covers only 50% of what am i looking for. It changes the icon.. but no animation :( as i mentioned. I don't think its because of style, as its animating while opening drawer. – dhir Sep 03 '16 at 02:44