Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Lollipop EditText: AutoComplete Not Working For Email Addresses

I have a bunch of EditTexts in a registration Fragment.

On KitKat and below, any EditText whose inputType is an email address will use the system's autocomplete, which is convenient for users putting in their email addresses.

However, on Lollipop (5.0.1 on a Nexus 4, for what it's worth), it refuses to use autocomplete. Here is my code for setting up the input type:

mEditText.setInputType(InputType.TYPE_CLASS_TEXT
                | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
                | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT));

The following code which is just capitalizing the first letter of each word rather than setting the input as an email address is causing AutoComplete to work on all API levels (even though the flag I'm setting is for AutoCorrect instead of AutoComplete):

mEditText.setInputType(InputType.TYPE_CLASS_TEXT
            | InputType.TYPE_TEXT_FLAG_CAP_WORDS
            | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);

which is extra-confusing, since looking at the docs for TYPE_TEXT_FLAG_AUTO_CORRECT, it looks like that should actually be disabling AutoComplete.

TL;DR: How in the hell do you enable auto-completion on a Lollipop EditText which you're expecting to get an email address?

like image 309
DesignatedNerd Avatar asked Oct 31 '22 08:10

DesignatedNerd


1 Answers

Nick Butcher has a great post on this.

like image 199
Bryan Stern Avatar answered Nov 11 '22 10:11

Bryan Stern