TextView设置渐变色
This commit is contained in:
parent
4a6db058d4
commit
55cb9f689b
23
Android/Demo1/TextViewColor.java
Normal file
23
Android/Demo1/TextViewColor.java
Normal 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();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user