textcolor的颜色渐变
问题描述:
我有一个textview。我想通过渐变来改变文字的颜色,但它不起作用textcolor的颜色渐变
<shape android:shape="rectangle" >
<gradient
android:angle="90"
android:startColor="#eabd00"
android:centerColor="#fef1b2"
android:endColor="#f9e273"
android:type="linear" />
</shape>
有人能帮助我吗?谢谢大家。
答
试试这个
TextView textView = findViewById(R.id.btnLogin)
Shader textShader=new LinearGradient(0, 0, 0, 20,
new int[]{R.color.colorAccent,R.color.colorPrimary},
new float[]{0, 1}, TileMode.CLAMP);
textView.getPaint().setShader(textShader);
或本
TextView txt1 = (TextView) findViewById(R.id.textview);
int[] color = {Color.DKGRAY,Color.CYAN};
float[] position = {0, 1};
TileMode tile_mode = TileMode.MIRROR; // or TileMode.REPEAT;
LinearGradient lin_grad = new LinearGradient(0, 0, 0, 50,color,position, tile_mode);
Shader shader_gradient = lin_grad;
txt1.getPaint().setShader(shader_gradient);