KiKo KiKo - 8 months ago 56
Android Question

AlertDialog with EditText with InputType email - Android

I'm creating alert dialog with one EditText. I want that EditText to have input type email. This is my code:

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

alert.setMessage("Enter your email");

final EditText email = new EditText(this);


alert.setPositiveButton("Ok", null);

alert.setNegativeButton("Cancel", null);;

I also set Hint to that EditText and it's work, but input type does't work.....Any suggestion?

Answer Source

You have to add below code to make it work :


See InputType. TYPE_TEXT_VARIATION_EMAIL_ADDRESS is just a variation basically that you add to the TYPE_CLASS_TEXT flag. It somehow makes sense.