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);
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 set Hint to that EditText and it's work, but input type does't work.....Any suggestion?
You have to add below code to make it work :
email.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With