Here It goes,
int[] color = {Color.DKGRAY,Color.CYAN};
float[] position = {0, 1};
TileMode tile_mode = TileMode.REPEAT;
LinearGradient lin_grad = new LinearGradient(0, 0, 0, 35,color,position, tile_mode);
Shader shader_gradient = lin_grad;
your_text_view.getPaint().setShader(shader_gradient);
Edited:
Hi @android developer,
If you want to do some vertical or any gradients to the view,
Please use,
RadialGradient
instead of LinearGradient.
Only thing is you have to adjust,
x coordinate of the center of the radius.
y coordinate of the center of the radius.
and also,
radius value of the view.
and use Tile Mode as Mirror instead of Repeat.
I have sample but it may not exact of what you want,
TileMode tile_mode = TileMode.MIRROR or TileMode.REPEAT;
RadialGradient rad_grad = new RadialGradient(0, 3, 5, Color.BLUE,Color.RED,tile_mode, tile_mode);
Shader shader_gradient = rad_grad;
your_text_view.getPaint().setShader(shader_gradient);
And you can use SweepGradient
also instead of LinearGradient
.