这是一个粗心造成的低级错误,没有参考价值,因为别人回答了这个问题,所以我只好保留。
我用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
似乎有两种状态enabled
和selected
。我不明白这个enabled
是什么意思。
当我点击second
并选择second
时,first
的边框消失了,这正是我想要的,但是当我选中first
时,second
的边框仍然没有消失。
我试过将边框的宽度设置为0dp
,但仍然不起作用,仍然有一条细黑线。
border = FilterChipDefaults.filterChipBorder(
borderColor = Color.Transparent,
disabledBorderColor = Color.Transparent,
borderWidth = 0.dp,
selectedBorderWidth = 0.dp
)
1条答案
按热度按时间vlurs2pr1#
必须在两个
FilterChip
中都应用属性borderColor = Color.Transparent
。当启用且未选择时,应用此芯片的边框颜色。
.