ColorDrawable

来源:互联网 发布:在4a做文案策划 知乎 编辑:程序博客网 时间:2024/06/06 05:48

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);        }    }


0 0
原创粉丝点击