Animate ActionBarDrawerToggle icon programmatically

后端 未结 2 790
陌清茗
陌清茗 2020-12-17 02:34

I want to animate the drawer icon from a burger to an arrow and vice versa manually, not only when drawer is being dragged, is it possible? I\'m using support library appcom

2条回答
  •  情书的邮戳
    2020-12-17 02:53

    I found a way to animate the icon with a simple ValueAnimator and .onDrawerSlide method.

        ValueAnimator anim = ValueAnimator.ofFloat(start, end);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float slideOffset = (Float) valueAnimator.getAnimatedValue();
                drawerToggle.onDrawerSlide(drawerLayout, slideOffset);
            }
        });
        anim.setInterpolator(new DecelerateInterpolator());
        anim.setDuration(300);
        anim.start();
    

    But maybe there is a better solution.

提交回复
热议问题