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

标签 android android-jetpack-compose android-bottomappbar android-jetpack-compose-scaffold

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

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

enter image description here

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

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 {
                /* .... */
            }
        }
    }

enter image description here

关于android - Jetpack compose - 更改底部栏切口颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68565454/

相关文章:

flutter - 无法在flutter中显示BottomNavigationBar

android - Accordion 在我的 Android 应用程序中无法工作

android - 重新选择 ActionBar 中的 Spinner 项

android - android中synchronized中的return语句呢?

Android 蓝牙连接问题

android - Jetpack compose 中的 AppCompatActivity 而不是 ComponentActivity

android - Jetpack 撰写内部编译器参数警告

java - 为什么jetpack compose中没有热重载?理论上他们将来是否有可能在 compose 中添加类似热重载的 flutter 功能?

android - 如何确保 CoordinatorLayout 子元素不重叠

android - 底部 AppBar 两侧都有图标