The Android Developer Challenge is back! Submit your idea before December 2.

AnimatedStateListDrawableCompat

open class AnimatedStateListDrawableCompat : StateListDrawable, TintAwareDrawable
androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat

A Drawable providing animated transitions between states.

A port of android.graphics.drawable.AnimatedStateListDrawable 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

Summary

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

<init>

AnimatedStateListDrawableCompat()

Public methods

addState

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

Add a new drawable to the set of keyframes.

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

addTransition

open fun <T> addTransition(fromId: Int, toId: Int, @NonNull transition: T, reversible: Boolean): Unit where T : Drawable!, T : Animatable!

Adds a new transition between keyframes.

Parameters
fromId Int: Unique identifier of the starting keyframe
toId Int: Unique identifier of the ending keyframe
transition Int: An Animatable drawable to use as a transition, may not be null
reversible Int: Whether the transition can be reversed

create

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

Creates an AnimatedStateListDrawableCompat.

Parameters
context Context: context to inflate against
resId Context: the resource ID for AnimatedStateListDrawable object.
theme Context: the theme to apply, may be null.
Return
AnimatedStateListDrawableCompat?: a new AnimatedStateListDrawableCompat or null if parsing error is found.

createFromXmlInner

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

Create a AnimatedStateListDrawableCompat from inside an XML document using an optional Resources.Theme. Called on a parser positioned at a tag in an XML document, tries to create an AnimatedStateListDrawableCompat from that tag.

inflate

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

Inflate this Drawable from an XML resource optionally styled by a theme. This can't be called more than once for each Drawable.

Parameters
r Context: Resources used to resolve attribute values
parser Context: XML parser from which to inflate this Drawable
attrs Context: Base set of attribute values
theme Context: Theme to apply, may be null
context Context: context to inflate against
resources Context: Resources used to resolve attribute values
Exceptions
XmlPullParserException
IOException

isStateful

open fun isStateful(): Boolean

jumpToCurrentState

open fun jumpToCurrentState(): Unit

mutate

open fun mutate(): Drawable

setVisible

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

Protected methods

onStateChange

protected open fun onStateChange(stateSet: IntArray!): Boolean