AnimatedStateListDrawableCompat

class AnimatedStateListDrawableCompat : StateListDrawableCompat


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
state_focusedstate_window_focusedstate_enabledstate_checkablestate_checkedstate_selectedstate_activatedstate_activestate_singlestate_firststate_middlestate_laststate_pressed

Summary

Public constructors

Public functions

Unit
addState(stateSet: IntArray, drawable: Drawable, id: Int)

Add a new drawable to the set of keyframes.

Unit
<T : Drawable? & Animatable?> addTransition(
    fromId: Int,
    toId: Int,
    transition: T,
    reversible: Boolean
)

Adds a new transition between keyframes.

java-static AnimatedStateListDrawableCompat?
create(context: Context, resId: @DrawableRes Int, theme: Resources.Theme?)

Creates an AnimatedStateListDrawableCompat.

java-static AnimatedStateListDrawableCompat
createFromXmlInner(
    context: Context,
    resources: Resources,
    parser: XmlPullParser,
    attrs: AttributeSet,
    theme: Resources.Theme?
)

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

Unit
inflate(
    context: Context,
    resources: Resources,
    parser: XmlPullParser,
    attrs: AttributeSet,
    theme: Resources.Theme?
)

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

Boolean
Unit
Drawable
abstract Unit
abstract Unit
abstract Unit
Boolean
setVisible(visible: Boolean, restart: Boolean)

Protected functions

Boolean

Inherited functions

From android.graphics.drawable.Drawable
Unit
Boolean
Unit
Rect!
Unit
copyBounds(bounds: Rect!)
java-static Drawable!
createFromPath(pathName: String!)
java-static Drawable!
createFromResourceStream(
    res: Resources!,
    value: TypedValue!,
    is: InputStream!,
    srcName: String!
)
java-static Drawable!
createFromStream(is: InputStream!, srcName: String!)
java-static Drawable!
java-static Drawable!
createFromXmlInner(
    r: Resources!,
    parser: XmlPullParser!,
    attrs: AttributeSet!
)
abstract Unit
draw(p: Canvas!)
Int
Rect!
Drawable.Callback!
Int
ColorFilter!
Drawable.ConstantState!
Drawable!
Rect!
Unit
Int
Int
Int
Int
Int
Int
abstract Int

This function is deprecated.

Insets!
Unit
getOutline(outline: Outline!)
Boolean
getPadding(padding: Rect!)
IntArray<Int>!
Region!
Boolean
Unit
inflate(r: Resources!, parser: XmlPullParser!, attrs: AttributeSet!)
Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Unit
Drawable!
Unit
onBoundsChange(bounds: Rect!)
Boolean
onLayoutDirectionChanged(layoutDirection: Int)
Boolean
Boolean
java-static Int
resolveOpacity(op1: Int, op2: Int)
Unit
scheduleSelf(what: Runnable!, when: Long)
abstract Unit
Unit
Unit
setBounds(left: Int, top: Int, right: Int, bottom: Int)
Unit
Unit
abstract Unit
Unit
setDither(dither: Boolean)

This function is deprecated.

Unit
Unit
Unit
setHotspotBounds(left: Int, top: Int, right: Int, bottom: Int)
Boolean
setLayoutDirection(layoutDirection: Int)
Boolean
setLevel(level: Int)
Boolean
setState(stateSet: IntArray!)
Unit
setTint(tintColor: Int)
Unit
Unit
Unit
Boolean
setVisible(visible: Boolean, restart: Boolean)
Unit
From android.graphics.drawable.Drawable.Callback
abstract Unit
abstract Unit
scheduleDrawable(p: Drawable!, p1: Runnable!, p2: Long)
abstract Unit
From androidx.appcompat.graphics.drawable.DrawableContainerCompat
Boolean
@RequiresApi(value = 21)
canApplyTheme()
Unit
draw(canvas: Canvas)
Int
Int
Drawable.ConstantState!
Drawable
Unit
Int
Int
Int
Int
Int

This function is deprecated.

Unit
@RequiresApi(value = 21)
getOutline(outline: Outline)
Boolean
getPadding(padding: Rect)
Unit
Boolean
Unit
onBoundsChange(bounds: Rect!)
Boolean
onLayoutDirectionChanged(layoutDirection: Int)
Boolean
Boolean
Unit
scheduleDrawable(who: Drawable, what: Runnable, when: Long)
Unit
setAlpha(alpha: Int)
Unit
Unit
setColorFilter(colorFilter: ColorFilter!)
Unit
setDither(dither: Boolean)

This function is deprecated.

Unit

Change the global fade duration when a new drawable is entering the scene.

Unit

Change the global fade duration when a new drawable is leaving the scene.

Unit
Unit
setHotspotBounds(left: Int, top: Int, right: Int, bottom: Int)
Unit
setTint(tintColor: @ColorInt Int)
Unit
Unit
From androidx.appcompat.graphics.drawable.StateListDrawableCompat
Unit
addState(stateSet: IntArray!, drawable: Drawable!)

Add a new image/string ID to the set of images.

Unit
@RequiresApi(value = 21)
applyTheme(theme: Resources.Theme)

Public constructors

AnimatedStateListDrawableCompat

Added in 1.1.0
AnimatedStateListDrawableCompat()

Public functions

addState

Added in 1.1.0
fun addState(stateSet: IntArray, 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: Drawable

The drawable to show when in the specified state, may not be null

id: Int

The unique identifier for the keyframe

addTransition

Added in 1.1.0
fun <T : Drawable? & Animatable?> addTransition(
    fromId: Int,
    toId: Int,
    transition: T,
    reversible: Boolean
): Unit

Adds a new transition between keyframes.

Parameters
fromId: Int

Unique identifier of the starting keyframe

toId: Int

Unique identifier of the ending keyframe

transition: T

An Animatable drawable to use as a transition, may not be null

reversible: Boolean

Whether the transition can be reversed

create

Added in 1.1.0
java-static fun create(context: Context, resId: @DrawableRes Int, theme: Resources.Theme?): AnimatedStateListDrawableCompat?

Creates an AnimatedStateListDrawableCompat.

Parameters
context: Context

context to inflate against

resId: @DrawableRes Int

the resource ID for AnimatedStateListDrawable object.

theme: Resources.Theme?

the theme to apply, may be null.

Returns
AnimatedStateListDrawableCompat?

a new AnimatedStateListDrawableCompat or null if parsing error is found.

createFromXmlInner

Added in 1.1.0
java-static fun createFromXmlInner(
    context: Context,
    resources: Resources,
    parser: XmlPullParser,
    attrs: AttributeSet,
    theme: Resources.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

Added in 1.1.0
fun inflate(
    context: Context,
    resources: Resources,
    parser: XmlPullParser,
    attrs: AttributeSet,
    theme: Resources.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
context: Context

context to inflate against

resources: Resources

Resources used to resolve attribute values

parser: XmlPullParser

XML parser from which to inflate this Drawable

attrs: AttributeSet

Base set of attribute values

theme: Resources.Theme?

Theme to apply, may be null

Throws
org.xmlpull.v1.XmlPullParserException

if the XML is malformed

java.io.IOException

if the XML could not be read

isStateful

fun isStateful(): Boolean

jumpToCurrentState

fun jumpToCurrentState(): Unit

mutate

fun mutate(): Drawable

setTint

abstract fun setTint(tint: @ColorInt Int): Unit

setTintList

abstract fun setTintList(tint: ColorStateList!): Unit

setTintMode

abstract fun setTintMode(tintMode: PorterDuff.Mode!): Unit

setVisible

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

Protected functions

onStateChange

protected fun onStateChange(stateSet: IntArray): Boolean