You are using a four-parameter constructor for an ActionBarDrawerToggle , which means you need to call the toggle onOptionsItemSelected() method in MainActivity onOptionsItemSelected() to open / close the box.
For example:
@Override public boolean onOptionsItemSelected(MenuItem item) { if(mDrawerToggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); }
If you provide your own Toolbar — for example, as an ActionBar support (although there is no need to install it as such) — you can instead pass this Toolbar as the third argument in the call to the ActionBarDrawerToggle constructor. 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);
Opening / closing the box will then be handled by ActionBarDrawerToggle internally, and you will not need to access the onOptionsItemSelected() switch.
setDisplayHomeAsUpEnabled() also not needed for this setting, which is convenient if you do not want to set the Toolbar as a Toolbar ActionBar .
Mike M.
source share