Package icyllis.modernui.util
Class ColorStateList
java.lang.Object
icyllis.modernui.util.ColorStateList
Lets you map
View
state sets to colors.
This defines a set of state spec / color pairs where each state spec specifies a set of states that a view must either be in or not be in and the color specifies the color associated with that spec.
-
Constructor Summary
ConstructorDescriptionColorStateList
(int[][] states, int[] colors) Creates a ColorStateList that returns the specified mapping from states to colors. -
Method Summary
Modifier and TypeMethodDescriptionint
getColorForState
(int[] stateSet, int defaultColor) Return the color associated with the given set ofView
states.int[]
Return the colors in thisColorStateList
.int
Return the default color in thisColorStateList
.int[][]
Return the states in thisColorStateList
.boolean
Return whether the state spec list has at least one item explicitly specifyingboolean
hasState
(int state) Returns whether the specified state is referenced in any of the state specs contained within this ColorStateList.boolean
isOpaque()
Indicates whether this color state list is opaque, which means that every color returned fromgetColorForState(int[], int)
has an alpha value of 255.boolean
Indicates whether this color state list contains at least one state spec and the first spec is not empty (e.g.toString()
static ColorStateList
valueOf
(int color) withAlpha
(int alpha) Creates a new ColorStateList that has the same states and colors as this one but where each color has the specified alpha value (0-255).
-
Constructor Details
-
ColorStateList
public ColorStateList(int[][] states, int[] colors) Creates a ColorStateList that returns the specified mapping from states to colors.
-
-
Method Details
-
valueOf
- Returns:
- A ColorStateList containing a single color.
-
withAlpha
Creates a new ColorStateList that has the same states and colors as this one but where each color has the specified alpha value (0-255).- Parameters:
alpha
- The new alpha channel value (0-255).- Returns:
- A new color state list.
-
isStateful
public boolean isStateful()Indicates whether this color state list contains at least one state spec and the first spec is not empty (e.g. match-all).- Returns:
- True if this color state list changes color based on state, false otherwise.
- See Also:
-
hasFocusStateSpecified
@Internal public boolean hasFocusStateSpecified()Return whether the state spec list has at least one item explicitly specifying -
isOpaque
public boolean isOpaque()Indicates whether this color state list is opaque, which means that every color returned fromgetColorForState(int[], int)
has an alpha value of 255.- Returns:
- True if this color state list is opaque.
-
getColorForState
public int getColorForState(int[] stateSet, int defaultColor) Return the color associated with the given set ofView
states.- Parameters:
stateSet
- an array ofView
statesdefaultColor
- the color to return if there's no matching state spec in thisColorStateList
that matches the stateSet.- Returns:
- the color associated with that set of states in this
ColorStateList
.
-
getDefaultColor
public int getDefaultColor()Return the default color in thisColorStateList
.- Returns:
- the default color in this
ColorStateList
.
-
getStates
@Internal public int[][] getStates()Return the states in thisColorStateList
. The returned array should not be modified.- Returns:
- the states in this
ColorStateList
-
getColors
@Internal public int[] getColors()Return the colors in thisColorStateList
. The returned array should not be modified.- Returns:
- the colors in this
ColorStateList
-
hasState
@Internal public boolean hasState(int state) Returns whether the specified state is referenced in any of the state specs contained within this ColorStateList.Any reference, either positive or negative {ex. ~R.attr.state_enabled}, will cause this method to return
true
. Wildcards are not counted as references.- Parameters:
state
- the state to search for- Returns:
true
if the state if referenced,false
otherwise
-
toString
-