Skip to content

Instantly share code, notes, and snippets.

@shau-lok
Created July 4, 2016 11:05
Show Gist options
  • Save shau-lok/01136b55658f09b27cb217c07a04f42c to your computer and use it in GitHub Desktop.
Save shau-lok/01136b55658f09b27cb217c07a04f42c to your computer and use it in GitHub Desktop.
Color alpha
/**
* @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