Last active
August 12, 2020 06:31
Star
You must be signed in to star a gist
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
fun Context.attributeColorWithAlpha( | |
@AttrRes overlayColorAttributeResId: Int, | |
@FloatRange(from = 0.0, to = 1.0) overlayAlpha: Float | |
): Int { | |
val surfaceColor = MaterialColors.getColor(this, R.attr.colorSurface, "Color surface not found") | |
val colorWithAlpha = MaterialColors.getColor(this, overlayColorAttributeResId, "Color attribute not found").let { | |
MaterialColors.compositeARGBWithAlpha(it, (255 * overlayAlpha).roundToInt()) | |
} | |
return MaterialColors.layer(surfaceColor, colorWithAlpha) | |
} |
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
val error8Alpha = context.attributeColorWithAlpha(R.attr.colorError, 0.08f) | |
val success50Alpha = context.attributeColorWithAlpha(R.attr.success, 0.5f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment