Created
November 18, 2014 09:28
-
-
Save ishitcno1/0c8bcb8ad72cb0879acb to your computer and use it in GitHub Desktop.
rainbow textview android ref: http://chiuki.github.io/android-shaders-filters/#/5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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