Tool bar setNavigationOnClickListener breaks ActionbarDrawerToggle functionality

前端 未结 5 2109
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 11:50

I\'m swapping out the action bar for the tool bar, and I nearly have every piece of the puzzle in place. My issue is specifically if I navigate \'up\' and restore the naviga

5条回答
  •  旧时难觅i
    2020-12-15 12:49

    To animate we can use.

    ValueAnimator drawerAnimator = ValueAnimator.ofFloat(Constants.HAMBURGER, Constants.BACK);
    drawerAnimator.addUpdateListener(drawerAnimationUpdateListener);
    drawerAnimator.setDuration(Constants.DRAWER_ANIMATION_DURATION);
    drawerAnimator.setInterpolator(new LinearInterpolator());
    

    pass action 0 for HAMBURGER icon and 1 for BACK.

    public void updateNavigationDrawer(int action) {
        drawerArrowDrawable = actionBarDrawerToggle.getDrawerArrowDrawable();
        if (action == Constants.BACK) {
            actionBarDrawerToggle.setDrawerIndicatorEnabled(false);
            actionBarDrawerToggle.setHomeAsUpIndicator(drawerArrowDrawable);
            actionBarDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //onBackPress();
                }
            });
           drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED););
        } else {
            actionBarDrawerToggle.setDrawerIndicatorEnabled(true);
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
        }
        if (drawerArrowDrawable.getProgress() != action) {
            if (action == Constants.BACK) {
                drawerAnimator.start();
            } else {
                drawerAnimator.reverse();
            }
        }
    }
    

提交回复
热议问题