AlertDialog with EditText with Email InputType - Android

I am creating a dialog box with one EditText. I want an input type email to appear in EditText. This is my code:

AlertDialog.Builder alert = new AlertDialog.Builder(this);

alert.setMessage("Enter your email");

final EditText email = new EditText(this);
email.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
email.setHint("Email...");

alert.setView(email);

alert.setPositiveButton("Ok", null);

alert.setNegativeButton("Cancel", null);

alert.show();

I also install Hint for this EditText, and it works, but the input type does not work ..... Any suggestion?

+4
source share
1 answer

You need to add the code below to make it work:

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

See InputType. TYPE_TEXT_VARIATION_EMAIL_ADDRESS- This is just an option that you add to the icon TYPE_CLASS_TEXT. It somehow makes sense.

+5
source

Source: https://habr.com/ru/post/1533770/


All Articles