MainActivity.java
public class MainActivity extends AppCompatActivity { DrawerLayout drawerLayout; Toolbar toolbar; ActionBarDrawerToggle actionBarDrawerToggle; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); drawerLayout= (DrawerLayout) findViewById(R.id.drawer_layout); toolbar= (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); actionBarDrawerToggle=new ActionBarDrawerToggle(this,drawerLayout, R.string.drawer_open, R.string.drawer_close); drawerLayout.addDrawerListener(actionBarDrawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); } @Override protected void onPostCreate(@Nullable Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); actionBarDrawerToggle.syncState(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); actionBarDrawerToggle.onConfigurationChanged(newConfig); } @Override public boolean onOptionsItemSelected(MenuItem item) { if (actionBarDrawerToggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); } }
References
https://github.com/mhdr/AndroidSamples/tree/master/047
https://www.youtube.com/watch?v=dvYGgSxiR1c&index=77&list=PLshdtb5UWjSp0879mLeCsDQN6L73XBZTk
https://developer.android.com/training/implementing-navigation/nav-drawer.html
http://codetheory.in/android-navigation-drawer/