Class LevelListDrawable

All Implemented Interfaces:
Drawable.Callback

public class LevelListDrawable extends DrawableContainer
A resource that manages a number of alternate Drawables, each assigned a maximum numerical value. Setting the level value of the object with Drawable.setLevel(int) will load the image with the next greater or equal value assigned to its max attribute.

A good example use of a LevelListDrawable would be a Wi-Fi signal strength indicator icon, with different images to indicate the current signal level.

  • Constructor Details

    • LevelListDrawable

      public LevelListDrawable()
  • Method Details

    • addLevel

      public void addLevel(int low, int high, Drawable drawable)
    • onLevelChange

      protected boolean onLevelChange(int level)
      Description copied from class: Drawable
      Override this in your subclass to change appearance if you vary based on level.
      Overrides:
      onLevelChange in class DrawableContainer
      Returns:
      Returns true if the level 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 level.
    • mutate

      @NonNull public Drawable mutate()
      Description copied from class: Drawable
      Make this drawable mutable. This operation cannot be reversed. A mutable drawable is guaranteed to not share its state with any other drawable. This is especially useful when you need to modify properties of drawables loaded from resources. By default, all drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification.

      Calling this method on a mutable Drawable will have no effect.

      Overrides:
      mutate in class DrawableContainer
      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 DrawableContainer
    • setConstantState

      protected void setConstantState(@NonNull DrawableContainer.DrawableContainerState state)
      Overrides:
      setConstantState in class DrawableContainer