44

The following Code doesn't seem to work,I want the email keyboard with @ and .com to get displayed for the edit text.

emailEditText.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);

CalvT
  • 3,123
  • 6
  • 37
  • 54
Sreekanth Karumanaghat
  • 3,383
  • 6
  • 44
  • 72

3 Answers3

92

Add this to your layout:

android:inputType="textEmailAddress"

agamov
  • 4,407
  • 1
  • 27
  • 31
  • 2
    That works if you can set it in your layout. But if you need to *programatically* change the keyboard to this type (i.e. with a toggle-button), SK's answer below is the solution. – JosephK Oct 23 '14 at 07:46
  • @JosephK what is the reason for dynamically changing inputType for email EditText? :) – agamov Oct 23 '14 at 07:57
  • 1
    I had a client request we put a button in to toggle the keyboard from number-pad to email-entry - specific type of number-pad and specific type of alpha (with the @ sign). – JosephK Oct 24 '14 at 01:32
78

Well I found the solution which is to use

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

Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
Sreekanth Karumanaghat
  • 3,383
  • 6
  • 44
  • 72
1

In Kotlin way:

email_field.valueEditText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
Aydın Ahmed
  • 559
  • 5
  • 11