繁体   English   中英

Jetpack compose - 更改底部栏切口颜色

[英]Jetpack compose - change bottom bar cutout color

如何更改底部栏的切口颜色?

我知道它采用MaterialTheme.colors.background的颜色,但我不想更改所有组件的背景颜色,仅更改底部栏的背景颜色。 (图中剪下的白色。)

在此处输入图片说明

我尝试了不同的方法,例如只为底部栏设置一个新主题,但这不起作用。

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

在您的情况下,您可以将Modifier.background应用于BottomAppBar

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

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

在此处输入图片说明

解决方案比我想象的要容易。 只需在底部栏下方添加一些内容:

bottomBar = {
        Box {
            Spacer(modifier = Modifier.matchParentSize().background(color = Color.Blue))
            BottomAppBar(
                cutoutShape = fabShape,
                content = {
                    MyBottomNavigation(navController, bottomNavigationItems)
                })
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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