Android app with two navigation drawers or how to fight the indicator

What the fuck

Sometimes I feel like android is FUCKING troublesome. Like 80% of the time I am fighting bugs and making workarounds.

So I wanted to have two navigation drawers. One on the left and one on the right. Easy!
I am using a toolbar for an ActionBar. The problem is that when I open the right drawer by swiping the indicator in the upper left corner is changing from a hamburger menu to an arrow. I want it to remain as a hamburger menu even if the right drawer is opened. And I want it to change only when the left drawer is opened.

The Answer

So I found that the ActionBarDrawerToggle listener is called once for each drawer you have. So you may have only one listener, lets say in the Left Drawer fragment, but it will be called twice: once for the left and once for the right drawer. WTF..
To avoid the hamburger to arrow transformation you must override the onDrawerSlide method in the ActionBarDrawerToggle method and call the super only if you want to have the transformation, like this:

public void onDrawerSlide(View drawerView, float slideOffset) {
    // You can debug to see that this is called twice.
   if(drawerView.getId() == {
    super.onDrawerSlide(drawerView, slideOffset);

So if you want to implement toolbar with drawer navigation checkout THIS Github repo.

So in my case I have two navigation fragments: Left and Right fragments. In the left fragment I have an ActionBarDrawerToggle which is connected with the hamburger menu. In the right fragment I have a simple ListView WITHOUT any listeners(I mean DrawerToggle listeners) in the fragment. You can easily debug to see that your methods in your ActionBarDrawerToggle listener in the left fragment will be called even when there is an action on the right fragment. That is why you have to check for the drawerView id to make sure you are working with the correct drawer.

That is it…

You may also like...