Reputation: 241
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.
Upvotes: 24
Views: 7308
Reputation: 1671
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
KeyboardType
s such asKeyboardType.Email
,KeyboardType.Uri
. It will not be applied to KeyboardTypes such asKeyboardType.Number
. Most of keyboard implementations ignore this value forKeyboardType
s such asKeyboardType.Text
.
So, be careful which keyboardType
you are using.
Upvotes: 17
Reputation: 3393
A workaround I found to not show keyboard suggestions/hints is to set keyboardType
of KeyboardOptions
to KeyboardType.Password
The text in the TextField
will still be shown as normal text but the keyboard will not suggest words to complete.
OutlinedTextField(
value = textValue,
onValueChange = onTextChange,
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Password // Password keyboard hides suggestions
),
)
Upvotes: 6