简体   繁体   中英

Jetpack compose - change bottom bar cutout color

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.)

在此处输入图片说明

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)
            })
    }
}

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

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

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

在此处输入图片说明

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)
                })
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM