Android 12 Developer Preview is here! Try it out, and give us your feedback!


open class AnimatedStateListDrawableCompat : StateListDrawable, TintAwareDrawable

A Drawable providing animated transitions between states.

A port of compatible with older versions of the platform.

This drawable can be defined in an XML file with the <animated-selector> element. Each keyframe Drawable is defined in a nested <item> element. Transitions are defined in a nested <transition> element.

Notable exceptions not supported by this class:

  • drawables defined as children of <item>s or <transition>s (except vectors) ignore theme attributes prior to API level 21
  • Animated vector transitions do not support reversing prior to API level 24
android.R.attr#state_focused android.R.attr#state_window_focused android.R.attr#state_enabled android.R.attr#state_checkable android.R.attr#state_checked android.R.attr#state_selected android.R.attr#state_activated android.R.attr#state_active android.R.attr#state_single android.R.attr#state_first android.R.attr#state_middle android.R.attr#state_last android.R.attr#state_pressed


Public constructors

Public methods
open Unit
addState(@NonNull stateSet: IntArray, @NonNull drawable: Drawable, id: Int)

Add a new drawable to the set of keyframes.

open Unit
addTransition(fromId: Int, toId: Int, @NonNull transition: T, reversible: Boolean)

Adds a new transition between keyframes.

open static AnimatedStateListDrawableCompat?
create(@NonNull context: Context, @DrawableRes resId: Int, @Nullable theme: Theme?)

Creates an AnimatedStateListDrawableCompat.

open static AnimatedStateListDrawableCompat!
createFromXmlInner(@NonNull context: Context, @NonNull resources: Resources, @NonNull parser: XmlPullParser, @NonNull attrs: AttributeSet, @Nullable theme: Theme?)

Create a AnimatedStateListDrawableCompat from inside an XML document using an optional Resources.Theme.

open Unit
inflate(@NonNull context: Context, @NonNull resources: Resources, @NonNull parser: XmlPullParser, @NonNull attrs: AttributeSet, @Nullable theme: Theme?)

Inflate this Drawable from an XML resource optionally styled by a theme.

open Boolean

open Unit

open Drawable

open Boolean
setVisible(visible: Boolean, restart: Boolean)

Protected methods
open Boolean
onStateChange(stateSet: IntArray!)

Public constructors



Public methods


open fun addState(
    @NonNull stateSet: IntArray,
    @NonNull drawable: Drawable,
    id: Int
): Unit

Add a new drawable to the set of keyframes.

stateSet IntArray: An array of resource IDs to associate with the keyframe
drawable Drawable: The drawable to show when in the specified state, may not be null
id Int: The unique identifier for the keyframe


open fun <T> addTransition(