简体   繁体   English

禁用汉堡包箭头动画

[英]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还需要同时处理onDrawerOpenedonDrawerClosed

@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.

相关问题 在工具栏上禁用汉堡以返回箭头动画 - Disable hamburger to back arrow animation on Toolbar Xamarin.Forms:如何在Android上禁用向汉堡包过渡的箭头动画? - Xamarin.Forms: how to disable arrow to hamburger transition animation on Android? 汉堡箭头动画无法以编程方式工作 - Hamburger to arrow animation not working programmatically 抽屉上没有汉堡到箭头的动画或图标 - No Hamburger to Arrow animation or icon showing on Drawer 为什么在工具栏上执行汉堡到箭头的动画时会有不同的动画? - Why there are different animation when performing hamburger to arrow animation on toolbar? 从添加片段的汉堡包到箭头图标过渡动画 - Transition animation from hamburger to arrow icon on adding fragment 汉堡图标两侧带有两个NavigationView工具栏中的后箭头动画? - Hamburger icon both side with back arrow animation in toolbar for Two NavigationView? 展开动作视图时导航抽屉图标(汉堡和箭头)动画 - Navigation drawer icons (hamburger & arrow) animation when expand action view 后退箭头未转换为汉堡包图标 - Back arrow is not converting to hamburger icon Android汉堡菜单和后退箭头 - Android Hamburger Menu and Back Arrow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM