天天看点

ActionBar,DrawerLayout打开关闭

ActionBar actionBar = getSupportActionBar();

actionBar.setDisplayHomeAsUpEnabled(true);//设置返回键是否可见 默认不可见

// 打开  关闭
    mActionBarDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, R.string.open, R.string.close);
    mActionBarDrawerToggle.syncState();//同步DrawerLayout的状态
    mDrawerLayout.addDrawerListener(mActionBarDrawerToggle); //监听ActionBarDrawerToggle
           

@Override

public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {

case android.R.id.home:

mActionBarDrawerToggle.onOptionsItemSelected(item);

break;

}

return super.onOptionsItemSelected(item);

}