How do you animate the change of background color of a view on Android?
For example:
I have a view with a red background color. The background color of the
This is the method I use in a Base Activity to change background. I'm using GradientDrawables generated in code, but could be adapted to suit.
protected void setPageBackground(View root, int type){
if (root!=null) {
Drawable currentBG = root.getBackground();
//add your own logic here to determine the newBG
Drawable newBG = Utils.createGradientDrawable(type);
if (currentBG==null) {
if(Build.VERSION.SDK_INT
update: In case anyone runs in to same issue I found, for some reason on Android <4.3 using setCrossFadeEnabled(true)
cause a undesirable white out effect so I had to switch to a solid colour for <4.3 using @Roman Minenok ValueAnimator method noted above.