Member-only story

Getting and setting the InputType of an Android EditText

Suragch
3 min readJan 11, 2019

--

This is a combination of two answers I wrote on Stack Overflow (here and here).

Setting the InputType of an EditText tells the system keyboard what kind of input you are expecting. If your edit text is for inputting a phone number, then you want the keyboard to show numbers. It would be annoying for the user to have to manually switch to a numeric keyboard.

The post below shows you how to set the InputType and how that affects the default Google keyboard. You can use this to choose the best InputType for the kind of input you are asking the user for. Not every keyboard reacts the same as the Google keyboard, but if you are an IME developer, you can use it as a model. It is the responsibility of keyboard makers to check the InputType of the current EditText and show an appropriate keyboard layout.

Here are the various Input Types as shown on the standard keyboard.

Setting the input type programmatically

editText.setInputType(InputType.TYPE_CLASS_TEXT);

Other options besides TYPE_CLASS_TEXT can be found in the documentation.

Setting the input type in XML

<EditText
android:inputType="text"
/>

--

--

Suragch
Suragch

Written by Suragch

Flutter and Dart developer. Twitter: @suragch1, Email: suragch@suragch.dev

Responses (1)