//自定义 布局中引用即可
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26public 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); } }
最后
以上就是自然绿草最近收集整理的关于文字两种颜色渐变的全部内容,更多相关文字两种颜色渐变内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复