reference to : http://blog.csdn.net/chencehnggq/article/details/21492417
activity.java
mToolbar = (Toolbar) findViewById(R.id.toolbar); mToolbar.setTitle(getResources().getString(R.string.app_name)); mToolbar.setTitleTextColor(getResources().getColor(R.color.common_white)); setSupportActionBar(mToolbar); ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, mToolbar, R.string.app_name, R.string.app_name ); mDrawerLayout.addDrawerListener(mDrawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); mDrawerToggle.syncState();
public void onBackPressed() { if (!mDrawerLayout.isDrawerOpen(mLeftMenu)) { mDrawerLayout.openDrawer(mLeftMenu); } else { super.onBackPressed(); } }
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/white</item>
</style>