Clicking hamburger icon on Toolbar does not open Navigation Drawer
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:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.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
.