如何在 Jetpack Compose 中将 TextField 的 inputType 设置为二进制(0 和 1)?

How to set the inputType for a TextField as a binary (0 and 1) in Jetpack Compose?

我正在尝试将 TextField 的输入类型设置为二进制,但没有 KeyboardOptions KeyboardType as Binary。

那么我怎样才能做到这一点?

  TextField(
        value = text,
        keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
        onValueChange = {
            text = it
        },
        label = { Text("Enter Binary") }
    )

没有这样的输入选项,但您可以过滤掉无效值:

TextField(
    value = text,
    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
    onValueChange = {
        text = it.filter { it == '0' || it == '1' }
    },
    label = { Text("Enter Binary") }
)