android Textview颜色渐变
16lz
2021-01-23
1.在代码中设置:
TextView mText = (TextView) findViewById(R.id.text);LinearGradient mLinearGradient = new LinearGradient(0, 0, 0, mText.getPaint().getTextSize(), Color.WHITE, Color.BLACK, Shader.TileMode.CLAMP);mText.getPaint().setShader(mLinearGradient);
2.自定义控件:
package com.leigo.demo.view;import android.content.Context;import android.graphics.Color;import android.graphics.LinearGradient;import android.graphics.Shader;import android.util.AttributeSet;import android.widget.TextView;/** * Created by Administrator on 2014/9/9. */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 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, 0, getHeight(), Color.WHITE, Color.BLACK, Shader.TileMode.CLAMP)); } }}
更多相关文章
- Android:横行滚动且隔行变色的ListView控件
- 第一章:初入Android大门(通过Button设置TextView颜色)
- Android下拉刷新上拉加载控件的使用
- Android space控件:间隙留白
- android 控件 3d 旋转效果
- Android 基础布局控件自定义view使用练习
- Android中自定义滑动选中控件WheelView
- android spinner 每行字体颜色都变化
- Android 控件之一:Button 按钮