InputType is an Android attribute that determines the nature of input data and keyboard behavior for text fields. The InputType value is a bitmask that combines the input class (text, number, phone, date) and modifiers (multiline, autocomplete, capital letters, hidden input). InputType affects the type of keyboard displayed, input character filtering, and autofill behavior. According to Android Developers (2026), InputType is one of the most important attributes for ensuring correct data input and should be explicitly set for every editable text field.
Key Takeaways
InputType is an integer constant (Int) that encodes the input mode for a text field. In Android, it is defined in the android.text.InputType class. The InputType value consists of two parts: the input class (bits 0–4) and modifiers (bits 5–31). The input class defines the basic data type — text, number, phone, date. Modifiers refine the behavior within the selected class — for example, for the text class, you can enable autocomplete, capital letters, or multiline input.
The InputType mechanism works on three levels: at the Android framework level, it determines which InputConnection will be created (the connection between EditText and IME); at the IME (keyboard) level, it specifies which characters to display and how to handle input; at the application level, it filters characters through the InputFilter built into EditText. According to Android Source Code (AOSP, 2026), the bitmask is handled in the TextView.getInputType() method, which returns the current value, and setInputType(), which reconfigures internal filters and the IME connection.
An important feature of InputType is that it cannot be read from another process for security reasons. This prevents data theft through access to the input type (for example, determining whether a field is a password). When attempting to read InputType from another application, TYPE_CLASS_TEXT is returned by default.
// Basic InputType constants
InputType.TYPE_CLASS_TEXT // 0x0001 = 1
InputType.TYPE_CLASS_NUMBER // 0x0002 = 2
InputType.TYPE_CLASS_PHONE // 0x0003 = 3
InputType.TYPE_CLASS_DATETIME // 0x0004 = 4
// Mask for extracting class
InputType.TYPE_MASK_CLASS // 0x0000000F
Android defines four basic InputType classes. Each class corresponds to a specific data category and activates the corresponding keyboard type. The class is specified in bits 0–4 of the bitmask and can be extracted using the TYPE_MASK_CLASS (0x0F) mask.
| Class | Constant | Keyboard | Usage |
|---|---|---|---|
| TEXT | TYPE_CLASS_TEXT (1) | QWERTY keyboard | Text, comments, description |
| NUMBER | TYPE_CLASS_NUMBER (2) | Numeric | Quantity, price, age |
| PHONE | TYPE_CLASS_PHONE (3) | Phone | Phone number |
| DATETIME | TYPE_CLASS_DATETIME (4) | Date/time | Date, time |
TYPE_CLASS_DATETIME is rarely used directly — date input typically uses DatePicker or DatePickerDialog rather than a text field. However, in some scenarios (quick manual date entry), this class can be useful. It does not have a specialized keyboard and usually displays a numeric keyboard.
Each input class can be combined with variations — subtypes specified in bits 5–7. For example, TYPE_TEXT_VARIATION_PASSWORD (bit 5) adds hidden input to the TEXT class. Variation bits: 0x000000E0 (TYPE_MASK_VARIATION mask).
Modifier flags of InputType (bits 8–31) add additional capabilities to the base class. They do not change the keyboard type but modify input behavior. Flags are specific to each class — TEXT flags do not work with NUMBER, and vice versa. Below are the main modifiers for each class.
According to Android Developers Documentation (2026), flags for different classes do not overlap — attempting to use a TEXT flag with NUMBER will be ignored. To check a set flag, use bitwise AND: (inputType and FLAG) != 0.
The correct combination of InputType classes and flags is the key to creating user-friendly forms. Let us look at typical scenarios and their corresponding InputType configurations. Each scenario optimizes input for a specific data type, making the form intuitive and speeding up completion.
| Scenario | InputType | Keyboard |
|---|---|---|
| Name | textCapWords | QWERTY, each word capitalized |
| textEmailAddress | QWERTY with @ and . | |
| Password | textPassword | QWERTY, hidden input |
| Phone | phone | Digits with +, #, * |
| Price | numberDecimal | Digits with decimal point |
| Quantity | number | Digits only |
| Comment | textCapSentences|textMultiLine | QWERTY, multiline |
| Search | text|textNoSuggestions | QWERTY without suggestions |
// Combination for price field
editText.inputType = InputType.TYPE_CLASS_NUMBER or
InputType.TYPE_NUMBER_FLAG_DECIMAL
// Combination for comment field
editText.inputType = InputType.TYPE_CLASS_TEXT or
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES or
InputType.TYPE_TEXT_FLAG_MULTI_LINE
Setting InputType programmatically via setInputType() overwrites the previous value. If you need to change only part of the mask (for example, add a flag), you must save the current value, modify it, and apply it back. Each call to setInputType() reconfigures the internal EditText filters.
The setRawInputType() method differs from setInputType in that it does not trigger reconfiguration of filters and suggestions. It is used for temporarily changing InputType without a full reload of the EditText state. After calling setInputType(), it is recommended to restart the IME to update the keyboard.
// Toggle between password and visible text
fun togglePasswordVisibility(editText: EditText) {
val currentType = editText.inputType
val isPassword = (currentType and
InputType.TYPE_TEXT_VARIATION_PASSWORD) != 0
editText.inputType = if (isPassword) {
InputType.TYPE_CLASS_TEXT or
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
} else {
InputType.TYPE_CLASS_TEXT or
InputType.TYPE_TEXT_VARIATION_PASSWORD
}
// Keep cursor position
val cursorPos = editText.selectionStart
editText.setSelection(cursorPos)
}
// Get input class
fun getInputClass(inputType: Int): Int {
return inputType and InputType.TYPE_MASK_CLASS
}
// Get input variation
fun getInputVariation(inputType: Int): Int {
return inputType and InputType.TYPE_MASK_VARIATION
}
// Check if password field
fun isPasswordField(editText: EditText): Boolean {
return (editText.inputType and
InputType.TYPE_TEXT_VARIATION_PASSWORD) != 0
}
Choosing the right InputType is not only about UX but also about security and data correctness. Key recommendations include: always specify an explicit InputType for every EditText; use the most specific input class possible; do not combine flags from different classes; use PASSWORD variations for sensitive data fields; use imeOptions="actionSearch" for search fields.
InputType also affects the operation of accessibility services (Accessibility). Fields with the textPassword type receive additional protection from screen readers — they do not read entered characters aloud. For textEmailAddress fields, the Screen Reader informs the user that the field is intended for email and provides appropriate hints.
According to Material Design Guidelines (2025), InputType should match the type of data the user is entering. Incorrect InputType not only slows down input but can also lead to errors: for example, if you leave textMultiLine for a phone number field, the keyboard will not show the numeric keypad, and the user will have to switch layouts manually every time.
Frequently Asked Questions
InputType is an EditText attribute that defines the type of input data through a bitmask. Keyboard Type is an unofficial name for the visual keyboard type activated by InputType. InputType also affects character filtering, autocorrect, and autocomplete — not just the keyboard layout.
Set editText.inputType = InputType.TYPE_CLASS_TEXT or use the constant InputType.TYPE_NULL (0x00000000) for a complete reset. With TYPE_NULL, the field will not show a keyboard when focused. To return to standard text input, set TYPE_CLASS_TEXT without flags.
You cannot create a new InputType class, as it is part of the Android framework. However, you can combine existing classes and flags to achieve the desired behavior. Implement additional character filtering through InputFilter, which is set on EditText using the setFilters() method.
InputType is passed to the input system through InputConnection. The IME reads the InputType class and variation and selects the corresponding keyboard layout. For example, TYPE_CLASS_NUMBER with TYPE_NUMBER_FLAG_DECIMAL causes the keyboard to show a numeric keypad with a decimal point. Most modern keyboards follow these recommendations.
Use the editText.inputType property in Kotlin or editText.getInputType() in Java. To extract the class, apply the mask: inputType and InputType.TYPE_MASK_CLASS. To check a specific flag: inputType and InputType.TYPE_TEXT_FLAG_MULTI_LINE — if the result != 0, the flag is set.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also