Android Jetpack Compose TextField 禁用键盘自动建议功能

19

我正在寻找一种方法来禁用TextField Composable中的键盘自动建议。

在大约4个月前的Android旧版本中,您可以这样做,将inputType设置为textNoSuggestions | textVisiblePassword

<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textNoSuggestions|textVisiblePassword" />

我在这里使用两种输入类型,因为不是所有的键盘都支持textNoSuggestions字段。

Jetpack Compose的TextField有没有一种方法可以实现这个功能? 我在他们的KeyboardOptions中没有看到任何模仿此功能的选项。

1个回答

14
var text by remember { mutableStateOf("") }
TextField(
    value = text,
    keyboardOptions = KeyboardOptions(
        keyboardType = KeyboardType.Email,
        autoCorrect = false
    ),
    onValueChange = {
        text = it
    }
)

我们可以使用 autoCorrect = false。
但是根据文档,autoCorrect 参数:
“告诉键盘是否启用自动更正。仅适用于基于文本的 KeyboardTypes,如 KeyboardType.Email、KeyboardType.Uri。它不会应用于 KeyboardType.Number 等 KeyboardTypes。大多数键盘实现会忽略这个值,对于 KeyboardType.Text 等 KeyboardTypes。”
因此,请注意使用哪种 keyboardType。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接