[英]Disable hamburger to arrow animation
I am trying to implement a two-drawer layout with the android v7 support library. 我正在尝试使用android v7支持库实现双抽屉布局。 I have a navigation drawer on the left (Gravity.START) side and a notification drawer on the right (Gravity.END) side. 我在左侧(Gravity.START)侧有一个导航抽屉,在右侧(Gravity.END)侧有一个通知抽屉。 The problem is that I need the hamburger in the action bar to stay a hamburger when the notification drawer is pulled out, but stay animated and change to an arrow if the navigation drawer is pulled out. 问题是我需要操作栏中的汉堡包在拉出通知抽屉时保留汉堡包,但如果拉出导航抽屉,则保持动画并更改为箭头。 Currently it changes to an arrow when either one is pulled out. 目前,当任何一个被拉出时,它会变为箭头。 I have successfully disabled the animation by overriding onDrawerSlide(View, float)
and only calling to super.onDrawerSlide(View, float)
if the View is the navigation drawer and doing nothing if the View is the notification drawer like this: 我通过覆盖onDrawerSlide(View, float)
成功禁用了动画,如果View是导航抽屉,则只调用super.onDrawerSlide(View, float)
如果View是通知抽屉, super.onDrawerSlide(View, float)
执行任何操作:
@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
}
}
However, once the notification drawer has fully opened, the icon still changes to an arrow. 但是,一旦通知抽屉完全打开,图标仍会变为箭头。 Any idea how to disable this change? 知道如何禁用此更改吗?
Along with handling onDrawerSlide
you need to handle both onDrawerOpened
and onDrawerClosed
: 除了处理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
}
}
从支持v7版本25.3.0开始,您可以禁用动画
yourActionBarDrawerToggle.setDrawerSlideAnimationEnabled(false);
The above accepted answer not working for me but the below one does 以上接受的答案对我不起作用,但下面的答案不适用
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, 0); // this disables the animation
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.