TextView设置渐变色

This commit is contained in:
yutou 2023-04-02 16:00:19 +08:00
parent 4a6db058d4
commit 55cb9f689b

View File

@ -0,0 +1,23 @@
//设置TextView渐变色
public void setTextViewColor(){
//渐变色
int[] colors = {
Color.parseColor("#E38100"),
Color.parseColor("#F1B868"),
Color.parseColor("#DA9505"),
Color.parseColor("#FDB871"),
Color.parseColor("#E57810")
};
//渐变位置
float[] position = {
0f,
0.2f,
0.4f,
0.8f,
1.0f
};
//设置渐变
LinearGradient mLinearGradient = new LinearGradient(0, 0, title.getPaint().getTextSize() * title.getText().length(), 0, colors, position, Shader.TileMode.CLAMP);
title.getPaint().setShader(mLinearGradient);
title.invalidate();
}