Class StateListDrawable
java.lang.Object
icyllis.modernui.graphics.drawable.Drawable
icyllis.modernui.graphics.drawable.DrawableContainer
icyllis.modernui.graphics.drawable.StateListDrawable
- All Implemented Interfaces:
Drawable.Callback
Lets you assign a number of graphic images to a single Drawable and swap out the visible item by a string
ID value.
-
Nested Class Summary
Nested classes/interfaces inherited from class icyllis.modernui.graphics.drawable.DrawableContainer
DrawableContainer.DrawableContainerStateNested classes/interfaces inherited from class icyllis.modernui.graphics.drawable.Drawable
Drawable.Callback, Drawable.ConstantState -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a new image/string ID to the set of images.voidClears the mutated state, allowing this drawable to be cached and mutated again.intfindStateDrawableIndex(int[] stateSet) Gets the index of the drawable with the provided state set.intGets the number of states contained in this drawable.getStateDrawable(int index) Gets the drawable at an index.int[]getStateSet(int index) Gets the state set at an index.booleanIndicates whether this drawable has at least one state spec explicitly specifying state_focused.booleanIndicates whether this drawable will change its appearance based on state.mutate()Make this drawable mutable.protected booleanonStateChange(int[] stateSet) Override this in your subclass to change appearance if you recognize the specified state.protected voidMethods inherited from class icyllis.modernui.graphics.drawable.DrawableContainer
draw, getAlpha, getConstantState, getCurrent, getCurrentIndex, getHotspotBounds, getIntrinsicHeight, getIntrinsicWidth, getMinimumHeight, getMinimumWidth, getOutline, getPadding, invalidateDrawable, isAutoMirrored, jumpToCurrentState, onBoundsChange, onLayoutDirectionChanged, onLevelChange, scheduleDrawable, selectDrawable, setAlpha, setAutoMirrored, setEnterFadeDuration, setExitFadeDuration, setHotspot, setHotspotBounds, setTintBlendMode, setTintList, setVisible, unscheduleDrawableMethods inherited from class icyllis.modernui.graphics.drawable.Drawable
applyTheme, canApplyTheme, copyBounds, copyBounds, getBounds, getCallback, getChangingConfigurations, getColorFilter, getDirtyBounds, getLayoutDirection, getLevel, getState, invalidateSelf, isVisible, scaleFromDensity, scaleFromDensity, scheduleSelf, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setLayoutDirection, setLevel, setState, setTint, unscheduleSelf
-
Constructor Details
-
StateListDrawable
public StateListDrawable()
-
-
Method Details
-
addState
Add a new image/string ID to the set of images.- Parameters:
stateSet- An array of resource Ids to associate with the image. Switch to this image by calling setState().drawable- The image to show. Note this must be a unique Drawable that is not shared between any other View or Drawable otherwise the results are undefined and can lead to unexpected rendering behavior
-
isStateful
public boolean isStateful()Description copied from class:DrawableIndicates whether this drawable will change its appearance based on state. Clients can use this to determine whether it is necessary to calculate their state and call setState.- Overrides:
isStatefulin classDrawableContainer- Returns:
- True if this drawable changes its appearance based on state, false otherwise.
- See Also:
-
hasFocusStateSpecified
public boolean hasFocusStateSpecified()Description copied from class:DrawableIndicates whether this drawable has at least one state spec explicitly specifying state_focused.Note: A View uses a
Drawableinstance as its background and it changes its appearance based on a state. On keyboard devices, it should specify its state_focused to make sure the user knows which view is holding the focus.- Overrides:
hasFocusStateSpecifiedin classDrawableContainer- Returns:
trueif state_focused is specified for this drawable.
-
onStateChange
Description copied from class:DrawableOverride this in your subclass to change appearance if you recognize the specified state.- Overrides:
onStateChangein classDrawableContainer- Returns:
- Returns true if the state change has caused the appearance of the Drawable to change (that is, it needs to be drawn), else false if it looks the same and there is no need to redraw it since its last state.
-
getStateCount
public int getStateCount()Gets the number of states contained in this drawable.- Returns:
- The number of states contained in this drawable.
- See Also:
-
getStateSet
Gets the state set at an index.- Parameters:
index- The index of the state set.- Returns:
- The state set at the index.
- See Also:
-
getStateDrawable
Gets the drawable at an index.- Parameters:
index- The index of the drawable.- Returns:
- The drawable at the index.
- See Also:
-
findStateDrawableIndex
Gets the index of the drawable with the provided state set.- Parameters:
stateSet- the state set to look up- Returns:
- the index of the provided state set, or -1 if not found
- See Also:
-
mutate
Description copied from class:DrawableMake this drawable mutable. This operation cannot be reversed. A mutable drawable is guaranteed to not share its state with any other drawable. This is especially useful when you need to modify properties of drawables loaded from resources. By default, all drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification.Calling this method on a mutable Drawable will have no effect.
- Overrides:
mutatein classDrawableContainer- Returns:
- This drawable.
- See Also:
-
clearMutated
public void clearMutated()Description copied from class:DrawableClears the mutated state, allowing this drawable to be cached and mutated again.- Overrides:
clearMutatedin classDrawableContainer
-
setConstantState
- Overrides:
setConstantStatein classDrawableContainer
-