Pages

Friday, June 21, 2013

Set Gradient color in TextView.

Hello Everyone! Today I am going to post to set gradiant color in TextView using LinearGradient, RadialGradient.

LinearGradient

Add some code in onCreate() method.



1>
TextView txt1 = (TextView) findViewById(R.id.textview);
int[] color = {Color.DKGRAY,Color.CYAN};
float[] position = {0, 1};
TileMode tile_mode = TileMode.MIRROR; // or TileMode.REPEAT;
LinearGradient lin_grad = new LinearGradient(0, 0, 0, 50,color,position, tile_mode);
Shader shader_gradient = lin_grad;
txt1.getPaint().setShader(shader_gradient);
   




2>
TextView txt1 = (TextView) findViewById(R.id.textview);
int[] color = {Color.DKGRAY,Color.CYAN};
float[] position = {0, 1};
TileMode tile_mode0= TileMode.REPEAT; // or TileMode.REPEAT;
 LinearGradient lin_grad0 = new LinearGradient(0, 0, 0, 200,color,position, tile_mode0);
Shader shader_gradient0 = lin_grad0;
txt1.getPaint().setShader(shader_gradient0);



See more detail of the LinearGradient

RedialGradient


1>  
TextView txt1 = (TextView) findViewById(R.id.textview);
int[] color = {Color.DKGRAY,Color.CYAN};
TileMode tile_mode1 = TileMode.REPEAT;// or TileMode.REPEAT;
RadialGradient rad_grad = new RadialGradient(0, 3, 5, color[0], color[1], tile_mode1);
Shader shader_gradient1 = rad_grad;
txt1.getPaint().setShader(shader_gradient1);



See more detail of the RedialGradient