android 如何在BottomBar Jetpack Composer中删除选定椭圆形项目颜色

8yoxcaq7  于 2022-11-20  发布在  Android
关注(0)|答案(1)|浏览(154)

我想删除所选项目后面的蓝色椭圆。如何执行此操作?

NavigationBarItem(
        selected = selected,
        onClick = onClick,
        icon = if (selected) selectedIcon else icon,
        modifier = modifier,
        enabled = enabled,
        label = label,
        alwaysShowLabel = alwaysShowLabel,
        colors = NavigationBarItemDefaults.colors(
            selectedIconColor = AppDefaults.navigationSelectedItemColor(),
            unselectedIconColor = AppDefaults.navigationContentColor(),
            selectedTextColor = AppDefaults.navigationSelectedItemColor(),
            unselectedTextColor = AppDefaults.navigationContentColor(),
            indicatorColor = AppDefaults.navigationIndicatorColor()
        )
    )

flseospp

flseospp1#

指示器的颜色由NavigationBarItem中的**indicatorColor**属性定义。
要删除它,您必须应用与NavigationBar相同的containerColor
如果使用默认值(containerColor = surface颜色),则必须计算应用于containerColor的不同高程处的表面色调颜色。
类似于:

NavigationBarItem(
    icon = { androidx.compose.material3.Icon(Icons.Filled.Favorite, contentDescription = item) },
    label = { androidx.compose.material3.Text(item) },
    selected = selectedItem == index,
    onClick = { selectedItem = index },
    colors = androidx.compose.material3.NavigationBarItemDefaults
        .colors(
            selectedIconColor = Red,
            indicatorColor = MaterialTheme.colorScheme.surfaceColorAtElevation(LocalAbsoluteTonalElevation.current) 
        )
)

在其他情况下只使用相同的颜色:

NavigationBar(
    containerColor = Yellow
){

    items.forEachIndexed { index, item ->
        NavigationBarItem(
            icon = { androidx.compose.material3.Icon(Icons.Filled.Favorite, contentDescription = item) },
            label = { androidx.compose.material3.Text(item) },
            selected = selectedItem == index,
            onClick = { selectedItem = index },
            colors = androidx.compose.material3.NavigationBarItemDefaults
                .colors(
                    selectedIconColor = Red,
                    indicatorColor = Yellow )
        )
    }
}

相关问题