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.DrawableContainerState
Nested classes/interfaces inherited from class icyllis.modernui.graphics.drawable.Drawable
Drawable.Callback, Drawable.ConstantState
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a new image/string ID to the set of images.void
Clears the mutated state, allowing this drawable to be cached and mutated again.int
findStateDrawableIndex
(int[] stateSet) Gets the index of the drawable with the provided state set.int
Gets 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.boolean
Indicates whether this drawable has at least one state spec explicitly specifying state_focused.boolean
Indicates whether this drawable will change its appearance based on state.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
Methods inherited from class icyllis.modernui.graphics.drawable.DrawableContainer
draw, getAlpha, getConstantState, getCurrent, getCurrentIndex, getHotspotBounds, getIntrinsicHeight, getIntrinsicWidth, getMinimumHeight, getMinimumWidth, getPadding, invalidateDrawable, isAutoMirrored, jumpToCurrentState, onBoundsChange, onLayoutDirectionChanged, onLevelChange, scheduleDrawable, selectDrawable, setAlpha, setAutoMirrored, setEnterFadeDuration, setExitFadeDuration, setHotspot, setHotspotBounds, setTintBlendMode, setTintList, setVisible, unscheduleDrawable
Methods inherited from class icyllis.modernui.graphics.drawable.Drawable
applyTheme, canApplyTheme, copyBounds, copyBounds, getBounds, getCallback, getChangingConfigurations, getColorFilter, 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:Drawable
Indicates 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:
isStateful
in classDrawableContainer
- Returns:
- True if this drawable changes its appearance based on state, false otherwise.
- See Also:
-
hasFocusStateSpecified
public boolean hasFocusStateSpecified()Description copied from class:Drawable
Indicates whether this drawable has at least one state spec explicitly specifying state_focused.Note: A View uses a
Drawable
instance 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:
hasFocusStateSpecified
in classDrawableContainer
- Returns:
true
if state_focused is specified for this drawable.
-
onStateChange
Description copied from class:Drawable
Override this in your subclass to change appearance if you recognize the specified state.- Overrides:
onStateChange
in 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:Drawable
Make 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:
mutate
in classDrawableContainer
- Returns:
- This drawable.
- See Also:
-
clearMutated
public void clearMutated()Description copied from class:Drawable
Clears the mutated state, allowing this drawable to be cached and mutated again.- Overrides:
clearMutated
in classDrawableContainer
-
setConstantState
- Overrides:
setConstantState
in classDrawableContainer
-