17

I'm looking for a way to disable the keyboard auto suggestions with the TextField Composable.

In the olden days of Android from about 4 months ago, using EditText you could do something like this, setting the inputType to textNoSuggestions|textVisiblePassword.

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

I'm using both inputTypes here because not all keyboards support the textNoSuggestions field.

Is there a way to do this with Jetpack Compose's TextField? I'm not seeing anything in their KeyboardOptions to mimic this functionality.

mPandaRed
  • 171
  • 1
  • 5

1 Answers1

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

We can use the autoCorrect = false. But, according to the documentation, the autoCorrect parameter:

"Informs the keyboard whether to enable auto correct. Only applicable to text based KeyboardTypes such as KeyboardType.Email, KeyboardType.Uri. It will not be applied to KeyboardTypes such as KeyboardType.Number. Most of keyboard implementations ignore this value for KeyboardTypes such as KeyboardType.Text."

So, be careful which keyboardType you are using.

Thiago Souza
  • 1,171
  • 8
  • 16