如何使用动画更改操作栏颜色?

Tud*_* S. 1 android android-animation android-actionbar

每当服务器上的配色方案发生变化时,它也应该在应用程序上进行更改.到目前为止,我已经设法让动作栏改变它的颜色.唯一的问题是,当收到通知时,颜色会立即发生变化.有没有办法动画从旧颜色到新颜色的过渡?

谢谢!

Djo*_*sic 16

在此示例中,将更改颜色(状态栏,工具栏)(带动画),您需要稍微修改它以满足您自己的需要.

        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();
Run Code Online (Sandbox Code Playgroud)