2

How to change the color of the cut out for the bottom bar?

I know it takes the color from MaterialTheme.colors.background, but I don't want to change the background color for all components, only for the bottom bar. (The white color in the cut out in the picture.)

enter image description here

I have tried different things, for example setting a new theme just for the bottom bar, but that doesn't work.

val bottomBarColors = MaterialTheme.colors.copy(background = Color.LightGray)
...

bottomBar = {
    MaterialTheme(
        colors = bottomBarColors,
        typography = MaterialTheme.typography,
        shapes = MaterialTheme.shapes
    ) {
        BottomAppBar(
            cutoutShape = fabShape,
            content = {
                MyBottomNavigation(navController, bottomNavigationItems)
            })
    }
}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Mackan
  • 1,305
  • 2
  • 17
  • 30

2 Answers2

3

In your case you can apply the Modifier.background to the BottomAppBar:

    bottomBar = {
        BottomAppBar(
            modifier = Modifier.background(Color.Red),
            cutoutShape = fabShape) {

            BottomNavigation {
                /* .... */
            }
        }
    }

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
-1

The solution was easier than I thought. Just add something below the bottom bar:

bottomBar = {
        Box {
            Spacer(modifier = Modifier.matchParentSize().background(color = Color.Blue))
            BottomAppBar(
                cutoutShape = fabShape,
                content = {
                    MyBottomNavigation(navController, bottomNavigationItems)
                })
    }
}
Mackan
  • 1,305
  • 2
  • 17
  • 30