Creating AnimatedVectorDrawables on Android requires you to create three xml resources that represents each of the following
animated-vector , objectAnimator and vector. The <vector /> is the actual file that represents the vector drawable.
The <objectAnimator /> defines the animation to apply to different parts of the vector and the <animated-vector />
is used to link the vector drawable and the animation together.
As an example, to create an animated vector drawable that transforms a play icon to stop icon, the following xml files will be created. The Vector drawable:
Then an animator that defines the transformation on the pathData property of the vector and morphs it into the stop icon.
Finally, we create the AnimatedVectorDrawable xml file links the animation to the vector:
At IO 2016, Google announced a new xml bundle format that enables creating AnimatedVectorDrawables using a single xml file.
The XML bundle format requires build tools version 24 and above to work, and also requires adding the aapt namespace to your xml declaration.
For example, the three xml files for the AnimatedVectorDrawable above can be written in a single xml file as shown below:
The keys things to note in this new format are:
Inclusion of the appt namespace inside the <animated-vector .. opening xml tag:
The android:drawable atttibute of the <animated-vector has been removed and now you put the vector xml directly within this tag:
Finally, within each of the <tagret.. tags, you can either directly specify the objectAnimator wihtin an <appt:attr name="android:animation>, or
reference an external animation located in res/animator/...
You can add the tools:ignore="MissingPrefix" to suppress lint warnings because the bundle format is not yet recognized by lint.