如何使用动画更改操作栏颜色?
How can I change the action bar colour with animation?
每当服务器上的配色方案发生变化时,它也应该在应用程序上发生变化。到目前为止,我已经设法让操作栏改变了颜色。唯一的问题是当收到通知时,颜色会瞬间改变。有没有办法制作从旧颜色到新颜色的动画过渡?
谢谢!
在此示例中,两种颜色(状态栏、工具栏)都将更改(带有动画),您需要对其进行一些修改以满足您自己的需要。
Integer colorFrom = Color.parseColor(ThemeColor.getPrevColor());
Integer colorTo = Color.parseColor(ThemeColor.getColor());
Integer colorStatusFrom = Color.parseColor(ThemeColor.getPrevStatusColor());
Integer colorStatusTo = Color.parseColor(ThemeColor.getStatusColor());
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
ValueAnimator colorStatusAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorStatusFrom, colorStatusTo);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
toolbar.setBackgroundColor((Integer) animator.getAnimatedValue());
}
});
colorStatusAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
if (currentapiVersion >= Build.VERSION_CODES.LOLLIPOP) {
getActivity().getWindow().setStatusBarColor((Integer) animator.getAnimatedValue());
}
if (currentapiVersion == Build.VERSION_CODES.KITKAT) {
tintManager.setStatusBarTintColor((Integer) animator.getAnimatedValue());
}
}
});
colorAnimation.setDuration(1300);
colorAnimation.setStartDelay(0);
colorAnimation.start();
colorStatusAnimation.setDuration(1300);
colorStatusAnimation.setStartDelay(0);
colorStatusAnimation.start();
每当服务器上的配色方案发生变化时,它也应该在应用程序上发生变化。到目前为止,我已经设法让操作栏改变了颜色。唯一的问题是当收到通知时,颜色会瞬间改变。有没有办法制作从旧颜色到新颜色的动画过渡?
谢谢!
在此示例中,两种颜色(状态栏、工具栏)都将更改(带有动画),您需要对其进行一些修改以满足您自己的需要。
Integer colorFrom = Color.parseColor(ThemeColor.getPrevColor());
Integer colorTo = Color.parseColor(ThemeColor.getColor());
Integer colorStatusFrom = Color.parseColor(ThemeColor.getPrevStatusColor());
Integer colorStatusTo = Color.parseColor(ThemeColor.getStatusColor());
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
ValueAnimator colorStatusAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorStatusFrom, colorStatusTo);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
toolbar.setBackgroundColor((Integer) animator.getAnimatedValue());
}
});
colorStatusAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
if (currentapiVersion >= Build.VERSION_CODES.LOLLIPOP) {
getActivity().getWindow().setStatusBarColor((Integer) animator.getAnimatedValue());
}
if (currentapiVersion == Build.VERSION_CODES.KITKAT) {
tintManager.setStatusBarTintColor((Integer) animator.getAnimatedValue());
}
}
});
colorAnimation.setDuration(1300);
colorAnimation.setStartDelay(0);
colorAnimation.start();
colorStatusAnimation.setDuration(1300);
colorStatusAnimation.setStartDelay(0);
colorStatusAnimation.start();