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
ConstructorsConstructorDescriptionColorStateList
(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 default color 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.static int
modulateColor
(int baseColor, float alphaMod) Apply alpha modulation to base color.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
Creates a ColorStateList that returns the specified mapping from states to colors. The given arrays should not be modified after construction.
-
-
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.
-
modulateColor
public static int modulateColor(int baseColor, float alphaMod) Apply alpha modulation to base color.- Parameters:
baseColor
- base coloralphaMod
- alpha multiplier applied to the base color- Returns:
- modulated color
-
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
Return the default color in thisColorStateList
.- Returns:
- the default color 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
-