Created
May 14, 2019 03:05
-
-
Save Pinned/91b09089ed0eb8d93ee79376c80c6c07 to your computer and use it in GitHub Desktop.
颜色转换,变暗效果。可用于按钮点击效果。 Convert the color, return the new color that dark than before. this can be used for btn click preview.
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 static int manipulateColor(int color, float rFactor, float gFactor, float bFactor) { | |
int a = Color.alpha(color); | |
int r = Math.round(Color.red(color) * rFactor); | |
int g = Math.round(Color.green(color) * gFactor); | |
int b = Math.round(Color.blue(color) * bFactor); | |
return Color.argb(a, | |
Math.min(r, 255), | |
Math.min(g, 255), | |
Math.min(b, 255)); | |
} | |
public static void example() { | |
int color = Color.argb(255, 244, 68, 68); | |
int colorDark = manipulateColor(color, 0.8f, 0.6f, 0.6f); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment