Class ColorStateList

java.lang.Object
icyllis.modernui.util.ColorStateList

public class ColorStateList extends Object
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 Details

    • ColorStateList

      public ColorStateList(int[][] states, int[] colors)
      Creates a ColorStateList that returns the specified mapping from states to colors.
  • Method Details

    • valueOf

      @Nonnull public static ColorStateList valueOf(int color)
      Returns:
      A ColorStateList containing a single color.
    • withAlpha

      @Nonnull public ColorStateList 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).
      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 from getColorForState(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 of View states.
      Parameters:
      stateSet - an array of View states
      defaultColor - the color to return if there's no matching state spec in this ColorStateList 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 this ColorStateList.
      Returns:
      the default color in this ColorStateList.
    • getStates

      @Internal public int[][] getStates()
      Return the states in this ColorStateList. The returned array should not be modified.
      Returns:
      the states in this ColorStateList
    • getColors

      @Internal public int[] getColors()
      Return the colors in this ColorStateList. 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

      public String toString()
      Overrides:
      toString in class Object