//自定义 布局中引用即可
public class TwoTextView extends TextView {
private LinearGradient mLinearGradient;
private Paint mPaint;
private int mViewWidth = 0;
private Rect mTextBound = new Rect();
public TwoTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
mViewWidth = getMeasuredWidth();
mPaint = getPaint();
String mTipText = getText().toString();
mPaint.getTextBounds(mTipText, 0, mTipText.length(), mTextBound);
mLinearGradient = new LinearGradient(0, 0, mViewWidth, 0,
new int[]{Color.parseColor("#58BEFF"),
Color.parseColor("#4463FF")},
null, Shader.TileMode.REPEAT);
mPaint.setShader(mLinearGradient);
canvas.drawText(mTipText, getMeasuredWidth() / 2 - mTextBound.width() / 2, getMeasuredHeight() / 2 + mTextBound.height() / 2, mPaint);
}
}