ConstantState
abstract class ConstantState
kotlin.Any | |
↳ | android.graphics.drawable.Drawable.ConstantState |
This abstract class is used by Drawable
s to store shared constant state and data between Drawables. BitmapDrawable
s 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.
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 |
newDrawable(res: Resources?) Creates a new Drawable instance from its constant state using the specified resources. |
open Drawable |
newDrawable(res: Resources?, theme: Resources.Theme?) Creates a new Drawable instance from its constant state using the specified resources and theme. |
Public constructors
ConstantState
ConstantState()
Public methods
canApplyTheme
open fun canApplyTheme(): Boolean
Return whether this constant state can have a theme applied.
getChangingConfigurations
abstract fun getChangingConfigurations(): Int
Return a bit mask of configuration changes that will impact this drawable (and thus require completely reloading it).
newDrawable
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 . |
See Also
newDrawable
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
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 . |