added in API level 1

Drawable.ConstantState

public static abstract class Drawable.ConstantState
extends Object

java.lang.Object
   ↳ 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(Resources) can be used as a factory to create new Drawable instances from this ConstantState.

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

Summary

Public constructors

Drawable.ConstantState()

Public methods

boolean canApplyTheme()

Return whether this constant state can have a theme applied.

abstract int getChangingConfigurations()

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

Drawable newDrawable(Resources res)

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

abstract Drawable newDrawable()

Creates a new Drawable instance from its constant state.

Drawable newDrawable(Resources res, Resources.Theme theme)

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

Inherited methods

Public constructors

Drawable.ConstantState

added in API level 1
Drawable.ConstantState ()

Public methods

canApplyTheme

added in API level 21
boolean canApplyTheme ()

Return whether this constant state can have a theme applied.

Returns
boolean

getChangingConfigurations

added in API level 1
int getChangingConfigurations ()

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

Returns
int

Value is either 0 or combination of CONFIG_MCC, CONFIG_MNC, CONFIG_LOCALE, CONFIG_TOUCHSCREEN, CONFIG_KEYBOARD, CONFIG_KEYBOARD_HIDDEN, CONFIG_NAVIGATION, CONFIG_ORIENTATION, CONFIG_SCREEN_LAYOUT, CONFIG_UI_MODE, CONFIG_SCREEN_SIZE, CONFIG_SMALLEST_SCREEN_SIZE, CONFIG_DENSITY, CONFIG_LAYOUT_DIRECTION, CONFIG_COLOR_MODE or CONFIG_FONT_SCALE.

newDrawable

added in API level 5
Drawable newDrawable (Resources res)

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.

Returns
Drawable a new drawable object based on this constant state

This value will never be null.

newDrawable

added in API level 1
Drawable newDrawable ()

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(Resources) instead to provide an appropriate Resources object.

Returns
Drawable a new drawable object based on this constant state

This value will never be null.

newDrawable

added in API level 21
Drawable newDrawable (Resources res, 
                Resources.Theme theme)

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(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.

Returns
Drawable a new drawable object based on this constant state

This value will never be null.