Let’s start off with one of the easiest keyboard features: Input Types. Specifying an Input Type allows you to control which characters the keyboard will display. For example, if you need the user to enter a phone number, you should specify the ‘phone’ Input Type and the keyboard will only display digits and valid phone number symbols.
How to specify an Input Type
Setting an Input Type is extremely easy, just set the
android:inputType xml attribute and you’re all set! Here’s an example of how to set your text field to accept a phone number.
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="phone" />
That’s all there is to it! There are dozens of other options, and they can even be combined to give special fields like a hidden password field that only accepts numbers.
Here are a few other common Input Types:
- password (makes text appear as dots)
Since specifying an Input Type is so easy and so useful, there’s no excuse not to do it.
If you want to learn more, here’s a link to the full Android documentation.