Skip to content

TextView TextColor Animation

Weiping Huang edited this page Apr 6, 2017 · 3 revisions

WoWoTextViewColorAnimation performs an animation to change the text color of a TextView. Any sub-class that extends TextView is able to change its text color with this kind of animation.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addAnimations(findViewById(R.id.test1), Chameleon.RGB);
    addAnimations(findViewById(R.id.test2), Chameleon.HSV);
}

private void addAnimations(View view, Chameleon chameleon) {
    ViewAnimation viewAnimation = new ViewAnimation(view);
    viewAnimation.add(WoWoTextViewColorAnimation.builder().page(0)
            .from("#ff0000").to("#00ff00").chameleon(chameleon).build());
    viewAnimation.add(WoWoTextViewColorAnimation.builder().page(1)
            .from("#00ff00").to("#0000ff").chameleon(chameleon).build());
    viewAnimation.add(WoWoTextViewColorAnimation.builder().page(2)
            .from("#0000ff").to("#ff0000").chameleon(chameleon).build());
    viewAnimation.add(WoWoTextViewColorAnimation.builder().page(3).start(0).end(0.5)
            .from("#ff0000").to("#000000").chameleon(chameleon).build());
    viewAnimation.add(WoWoTextViewColorAnimation.builder().page(3).start(0.5).end(1)
            .from("#000000").to("#ff0000").chameleon(chameleon).build());
    wowo.addAnimation(viewAnimation);
    wowo.setEase(ease);
    wowo.setUseSameEaseBack(useSameEaseTypeBack);
    wowo.ready();
}

You may notice that there are 2 kind of discolorations of this animation. As a matter of fact, every animation that extends from SingleColorPageAnimation and MultiColorPageAnimation has a parameter named Chameleon which performs the discoloration job. Check Chameleon Wiki to know about the difference between RGB and HSV discoloration-styles and how they works.

If you wanna change text color of some custom views that do not extends from TextView. Then you can extends SingleColorPageAnimation or MultiColorPageAnimation by yourself to perform this magic. Check Custom Animation for more informations.

WoWoTextViewColorAnimation extends SingleColorPageAnimation and PageAnimation. Check more implementation details in its superclasses.

Methods List of WoWoTextViewColorAnimation.builder()

Clone this wiki locally