Package icyllis.modernui.graphics.drawable

# Class ColorDrawable

java.lang.Object
icyllis.modernui.graphics.drawable.Drawable
icyllis.modernui.graphics.drawable.ColorDrawable

public class ColorDrawable extends Drawable
A specialized Drawable that fills the Canvas with a specified color.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class icyllis.modernui.graphics.drawable.Drawable

  `Drawable.Callback, Drawable.ConstantState`

- ## Field Summary

  ### Fields inherited from class icyllis.modernui.graphics.drawable.Drawable

  `MAX_LEVEL`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ColorDrawable()`
  Creates a new black ColorDrawable.
  `ColorDrawable(int color)`
  Creates a new ColorDrawable with the specified color.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clearMutated()`
  Clears the mutated state, allowing this drawable to be cached and mutated again.
  `void`
  `draw(Canvas canvas)`
  Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha).
  `int`
  `getAlpha()`
  Returns the alpha value of this drawable's color.
  `int`
  `getColor()`
  Gets the drawable's color value.
  `Drawable.ConstantState`
  `getConstantState()`
  Return a `Drawable.ConstantState` instance that holds the shared state of this Drawable.
  `boolean`
  `hasFocusStateSpecified()`
  Indicates whether this drawable has at least one state spec explicitly specifying state_focused.
  `boolean`
  `isStateful()`
  Indicates whether this drawable will change its appearance based on state.
  `Drawable`
  `mutate()`
  A mutable BitmapDrawable still shares its Bitmap with any other Drawable that comes from the same resource.
  `protected boolean`
  `onStateChange(int[] stateSet)`
  Override this in your subclass to change appearance if you recognize the specified state.
  `void`
  `setAlpha(int alpha)`
  Applies the given alpha to the underlying color.
  `void`
  `setColor(int color)`
  Sets the drawable's color value.
  `void`
  `setTintBlendMode(BlendMode blendMode)`
  Specifies a tint blending mode for this drawable.
  `void`
  `setTintList(ColorStateList tint)`
  Specifies tint color for this drawable as a color state list.

  ### Methods inherited from class icyllis.modernui.graphics.drawable.Drawable

  `applyTheme, canApplyTheme, copyBounds, copyBounds, getBounds, getCallback, getChangingConfigurations, getColorFilter, getCurrent, getHotspotBounds, getIntrinsicHeight, getIntrinsicWidth, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getPadding, getState, invalidateSelf, isAutoMirrored, isVisible, jumpToCurrentState, onBoundsChange, onLayoutDirectionChanged, onLevelChange, scaleFromDensity, scaleFromDensity, scheduleSelf, setAutoMirrored, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setHotspot, setHotspotBounds, setLayoutDirection, setLevel, setState, setTint, setVisible, unscheduleSelf`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ColorDrawable

    public ColorDrawable()
    Creates a new black ColorDrawable.

  - ### ColorDrawable

    public ColorDrawable(@ColorInt int color)
    Creates a new ColorDrawable with the specified color.
    Parameters:
      `color` - The color to draw.

- ## Method Details

  - ### mutate

    @NonNull public Drawable mutate()
    A mutable BitmapDrawable still shares its Bitmap with any other Drawable that comes from the same resource.
    Overrides:
      `mutate` in class `Drawable`
    Returns:
      This drawable.
    See Also:
      - `Drawable.ConstantState`
      - `Drawable.getConstantState()`

  - ### 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 class `Drawable`

  - ### draw

    public void draw(@NonNull Canvas canvas)
    Description copied from class: `Drawable`
    Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha).
    Specified by:
      `draw` in class `Drawable`
    Parameters:
      `canvas` - The canvas to draw into

  - ### getColor

    @ColorInt public int getColor()
    Gets the drawable's color value.
    Returns:
      int The color to draw.

  - ### setColor

    public void setColor(@ColorInt int color)
    Sets the drawable's color value. This action will clobber the results of prior calls to `setAlpha(int)` on this object, which side-affected the underlying color.
    Parameters:
      `color` - The color to draw.

  - ### getAlpha

    public int getAlpha()
    Returns the alpha value of this drawable's color. Note this may not be the same alpha value provided in `Drawable.setAlpha(int)`. Instead, this will return the alpha of the color combined with the alpha provided by setAlpha
    Overrides:
      `getAlpha` in class `Drawable`
    Returns:
      A value between 0 and 255.
    See Also:
      - `setAlpha(int)`

  - ### setAlpha

    public void setAlpha(int alpha)
    Applies the given alpha to the underlying color. Note if the color already has an alpha applied to it, this will apply this alpha to the existing value instead of overwriting it.
    Overrides:
      `setAlpha` in class `Drawable`
    Parameters:
      `alpha` - The alpha value to set, between 0 and 255.

  - ### setTintList

    public void setTintList(@Nullable ColorStateList tint)
    Description copied from class: `Drawable`
    Specifies tint color for this drawable as a color state list.

    A Drawable's drawing content will be blended together with its tint before it is drawn to the screen.

    Note: Setting a color filter via `Drawable.setColorFilter(ColorFilter)` overrides tint.

    Overrides:
      `setTintList` in class `Drawable`
    Parameters:
      `tint` - Color state list to use for tinting this drawable, or `null` to clear the tint
    See Also:
      - `Drawable.setTint(int)`
      - `Drawable.setTintBlendMode(BlendMode)`

  - ### setTintBlendMode

    public void setTintBlendMode(@NonNull BlendMode blendMode)
    Description copied from class: `Drawable`
    Specifies a tint blending mode for this drawable.

    Defines how this drawable's tint color should be blended into the drawable before it is drawn to screen. Default tint mode is `BlendMode.SRC_IN`.

    Note: Setting a color filter via `Drawable.setColorFilter(ColorFilter)`

    Overrides:
      `setTintBlendMode` in class `Drawable`
    Parameters:
      `blendMode` - BlendMode to apply to the drawable, a value of null sets the default blend mode value of `BlendMode.SRC_IN`
    See Also:
      - `Drawable.setTint(int)`
      - `Drawable.setTintList(ColorStateList)`

  - ### onStateChange

    protected boolean onStateChange(@NonNull int[] stateSet)
    Description copied from class: `Drawable`
    Override this in your subclass to change appearance if you recognize the specified state.
    Overrides:
      `onStateChange` in class `Drawable`
    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.

  - ### 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 class `Drawable`
    Returns:
      True if this drawable changes its appearance based on state, false otherwise.
    See Also:
      - `Drawable.setState(int[])`

  - ### 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 class `Drawable`
    Returns:
      `true` if state_focused is specified for this drawable.

  - ### getConstantState

    public Drawable.ConstantState getConstantState()
    Description copied from class: `Drawable`
    Return a `Drawable.ConstantState` instance that holds the shared state of this Drawable.
    Overrides:
      `getConstantState` in class `Drawable`
    Returns:
      The ConstantState associated to that Drawable.
    See Also:
      - `Drawable.ConstantState`
      - `Drawable.mutate()`