我正在尝试使用android v7支持库实现双抽屉布局。我在左侧(Gravity.START)侧有一个导航抽屉,在右侧(Gravity.END)侧有一个通知抽屉。问题是,我需要操作栏中的汉堡包在拉出通知抽屉时保留汉堡包,但如果拉出导航抽屉,则保持动画并更改为箭头。目前,当任何一个被拉出时,它会变为箭头。我通过覆盖onDrawerSlide(View, float)
成功禁用了动画,如果View是导航抽屉,则只调用super.onDrawerSlide(View, float)
,如果View是通知抽屉,则不执行任何操作:
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// Make sure it was the navigation drawer
if(drawerView.equals(navigationDrawer)) {
super.onDrawerSlide(drawerView, slideOffset);
}
else {
// Do nothing
}
}
但是,一旦通知抽屉完全打开,图标仍会变为箭头。知道如何禁用此更改吗?
答案 0 :(得分:4)
在处理onDrawerSlide
时,您需要同时处理onDrawerOpened
和onDrawerClosed
:
@Override
public void onDrawerOpened(View drawerView, float slideOffset) {
// Make sure it was the navigation drawer
if(drawerView.equals(navigationDrawer)) {
super.onDrawerOpened(drawerView, slideOffset);
}
else {
// Do nothing
}
}
@Override
public void onDrawerClosed(View drawerView, float slideOffset) {
// Make sure it was the navigation drawer
if(drawerView.equals(navigationDrawer)) {
super.onDrawerClosed(drawerView, slideOffset);
}
else {
// Do nothing
}
}
答案 1 :(得分:2)
从支持v7版本25.3.0开始,您可以禁用动画
yourActionBarDrawerToggle.setDrawerSlideAnimationEnabled(false);
答案 2 :(得分:0)
以上接受的答案对我不起作用,但下面的答案
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, 0); // this disables the animation
}