Brett Best
07/14/2020, 4:02 PMmanueldidonna
07/14/2020, 4:22 PMBrett Best
07/14/2020, 4:26 PMmanueldidonna
07/14/2020, 5:11 PM@Composable
fun primaryColor(elevation: Int): Color {
//this is a composable so you need the annotation
val colors = MaterialTheme.colors
return /** do whatever you want with colors and elevation */
}
Brett Best
07/14/2020, 5:27 PMTopAppBar(
title = { Text(selectedItem.value.label) },
elevation = 0.dp
)
Unless I specify the elevation to be 0, the color specified in my MaterialTheme get adjusted. This seems to be done internally using getBackgroundColorForElevation(color: Color, elevation: Dp)
. Looking at the implementation, if I implemented an Ambient for my color palette I can disable that behaviour.manueldidonna
07/14/2020, 6:21 PMSurface
composable applies the elevation to the color if it's the surface one (color == ColorPalette.surface
) and the theme is dark. If you want to use an unelevated surface color, set ColorPalette.surface to a placeholder value and pass your real color as the backgroundColor
parameter of TopAppBar@Composable fun UnelevatedAppBar() {
val colors = MaterialTheme.colors
val surface = colors.surface
MaterialTheme(colors.copy(surface=FakeColor)) {
TopAppBar(... backgroundColor = surface)
}
}