Added in API level 1

ConstantState

abstract class ConstantState
kotlin.Any
   ↳ android.graphics.drawable.Drawable.ConstantState

This abstract class is used by Drawables to store shared constant state and data between Drawables. BitmapDrawables created from the same resource will for instance share a unique bitmap stored in their ConstantState.

newDrawable(android.content.res.Resources) can be used as a factory to create new Drawable instances from this ConstantState.

Use Drawable#getConstantState() to retrieve the ConstantState of a Drawable. Calling Drawable#mutate() on a Drawable should typically create a new ConstantState for that Drawable.

Summary

Public constructors

Public methods
open Boolean

Return whether this constant state can have a theme applied.

abstract Int

Return a bit mask of configuration changes that will impact this drawable (and thus require completely reloading it).

abstract Drawable

Creates a new Drawable instance from its constant state.

open Drawable

Creates a new Drawable instance from its constant state using the specified resources.

open Drawable

Creates a new Drawable instance from its constant state using the specified resources and theme.

Public constructors

ConstantState

ConstantState()

Public methods

canApplyTheme

Added in API level 21
open fun canApplyTheme(): Boolean

Return whether this constant state can have a theme applied.

newDrawable

Added in API level 1
abstract fun newDrawable(): Drawable

Creates a new Drawable instance from its constant state.

Note: Using this method means density-dependent properties, such as pixel dimensions or bitmap images, will not be updated to match the density of the target display. To ensure correct scaling, use newDrawable(android.content.res.Resources) instead to provide an appropriate Resources object.

Return
Drawable a new drawable object based on this constant state This value cannot be null.

newDrawable

Added in API level 5
open fun newDrawable(res: Resources?): Drawable

Creates a new Drawable instance from its constant state using the specified resources. This method should be implemented for drawables that have density-dependent properties.

The default implementation for this method calls through to newDrawable().

Parameters
res Resources?: the resources of the context in which the drawable will be displayed This value may be null.
Return
Drawable a new drawable object based on this constant state This value cannot be null.

newDrawable

Added in API level 21
open fun newDrawable(
    res: Resources?,
    theme: Resources.Theme?
): Drawable

Creates a new Drawable instance from its constant state using the specified resources and theme. This method should be implemented for drawables that have theme-dependent properties.

The default implementation for this method calls through to newDrawable(android.content.res.Resources).

Parameters
res Resources?: the resources of the context in which the drawable will be displayed This value may be null.
theme Resources.Theme?: the theme of the context in which the drawable will be displayed This value may be null.
Return
Drawable a new drawable object based on this constant state This value cannot be null.