Package 

Class DrawableCompat

    • Method Detail

      • setAutoMirrored

         static void setAutoMirrored(@NonNull() Drawable drawable, boolean mirrored)

        Set whether this Drawable is automatically mirrored when its layoutdirection is RTL (right-to left). See android.util.LayoutDirection.

        If running on a pre-KITKAT devicethis method does nothing.

        Parameters:
        drawable - The Drawable against which to invoke the method.
        mirrored - Set to true if the Drawable should be mirrored, false ifnot.
      • isAutoMirrored

         static boolean isAutoMirrored(@NonNull() Drawable drawable)

        Tells if this Drawable will be automatically mirrored when its layoutdirection is RTL right-to-left. See android.util.LayoutDirection.

        If running on a pre-KITKAT devicethis method returns false.

        Parameters:
        drawable - The Drawable against which to invoke the method.
      • setHotspot

         static void setHotspot(@NonNull() Drawable drawable, float x, float y)

        Specifies the hotspot's location within the drawable.

        Parameters:
        drawable - The Drawable against which to invoke the method.
        x - The X coordinate of the center of the hotspot
        y - The Y coordinate of the center of the hotspot
      • setHotspotBounds

         static void setHotspotBounds(@NonNull() Drawable drawable, int left, int top, int right, int bottom)

        Sets the bounds to which the hotspot is constrained, if they should bedifferent from the drawable bounds.

        Parameters:
        drawable - The Drawable against which to invoke the method.
      • setTint

         static void setTint(@NonNull() Drawable drawable, @ColorInt() int tint)

        Specifies a tint for {@code drawable}.

        Parameters:
        drawable - The Drawable against which to invoke the method.
        tint - Color to use for tinting this drawable
      • setTintList

         static void setTintList(@NonNull() Drawable drawable, @Nullable() ColorStateList tint)

        Specifies a tint for {@code drawable} as a color state list.

        Parameters:
        drawable - The Drawable against which to invoke the method.
        tint - Color state list to use for tinting this drawable, or null to clear the tint
      • setTintMode

         static void setTintMode(@NonNull() Drawable drawable, @NonNull() PorterDuff.Mode tintMode)

        Specifies a tint blending mode for {@code drawable}.

        Parameters:
        drawable - The Drawable against which to invoke the method.
        tintMode - A Porter-Duff blending mode
      • getAlpha

         static int getAlpha(@NonNull() Drawable drawable)

        Get the alpha value of the {@code drawable}.0 means fully transparent, 255 means fully opaque.

        Parameters:
        drawable - The Drawable against which to invoke the method.
      • canApplyTheme

         static boolean canApplyTheme(@NonNull() Drawable drawable)

        Whether a theme can be applied to this Drawable and its children.

      • wrap

         static Drawable wrap(@NonNull() Drawable drawable)

        Potentially wrap {@code drawable} so that it may be used for tinting across thedifferent API levels, via the tinting methods in this class.

        If the given drawable is wrapped, we will copy over certain state over to the wrappeddrawable, 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 withthe 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.

        Parameters:
        drawable - The Drawable to process
      • unwrap

         static <T extends Drawable> T unwrap(@NonNull() Drawable drawable)

        Unwrap {@code drawable} if it is the result of a call to wrap. Ifthe {@code drawable} is not the result of a call to wrap then {@code drawable} is returned as-is.

        Parameters:
        drawable - The drawable to unwrap
      • setLayoutDirection

         static boolean setLayoutDirection(@NonNull() Drawable drawable, int layoutDirection)

        Set the layout direction for this drawable. Should be a resolvedlayout direction, as the Drawable has no capacity to do the resolution onits own.

        Parameters:
        layoutDirection - the resolved layout direction for the drawable,either LAYOUT_DIRECTION_LTR or LAYOUT_DIRECTION_RTL