禁止汉堡包箭头动画汉堡包、箭头、动画

2023-09-12 21:56:36 作者:梦雪樱飞

我想实现的是Android V7支持库两抽屉布局。我在左边(Gravity.START)一侧的抽屉式导航栏,右​​侧(Gravity.END)侧的通知抽屉。问题是,我需要在操作栏上的汉堡包留一个汉堡时通知抽屉拉出,但留下的动画,并变成一个箭头,如果导航抽屉拉出。目前,它变成箭头当任一个被拉出。通过重写我已经成功地禁用动画 onDrawerSlide(查看和float),只有打电话给 super.onDrawerSlide(查看和float)如果该视图导航抽屉,什么都不做,如果视图是通知抽屉是这样的:

I am trying to implement a two-drawer layout with the android v7 support library. I have a navigation drawer on the left (Gravity.START) side and a notification drawer on the right (Gravity.END) side. 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:

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

推荐答案

随着处理 onDrawerSlide 你需要同时处理 onDrawerOpened onDrawerClosed

Along with handling onDrawerSlide you need to handle both onDrawerOpened and 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
    }
}
 
精彩推荐
图片推荐