Android Jetpack组合顶栏和底栏默认高程内容不';不要装满它的容器
如何修复顶杆和底杆不填满其容器。 顶栏和底栏分别使用默认高程 您可以看到,顶部栏没有填充“最大宽度”,它有阴影,而底部栏有自己的文字组成Android Jetpack组合顶栏和底栏默认高程内容不';不要装满它的容器,android,kotlin,android-jetpack-compose,android-elevation,android-jetpack-compose-scaffold,Android,Kotlin,Android Jetpack Compose,Android Elevation,Android Jetpack Compose Scaffold,如何修复顶杆和底杆不填满其容器。 顶栏和底栏分别使用默认高程 您可以看到,顶部栏没有填充“最大宽度”,它有阴影,而底部栏有自己的文字组成 Scaffold( topBar = { TopAppBar( title = { Text( text = "TEST" ) }, actions = { IconButton(
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
)
}
}
}
){
}
发生这种情况是因为默认情况下,
TopAppBar
和BottomNavigation
具有高度,并且在主题中使用半透明颜色作为主颜色
你可以:
- 移除标高:
TopAppBar(标高=0.dp)
- 使用纯色背景色
- 尝试使用以下方法将半透明颜色转换为不透明颜色:
TopAppBar(backgroundColor=Color(0xD9FFFFFF).compositeOver(Color.White))