【问题标题】:How do I achieve this rounded corner shape around icon of a selected bottom nav item with Jetpack compose如何使用 Jetpack compose 在所选底部导航项的图标周围实现圆角形状
【发布时间】:2022-10-25 18:18:59
【问题描述】:


这就是我的 BottomNavigationItem 的样子。

 BottomNavigationItem(
                selected = selected,
                onClick = {...}
                icon = {
                        Icon(
                            imageVector = if (selected) navItem.iconFilled else navItem.iconOutlined,
                            contentDescription = navItem.route,
                           // modifier = Modifier.background(Color.DarkGray, shape = RoundedCornerShape(10.dp)).padding(10.dp)
                        )
                },
                label = {...},
                selectedContentColor = MaterialTheme.colors.onPrimary,
                unselectedContentColor = MaterialTheme.colors.onPrimary.copy(0.4f)
            )
        }
    }

【问题讨论】:

    标签: android android-studio android-jetpack-compose android-jetpack-compose-material3


    【解决方案1】:

    只需使用 M3 和 NavigationBar

    NavigationBar {
        items.forEachIndexed { index, item ->
            NavigationBarItem(
                icon = { Icon(Icons.Filled.Favorite, contentDescription = item) },
                label = { Text(item) },
                selected = selectedItem == index,
                onClick = { selectedItem = index }
            )
        }
    }
    

    【讨论】:

    • 非常感谢,不知道它一直在文档站点上,我感觉很糟糕
    猜你喜欢
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2023-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多