9

I'm able to change the fillColor of an AnimatedVectorDrawable by using xml files.

<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/my_svg">
    <target
        android:animation="@animator/myanimator"
        android:name="color" />
</animated-vector>


<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="3000"
    android:propertyName="fillColor"
    android:valueType="intType"
    android:interpolator="@android:interpolator/decelerate_cubic"
    android:valueFrom="@color/blue"
    android:valueTo="@color/green" />

</set>

 mImageView = (ImageView)findViewById(R.id.ImageView);
 Drawable drawable = mImageView.getDrawable();

if (drawable instanceof Animatable) {
    ((Animatable) drawable).start();
}

But is there a way to change the color at runtime?

1
  • Did you find a solution to this in the end? I can't see a way of accessing an AnimatedVectorDrawable's Animators. Seems silly to me. Commented Aug 25, 2016 at 13:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.