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 Textview颜色渐变_第1张图片

更多相关文章

  1. Android:横行滚动且隔行变色的ListView控件
  2. 第一章:初入Android大门(通过Button设置TextView颜色)
  3. Android下拉刷新上拉加载控件的使用
  4. Android space控件:间隙留白
  5. android 控件 3d 旋转效果
  6. Android 基础布局控件自定义view使用练习
  7. Android中自定义滑动选中控件WheelView
  8. android spinner 每行字体颜色都变化
  9. Android 控件之一:Button 按钮

随机推荐

  1. Android中获取IMEI码
  2. android 返回到首页
  3. AndroidManifest文件中android属性
  4. Unity调用安卓
  5. Android(安卓)获取经纬度
  6. Android中hardware源码(android-5.0.2)
  7. Android View滑动
  8. android开启闪光灯
  9. 安卓课程二十二 ImageView的基本用法
  10. 升级到Android 10和gradle升级