动画导航栏颜色Android

rkm*_*max 2 android android-5.0-lollipop

我有我的风格

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="MYTheme" parent="...">
        <item name="android:navigationBarColor">@color/navigationBarColor</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

我知道我可以改变导航栏的颜色

getWindow().setNavigationBarColor(...);
Run Code Online (Sandbox Code Playgroud)

我想用动画改变颜色,当前颜色和新颜色之间的过渡

Ego*_*uba 6

您可以使用 动画颜色变化ValueAnimator.ofArgb。我必须提到它仅从 API >= 21 开始才受支持。不过,这应该不是问题,因为setNavigationBarColoris >= 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();
Run Code Online (Sandbox Code Playgroud)