Android EditText Customizing the InputType

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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:

TypeDescription
textUriText that will be used as a URI
textEmailAddressText that will be used as an e-mail address
textPersonNameText that is the name of a person
textPasswordText that is a password that should be obscured
numberA numeric only field
phoneFor entering a phone number
dateFor entering a date
timeFor entering a time
textMultiLineAllow multiple lines of text in the field

The 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:

TypeDescription
textCapSentencesNormal text keyboard that capitalizes the first letter for each new sentence
textCapWordsNormal text keyboard that capitalizes every word. Good for titles or person names
textAutoCorrectNormal text keyboard that corrects commonly misspelled words

You can set multiple inputType attributes if needed (separated by '|').
Example:

<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.



Got any Android Question?