ColorDrawable

ColorDrawable 是最简单的 Drawable,也是平时用的最多的,比如:

    android:background="@color/colorAccent"


对于 Drawable 而言,看 draw 函数基本就够了:

    @Override
    public void draw(Canvas canvas) {
        final ColorFilter colorFilter = mPaint.getColorFilter();
        if ((mColorState.mUseColor >>> 24) != 0 || colorFilter != null || mTintFilter != null) {
            if (colorFilter == null) {
                mPaint.setColorFilter(mTintFilter);
            }

            mPaint.setColor(mColorState.mUseColor);
            canvas.drawRect(getBounds(), mPaint);

            // Restore original color filter.
            mPaint.setColorFilter(colorFilter);
        }
    }


你可能感兴趣的:(ColorDrawable)