FileDocCategorySizeDatePackage
ColorDrawable.javaAPI DocAndroid 1.5 API4490Wed May 06 22:42:00 BST 2009android.graphics.drawable

ColorDrawable

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.

attr
ref android.R.styleable#ColorDrawable_color

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

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

param
color The color to draw.

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

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

        canvas.drawColor(mState.mUseColor);
    
public intgetAlpha()
Returns the alpha value of this drawable's color.

return
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, com.android.internal.R.styleable.ColorDrawable);

        int color = mState.mBaseColor;
        color = a.getColor(com.android.internal.R.styleable.ColorDrawable_color, color);
        mState.mBaseColor = mState.mUseColor = color;

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

param
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.

param
colorFilter Ignore.