Customizing the InputType
Text fields can have different input types, such as number, date, password, or email address. The type determines what kind of characters are allowed inside the field, and may prompt the virtual keyboard to optimize its layout for frequently used characters.
By default, any text contents within an
EditText control is displayed as plain text. By setting the
inputType attribute, we can facilitate input of different types of information, like phone numbers and passwords:
<EditText ... android:inputType="phone"> </EditText>
Most common input types include:
|Type | Description | |——————|———————————————––| |textUri | Text that will be used as a URI | |textEmailAddress | Text that will be used as an e-mail address | |textPersonName | Text that is the name of a person | |textPassword | Text that is a password that should be obscured | |number | A numeric only field | |phone | For entering a phone number | |date | For entering a date | |time | For entering a time | |textMultiLine | Allow multiple lines of text in the field |
android:inputType also allows you to specify certain keyboard behaviors, such as whether to capitalize all new words or use features like auto-complete and spelling suggestions.
Here are some of the common input type values that define keyboard behaviors:
|Type | Description | |——————|———————————————––| |textCapSentences | Normal text keyboard that capitalizes the first letter for each new sentence| |textCapWords | Normal text keyboard that capitalizes every word. Good for titles or person names| |textAutoCorrect | Normal text keyboard that corrects commonly misspelled words|
You can set multiple
inputType attributes if needed (separated by ‘|’).
<EditText android:id="@+id/postal_address" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/postal_address_hint" android:inputType="textPostalAddress| textCapWords| textNoSuggestions" />
You can see a list of all available input types here.