簡體   English   中英

如何在 Android Jetpack Compose 中進行圓底導航

[英]How to make rounded bottom navigation in Android Jetpack Compose

我想在 Android Jetpack compose 中制作一個底部導航,但是在我找到的每個來源中,用 compose 構建的導航都是正常的,平坦的就像這樣, 在此處輸入圖像描述

關鍵是我找不到制作這樣的東西的方法在此處輸入圖像描述

我怎么能只做一件事? 謝謝

使用clipRoundedCornerShap

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))
        )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM