Android L action items animation

android, android-5.0-lollipop, animation

Solution

You can create frame-based animated icons using the <animation-list> XML element or AnimationDrawable class. Starting in L, you can create state-based animated icons using the <animated-selector> XML element or AnimatedStateListDrawable class.

Here is an example of the animated check box from the L preview:

<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/colorControlActivated" />
            </item>
            ...

Here there are several state-based frames implemented as PNGs and a transition defined between the "off" and "on" states implemented as a PNG-based animation. The last three numbers of the drawable names indicate the frame, the check box uses 15 frames for each of its "to checked" and "to unchecked" animations.

You can also use the <animation-list> on its own for a simple animation with only two states.

Problem

Android L preview has lots cool animations, especially I am interesting in animating action items inside `ActionBar`. Here video of this animation from the google material design web page. Does anybody know how to implement this animation?

Original source