Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable hamburger to back arrow animation on Toolbar

It's very easy to implement Toolbar with hamburger to back arrow animation. In my opinion this animation is pointless because as per material design spec navigation drawer covers the Toolbar when opened. My question is how to properly disable this animation and show either hamburger or back arrow using getSupportActionBar().setDisplayHomeAsUpEnabled(true);

This is how I did it, but it looks like a dirty hack:

mDrawerToggle.setDrawerIndicatorEnabled(false);  if (showHomeAsUp) {     mDrawerToggle.setHomeAsUpIndicator(R.drawable.lib_ic_arrow_back_light);     mDrawerToggle.setToolbarNavigationClickListener(view -> finish()); } else {     mDrawerToggle.setHomeAsUpIndicator(R.drawable.lib_ic_menu_light);     mDrawerToggle.setToolbarNavigationClickListener(view -> toggleDrawer()); } 

Any clues how this should be properly implemented to use just setDisplayHomeAsUpEnabled to switch between hamburger and back arrow icons?

like image 906
tomrozb Avatar asked Nov 25 '14 01:11

tomrozb


1 Answers

This will disable the animation, when creating the drawerToggle, override onDrawerSlide():

drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,         getToolbar(), R.string.open, R.string.close) {      @Override     public void onDrawerClosed(View view) {         super.onDrawerClosed(view);     }      @Override     public void onDrawerOpened(View drawerView) {         super.onDrawerOpened(drawerView);     }      @Override     public void onDrawerSlide(View drawerView, float slideOffset) {         super.onDrawerSlide(drawerView, 0); // this disables the animation      } }; 

If you want to remove the arrow completely, you can add

 super.onDrawerSlide(drawerView, 0); // this disables the arrow @ completed state 

at the end of the onDrawerOpened function.

like image 171
Frank Avatar answered Oct 04 '22 15:10

Frank