【发布时间】:2018-12-11 12:03:21
【问题描述】:
我想用交叉淡入淡出动画实现变色状态栏,如下所示。我能知道怎么做吗?
状态栏变色动画:
谢谢!
已编辑(2018 年 7 月 7 日) - 伙计们,这不是重复的
不管怎样,我终于找到了使用 ValueAnimator 和 ArgbEvaluator 的解决方案。
val mColorAnimation = ValueAnimator.ofObject(ArgbEvaluator(), firstColor, secondColor, thirdColor, fourthColor)
mColorAnimation.duration = (pageCount - 1) * 10000000000L
mColorAnimation.addUpdateListener { animator ->
val color = animator.animatedValue as Int
// change status, navigation, and action bar color
window.statusBarColor = color
window.navigationBarColor = color
supportActionBar?.setBackgroundDrawable(ColorDrawable(color))
}
main_viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener{
override fun onPageScrollStateChanged(state: Int) { /* unused */ }
override fun onPageSelected(position: Int) { /* unused */ }
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
mColorAnimation.currentPlayTime = ((positionOffset + position) * 10000000000).toLong()
}
})
【问题讨论】:
标签: android user-interface animation statusbar