Disable hamburger for arrow animation

I am trying to implement a two-drawer layout using android v7 support library. I have a navigation box on the left (Gravity.START) and a notification box on the right (Gravity.END). The problem is that I need a hamburger in the action bar to remain a hamburger when the notification drawer is pulled out, but stay animated and switch to the arrow if the drawer is pulled out. Currently, it changes to an arrow when one of them is pulled out. I successfully turned off the animation, overriding onDrawerSlide(View, float)and calling only super.onDrawerSlide(View, float)if View is a navigation box and does nothing if View is a notification box as follows:

@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
    // Make sure it was the navigation drawer
    if(drawerView.equals(navigationDrawer)) {
        super.onDrawerSlide(drawerView, slideOffset);
    }
    else {
        // Do nothing
    }
}

However, as soon as the notification box is fully open, the icon still changes to an arrow. Any idea how to disable this change?

+4
source share
3 answers

Along with processing, onDrawerSlideyou need to process both onDrawerOpened, and onDrawerClosed:

@Override
public void onDrawerOpened(View drawerView, float slideOffset) {
    // Make sure it was the navigation drawer
    if(drawerView.equals(navigationDrawer)) {
        super.onDrawerOpened(drawerView, slideOffset);
    }
    else {
        // Do nothing
    }
}

@Override
public void onDrawerClosed(View drawerView, float slideOffset) {
    // Make sure it was the navigation drawer
    if(drawerView.equals(navigationDrawer)) {
        super.onDrawerClosed(drawerView, slideOffset);
    }
    else {
        // Do nothing
    }
}
+4
source

With support for version v7 version 25.3.0 you can disable the animation

yourActionBarDrawerToggle.setDrawerSlideAnimationEnabled(false);
+1
source

, ,

@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
    super.onDrawerSlide(drawerView, 0); // this disables the animation 
}
0

Source: https://habr.com/ru/post/1569933/


All Articles