10

I have a Double Navigation Drawer

I have two problems.

1) The navigation drawer icon on the left (3 bars) animate when opening or closing the navigation drawer on the right.

2) I do not know how to add the icon to the right and have it animate only for the right drawer.

Community
  • 1
  • 1
clocksmith
  • 6,226
  • 3
  • 32
  • 45
  • I too would like to know this. I know you can prevent the animation by overriding the onDrawerSlide method, but then icon just jumps over rather than animate. – Chase Florell Apr 12 '14 at 03:50
  • @ChaseFlorell Have you checked out the [ActionBarDrawerToggle source](https://android.googlesource.com/platform/frameworks/support/+/refs/heads/master/v4/java/android/support/v4/app/ActionBarDrawerToggle.java)? It's the class that animates the action bar icon, assuming you're following the [example in the docs](http://developer.android.com/training/implementing-navigation/nav-drawer.html#OpenClose). It should be pretty straightforward to duplicate that for left/right behaviour; adding the icon for the right side might be the tricky part. – Adam S Apr 12 '14 at 04:14
  • @AdamS Yeah I've got the icon on the right... easy peasy. But the OnDrawerSlide override that I'm doing only prevents the animation... The icon now just jumps to the left. https://gist.github.com/ChaseFlorell/10519029 – Chase Florell Apr 12 '14 at 04:38

1 Answers1

19

You need to override the onDrawerSlide method of ActionBarDrawerToggle and set the slideOffset to 0 if the drawer is right drawer. So this would disable the animation of the navigation drawer image enter image description here for right drawer.

  @Override
  public void onDrawerSlide(View drawerView, float slideOffset) 
  {
        if(drawerView!=null && drawerView == rightDrawerListView){
              super.onDrawerSlide(drawerView, 0);
        }else{
              super.onDrawerSlide(drawerView, slideOffset);
        }
  }

This worked for me similar to Google+.

Jagadeesh
  • 883
  • 1
  • 10
  • 26
  • 8
    This worked for me, plus I had to add `super.onDrawerSlide(drawerView, 0);` to the end of my `onDrawerOpened()` method, to prevent it from snapping open after the drawer animated. – Peter Jun 20 '14 at 15:00
  • That worked for me too, adding if (drawerView != null && drawerView == navDrawRight.getView()) { super.onDrawerSlide(drawerView, 0); } to the end of the onDrawerOpened() – R. Campos Aug 21 '14 at 12:40
  • If i call `openDrawer(mDrawer)` in the activities `onCreate()` the icon starts off to the side, Anyone know a fix for this? – JStephen Mar 06 '15 at 17:02
  • 1
    I tried this. I am getting error about no method `onDrawerSlide` in `super` class. Why? I am using v7 ActionBar. I think this is the problem. – Sharikov Vladislav Jun 21 '15 at 12:45
  • Tried. But there is no toggle icon for right drawer. – eastwater Jun 22 '17 at 17:09