diff --git a/Android/Demo1/TextViewColor.java b/Android/Demo1/TextViewColor.java new file mode 100644 index 0000000..f4d5614 --- /dev/null +++ b/Android/Demo1/TextViewColor.java @@ -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(); +} \ No newline at end of file