private void setTextViewStyles(TextView textView) { int[] colors = {Color.RED, Color.YELLOW, Color.BLUE};//颜色的数组 float[] position = {0f, 0.7f, 1.0f};//颜色渐变位置的数组 LinearGradient mLinearGradient = new LinearGradient(0, 0, textView.getPaint().getTextSize() * textView.getText().length(), 0, colors, position, Shader.TileMode.CLAMP); textView.getPaint().setShader(mLinearGradient); textView.invalidate(); }