Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ishitcno1
Created November 18, 2014 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishitcno1/0c8bcb8ad72cb0879acb to your computer and use it in GitHub Desktop.
Save ishitcno1/0c8bcb8ad72cb0879acb to your computer and use it in GitHub Desktop.
public class RainbowTextView extends TextView {
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
int[] rainbow = getRainbowColors();
Shader shader = new LinearGradient(0, 0, 0, w, rainbow,
null, Shader.TileMode.MIRROR);
Matrix matrix = new Matrix();
matrix.setRotate(90);
shader.setLocalMatrix(matrix);
getPaint().setShader(shader);
}
private int[] getRainbowColors() {
return new int[] {
getResources().getColor(R.color.rainbow_red),
getResources().getColor(R.color.rainbow_yellow),
getResources().getColor(R.color.rainbow_green),
getResources().getColor(R.color.rainbow_blue),
getResources().getColor(R.color.rainbow_purple)
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment