Jetpack Compose 中单选按钮的自定义可绘制选定状态
Custom drawable selected state for Radio Button in Jetpack Compose
想知道是否有办法将单选按钮的选定状态设置为 Jetpack Compose 中的自定义图标
单选按钮source
没有更改 RadioButton 外观的选项。
但是这里:
// Draw the radio button
val strokeWidth = RadioStrokeWidth.toPx()
drawCircle(
radioColor.value,
RadioRadius.toPx() - strokeWidth / 2,
style = Stroke(strokeWidth)
)
if (dotRadius.value > 0.dp) {
drawCircle(radioColor.value, dotRadius.value.toPx() - strokeWidth / 2, style = Fill)
}
想画什么就画什么
您可以使用 IconToggleButton 代替 RadioButton
IconToggleButton( checked = state.value == item,
onCheckedChange = { state.value = item })
{
Icon(
painter = painterResource(if (state.value == item) R.drawable.select_radio else R.drawable.unselect_radio),
contentDescription = "Radio button icon",
tint = Color(
0xFF9B51E0
)
)
}
想知道是否有办法将单选按钮的选定状态设置为 Jetpack Compose 中的自定义图标
单选按钮source
没有更改 RadioButton 外观的选项。
但是这里:
// Draw the radio button
val strokeWidth = RadioStrokeWidth.toPx()
drawCircle(
radioColor.value,
RadioRadius.toPx() - strokeWidth / 2,
style = Stroke(strokeWidth)
)
if (dotRadius.value > 0.dp) {
drawCircle(radioColor.value, dotRadius.value.toPx() - strokeWidth / 2, style = Fill)
}
想画什么就画什么
您可以使用 IconToggleButton 代替 RadioButton
IconToggleButton( checked = state.value == item,
onCheckedChange = { state.value = item })
{
Icon(
painter = painterResource(if (state.value == item) R.drawable.select_radio else R.drawable.unselect_radio),
contentDescription = "Radio button icon",
tint = Color(
0xFF9B51E0
)
)
}