Skip to content Skip to sidebar Skip to footer

Clicking Hamburger Icon On Toolbar Does Not Open Navigation Drawer

I have this nav drawer which was working perfectly fine. Refactoring my code I removed all onOptionsItemSelecteds in activities and made all activities inherit from a base activit

Solution 1:

You're using the four-parameter constructor for ActionBarDrawerToggle, which means you'll have to call the toggle's onOptionsItemSelected() method in MainActivity's onOptionsItemSelected() override in order to open/close the drawer.

For example:

@OverridepublicbooleanonOptionsItemSelected(MenuItem item) {
    if(mDrawerToggle.onOptionsItemSelected(item)) {
        returntrue;
    }

    returnsuper.onOptionsItemSelected(item);
}

If you happen to be providing your own Toolbar – e.g., as the support ActionBar (though it's not necessary to set it as such) – then you can instead pass that Toolbar as the third argument in the ActionBarDrawerToggle constructor call. For example:

Toolbar toolbar = findViewById(R.id.toolbar);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
        toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

The drawer opening/closing will then be handled by ActionBarDrawerToggle internally, and you won't need to call through to the toggle in onOptionsItemSelected().

The setDisplayHomeAsUpEnabled() call is also unnecessary for this setup, which is handy if you don't want to set the Toolbar as the ActionBar.

Post a Comment for "Clicking Hamburger Icon On Toolbar Does Not Open Navigation Drawer"