Text color animation

前端 未结 8 1834
南旧
南旧 2020-12-14 10:09

Is there a way to animate a text color change (from anycolor to white)?

The only variant I came up with, is placing two textviews (with the same text) in one place,

8条回答
  •  萌比男神i
    2020-12-14 10:48

    Although I haven't found a totally distinct method, I have tried to use a TextSwitcher (with the fade animation) to create the colour-change effect. A TextSwitcher is a kind of ViewSwitcher which literally animates between two (internal) TextViews. Did you manually implement the same system unknowingly? ;) It manages a bit more of the process for you, so you may find it easier to work with (especially if you want to try more involved animations). I would create new subclass of TextSwitcher and some methods e.g. setColour() which can set the new colour and then trigger an animation. The animation code can then be moved outside of your main application.

    • make sure you keep a handle on the two TextViews that are put into the switcher
    • change the colour of the other TextView and call setText() to animate between them

    If you are already using a ViewSwitcher then I don't think there is an easier way to implement this.

提交回复
热议问题