【问题标题】:Disable keyboard on textField in Jetpack Compose Android?在 Jetpack Compose Android 的 textField 上禁用键盘?
【发布时间】:2022-11-21 13:17:57
【问题描述】:

我在做计算器。所以我用数字和功能制作了我的按钮。必须计算的表达式位于 TextField 中,因为我希望用户也可以在表达式的中间添加数字或函数,因此对于 TextField,我有光标。但是我想在用户单击 TextField 时禁用键盘。

在 XML 中,解决方案是:

public static void disableSoftInputFromAppearing(EditText editText) {
    if (Build.VERSION.SDK_INT >= 11) {
        editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
        editText.setTextIsSelectable(true);
    } else {
        editText.setRawInputType(InputType.TYPE_NULL);
        editText.setFocusable(true);
    }
}

我的问题:如何在 compose textField 中执行此操作?

##在Compose中,解决方案是:

CompositionLocalProvider(
    LocalTextInputService provides null
) {
    TextField(
        value = value,
        onValueChange = { value = it },
        label = { Text("The Label") }
    )
}

【问题讨论】:

  • 你找到任何解决方案了吗?我也面临同样的问题

标签: android


【解决方案1】:
CompositionLocalProvider(
    LocalTextInputService provides null
) {
    TextField(
        value = value,
        onValueChange = { value = it },
        label = { Text("The Label") }
    )
}

【讨论】:

    猜你喜欢
    • 2021-11-16
    • 2021-08-26
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 2020-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多