Skip to content

Instantly share code, notes, and snippets.

@AKiniyalocts
Created September 1, 2016 19:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AKiniyalocts/bd186c16ae3556193bc20c5b00f1792f to your computer and use it in GitHub Desktop.
Save AKiniyalocts/bd186c16ae3556193bc20c5b00f1792f to your computer and use it in GitHub Desktop.
Status/Toolbar color transition animator
private void safeAnimateToolbarAndStatus(boolean reverse){
Integer colorFrom = reverse ? ContextCompat.getColor(this, R.color.limeade) : ContextCompat.getColor(this, R.color.b4);
Integer colorTo = reverse ? ContextCompat.getColor(this, R.color.b4) : ContextCompat.getColor(this, R.color.limeade);
Integer colorStatusFrom = reverse ? ContextCompat.getColor(this, R.color.limeade_pressed) : ContextCompat.getColor(this, R.color.dark_grey);
Integer colorStatusTo = reverse ? ContextCompat.getColor(this, R.color.dark_grey) : ContextCompat.getColor(this, R.color.limeade_pressed);
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
ValueAnimator colorStatusAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorStatusFrom, colorStatusTo);
colorAnimation.addUpdateListener(animator -> toolbar.setBackgroundColor((Integer) animator.getAnimatedValue()));
colorStatusAnimation.addUpdateListener(animator -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
this.getWindow().setStatusBarColor((Integer) animator.getAnimatedValue());
}
});
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setDuration(700);
animatorSet.playTogether(colorAnimation, colorStatusAnimation);
animatorSet.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment