我的风格
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MYTheme" parent="...">
<item name="android:navigationBarColor">@color/navigationBarColor</item>
</style>
</resources>
我知道我可以用
更改导航栏的颜色getWindow().setNavigationBarColor(...);
我想用动画改变颜色,当前颜色和新颜色之间的过渡
答案 0 :(得分:4)
您可以使用ValueAnimator.ofArgb
设置颜色更改动画。我必须提一下,只有从API&gt; = 21开始才支持它。但这应该不是问题,因为setNavigationBarColor
也是&gt; = 21。
int from = getWindow().getNavigationBarColor();
int to = Color.BLACK; // new color to animate to
ValueAnimator colorAnimation = ValueAnimator.ofArgb(from, to);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
getWindow().setNavigationBarColor((Integer) animator.getAnimatedValue());
}
});
colorAnimation.start();
答案 1 :(得分:0)
我同意Egor N的回答。但我的答案将使你的应用程序向后兼容API 11而不是21,正如他所建议的那样。
我分享this answer
Integer colorFrom = getWindow().getNavigationBarColor();
Integer colorTo = Color.BLACK;
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
getWindow().setNavigationBarColor((Integer) animator.getAnimatedValue());
}
});
colorAnimation.start();