FileDocCategorySizeDatePackage
Drawable.javaAPI DocAndroid 5.1 API49113Thu Mar 12 22:22:30 GMT 2015android.graphics.drawable

Drawable

public abstract class Drawable extends Object
A Drawable is a general abstraction for "something that can be drawn." Most often you will deal with Drawable as the type of resource retrieved for drawing things to the screen; the Drawable class provides a generic API for dealing with an underlying visual resource that may take a variety of forms. Unlike a {@link android.view.View}, a Drawable does not have any facility to receive events or otherwise interact with the user.

In addition to simple drawing, Drawable provides a number of generic mechanisms for its client to interact with what is being drawn:

  • The {@link #setBounds} method must be called to tell the Drawable where it is drawn and how large it should be. All Drawables should respect the requested size, often simply by scaling their imagery. A client can find the preferred size for some Drawables with the {@link #getIntrinsicHeight} and {@link #getIntrinsicWidth} methods.
  • The {@link #getPadding} method can return from some Drawables information about how to frame content that is placed inside of them. For example, a Drawable that is intended to be the frame for a button widget would need to return padding that correctly places the label inside of itself.
  • The {@link #setState} method allows the client to tell the Drawable in which state it is to be drawn, such as "focused", "selected", etc. Some drawables may modify their imagery based on the selected state.
  • The {@link #setLevel} method allows the client to supply a single continuous controller that can modify the Drawable is displayed, such as a battery level or progress level. Some drawables may modify their imagery based on the current level.
  • A Drawable can perform animations by calling back to its client through the {@link Callback} interface. All clients should support this interface (via {@link #setCallback}) so that animations will work. A simple way to do this is through the system facilities such as {@link android.view.View#setBackground(Drawable)} and {@link android.widget.ImageView}.
Though usually not visible to the application, Drawables may take a variety of forms:
  • Bitmap: the simplest Drawable, a PNG or JPEG image.
  • Nine Patch: an extension to the PNG format allows it to specify information about how to stretch it and place things inside of it.
  • Shape: contains simple drawing commands instead of a raw bitmap, allowing it to resize better in some cases.
  • Layers: a compound drawable, which draws multiple underlying drawables on top of each other.
  • States: a compound drawable that selects one of a set of drawables based on its state.
  • Levels: a compound drawable that selects one of a set of drawables based on its level.
  • Scale: a compound drawable with a single child drawable, whose overall size is modified based on the current level.

Developer Guides

For more information about how to use drawables, read the Canvas and Drawables developer guide. For information and examples of creating drawable resources (XML or bitmap files that can be loaded in code), read the Drawable Resources document.

Fields Summary
private static final android.graphics.Rect
ZERO_BOUNDS_RECT
static final android.graphics.PorterDuff.Mode
DEFAULT_TINT_MODE
private int[]
mStateSet
private int
mLevel
private int
mChangingConfigurations
private android.graphics.Rect
mBounds
private WeakReference
mCallback
private boolean
mVisible
private int
mLayoutDirection
Constructors Summary
Methods Summary
public voidapplyTheme(android.content.res.Resources.Theme t)
Applies the specified theme to this Drawable and its children.

    
public booleancanApplyTheme()

        return false;
    
public voidclearColorFilter()
Removes the color filter for this drawable.

        setColorFilter(null);
    
public voidclearMutated()
Clears the mutated state, allowing this drawable to be cached and mutated again.

This is hidden because only framework drawables can be cached, so custom drawables don't need to support constant state, mutate(), or clearMutated().

hide

        // Default implementation is no-op.
    
public final voidcopyBounds(android.graphics.Rect bounds)
Return a copy of the drawable's bounds in the specified Rect (allocated by the caller). The bounds specify where this will draw when its draw() method is called.

param
bounds Rect to receive the drawable's bounds (allocated by the caller).

        bounds.set(mBounds);
    
public final android.graphics.RectcopyBounds()
Return a copy of the drawable's bounds in a new Rect. This returns the same values as getBounds(), but the returned object is guaranteed to not be changed later by the drawable (i.e. it retains no reference to this rect). If the caller already has a Rect allocated, call copyBounds(rect).

return
A copy of the drawable's bounds

        return new Rect(mBounds);
    
public static android.graphics.drawable.DrawablecreateFromPath(java.lang.String pathName)
Create a drawable from file path name.

        if (pathName == null) {
            return null;
        }

        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, pathName);
        try {
            Bitmap bm = BitmapFactory.decodeFile(pathName);
            if (bm != null) {
                return drawableFromBitmap(null, bm, null, null, null, pathName);
            }
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
        }

        return null;
    
public static android.graphics.drawable.DrawablecreateFromResourceStream(android.content.res.Resources res, android.util.TypedValue value, java.io.InputStream is, java.lang.String srcName)
Create a drawable from an inputstream, using the given resources and value to determine density information.

        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, srcName != null ? srcName : "Unknown drawable");
        try {
            return createFromResourceStream(res, value, is, srcName, null);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
        }
    
public static android.graphics.drawable.DrawablecreateFromResourceStream(android.content.res.Resources res, android.util.TypedValue value, java.io.InputStream is, java.lang.String srcName, BitmapFactory.Options opts)
Create a drawable from an inputstream, using the given resources and value to determine density information.

        if (is == null) {
            return null;
        }

        /*  ugh. The decodeStream contract is that we have already allocated
            the pad rect, but if the bitmap does not had a ninepatch chunk,
            then the pad will be ignored. If we could change this to lazily
            alloc/assign the rect, we could avoid the GC churn of making new
            Rects only to drop them on the floor.
        */
        Rect pad = new Rect();

        // Special stuff for compatibility mode: if the target density is not
        // the same as the display density, but the resource -is- the same as
        // the display density, then don't scale it down to the target density.
        // This allows us to load the system's density-correct resources into
        // an application in compatibility mode, without scaling those down
        // to the compatibility density only to have them scaled back up when
        // drawn to the screen.
        if (opts == null) opts = new BitmapFactory.Options();
        opts.inScreenDensity = res != null
                ? res.getDisplayMetrics().noncompatDensityDpi : DisplayMetrics.DENSITY_DEVICE;
        Bitmap  bm = BitmapFactory.decodeResourceStream(res, value, is, pad, opts);
        if (bm != null) {
            byte[] np = bm.getNinePatchChunk();
            if (np == null || !NinePatch.isNinePatchChunk(np)) {
                np = null;
                pad = null;
            }

            final Rect opticalInsets = new Rect();
            bm.getOpticalInsets(opticalInsets);
            return drawableFromBitmap(res, bm, np, pad, opticalInsets, srcName);
        }
        return null;
    
public static android.graphics.drawable.DrawablecreateFromStream(java.io.InputStream is, java.lang.String srcName)
Create a drawable from an inputstream

        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, srcName != null ? srcName : "Unknown drawable");
        try {
            return createFromResourceStream(null, null, is, srcName);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
        }
    
public static android.graphics.drawable.DrawablecreateFromXml(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser)
Create a drawable from an XML document. For more information on how to create resources in XML, see Drawable Resources.

        return createFromXml(r, parser, null);
    
public static android.graphics.drawable.DrawablecreateFromXml(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.content.res.Resources.Theme theme)
Create a drawable from an XML document using an optional {@link Theme}. For more information on how to create resources in XML, see Drawable Resources.

        AttributeSet attrs = Xml.asAttributeSet(parser);

        int type;
        while ((type=parser.next()) != XmlPullParser.START_TAG &&
                type != XmlPullParser.END_DOCUMENT) {
            // Empty loop
        }

        if (type != XmlPullParser.START_TAG) {
            throw new XmlPullParserException("No start tag found");
        }

        Drawable drawable = createFromXmlInner(r, parser, attrs, theme);

        if (drawable == null) {
            throw new RuntimeException("Unknown initial tag: " + parser.getName());
        }

        return drawable;
    
public static android.graphics.drawable.DrawablecreateFromXmlInner(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs)
Create from inside an XML document. Called on a parser positioned at a tag in an XML document, tries to create a Drawable from that tag. Returns null if the tag is not a valid drawable.

        return createFromXmlInner(r, parser, attrs, null);
    
public static android.graphics.drawable.DrawablecreateFromXmlInner(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs, android.content.res.Resources.Theme theme)
Create a drawable from inside an XML document using an optional {@link Theme}. Called on a parser positioned at a tag in an XML document, tries to create a Drawable from that tag. Returns {@code null} if the tag is not a valid drawable.

        final Drawable drawable;

        final String name = parser.getName();
        switch (name) {
            case "selector":
                drawable = new StateListDrawable();
                break;
            case "animated-selector":
                drawable = new AnimatedStateListDrawable();
                break;
            case "level-list":
                drawable = new LevelListDrawable();
                break;
            case "layer-list":
                drawable = new LayerDrawable();
                break;
            case "transition":
                drawable = new TransitionDrawable();
                break;
            case "ripple":
                drawable = new RippleDrawable();
                break;
            case "color":
                drawable = new ColorDrawable();
                break;
            case "shape":
                drawable = new GradientDrawable();
                break;
            case "vector":
                drawable = new VectorDrawable();
                break;
            case "animated-vector":
                drawable = new AnimatedVectorDrawable();
                break;
            case "scale":
                drawable = new ScaleDrawable();
                break;
            case "clip":
                drawable = new ClipDrawable();
                break;
            case "rotate":
                drawable = new RotateDrawable();
                break;
            case "animated-rotate":
                drawable = new AnimatedRotateDrawable();
                break;
            case "animation-list":
                drawable = new AnimationDrawable();
                break;
            case "inset":
                drawable = new InsetDrawable();
                break;
            case "bitmap":
                drawable = new BitmapDrawable(r);
                if (r != null) {
                    ((BitmapDrawable) drawable).setTargetDensity(r.getDisplayMetrics());
                }
                break;
            case "nine-patch":
                drawable = new NinePatchDrawable();
                if (r != null) {
                    ((NinePatchDrawable) drawable).setTargetDensity(r.getDisplayMetrics());
                }
                break;
            default:
                throw new XmlPullParserException(parser.getPositionDescription() +
                        ": invalid drawable tag " + name);

        }
        drawable.inflate(r, parser, attrs, theme);
        return drawable;
    
public abstract voiddraw(android.graphics.Canvas canvas)
Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).

param
canvas The canvas to draw into

private static android.graphics.drawable.DrawabledrawableFromBitmap(android.content.res.Resources res, android.graphics.Bitmap bm, byte[] np, android.graphics.Rect pad, android.graphics.Rect layoutBounds, java.lang.String srcName)


        if (np != null) {
            return new NinePatchDrawable(res, bm, np, pad, layoutBounds, srcName);
        }

        return new BitmapDrawable(res, bm);
    
public intgetAlpha()
Gets the current alpha value for the drawable. 0 means fully transparent, 255 means fully opaque. This method is implemented by Drawable subclasses and the value returned is specific to how that class treats alpha. The default return value is 255 if the class does not override this method to return a value specific to its use of alpha.

        return 0xFF;
    
public final android.graphics.RectgetBounds()
Return the drawable's bounds Rect. Note: for efficiency, the returned object may be the same object stored in the drawable (though this is not guaranteed), so if a persistent copy of the bounds is needed, call copyBounds(rect) instead. You should also not change the object returned by this method as it may be the same object stored in the drawable.

return
The bounds of the drawable (which may change later, so caller beware). DO NOT ALTER the returned object as it may change the stored bounds of this drawable.
see
#copyBounds()
see
#copyBounds(android.graphics.Rect)

        if (mBounds == ZERO_BOUNDS_RECT) {
            mBounds = new Rect();
        }

        return mBounds;
    
public android.graphics.drawable.Drawable$CallbackgetCallback()
Return the current {@link Callback} implementation attached to this Drawable.

return
A {@link Callback} instance or null if no callback was set.
see
#setCallback(android.graphics.drawable.Drawable.Callback)

        if (mCallback != null) {
            return mCallback.get();
        }
        return null;
    
public intgetChangingConfigurations()
Return a mask of the configuration parameters for which this drawable may change, requiring that it be re-created. The default implementation returns whatever was provided through {@link #setChangingConfigurations(int)} or 0 by default. Subclasses may extend this to or in the changing configurations of any other drawables they hold.

return
Returns a mask of the changing configuration parameters, as defined by {@link android.content.pm.ActivityInfo}.
see
android.content.pm.ActivityInfo

        return mChangingConfigurations;
    
public android.graphics.ColorFiltergetColorFilter()
Returns the current color filter, or {@code null} if none set.

return
the current color filter, or {@code null} if none set

        return null;
    
public android.graphics.drawable.Drawable$ConstantStategetConstantState()
Return a {@link ConstantState} instance that holds the shared state of this Drawable.

return
The ConstantState associated to that Drawable.
see
ConstantState
see
Drawable#mutate()

        return null;
    
public android.graphics.drawable.DrawablegetCurrent()

return
The current drawable that will be used by this drawable. For simple drawables, this is just the drawable itself. For drawables that change state like {@link StateListDrawable} and {@link LevelListDrawable} this will be the child drawable currently in use.

        return this;
    
public android.graphics.RectgetDirtyBounds()
Return the drawable's dirty bounds Rect. Note: for efficiency, the returned object may be the same object stored in the drawable (though this is not guaranteed).

By default, this returns the full drawable bounds. Custom drawables may override this method to perform more precise invalidation.

return
The dirty bounds of this drawable

        return getBounds();
    
public voidgetHotspotBounds(android.graphics.Rect outRect)

hide
For internal use only. Individual results may vary.

        outRect.set(getBounds());
    
public intgetIntrinsicHeight()
Return the intrinsic height of the underlying drawable object. Returns -1 if it has no intrinsic height, such as with a solid color.

        return -1;
    
public intgetIntrinsicWidth()
Return the intrinsic width of the underlying drawable object. Returns -1 if it has no intrinsic width, such as with a solid color.

        return -1;
    
public intgetLayoutDirection()
Returns the resolved layout direction for this Drawable.

return
One of {@link android.view.View#LAYOUT_DIRECTION_LTR}, {@link android.view.View#LAYOUT_DIRECTION_RTL}
hide

        return mLayoutDirection;
    
public final intgetLevel()
Retrieve the current level.

return
int Current level, from 0 (minimum) to 10000 (maximum).

        return mLevel;
    
public intgetMinimumHeight()
Returns the minimum height suggested by this Drawable. If a View uses this Drawable as a background, it is suggested that the View use at least this value for its height. (There will be some scenarios where this will not be possible.) This value should INCLUDE any padding.

return
The minimum height suggested by this Drawable. If this Drawable doesn't have a suggested minimum height, 0 is returned.

        final int intrinsicHeight = getIntrinsicHeight();
        return intrinsicHeight > 0 ? intrinsicHeight : 0;
    
public intgetMinimumWidth()
Returns the minimum width suggested by this Drawable. If a View uses this Drawable as a background, it is suggested that the View use at least this value for its width. (There will be some scenarios where this will not be possible.) This value should INCLUDE any padding.

return
The minimum width suggested by this Drawable. If this Drawable doesn't have a suggested minimum width, 0 is returned.

        final int intrinsicWidth = getIntrinsicWidth();
        return intrinsicWidth > 0 ? intrinsicWidth : 0;
    
public abstract intgetOpacity()
Return the opacity/transparency of this Drawable. The returned value is one of the abstract format constants in {@link android.graphics.PixelFormat}: {@link android.graphics.PixelFormat#UNKNOWN}, {@link android.graphics.PixelFormat#TRANSLUCENT}, {@link android.graphics.PixelFormat#TRANSPARENT}, or {@link android.graphics.PixelFormat#OPAQUE}.

Generally a Drawable should be as conservative as possible with the value it returns. For example, if it contains multiple child drawables and only shows one of them at a time, if only one of the children is TRANSLUCENT and the others are OPAQUE then TRANSLUCENT should be returned. You can use the method {@link #resolveOpacity} to perform a standard reduction of two opacities to the appropriate single output.

Note that the returned value does not take into account a custom alpha or color filter that has been applied by the client through the {@link #setAlpha} or {@link #setColorFilter} methods.

return
int The opacity class of the Drawable.
see
android.graphics.PixelFormat

public android.graphics.InsetsgetOpticalInsets()
Return in insets the layout insets suggested by this Drawable for use with alignment operations during layout.

hide

        return Insets.NONE;
    
public voidgetOutline(android.graphics.Outline outline)
Called to get the drawable to populate the Outline that defines its drawing area.

This method is called by the default {@link android.view.ViewOutlineProvider} to define the outline of the View.

The default behavior defines the outline to be the bounding rectangle of 0 alpha. Subclasses that wish to convey a different shape or alpha value must override this method.

see
android.view.View#setOutlineProvider(android.view.ViewOutlineProvider)

        outline.setRect(getBounds());
        outline.setAlpha(0);
    
public booleangetPadding(android.graphics.Rect padding)
Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds. Positive values move toward the center of the Drawable (set Rect.inset).

return
true if this drawable actually has a padding, else false. When false is returned, the padding is always set to 0.

        padding.set(0, 0, 0, 0);
        return false;
    
public int[]getState()
Describes the current state, as a union of primitve states, such as {@link android.R.attr#state_focused}, {@link android.R.attr#state_selected}, etc. Some drawables may modify their imagery based on the selected state.

return
An array of resource Ids describing the current state.

        return mStateSet;
    
public android.graphics.RegiongetTransparentRegion()
Returns a Region representing the part of the Drawable that is completely transparent. This can be used to perform drawing operations, identifying which parts of the target will not change when rendering the Drawable. The default implementation returns null, indicating no transparent region; subclasses can optionally override this to return an actual Region if they want to supply this optimization information, but it is not required that they do so.

return
Returns null if the Drawables has no transparent region to report, else a Region holding the parts of the Drawable's bounds that are transparent.

        return null;
    
public voidinflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs)
Inflate this Drawable from an XML resource. Does not apply a theme.

see
#inflate(Resources, XmlPullParser, AttributeSet, Theme)

        inflate(r, parser, attrs, null);
    
public voidinflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs, android.content.res.Resources.Theme theme)
Inflate this Drawable from an XML resource optionally styled by a theme.

param
r Resources used to resolve attribute values
param
parser XML parser from which to inflate this Drawable
param
attrs Base set of attribute values
param
theme Theme to apply, may be null
throws
XmlPullParserException
throws
IOException

        final TypedArray a;
        if (theme != null) {
            a = theme.obtainStyledAttributes(
                    attrs, com.android.internal.R.styleable.Drawable, 0, 0);
        } else {
            a = r.obtainAttributes(attrs, com.android.internal.R.styleable.Drawable);
        }

        inflateWithAttributes(r, parser, a, com.android.internal.R.styleable.Drawable_visible);
        a.recycle();
    
voidinflateWithAttributes(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.content.res.TypedArray attrs, int visibleAttr)
Inflate a Drawable from an XML resource.

throws
XmlPullParserException
throws
IOException

        mVisible = attrs.getBoolean(visibleAttr, mVisible);
    
public voidinvalidateSelf()
Use the current {@link Callback} implementation to have this Drawable redrawn. Does nothing if there is no Callback attached to the Drawable.

see
Callback#invalidateDrawable
see
#getCallback()
see
#setCallback(android.graphics.drawable.Drawable.Callback)

        final Callback callback = getCallback();
        if (callback != null) {
            callback.invalidateDrawable(this);
        }
    
public booleanisAutoMirrored()
Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left. See {@link android.util.LayoutDirection}.

return
boolean Returns true if this Drawable will be automatically mirrored.

        return false;
    
public booleanisProjected()
Whether this drawable requests projection.

hide
magic!

        return false;
    
public booleanisStateful()
Indicates whether this drawable will change its appearance based on state. Clients can use this to determine whether it is necessary to calculate their state and call setState.

return
True if this drawable changes its appearance based on state, false otherwise.
see
#setState(int[])

        return false;
    
public final booleanisVisible()

        return mVisible;
    
public voidjumpToCurrentState()
If this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations.

    
public android.graphics.drawable.Drawablemutate()
Make this drawable mutable. This operation cannot be reversed. A mutable drawable is guaranteed to not share its state with any other drawable. This is especially useful when you need to modify properties of drawables loaded from resources. By default, all drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification. Calling this method on a mutable Drawable will have no effect.

return
This drawable.
see
ConstantState
see
#getConstantState()

        return this;
    
static android.content.res.TypedArrayobtainAttributes(android.content.res.Resources res, android.content.res.Resources.Theme theme, android.util.AttributeSet set, int[] attrs)
Obtains styled attributes from the theme, if available, or unstyled resources if the theme is null.

        if (theme == null) {
            return res.obtainAttributes(set, attrs);
        }
        return theme.obtainStyledAttributes(set, attrs, 0, 0);
    
protected voidonBoundsChange(android.graphics.Rect bounds)
Override this in your subclass to change appearance if you vary based on the bounds.

protected booleanonLevelChange(int level)
Override this in your subclass to change appearance if you vary based on level.

return
Returns true if the level change has caused the appearance of the Drawable to change (that is, it needs to be drawn), else false if it looks the same and there is no need to redraw it since its last level.

 return false; 
protected booleanonStateChange(int[] state)
Override this in your subclass to change appearance if you recognize the specified state.

return
Returns true if the state change has caused the appearance of the Drawable to change (that is, it needs to be drawn), else false if it looks the same and there is no need to redraw it since its last state.

 return false; 
public static android.graphics.PorterDuff.ModeparseTintMode(int value, android.graphics.PorterDuff.Mode defaultMode)
Parses a {@link android.graphics.PorterDuff.Mode} from a tintMode attribute's enum value.

hide

        switch (value) {
            case 3: return Mode.SRC_OVER;
            case 5: return Mode.SRC_IN;
            case 9: return Mode.SRC_ATOP;
            case 14: return Mode.MULTIPLY;
            case 15: return Mode.SCREEN;
            case 16: return Mode.ADD;
            default: return defaultMode;
        }
    
public static intresolveOpacity(int op1, int op2)
Return the appropriate opacity value for two source opacities. If either is UNKNOWN, that is returned; else, if either is TRANSLUCENT, that is returned; else, if either is TRANSPARENT, that is returned; else, OPAQUE is returned.

This is to help in implementing {@link #getOpacity}.

param
op1 One opacity value.
param
op2 Another opacity value.
return
int The combined opacity value.
see
#getOpacity

        if (op1 == op2) {
            return op1;
        }
        if (op1 == PixelFormat.UNKNOWN || op2 == PixelFormat.UNKNOWN) {
            return PixelFormat.UNKNOWN;
        }
        if (op1 == PixelFormat.TRANSLUCENT || op2 == PixelFormat.TRANSLUCENT) {
            return PixelFormat.TRANSLUCENT;
        }
        if (op1 == PixelFormat.TRANSPARENT || op2 == PixelFormat.TRANSPARENT) {
            return PixelFormat.TRANSPARENT;
        }
        return PixelFormat.OPAQUE;
    
public voidscheduleSelf(java.lang.Runnable what, long when)
Use the current {@link Callback} implementation to have this Drawable scheduled. Does nothing if there is no Callback attached to the Drawable.

param
what The action being scheduled.
param
when The time (in milliseconds) to run.
see
Callback#scheduleDrawable

        final Callback callback = getCallback();
        if (callback != null) {
            callback.scheduleDrawable(this, what, when);
        }
    
public abstract voidsetAlpha(int alpha)
Specify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque.

public voidsetAutoMirrored(boolean mirrored)
Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left). See {@link android.util.LayoutDirection}.

param
mirrored Set to true if the Drawable should be mirrored, false if not.

    
public voidsetBounds(int left, int top, int right, int bottom)
Specify a bounding rectangle for the Drawable. This is where the drawable will draw when its draw() method is called.


                                      
        

                             
              
        Rect oldBounds = mBounds;

        if (oldBounds == ZERO_BOUNDS_RECT) {
            oldBounds = mBounds = new Rect();
        }

        if (oldBounds.left != left || oldBounds.top != top ||
                oldBounds.right != right || oldBounds.bottom != bottom) {
            if (!oldBounds.isEmpty()) {
                // first invalidate the previous bounds
                invalidateSelf();
            }
            mBounds.set(left, top, right, bottom);
            onBoundsChange(mBounds);
        }
    
public voidsetBounds(android.graphics.Rect bounds)
Specify a bounding rectangle for the Drawable. This is where the drawable will draw when its draw() method is called.

        setBounds(bounds.left, bounds.top, bounds.right, bounds.bottom);
    
public final voidsetCallback(android.graphics.drawable.Drawable$Callback cb)
Bind a {@link Callback} object to this Drawable. Required for clients that want to support animated drawables.

param
cb The client's Callback implementation.
see
#getCallback()

        mCallback = new WeakReference<Callback>(cb);
    
public voidsetChangingConfigurations(int configs)
Set a mask of the configuration parameters for which this drawable may change, requiring that it be re-created.

param
configs A mask of the changing configuration parameters, as defined by {@link android.content.pm.ActivityInfo}.
see
android.content.pm.ActivityInfo

        mChangingConfigurations = configs;
    
public abstract voidsetColorFilter(android.graphics.ColorFilter cf)
Specify an optional color filter for the drawable. Pass {@code null} to remove any existing color filter.

param
cf the color filter to apply, or {@code null} to remove the existing color filter

public voidsetColorFilter(int color, android.graphics.PorterDuff.Mode mode)
Specify a color and Porter-Duff mode to be the color filter for this drawable.

        setColorFilter(new PorterDuffColorFilter(color, mode));
    
public voidsetDither(boolean dither)
Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component. This can improve the look on those devices, but can also slow down the drawing a little.

public voidsetFilterBitmap(boolean filter)
Set to true to have the drawable filter its bitmap when scaled or rotated (for drawables that use bitmaps). If the drawable does not use bitmaps, this call is ignored. This can improve the look when scaled or rotated, but also slows down the drawing.

public voidsetHotspot(float x, float y)
Specifies the hotspot's location within the drawable.

param
x The X coordinate of the center of the hotspot
param
y The Y coordinate of the center of the hotspot

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

param
left
param
top
param
right
param
bottom

public voidsetLayoutDirection(int layoutDirection)
Set the layout direction for this drawable. Should be a resolved direction as the Drawable as no capacity to do the resolution on his own.

param
layoutDirection One of {@link android.view.View#LAYOUT_DIRECTION_LTR}, {@link android.view.View#LAYOUT_DIRECTION_RTL}
hide

        if (getLayoutDirection() != layoutDirection) {
            mLayoutDirection = layoutDirection;
        }
    
public final booleansetLevel(int level)
Specify the level for the drawable. This allows a drawable to vary its imagery based on a continuous controller, for example to show progress or volume level.

If the new level you are supplying causes the appearance of the Drawable to change, then it is responsible for calling {@link #invalidateSelf} in order to have itself redrawn, and true will be returned from this function.

param
level The new level, from 0 (minimum) to 10000 (maximum).
return
Returns true if this change in level has caused the appearance of the Drawable to change (hence requiring an invalidate), otherwise returns false.

        if (mLevel != level) {
            mLevel = level;
            return onLevelChange(level);
        }
        return false;
    
public booleansetState(int[] stateSet)
Specify a set of states for the drawable. These are use-case specific, so see the relevant documentation. As an example, the background for widgets like Button understand the following states: [{@link android.R.attr#state_focused}, {@link android.R.attr#state_pressed}].

If the new state you are supplying causes the appearance of the Drawable to change, then it is responsible for calling {@link #invalidateSelf} in order to have itself redrawn, and true will be returned from this function.

Note: The Drawable holds a reference on to stateSet until a new state array is given to it, so you must not modify this array during that time.

param
stateSet The new set of states to be displayed.
return
Returns true if this change in state has caused the appearance of the Drawable to change (hence requiring an invalidate), otherwise returns false.

        if (!Arrays.equals(mStateSet, stateSet)) {
            mStateSet = stateSet;
            return onStateChange(stateSet);
        }
        return false;
    
public voidsetTint(int tint)
Specifies a tint for this drawable.

Setting a color filter via {@link #setColorFilter(ColorFilter)} overrides tint.

param
tint Color to use for tinting this drawable
see
#setTintMode(PorterDuff.Mode)

        setTintList(ColorStateList.valueOf(tint));
    
public voidsetTintList(android.content.res.ColorStateList tint)
Specifies a tint for this drawable as a color state list.

Setting a color filter via {@link #setColorFilter(ColorFilter)} overrides tint.

param
tint Color state list to use for tinting this drawable, or null to clear the tint
see
#setTintMode(PorterDuff.Mode)

public voidsetTintMode(android.graphics.PorterDuff.Mode tintMode)
Specifies a tint blending mode for this drawable.

Setting a color filter via {@link #setColorFilter(ColorFilter)} overrides tint.

param
tintMode Color state list to use for tinting this drawable, or null to clear the tint
param
tintMode A Porter-Duff blending mode

public booleansetVisible(boolean visible, boolean restart)
Set whether this Drawable is visible. This generally does not impact the Drawable's behavior, but is a hint that can be used by some Drawables, for example, to decide whether run animations.

param
visible Set to true if visible, false if not.
param
restart You can supply true here to force the drawable to behave as if it has just become visible, even if it had last been set visible. Used for example to force animations to restart.
return
boolean Returns true if the new visibility is different than its previous state.

        boolean changed = mVisible != visible;
        if (changed) {
            mVisible = visible;
            invalidateSelf();
        }
        return changed;
    
public voidsetXfermode(android.graphics.Xfermode mode)

hide
Consider for future API inclusion

        // Base implementation drops it on the floor for compatibility. Whee!
        // TODO: For this to be included in the API proper, all framework drawables need impls.
        // For right now only BitmapDrawable has it.
    
public voidunscheduleSelf(java.lang.Runnable what)
Use the current {@link Callback} implementation to have this Drawable unscheduled. Does nothing if there is no Callback attached to the Drawable.

param
what The runnable that you no longer want called.
see
Callback#unscheduleDrawable

        final Callback callback = getCallback();
        if (callback != null) {
            callback.unscheduleDrawable(this, what);
        }
    
android.graphics.PorterDuffColorFilterupdateTintFilter(android.graphics.PorterDuffColorFilter tintFilter, android.content.res.ColorStateList tint, android.graphics.PorterDuff.Mode tintMode)
Ensures the tint filter is consistent with the current tint color and mode.

        if (tint == null || tintMode == null) {
            return null;
        }

        final int color = tint.getColorForState(getState(), Color.TRANSPARENT);
        if (tintFilter == null) {
            return new PorterDuffColorFilter(color, tintMode);
        }

        tintFilter.setColor(color);
        tintFilter.setMode(tintMode);
        return tintFilter;