我已经尝试过使用ActionBarDrawerToggle&amp ;;带有主题的Styles.xml,但我在Google&堆栈似乎是我需要的。
我正在使用v7 ActionBarDrawerToggle。
正如标题所说,我需要做的是保持抽屉打开时除抽屉外的所有物品。当选择一个项目时它关闭。
我希望箭头不见了留下的汉堡包图标。我可以轻松实现这一目标,但不会失去动画。另外一件事,我也想保留动画,所以汉堡包不会动画/旋转到箭头,而是动画/旋转到另一个汉堡包。
有什么想法吗?
谢谢!干杯!
这是代码
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main);
getActionBar().setBackgroundDrawable(new
ColorDrawable(Color.parseColor("#CC0000")));
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
linearMain = (LinearLayout) findViewById(R.id.linearMain);
mDrawerLayout = (DrawerLayout) findViewById(R.id.layout_mainactivity);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerList.setDividerHeight(1);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, R.string.drawer_open) {
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, menuItems));
Fragment fragment = null;
Class<TabLayoutFragment> fragmentClass = TabLayoutFragment.class;
try {
fragment = (Fragment) fragmentClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction =
fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragmentContainer, fragment);
fragmentTransaction.commit();
mDrawerList.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, final int
pos,long id){
mDrawerLayout.setDrawerListener( new
DrawerLayout.SimpleDrawerListener(){
@Override
public void onDrawerClosed(View drawerView){
super.onDrawerClosed(drawerView);
if (pos == 0){
TabLayoutFragment.tabLayoutViewPager.setCurrentItem(0);
} else if (pos == 1) {
TabLayoutFragment.tabLayoutViewPager.setCurrentItem(1);
}
}
});
mDrawerLayout.closeDrawer(linearMain);
}
});
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}