ColorDrawable.javaAPI DocAndroid 1.5 API4490Wed May 06 22:42:00 BST


public class ColorDrawable extends Drawable
A specialized Drawable that fills the Canvas with a specified color, with respect to the clip region. Note that a ColorDrawable ignores the ColorFilter. It also ignores the Bounds, meaning it will draw everywhere in the current clip, even if setBounds(...) was called with a smaller area.

It can be defined in an XML file with the <color> element.

ref android.R.styleable#ColorDrawable_color

Fields Summary
private ColorState
Constructors Summary
public ColorDrawable()
Creates a new black ColorDrawable.

public ColorDrawable(int color)
Creates a new ColorDrawable with the specified color.

color The color to draw.

        mState.mBaseColor = mState.mUseColor = color;
private ColorDrawable(ColorState state)

        mState = new ColorState(state);
Methods Summary
public voiddraw(Canvas canvas)

public intgetAlpha()
Returns the alpha value of this drawable's color.

A value between 0 and 255.

        return mState.mUseColor >>> 24;
public intgetChangingConfigurations()

        return super.getChangingConfigurations() | mState.mChangingConfigurations;
public ConstantStategetConstantState()

        mState.mChangingConfigurations = super.getChangingConfigurations();
        return mState;
public intgetOpacity()

        switch (mState.mUseColor >>> 24) {
            case 255:
                return PixelFormat.OPAQUE;
            case 0:
                return PixelFormat.TRANSPARENT;
        return PixelFormat.TRANSLUCENT;
public voidinflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs)

        super.inflate(r, parser, attrs);

        TypedArray a = r.obtainAttributes(attrs,;

        int color = mState.mBaseColor;
        color = a.getColor(, color);
        mState.mBaseColor = mState.mUseColor = color;

public voidsetAlpha(int alpha)
Sets the color's alpha value.

alpha The alpha value to set, between 0 and 255.

        alpha += alpha >> 7;   // make it 0..256
        int baseAlpha = mState.mBaseColor >>> 24;
        int useAlpha = baseAlpha * alpha >> 8;
        mState.mUseColor = (mState.mBaseColor << 8 >>> 8) | (useAlpha << 24);
public voidsetColorFilter(ColorFilter colorFilter)
Setting a color filter on a ColorDrawable has no effect.

colorFilter Ignore.