You can create an animated icon using animated raster and raster frames. On L, you can use AnimatedStateListDrawable to create stateful animations (such as checkbox animations).
Here is an example of an AnimatedDrawable (this is actually an implementation of the checkbox in the L preview) using 15 ms frames that can be started and stopped from the code:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:duration="15" android:drawable="@drawable/my_icon_frame_000" /> ...additional frames... </animation-list>
And here is the AnimatedStateListDrawable animation using AnimatedDrawable transitions to implement a checkbox animation that starts and stops automatically based on the View state:
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="false" android:state_checked="true"> <bitmap android:src="@drawable/btn_check_to_on_mtrl_015" android:tint="?attr/colorControlActivated" android:alpha="?attr/disabledAlpha" /> </item> <item android:state_enabled="false"> <bitmap android:src="@drawable/btn_check_to_on_mtrl_000" android:tint="?attr/colorControlNormal" android:alpha="?attr/disabledAlpha" /> </item> <item android:state_checked="true" android:id="@+id/on"> <bitmap android:src="@drawable/btn_check_to_on_mtrl_015" android:tint="?attr/colorControlActivated" /> </item> <item android:id="@+id/off"> <bitmap android:src="@drawable/btn_check_to_on_mtrl_000" android:tint="?attr/colorControlNormal" /> </item> <transition android:fromId="@+id/off" android:toId="@+id/on"> <animation-list> <item android:duration="15"> <bitmap android:src="@drawable/btn_check_to_on_mtrl_000" android:tint="?attr/colorControlNormal" /> </item> ...additional frames... </animation-list> </transition> <transition android:fromId="@+id/on" android:toId="@+id/off"> <animation-list> <item android:duration="15"> <bitmap android:src="@drawable/btn_check_to_off_mtrl_000" android:tint="?attr/colorControlActivated" /> </item> ...additional frames... </animation-list> </transition> </animated-selector>
alanv source share