(原创)实现渐变颜色的textview

package com.vsoontech.p2p.sample;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * @author zhou
 * @since 2016/8/19
 */

public class GradientTextView extends TextView {
    public GradientTextView(Context context) {
        super(context);
    }

    public GradientTextView(Context context,
                            AttributeSet attrs) {
        super(context, attrs);
    }

    public GradientTextView(Context context,
                            AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        getPaint().setShader(new LinearGradient(
                0, 0, 0, getHeight(),
                Color.YELLOW, Color.RED,
                Shader.TileMode.CLAMP));
    }
}
xml文件直接引用即可。

你可能感兴趣的:(渐变颜色的textview,渐变颜色的textview)