Modifier and Type | Method and Description |
---|---|
static void |
applyTheme(Drawable drawable,
Resources.Theme t)
Applies the specified theme to this Drawable and its children.
|
static boolean |
canApplyTheme(Drawable drawable)
Whether a theme can be applied to this Drawable and its children.
|
static void |
clearColorFilter(Drawable drawable)
Removes the color filter from the given drawable.
|
static int |
getAlpha(Drawable drawable)
Get the alpha value of the
drawable .
0 means fully transparent, 255 means fully opaque. |
static ColorFilter |
getColorFilter(Drawable drawable)
Returns the current color filter, or
null if none set. |
static int |
getLayoutDirection(Drawable drawable)
Returns the resolved layout direction for this Drawable.
|
static void |
inflate(Drawable drawable,
Resources res,
XmlPullParser parser,
AttributeSet attrs,
Resources.Theme theme)
Inflate this Drawable from an XML resource optionally styled by a theme.
|
static boolean |
isAutoMirrored(Drawable drawable)
Tells if this Drawable will be automatically mirrored when its layout
direction is RTL right-to-left.
|
static void |
jumpToCurrentState(Drawable drawable)
|
static void |
setAutoMirrored(Drawable drawable,
boolean mirrored)
Set whether this Drawable is automatically mirrored when its layout
direction is RTL (right-to left).
|
static void |
setHotspot(Drawable drawable,
float x,
float y)
Specifies the hotspot's location within the drawable.
|
static void |
setHotspotBounds(Drawable drawable,
int left,
int top,
int right,
int bottom)
Sets the bounds to which the hotspot is constrained, if they should be
different from the drawable bounds.
|
static boolean |
setLayoutDirection(Drawable drawable,
int layoutDirection)
Set the layout direction for this drawable.
|
static void |
setTint(Drawable drawable,
int tint)
Specifies a tint for
drawable . |
static void |
setTintList(Drawable drawable,
ColorStateList tint)
Specifies a tint for
drawable as a color state list. |
static void |
setTintMode(Drawable drawable,
PorterDuff.Mode tintMode)
Specifies a tint blending mode for
drawable . |
static <T extends Drawable> |
unwrap(Drawable drawable)
Unwrap
drawable if it is the result of a call to wrap(Drawable) . |
static Drawable |
wrap(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. |
public static void jumpToCurrentState(@NonNull Drawable drawable)
Drawable.jumpToCurrentState()
.
If running on a pre-Build.VERSION_CODES.HONEYCOMB
device this method does nothing.
drawable
- The Drawable against which to invoke the method.public static void setAutoMirrored(@NonNull Drawable drawable, boolean mirrored)
LayoutDirection
.
If running on a pre-Build.VERSION_CODES.KITKAT
device
this method does nothing.
drawable
- The Drawable against which to invoke the method.mirrored
- Set to true if the Drawable should be mirrored, false if
not.public static boolean isAutoMirrored(@NonNull Drawable drawable)
LayoutDirection
.
If running on a pre-Build.VERSION_CODES.KITKAT
device
this method returns false.
drawable
- The Drawable against which to invoke the method.public static void setHotspot(@NonNull Drawable drawable, float x, float y)
drawable
- The Drawable against which to invoke the method.x
- The X coordinate of the center of the hotspoty
- The Y coordinate of the center of the hotspotpublic static void setHotspotBounds(@NonNull Drawable drawable, int left, int top, int right, int bottom)
drawable
- The Drawable against which to invoke the method.public static void setTint(@NonNull Drawable drawable, int tint)
drawable
.drawable
- The Drawable against which to invoke the method.tint
- Color to use for tinting this drawablepublic static void setTintList(@NonNull Drawable drawable, @Nullable ColorStateList tint)
drawable
as a color state list.drawable
- The Drawable against which to invoke the method.tint
- Color state list to use for tinting this drawable, or null to clear the tintpublic static void setTintMode(@NonNull Drawable drawable, @Nullable PorterDuff.Mode tintMode)
drawable
.drawable
- The Drawable against which to invoke the method.tintMode
- A Porter-Duff blending modepublic static int getAlpha(@NonNull Drawable drawable)
drawable
.
0 means fully transparent, 255 means fully opaque.drawable
- The Drawable against which to invoke the method.public static void applyTheme(@NonNull Drawable drawable, @NonNull Resources.Theme t)
public static boolean canApplyTheme(@NonNull Drawable drawable)
public static ColorFilter getColorFilter(@NonNull Drawable drawable)
null
if none set.null
if none setpublic static void clearColorFilter(@NonNull Drawable drawable)
public static void inflate(@NonNull Drawable drawable, @NonNull Resources res, @NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Resources.Theme theme) throws XmlPullParserException, IOException
res
- Resources used to resolve attribute valuesparser
- XML parser from which to inflate this Drawableattrs
- Base set of attribute valuestheme
- Theme to apply, may be nullXmlPullParserException
IOException
public static Drawable wrap(@NonNull Drawable drawable)
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 it's 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 Drawable
again,
you can use the value returned from unwrap(Drawable)
.
drawable
- The Drawable to processsetTint(Drawable, int)
,
setTintList(Drawable, ColorStateList)
,
setTintMode(Drawable, PorterDuff.Mode)
,
unwrap(Drawable)
public static <T extends Drawable> T unwrap(@NonNull Drawable drawable)
drawable
if it is the result of a call to wrap(Drawable)
. If
the drawable
is not the result of a call to wrap(Drawable)
then
drawable
is returned as-is.drawable
- The drawable to unwrapDrawable
or drawable
if it hasn't been wrapped.wrap(Drawable)
public static boolean setLayoutDirection(@NonNull Drawable drawable, int layoutDirection)
layoutDirection
- the resolved layout direction for the drawable,
either ViewCompat.LAYOUT_DIRECTION_LTR
or ViewCompat.LAYOUT_DIRECTION_RTL
true
if the layout direction change has caused the
appearance of the drawable to change such that it needs to be
re-drawn, false
otherwisegetLayoutDirection(Drawable)
public static int getLayoutDirection(@NonNull Drawable drawable)
ViewCompat.LAYOUT_DIRECTION_LTR
,
ViewCompat.LAYOUT_DIRECTION_RTL
setLayoutDirection(Drawable, int)