3

如何修复顶部栏和底部栏未填满其容器。topbar 和 bottombar 分别使用默认的 Elevation

您可以看到顶部栏没有填充最大宽度并且有阴影,而底部栏有自己的文本

Scaffold(
        topBar = {
            TopAppBar(
                title = { Text( text = "TEST" ) },
                actions = {
                    IconButton(
                        onClick = { },
                    ) {
                        Icon(
                            imageVector = Icons.Filled.AccountCircle,
                            contentDescription = null
                        )
                    }
                },
            )
        },
        bottomBar = {
           BottomNavigation
            {
                val navBackStackEntry by bottomAppBarNavController.currentBackStackEntryAsState()
                val currentDestination = navBackStackEntry?.destination

                bottomBarItems.forEach { mainRoute ->
                    BottomNavigationItem(
                        selected = currentDestination?.hierarchy?.any { it.route == mainRoute.route } == true,
                        icon = {
                            Icon(
                                imageVector = mainRoute.icon,
                                contentDescription = stringResource(id = mainRoute.resourceId),
                            )
                        },
                        label = { Text( text = stringResource(id = mainRoute.resourceId), ) },
                        onClick = { },
                        alwaysShowLabel = false // This hides the title for the unselected items
                    )

                }
            }
        }
    ){

    }

Jetpack Compose 顶栏和底栏

4

1 回答 1

1

发生这种情况是因为默认情况下具有高度,TopAppBar并且BottomNavigation因为您在主题中使用半透明颜色作为primary颜色。

你可以:

  • 删除海拔:TopAppBar(elevation = 0.dp)
  • 使用纯色背景色
  • 尝试将半透明颜色转换为非透明颜色,例如: TopAppBar(backgroundColor = Color(0xD9FFFFFF).compositeOver(Color.White))
于 2021-06-10T05:45:57.210 回答