xml布局
private DrawerLayout drawer_layout;
private ActionBarDrawerToggle toggle;
private void initActionBar() {
//给main布局定义的id
drawer_layout = findViewById(R.id.drawer_layout);
//new一个actionBar
ActionBar actionBar = getSupportActionBar();
//给按钮设置默认按钮
actionBar.setDisplayHomeAsUpEnabled(true);
toggle = new ActionBarDrawerToggle(this,drawer_layout, R.string.open,R.string.close);
toggle.syncState();
drawer_layout.addDrawerListener(toggle);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(toggle.onOptionsItemSelected(item)){
return true;
}
return super.onOptionsItemSelected(item);
}