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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With