Peter
12/13/2024, 12:05 PMNavigationBar
and you want content to scroll behind it. How can I provide additional padding to each screen, so that content can scroll above navigation bar? (On screenshot, how can I make Text
scroll above the NavigationBar
)
Example in 🧵Peter
12/13/2024, 12:05 PM@Composable
@Preview
fun Test() {
var selectedItem by remember { mutableIntStateOf(0) }
val items = listOf("Songs", "Artists", "Playlists")
val selectedIcons = listOf(
Icons.Filled.Home,
Icons.Filled.Favorite,
Icons.Filled.Star
)
val unselectedIcons = listOf(
Icons.Outlined.Home,
Icons.Outlined.FavoriteBorder,
Icons.Outlined.StarBorder
)
Box {
Surface {
Column(modifier = Modifier.fillMaxSize().navigationBarsPadding()) {
Box(Modifier.weight(1f))
Text("Some text")
}
}
NavigationBar(
modifier = Modifier.align(Alignment.BottomCenter),
containerColor = Color.Gray.copy(alpha = 0.5f)
) {
items.forEachIndexed { index, item ->
NavigationBarItem(
icon = {
Icon(
if (selectedItem == index) selectedIcons[index] else unselectedIcons[index],
contentDescription = item
)
},
label = { Text(item) },
selected = selectedItem == index,
onClick = { selectedItem = index }
)
}
}
}
}
Stylianos Gakis
12/13/2024, 12:07 PMPeter
12/13/2024, 12:08 PMStylianos Gakis
12/13/2024, 12:08 PMPeter
12/13/2024, 12:08 PMPeter
12/13/2024, 12:08 PMPeter
12/13/2024, 12:09 PMModifier.navigationBarsPadding()
, like Modifier.myAppBarPadding()
?Stylianos Gakis
12/13/2024, 12:09 PMcontentPadding
input to your screen.
You can get the height using onPlaced
on your nav bar for example.
If you absolutely need it to be there on the first frame you might need to make it a custom layout yourselfStylianos Gakis
12/13/2024, 12:10 PMmaterial3.Scaffold
does this, because I think they also make this happen, albeit using SubComposeLayoutPeter
12/13/2024, 12:12 PMPeter
12/13/2024, 12:12 PMStylianos Gakis
12/13/2024, 12:14 PM