I'm using the ActionBarDrawerToggle from the v7 appcompat library in my app and have some troubles with the menu-to-arrow animation. According to the material design guidelines the navigation drawer should overlap the toolbar and the icon animation should not be used when opening the drawer as I understand.
Why is the animation enabled by default when opening/closing the navigation drawer and how can I disable it?
Also, how can I trigger the animation on other occurences? I found this solution but it only works for Android API 11+ and its overwritten by calling setDrawerIndicatorEnabled(false)
or by an expanded ActionView in the toolbar.
When you create your ActionBarDrawerToggle, do it like this to disable the animation/arrow and always show a hamburger:
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);
super.onDrawerSlide(drawerView, 0); // this disables the arrow @ completed state
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, 0); // this disables the animation
}
};
I came across this problem tooday and found simple and (I belive) a proper solution:
Just don't set ActionBarDrawerToggle instance as DrawerListener for your DrawerLayout. This way ActionBarDrawerToggle will not perform animation that depends on drawer slide offset.
If you need a listener for DrawerLayout use DrawerLayout.DrawerListener.
edit: You can also set ActionBarDrawerToggle as a listener, but than you must overide its onDrawerSlide method. e.g. like this:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open_desc, R.string.drawer_close_desc) {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, 0);
}
};
calling super.onDrawerSlide()
with 0 value instead of slideOffset, disables the animation
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