android Textview颜色渐变
16lz
2022-06-17
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限定行数最大值,点击按钮显示所有内容
- Android(安卓)动态设置全屏,退出全屏
- Android(安卓)带输入框的弹出框
- android调用NotificationManager.notify无效,通知栏不显示
- android edittxet 设置可点击不可编辑状态
- Android(安卓)实现图片的放大缩小及左右滑动(说明书效果)
- android隐藏以及显示软键盘以及不自动弹出键盘的方法
- Eclipse 开发 Android, Hello, DatePicker (学习7)
- Android(安卓)Keep screen on(保持屏幕唤醒)