Search code examples
kotlincolorsandroid-jetpack-compose

Jetpack Compose how to build custom Color by overlaying 2 existing colors in code?


Designers often building custom colors by putting existing colros from "our" custom theme one of top of another with alpha applied. How can I calculate resulting Color without applying multiple backgrounds one of top of another? Something like

val background = MaterialTheme.colors.MyDanger.copy(alpha = 0.12f) + MaterialTheme.colors.CustomTint16

Plus is not defined for Colors as it's not Commutative, but is there a way to just put one Color on top on another in Code and apply only result?


Solution

  • val result = color1.compositeOver(color2)
    

    Is what I was looking for