public class StateColor extends Object
Component object.
StateColor is created using the XML file in the color directory. The XML file contains a
state-container field. Each item under this field defines a color and its associated states.
The items are matched in sequence in the XML file. Therefore, you are advised to place items with more constraints
at the front and place items with no state attributes or items whose state attribute is
ComponentState.COMPONENT_STATE_EMPTY at the end as default items.
If the state attribute in an item has not been configured, the value is false by default.
The ohos:color attribute is mandatory for each item, and its value can be a hex value or a referenced value.
The ohos:alpha attribute is optional, and its value can be a floating-point value in the range from 0 to 1
or a referenced value.
| 构造器 | 说明 |
|---|---|
StateColor(int[][] states,
int[] colors) |
A constructor used to create a
StateColor object based on states and colors of the Component
object. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
int |
getColorOfState(int[] states,
int defaultColor) |
Obtains the color that maps to a given array of states of the
Component object. |
int |
getDefaultColor() |
Obtains the default color in this
StateColor object. |
static StateColor |
valueOf(int color) |
Creates a
StateColor object that contains a single color. |
public StateColor(int[][] states,
int[] colors)
StateColor object based on states and colors of the Component
object.
The lengths of state array and color array must be the same.
states - Indicates an array of states. A negative value indicates that no state is matched. If the array is
empty or contains only ComponentState.COMPONENT_STATE_EMPTY, any state is matched.
Generally, the state value is obtained from ComponentState.colors - Indicates the array of colors that map to the specified array of states.public int getColorOfState(int[] states,
int defaultColor)
Component object.states - Indicates an array of states. A negative value indicates that no state is matched. If the array is
empty or contains only ComponentState.COMPONENT_STATE_EMPTY, any state is matched.
Generally, the state value is obtained from ComponentState.defaultColor - Indicates the defaultColor object to return when no color maps to the given array of
states.public int getDefaultColor()
StateColor object.
The default color maps to ComponentState.COMPONENT_STATE_EMPTY. If
ComponentState.COMPONENT_STATE_EMPTY does not exist, the default color will be the color initially added
by calling addState(int[], int) or the color mapping to the first item configured in the XML file.
StateColor object.public static StateColor valueOf(int color)
StateColor object that contains a single color.color - Indicates the single color contained in this StateColor object.StateColor object that contains a single color.