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

问题描述

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

我知道它采用 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

,

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

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...