Is it possible to change the background color of a...
# compose
z
Is it possible to change the background color of a
DropdownMenu
? It seems to inherit it from the theme internally. Using
Modifier.background
doesnt work in the sense that Im able to see parts of the inherited background as well.
d
you can replace your theme with new colors just for
DropdownMenu
using
CompositionLocal
z
@Dmitry Strekha Im not using MaterialTheme actually, just their components. Everything is stylized perfectly... except for
DropdownMenu
.
s
I've had the same issue while using custom theme as well, and ended up wrapping
DropdownMenu
in a custom component and doing this:
Copy code
@Composable
internal fun ProvidersOverrides(
  colors: Colors = MaterialDebugColors,
  content: @Composable () -> Unit
) {
  MaterialTheme(
    colors = colors,
    shapes = Shapes(),
  ) {
    CompositionLocalProvider(
      LocalRippleTheme provides AppRippleTheme,
      LocalTextSelectionColors provides AppTextSelectionColors,
    ) {
      content()
    }
  }
}
With the actual component looking like this:
Copy code
fun DropdownMenu(...proxy params...) {
  ProvidersOverrides(
    colors = MaterialDebugColors.copy(surface = AppTheme.colors.surface)
  ) {
    DropdownMenu(...proxy params...)
  }
}
z
@steelahhh Thanks, Im effectively doing the same thing at the root of my custom theme currently. Id like to get rid of it if possible though as Im also passing in awful colors normally so that I can easily detect if Im relying on the wrong theme somewhere.