Animate drawer icon into arrow on setDisplayHomeAsUpEnabled?

前端 未结 3 736
一个人的身影
一个人的身影 2020-12-07 18:21

I\'m using setDisplayHomeAsUpEnabled in order to show the arrow instead of the drawer \"burger\" icon but it\'s not getting animated or anything. Instead it shows the arrow

3条回答
  •  情歌与酒
    2020-12-07 18:54

    I haven't tested this, but you may be able to achieve this by animating a float between 0 (drawer closed) and 1 (drawer open) and then passing the value into ActionBarDrawerToggle.onDrawerSlide(View, float). I believe that's how the toggle determines what state the animated toggle should be in.

    Something like this should work.

    ValueAnimator anim = ValueAnimator.ofFloat(start, end);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float slideOffset = (Float) valueAnimator.getAnimatedValue();
            toolbarDrawerToggle.onDrawerSlide(drawerLayout, slideOffset);
        }
    });
    anim.setInterpolator(new DecelerateInterpolator());
    // You can change this duration to more closely match that of the default animation.
    anim.setDuration(500);
    anim.start();
    

提交回复
热议问题