使用Android Material3过滤芯片的一些问题

d7v8vwbk  于 2023-02-17  发布在  Android
关注(0)|答案(1)|浏览(142)

这是一个粗心造成的低级错误,没有参考价值,因为别人回答了这个问题,所以我只好保留。

我用Compose的FilterChip创建了一个页面:

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TestPage() {

    var order by remember { mutableStateOf(true) }

    val updateIsASCOrder: (b: Boolean) -> Unit = { order = it }

    Row {
        FilterChip(
            border = FilterChipDefaults.filterChipBorder(
                borderColor = Color.Transparent,
                disabledBorderColor = Color.Transparent
            ),
            modifier = Modifier.weight(1f),
            selected = order,
            onClick = { updateIsASCOrder(true) },
            label = { Text("first") })
        FilterChip(
            modifier = Modifier.weight(1f),
            selected = !order,
            onClick = { updateIsASCOrder(false) },
            label = { Text("second") })
    }
}

然后运行结果,如下所示:

如何删除此灰色边框?

FilterChip中有一个概念我不是很理解,

/**
     * Creates a [SelectableChipBorder] that represents the default border used in a flat
     * [FilterChip].
     *
     * @param borderColor the border color of this chip when enabled and not selected
     * @param selectedBorderColor the border color of this chip when enabled and selected
     * @param disabledBorderColor the border color of this chip when not enabled and not
     * selected
     * @param disabledSelectedBorderColor the border color of this chip when not enabled
     * but selected
     * @param borderWidth the border stroke width of this chip when not selected
     * @param selectedBorderWidth the border stroke width of this chip when selected
     */
    @Composable
    fun filterChipBorder

FilterChip似乎有两种状态enabledselected。我不明白这个enabled是什么意思。

当我点击second并选择second时,first的边框消失了,这正是我想要的,但是当我选中first时,second的边框仍然没有消失。
我试过将边框的宽度设置为0dp,但仍然不起作用,仍然有一条细黑线。

border = FilterChipDefaults.filterChipBorder(
                borderColor = Color.Transparent,
                disabledBorderColor = Color.Transparent,
                borderWidth = 0.dp,
                selectedBorderWidth = 0.dp
            )
vlurs2pr

vlurs2pr1#

必须在两个FilterChip中都应用属性borderColor = Color.Transparent
启用未选择时,应用此芯片的边框颜色。

FilterChip(
        border = FilterChipDefaults.filterChipBorder(
            borderColor = Color.Transparent,
        )
       //....
  )


.

相关问题