Return to Snippet

Revision: 31318
at September 3, 2010 00:15 by sospartan


Initial Code
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;

public class BGColorTransitionDrawable extends TransitionDrawable {
        private int interval;
        public BGColorTransitionDrawable(Drawable[] layers) {
                super(layers);
                interval = 500;
                initVars();
        }
        public BGColorTransitionDrawable(Drawable[] layers, int interval) {
                super(layers);
                this.interval = interval;
                initVars();
        }
        private void initVars(){
                setCrossFadeEnabled(true);
                setId(0,0);
                setId(1,1);
        }
        public void changeColor(int color){
                setDrawableByLayerId(0, getDrawable(1));
                setDrawableByLayerId(1, new ColorDrawable(color));
                startTransition(interval);
        }

}

I set and call it like so.

                ColorDrawable layers[] = new ColorDrawable[2];
                layers[0] = new ColorDrawable(0xff0000ff);
                layers[1] = new ColorDrawable(0xffff0000);
                backgroundColorAnimation = new BGColorTransitionDrawable(layers);
                vColorSwapper.setBackgroundDrawable(backgroundColorAnimation);

                backgroundColorAnimation.setColor(0xff00ff00);

Initial URL

                                

Initial Description

                                

Initial Title
View background color animation

Initial Tags
background, color, animation, android

Initial Language
Java