如何在 Android Jetpack Compose 中制作圆形底部导航
How to make rounded bottom navigation in Android Jetpack Compose
我想在 Android Jetpack compose 中做一个底部导航,但在我找到的每个源中,用 compose 构建的导航是正常的,扁平的
像这样,
重点是我找不到制作这样东西的方法
我怎样才能只做一件事?
谢谢
使用clip
和RoundedCornerShap
:
var selectedItem by remember { mutableStateOf(0) }
val items = listOf("Songs", "Artists", "Playlists")
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.BottomStart) {
BottomNavigation(modifier = Modifier.clip(shape = RoundedCornerShape(topStart = 20.dp, topEnd = 20.dp))) {
items.forEachIndexed { index, item ->
BottomNavigationItem(
icon = { Icon(Icons.Filled.Favorite, contentDescription = null) },
label = { Text(item) },
selected = selectedItem == index,
onClick = { selectedItem = index }
)
}
}
}
只需使用 clip
Modifier
并在顶角添加 RoundedCornerShape
,这里是示例代码
BottomNavigation(
backgroundColor = colorResource(id = R.color.black),
modifier = Modifier.fillMaxWidth().clip(RoundedCornerShape(15.dp, 15.dp, 0.dp, 0.dp))
)
我想在 Android Jetpack compose 中做一个底部导航,但在我找到的每个源中,用 compose 构建的导航是正常的,扁平的
像这样,
重点是我找不到制作这样东西的方法
我怎样才能只做一件事? 谢谢
使用clip
和RoundedCornerShap
:
var selectedItem by remember { mutableStateOf(0) }
val items = listOf("Songs", "Artists", "Playlists")
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.BottomStart) {
BottomNavigation(modifier = Modifier.clip(shape = RoundedCornerShape(topStart = 20.dp, topEnd = 20.dp))) {
items.forEachIndexed { index, item ->
BottomNavigationItem(
icon = { Icon(Icons.Filled.Favorite, contentDescription = null) },
label = { Text(item) },
selected = selectedItem == index,
onClick = { selectedItem = index }
)
}
}
}
只需使用 clip
Modifier
并在顶角添加 RoundedCornerShape
,这里是示例代码
BottomNavigation(
backgroundColor = colorResource(id = R.color.black),
modifier = Modifier.fillMaxWidth().clip(RoundedCornerShape(15.dp, 15.dp, 0.dp, 0.dp))
)