Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

android - Disable hamburger to arrow animation

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...