Created
December 28, 2016 20:41
-
-
Save shrukul/d0eae14851c05c0e2ad3ed15c69872d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { | |
ValueAnimator anim; | |
@Override | |
public void onBackStackChanged() { | |
if (getSupportFragmentManager().getBackStackEntryCount() > 0) { | |
// getSupportActionBar().setDisplayHomeAsUpEnabled(true); // show back button | |
anim = ValueAnimator.ofFloat(0, 1); | |
toolbar.setNavigationOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
onBackPressed(); | |
} | |
}); | |
} else { | |
anim = ValueAnimator.ofFloat(1, 0); | |
//show hamburger | |
getSupportActionBar().setDisplayHomeAsUpEnabled(false); | |
actionBarDrawerToggle.syncState(); | |
toolbar.setNavigationOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
drawerLayout.openDrawer(GravityCompat.START); | |
} | |
}); | |
} | |
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | |
@Override | |
public void onAnimationUpdate(ValueAnimator valueAnimator) { | |
float slideOffset = (Float) valueAnimator.getAnimatedValue(); | |
actionBarDrawerToggle.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(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment