AnimatedStateListDrawableCompat


public class AnimatedStateListDrawableCompat extends 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 methods

void
addState(@NonNull int[] stateSet, @NonNull Drawable drawable, int id)

Add a new drawable to the set of keyframes.

void
<T extends Drawable & Animatable> addTransition(
    int fromId,
    int toId,
    @NonNull T transition,
    boolean reversible
)

Adds a new transition between keyframes.

static @Nullable AnimatedStateListDrawableCompat
create(
    @NonNull Context context,
    @DrawableRes int resId,
    @Nullable Resources.Theme theme
)

Creates an AnimatedStateListDrawableCompat.

static @NonNull AnimatedStateListDrawableCompat
createFromXmlInner(
    @NonNull Context context,
    @NonNull Resources resources,
    @NonNull XmlPullParser parser,
    @NonNull AttributeSet attrs,
    @Nullable Resources.Theme theme
)

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

void
inflate(
    @NonNull Context context,
    @NonNull Resources resources,
    @NonNull XmlPullParser parser,
    @NonNull AttributeSet attrs,
    @Nullable Resources.Theme theme
)

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

boolean
void
@NonNull Drawable
boolean
setVisible(boolean visible, boolean restart)

Protected methods

boolean
onStateChange(@NonNull int[] stateSet)

Inherited methods

From android.graphics.drawable.Drawable
void
boolean
void
final Rect
final void
copyBounds(Rect bounds)
static Drawable
static Drawable
createFromResourceStream(
    Resources res,
    TypedValue value,
    InputStream is,
    String srcName
)
static Drawable
static Drawable
static Drawable
createFromXmlInner(
    Resources r,
    XmlPullParser parser,
    AttributeSet attrs
)
abstract void
int
final Rect
Drawable.Callback
int
ColorFilter
Drawable.ConstantState
Drawable
Rect
void
int
int
int
final int
int
int
abstract int

This method is deprecated.

Insets
void
boolean
getPadding(Rect padding)
int[]
Region
boolean
void
void
boolean
boolean
boolean
boolean
final boolean
void
Drawable
void
boolean
onLayoutDirectionChanged(int layoutDirection)
boolean
onLevelChange(int level)
boolean
onStateChange(int[] state)
static int
resolveOpacity(int op1, int op2)
void
scheduleSelf(Runnable what, long when)
abstract void
setAlpha(int p)
void
setAutoMirrored(boolean mirrored)
void
setBounds(int left, int top, int right, int bottom)
final void
void
abstract void
void
setDither(boolean dither)

This method is deprecated.

void
setFilterBitmap(boolean filter)
void
setHotspot(float x, float y)
void
setHotspotBounds(int left, int top, int right, int bottom)
final boolean
setLayoutDirection(int layoutDirection)
final boolean
setLevel(int level)
boolean
setState(int[] stateSet)
void
setTint(int tintColor)
void
void
void
boolean
setVisible(boolean visible, boolean restart)
void
From android.graphics.drawable.Drawable.Callback
abstract void
abstract void
scheduleDrawable(Drawable p, Runnable p1, long p2)
abstract void
From androidx.appcompat.graphics.drawable.DrawableContainerCompat
boolean
@RequiresApi(value = 21)
canApplyTheme()
void
draw(@NonNull Canvas canvas)
int
int
final Drawable.ConstantState
@NonNull Drawable
void
int
int
int
int
int

This method is deprecated.

void
@RequiresApi(value = 21)
getOutline(@NonNull Outline outline)
boolean
void
boolean
void
boolean
onLayoutDirectionChanged(int layoutDirection)
boolean
onLevelChange(int level)
boolean
onStateChange(@NonNull int[] state)
void
scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when)
void
setAlpha(int alpha)
void
setAutoMirrored(boolean mirrored)
void
void
setDither(boolean dither)

This method is deprecated.

void

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

void

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

void
setHotspot(float x, float y)
void
setHotspotBounds(int left, int top, int right, int bottom)
void
setTint(@ColorInt int tintColor)
void
void
From androidx.appcompat.graphics.drawable.StateListDrawableCompat
void
addState(int[] stateSet, Drawable drawable)

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

void

Public constructors

AnimatedStateListDrawableCompat

Added in 1.1.0
public AnimatedStateListDrawableCompat()

Public methods

addState

Added in 1.1.0
public void addState(@NonNull int[] stateSet, @NonNull Drawable drawable, int id)

Add a new drawable to the set of keyframes.

Parameters
@NonNull int[] stateSet

An array of resource IDs to associate with the keyframe

@NonNull Drawable drawable

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

int id

The unique identifier for the keyframe

addTransition

Added in 1.1.0
public void <T extends Drawable & Animatable> addTransition(
    int fromId,
    int toId,
    @NonNull T transition,
    boolean reversible
)

Adds a new transition between keyframes.

Parameters
int fromId

Unique identifier of the starting keyframe

int toId

Unique identifier of the ending keyframe

@NonNull T transition

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

boolean reversible

Whether the transition can be reversed

create

Added in 1.1.0
public static @Nullable AnimatedStateListDrawableCompat create(
    @NonNull Context context,
    @DrawableRes int resId,
    @Nullable Resources.Theme theme
)

Creates an AnimatedStateListDrawableCompat.

Parameters
@NonNull Context context

context to inflate against

@DrawableRes int resId

the resource ID for AnimatedStateListDrawable object.

@Nullable Resources.Theme theme

the theme to apply, may be null.

Returns
@Nullable AnimatedStateListDrawableCompat

a new AnimatedStateListDrawableCompat or null if parsing error is found.

createFromXmlInner

Added in 1.1.0
public static @NonNull AnimatedStateListDrawableCompat createFromXmlInner(
    @NonNull Context context,
    @NonNull Resources resources,
    @NonNull XmlPullParser parser,
    @NonNull AttributeSet attrs,
    @Nullable Resources.Theme theme
)

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
public void inflate(
    @NonNull Context context,
    @NonNull Resources resources,
    @NonNull XmlPullParser parser,
    @NonNull AttributeSet attrs,
    @Nullable Resources.Theme theme
)

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

Parameters
@NonNull Context context

context to inflate against

@NonNull Resources resources

Resources used to resolve attribute values

@NonNull XmlPullParser parser

XML parser from which to inflate this Drawable

@NonNull AttributeSet attrs

Base set of attribute values

@Nullable Resources.Theme 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

public boolean isStateful()

jumpToCurrentState

public void jumpToCurrentState()

mutate

public @NonNull Drawable mutate()

setVisible

public boolean setVisible(boolean visible, boolean restart)

Protected methods

onStateChange

protected boolean onStateChange(@NonNull int[] stateSet)