Added in API level 1

LevelListDrawable


open class LevelListDrawable : DrawableContainer
kotlin.Any
   ↳ android.graphics.drawable.Drawable
   ↳ android.graphics.drawable.DrawableContainer
   ↳ android.graphics.drawable.LevelListDrawable

A resource that manages a number of alternate Drawables, each assigned a maximum numerical value. Setting the level value of the object with 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 battery level indicator icon, with different images to indicate the current battery level.

It can be defined in an XML file with the <level-list> element. Each Drawable level is defined in a nested <item>. For example:

<level-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:maxLevel="0" android:drawable="@drawable/ic_wifi_signal_1" />
   <item android:maxLevel="1" android:drawable="@drawable/ic_wifi_signal_2" />
   <item android:maxLevel="2" android:drawable="@drawable/ic_wifi_signal_3" />
   <item android:maxLevel="3" android:drawable="@drawable/ic_wifi_signal_4" />
  </level-list>
 

With this XML saved into the res/drawable/ folder of the project, it can be referenced as the drawable for an android.widget.ImageView. The default image is the first in the list. It can then be changed to one of the other levels with android.widget.ImageView#setImageLevel(int). For more information, see the guide to Drawable Resources.

Summary

XML attributes
android:drawable Reference to a drawable resource to use for the frame.
android:maxLevel The maximum level allowed for this item.
android:minLevel The minimum level allowed for this item.
Public constructors

Public methods
open Unit
addLevel(low: Int, high: Int, drawable: Drawable!)

open Unit
inflate(r: Resources, parser: XmlPullParser, attrs: AttributeSet, theme: Resources.Theme?)

open Drawable

Protected methods
open Boolean

open Unit

Inherited functions

XML attributes

android:drawable

android:drawable
Reference to a drawable resource to use for the frame. If not given, the drawable must be defined by the first child tag.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:maxLevel

android:maxLevel
The maximum level allowed for this item.

May be an integer value, such as "100".

android:minLevel

android:minLevel
The minimum level allowed for this item.

May be an integer value, such as "100".

Public constructors

LevelListDrawable

Added in API level 1
LevelListDrawable()

Public methods

addLevel

Added in API level 1
open fun addLevel(
    low: Int,
    high: Int,
    drawable: Drawable!
): Unit

inflate

Added in API level 21
open fun inflate(
    r: Resources,
    parser: XmlPullParser,
    attrs: AttributeSet,
    theme: Resources.Theme?
): Unit
Parameters
r Resources: Resources used to resolve attribute values This value cannot be null.
parser XmlPullParser: XML parser from which to inflate this Drawable This value cannot be null.
attrs AttributeSet: Base set of attribute values This value cannot be null.
theme Resources.Theme?: Theme to apply, may be null
Exceptions
org.xmlpull.v1.XmlPullParserException
java.io.IOException

mutate

Added in API level 3
open fun mutate(): Drawable
Return
Drawable This drawable. This value cannot be null.

Protected methods

onLevelChange

Added in API level 1
protected open fun onLevelChange(level: Int): Boolean
Return
Boolean 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.

setConstantState

Added in API level 1
protected open fun setConstantState(state: DrawableContainer.DrawableContainerState): Unit
Parameters
state DrawableContainer.DrawableContainerState: This value cannot be null.