StateListDrawableCompat


public class StateListDrawableCompat extends DrawableContainerCompat

Known direct subclasses
AnimatedStateListDrawableCompat

A Drawable providing animated transitions between states.


Lets you assign a number of graphic images to a single Drawable and swap out the visible item by a string ID value.

It can be defined in an XML file with the <selector> element. Each state Drawable is defined in a nested <item> element. For more information, see the guide to Drawable Resources. visiblevariablePaddingconstantSizestate_focusedstate_window_focusedstate_enabledstate_checkablestate_checkedstate_selectedstate_activatedstate_activestate_singlestate_firststate_middlestate_laststate_pressed

Adapted from platform class; altered with API level checks as necessary &uses ResourceManagerInternal for Drawable inflation.

Summary

Public constructors

Creates an empty state list drawable.

Public methods

void
addState(int[] stateSet, Drawable drawable)

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

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

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

boolean
@NonNull Drawable

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
void
boolean
onLayoutDirectionChanged(int layoutDirection)
boolean
onLevelChange(int level)
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
boolean
setVisible(boolean visible, boolean restart)
void

Public constructors

StateListDrawableCompat

Added in 1.6.0
public StateListDrawableCompat()

Creates an empty state list drawable.

Public methods

addState

Added in 1.6.0
public void addState(int[] stateSet, Drawable drawable)

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

Parameters
int[] stateSet

- An array of resource Ids to associate with the image. Switch to this image by calling setState().

Drawable drawable

-The image to show.

applyTheme

@RequiresApi(value = 21)
public void applyTheme(@NonNull Resources.Theme theme)

inflate

Added in 1.6.0
public void inflate(
    @NonNull Context context,
    @NonNull Resources r,
    @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 Resources r

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

isStateful

public boolean isStateful()

mutate

public @NonNull Drawable mutate()

Protected methods

onStateChange

protected boolean onStateChange(@NonNull int[] stateSet)