Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable keyboard on textField in Jetpack Compose Android? [duplicate]

I'm doing a calculator. So I made my Buttons with numbers and functions. The expression that has to be calculated is in a TextField because I want users can add numbers or functions also in the middle of the expression, so with the TextField, I have the cursor. But I want to disable the Keyboard when users click on the TextField.

In XML, the solution is:

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);
    }
}

My question: How can I do this in compose textField?

##In Compose, the solution is:

CompositionLocalProvider(
    LocalTextInputService provides null
) {
    TextField(
        value = value,
        onValueChange = { value = it },
        label = { Text("The Label") }
    )
}
like image 683
Md. Sarowal Avatar asked Nov 04 '25 10:11

Md. Sarowal


1 Answers

CompositionLocalProvider(
    LocalTextInputService provides null
) {
    TextField(
        value = value,
        onValueChange = { value = it },
        label = { Text("The Label") }
    )
}
like image 83
Md. Sarowal Avatar answered Nov 07 '25 09:11

Md. Sarowal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!