// Need the following import to get access to the app resources, since this
// class is in a sub-package.
+import android.graphics.drawable.ColorDrawable;
import com.example.android.apis.R;
import android.animation.*;
super(context);
// Create a colored background
- ShapeDrawable background = new ShapeDrawable(new RectShape());
+ ColorDrawable background = new ColorDrawable(RED);
setBackgroundDrawable(background);
- Paint paint = background.getPaint();
- paint.setColor(RED);
// Animate background color
- ValueAnimator colorAnim = ObjectAnimator.ofInt(paint, "color", BLUE);
+ ValueAnimator colorAnim = ObjectAnimator.ofInt(background, "color", BLUE);
colorAnim.setDuration(3000);
colorAnim.setEvaluator(new RGBEvaluator());
colorAnim.setRepeatCount(ValueAnimator.INFINITE);