0

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

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

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

1 回答 1

0

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

TextField(
    value = text,
    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
    onValueChange = {
        text = it.filter { it == '0' || it == '1' }
    },
    label = { Text("Enter Binary") }
)
于 2021-10-26T16:14:18.467 回答