Search code examples
androidanimationcolorstextview

How to create color changing animation? (Android)


I have a TextView and some text in it. I need to create an animation with 30 seconds duration, and it will slowly change the color of text from green to red. Any ideas?


Solution

  • 1) 30s is a really, really long time, hardly any users would wait to see the end of it.

    2) See Animating with ObjectAnimator. Something like ObjectAnimator.ofInt(textView, "textColor", Color.GREEN, Color.RED) should do what you want. Note, however, that the transition will be linear and will go through a lot of intermediary colors. until it hits #FF0000. You can of course specify the points in the middle but in general linear color transitions (in RGB) are not pretty.