Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: EditText.setInputType() how to setup for email but not auto-suggest

Tags:

android

I am using an EditText box for user to enter their email address.

I set it up using:

box.setInputType( InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS );

This results in the soft keyboard popping up with the '@' and '.' (and some keyboards '.com') keys on the initial keyboard layout. Great just what I want.

However, I notice the text is all black (when I specified white). I found this is due to auto-suggest. If I go into Settings->Languages/Keyboards->Touch Input->TextInput and disable Prediction and Word Completion, then the text shows up white.

Now the question: How do I get auto-complete programmatically disabled for this?

I have tried setting up the box by doing:

box.setInputType( InputType.TYPE_CLASS_TEXT | TYPE_TEXT_FLAG_NO_SUGGESTIONS );

This results in all white text (i.e. no auto-suggest). But then I longer have email '@' and '.com' buttons! Bah-humbug.

Anyway to get both? Thanks.

like image 889
bubba Avatar asked Jun 22 '12 20:06

bubba


People also ask

How to disable autofill in EditText Android?

Users can enable or disable autofill as well as change the autofill service by navigating to Settings > System > Languages & input > Advanced > Input assistance > Autofill service.

How to set input type in EditText Android?

To get the input type use getInputType() . int inputTypeValue = editText. getInputType(); The InputType values are defined (in hexadecimal) in the documentation.

What is the effect of setting the InputType attribute of a TextView to number?

The android:inputType attribute allows you to specify various behaviors for the input method. Most importantly, if your text field is intended for basic text input (such as for a text message), you should enable auto spelling correction with the "textAutoCorrect" value.


1 Answers

This code should do the trick:

box.setInputType( InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS );

You can add as many flags as you want, as long as they're compatible with each other.

like image 100
Cat Avatar answered Nov 15 '22 21:11

Cat