public class StateListDrawable extends DrawableContainer
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.
DrawableContainer.DrawableContainerState
Drawable.Callback, Drawable.ConstantState
Constructor and Description |
---|
StateListDrawable() |
Modifier and Type | Method and Description |
---|---|
void |
addState(int[] stateSet,
Drawable drawable)
Add a new image/string ID to the set of images.
|
void |
applyTheme(Resources.Theme theme)
Applies the specified theme to this Drawable and its children.
|
void |
clearMutated()
Clears the mutated state, allowing this drawable to be cached and
mutated again.
|
int |
getStateCount()
Gets the number of states contained in this drawable.
|
Drawable |
getStateDrawable(int index)
Gets the drawable at an index.
|
int |
getStateDrawableIndex(int[] stateSet)
Gets the index of the drawable with the provided state set.
|
int[] |
getStateSet(int index)
Gets the state set at an index.
|
void |
inflate(Resources r,
XmlPullParser parser,
AttributeSet attrs,
Resources.Theme theme)
Inflate this Drawable from an XML resource optionally styled by a theme.
|
boolean |
isStateful()
Indicates whether this drawable will change its appearance based on
state.
|
Drawable |
mutate()
Make this drawable mutable.
|
protected boolean |
onStateChange(int[] stateSet)
Override this in your subclass to change appearance if you recognize the
specified state.
|
protected void |
setConstantState(DrawableContainer.DrawableContainerState state) |
canApplyTheme, draw, getAlpha, getChangingConfigurations, getConstantState, getCurrent, getCurrentIndex, getHotspotBounds, getIntrinsicHeight, getIntrinsicWidth, getMinimumHeight, getMinimumWidth, getOpacity, getOpticalInsets, getOutline, getPadding, invalidateDrawable, isAutoMirrored, jumpToCurrentState, onBoundsChange, onLayoutDirectionChanged, onLevelChange, scheduleDrawable, selectDrawable, setAlpha, setAutoMirrored, setColorFilter, setCurrentIndex, setDither, setEnterFadeDuration, setExitFadeDuration, setHotspot, setHotspotBounds, setTintList, setTintMode, setVisible, unscheduleDrawable, updateDensity
clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXml, createFromXmlInner, createFromXmlInner, getBounds, getCallback, getColorFilter, getDirtyBounds, getLayoutDirection, getLevel, getState, getTransparentRegion, inflate, invalidateSelf, isFilterBitmap, isProjected, isVisible, obtainAttributes, parseTintMode, resolveOpacity, scheduleSelf, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setFilterBitmap, setLayoutDirection, setLevel, setState, setTint, setXfermode, unscheduleSelf
public void addState(int[] stateSet, Drawable drawable)
stateSet
- - An array of resource Ids to associate with the image.
Switch to this image by calling setState().drawable
- -The image to show.public boolean isStateful()
Drawable
isStateful
in class DrawableContainer
Drawable.setState(int[])
protected boolean onStateChange(int[] stateSet)
Drawable
onStateChange
in class DrawableContainer
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme) throws XmlPullParserException, IOException
Drawable
inflate
in class Drawable
r
- Resources used to resolve attribute valuesparser
- XML parser from which to inflate this Drawableattrs
- Base set of attribute valuestheme
- Theme to apply, may be nullXmlPullParserException
IOException
public int getStateCount()
getStateSet(int)
,
getStateDrawable(int)
public int[] getStateSet(int index)
index
- The index of the state set.getStateCount()
,
getStateDrawable(int)
public Drawable getStateDrawable(int index)
index
- The index of the drawable.getStateCount()
,
getStateSet(int)
public int getStateDrawableIndex(int[] stateSet)
stateSet
- the state set to look upgetStateDrawable(int)
,
getStateSet(int)
public Drawable mutate()
Drawable
mutate
in class DrawableContainer
Drawable.ConstantState
,
Drawable.getConstantState()
public void clearMutated()
Drawable
This is hidden because only framework drawables can be cached, so custom drawables don't need to support constant state, mutate(), or clearMutated().
clearMutated
in class DrawableContainer
public void applyTheme(Resources.Theme theme)
Drawable
applyTheme
in class DrawableContainer
theme
- the theme to applyprotected void setConstantState(DrawableContainer.DrawableContainerState state)
setConstantState
in class DrawableContainer