/ Published in: Java

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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);
Comments
