DrawableCompat
class DrawableCompat
Helper for accessing features in android.graphics.drawable.Drawable
.
Summary
Public functions |
|
---|---|
java-static Unit |
applyTheme(drawable: Drawable, theme: Resources.Theme) Applies the specified theme to this Drawable and its children. |
java-static Boolean |
canApplyTheme(drawable: Drawable) Whether a theme can be applied to this Drawable and its children. |
java-static Unit |
clearColorFilter(drawable: Drawable) Removes the color filter from the given drawable. |
java-static Int |
@ReplaceWith(expression = "drawable.getAlpha()") This function is deprecated. Call |
java-static ColorFilter? |
getColorFilter(drawable: Drawable) Returns the current color filter, or |
java-static Int |
getLayoutDirection(drawable: Drawable) Returns the resolved layout direction for this Drawable. |
java-static Unit |
inflate( Inflate this Drawable from an XML resource optionally styled by a theme. |
java-static Boolean |
@ReplaceWith(expression = "drawable.isAutoMirrored()") This function is deprecated. Call |
java-static Unit |
@ReplaceWith(expression = "drawable.jumpToCurrentState()") This function is deprecated. Use |
java-static Unit |
@ReplaceWith(expression = "drawable.setAutoMirrored(mirrored)") This function is deprecated. Call setAutoMirrored directly. |
java-static Unit |
setHotspot(drawable: Drawable, x: Float, y: Float) Specifies the hotspot's location within the drawable. |
java-static Unit |
Sets the bounds to which the hotspot is constrained, if they should be different from the drawable bounds. |
java-static Boolean |
setLayoutDirection(drawable: Drawable, layoutDirection: Int) Set the layout direction for this drawable. |
java-static Unit |
Specifies a tint for |
java-static Unit |
setTintList(drawable: Drawable, tint: ColorStateList?) Specifies a tint for |
java-static Unit |
setTintMode(drawable: Drawable, tintMode: PorterDuff.Mode?) Specifies a tint blending mode for |
java-static T! |
Unwrap |
java-static Drawable |
Potentially wrap |
Public functions
applyTheme
java-static fun applyTheme(drawable: Drawable, theme: Resources.Theme): Unit
Applies the specified theme to this Drawable and its children.
canApplyTheme
java-static fun canApplyTheme(drawable: Drawable): Boolean
Whether a theme can be applied to this Drawable and its children.
clearColorFilter
java-static fun clearColorFilter(drawable: Drawable): Unit
Removes the color filter from the given drawable.
@ReplaceWith(expression = "drawable.getAlpha()")
java-static fungetAlpha(drawable: Drawable): Int
Get the alpha value of the drawable
. 0 means fully transparent, 255 means fully opaque.
Parameters | |
---|---|
drawable: Drawable |
The Drawable against which to invoke the method. |
getColorFilter
java-static fun getColorFilter(drawable: Drawable): ColorFilter?
Returns the current color filter, or null
if none set.
Returns | |
---|---|
ColorFilter? |
the current color filter, or |
getLayoutDirection
java-static fun getLayoutDirection(drawable: Drawable): Int
Returns the resolved layout direction for this Drawable.
Returns | |
---|---|
Int |
See also | |
---|---|
setLayoutDirection |
inflate
java-static fun inflate(
drawable: Drawable,
res: Resources,
parser: XmlPullParser,
attrs: AttributeSet,
theme: Resources.Theme?
): Unit
Inflate this Drawable from an XML resource optionally styled by a theme.
Parameters | |
---|---|
drawable: Drawable |
drawable to inflate. |
res: Resources |
Resources used to resolve attribute values |
parser: XmlPullParser |
XML parser from which to inflate this Drawable |
attrs: AttributeSet |
Base set of attribute values |
theme: Resources.Theme? |
Theme to apply, may be null |
@ReplaceWith(expression = "drawable.isAutoMirrored()")
java-static funisAutoMirrored(drawable: Drawable): Boolean
Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left. See android.util.LayoutDirection
.
If running on a pre-KITKAT
device this method returns false.
Parameters | |
---|---|
drawable: Drawable |
The Drawable against which to invoke the method. |
Returns | |
---|---|
Boolean |
boolean Returns true if this Drawable will be automatically mirrored. |
@ReplaceWith(expression = "drawable.jumpToCurrentState()")
java-static funjumpToCurrentState(drawable: Drawable): Unit
Call Drawable.jumpToCurrentState()
.
Parameters | |
---|---|
drawable: Drawable |
The Drawable against which to invoke the method. |
@ReplaceWith(expression = "drawable.setAutoMirrored(mirrored)")
java-static funsetAutoMirrored(drawable: Drawable, mirrored: Boolean): Unit
Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left). See android.util.LayoutDirection
.
If running on a pre-KITKAT
device this method does nothing.
setHotspot
java-static fun setHotspot(drawable: Drawable, x: Float, y: Float): Unit
Specifies the hotspot's location within the drawable.
setHotspotBounds
java-static fun setHotspotBounds(
drawable: Drawable,
left: Int,
top: Int,
right: Int,
bottom: Int
): Unit
Sets the bounds to which the hotspot is constrained, if they should be different from the drawable bounds.
setLayoutDirection
java-static fun setLayoutDirection(drawable: Drawable, layoutDirection: Int): Boolean
Set the layout direction for this drawable. Should be a resolved layout direction, as the Drawable has no capacity to do the resolution on its own.
Parameters | |
---|---|
drawable: Drawable |
drawable for which to set the layout direction. |
layoutDirection: Int |
the resolved layout direction for the drawable, either |
Returns | |
---|---|
Boolean |
|
See also | |
---|---|
getLayoutDirection |
setTint
java-static fun setTint(drawable: Drawable, tint: @ColorInt Int): Unit
Specifies a tint for drawable
.
setTintList
java-static fun setTintList(drawable: Drawable, tint: ColorStateList?): Unit
Specifies a tint for drawable
as a color state list.
Parameters | |
---|---|
drawable: Drawable |
The Drawable against which to invoke the method. |
tint: ColorStateList? |
Color state list to use for tinting this drawable, or null to clear the tint |
setTintMode
java-static fun setTintMode(drawable: Drawable, tintMode: PorterDuff.Mode?): Unit
Specifies a tint blending mode for drawable
.
Parameters | |
---|---|
drawable: Drawable |
The Drawable against which to invoke the method. |
tintMode: PorterDuff.Mode? |
A Porter-Duff blending mode |
unwrap
java-static fun <T : Drawable?> unwrap(drawable: Drawable): T!
Unwrap drawable
if it is the result of a call to wrap
. If the drawable
is not the result of a call to wrap
then drawable
is returned as-is.
Parameters | |
---|---|
drawable: Drawable |
The drawable to unwrap |
Returns | |
---|---|
T! |
the unwrapped |
See also | |
---|---|
wrap |
wrap
java-static fun wrap(drawable: Drawable): Drawable
Potentially wrap drawable
so that it may be used for tinting across the different API levels, via the tinting methods in this class.
If the given drawable is wrapped, we will copy over certain state over to the wrapped drawable, such as its bounds, level, visibility and state.
You must use the result of this call. If the given drawable is being used by a view (as its background for instance), you must replace the original drawable with the result of this call:
Drawable bg = DrawableCompat.wrap(view.getBackground()); // Need to set the background with the wrapped drawable view.setBackground(bg); // You can now tint the drawable DrawableCompat.setTint(bg, ...);
If you need to get hold of the original android.graphics.drawable.Drawable
again, you can use the value returned from unwrap
.
Parameters | |
---|---|
drawable: Drawable |
The Drawable to process |
Returns | |
---|---|
Drawable |
A drawable capable of being tinted across all API levels. |
See also | |
---|---|
setTint |
|
setTintList |
|
setTintMode |
|
unwrap |