Created
July 4, 2016 11:05
-
-
Save shau-lok/01136b55658f09b27cb217c07a04f42c to your computer and use it in GitHub Desktop.
Color alpha
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
/** | |
* @param originalColor color, without alpha | |
* @param alpha from 0.0 to 1.0 | |
* @return | |
*/ | |
public static String addAlpha(String originalColor, double alpha) { | |
long alphaFixed = Math.round(alpha * 255); | |
String alphaHex = Long.toHexString(alphaFixed); | |
if (alphaHex.length() == 1) { | |
alphaHex = "0" + alphaHex; | |
} | |
originalColor = originalColor.replace("#", "#" + alphaHex); | |
return originalColor; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment