Android animate hamburger menu when opening a fragment

I am having an AppsList fragment from which I can click an app and go to the AppDetails fragment. And I have a NavigationDrawer. So when you open the AppDetails fragment I am displaying a back arrow where the NavigationDrawer hamburger menu is placed.

The problem is that the arrow is static and it only animates when you open the NavigationDrawer.

These is a workaround for this problem in StackOverflow.

Here is the code:

 public void animateDrawerIndicator(boolean shouldAnimate) {
        ValueAnimator anim;
        if(shouldAnimate) {
            anim = ValueAnimator.ofFloat(0, 1);
        } else {
            anim = ValueAnimator.ofFloat(1, 0);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float slideOffset = (Float) valueAnimator.getAnimatedValue();
                // You should get the drawer layout and 
                // toggler from your fragment to make the animation
        anim.setInterpolator(new DecelerateInterpolator());


You may also like...