Android 渐变色TextView

@SuppressLint("AppCompatCustomView")
public class GradientColorTextViewForManagerName extends TextView {
    public GradientColorTextViewForManagerName(Context context) {
        super(context);
    }

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

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

    @SuppressLint("DrawAllocation")
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        if (changed) {
            getPaint().setShader(new LinearGradient(0, 0, getWidth(), getHeight(), new int[]{0xFFFFEABA, 0xFFDFBB82, 0xFFBE8B49}, new float[]{0, 0.5f, 1}, Shader.TileMode.CLAMP));
        }
    }
}

https://www.jianshu.com/p/a9d09cb7577f

主要就是改前四个参数 可以实现 上下左右 或者斜着来的效果

后面的是颜色集合  还有渲染的模式.  这里注意会有颜色透明度因素影响,给TextView 设置颜色#FFFFFFFF就可以了.

猜你喜欢

转载自blog.csdn.net/FlyPig_Vip/article/details/87634608