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.
  • 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:
    • 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

      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:
    • 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:
    • 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:
    • 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: