InputType — what it is, input attributes and their configuration in Android

Author: IT Sectr Published: 2026-07-07 Reading time: 9 min

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 — a bitmask that defines the input class and modifiers for EditText.
  • Input classes — TYPE_CLASS_TEXT, TYPE_CLASS_NUMBER, TYPE_CLASS_PHONE, TYPE_CLASS_DATETIME.
  • Modifiers — flags that refine behavior: MULTI_LINE, AUTO_CORRECT, PASSWORD, CAP_SENTENCES.
  • Combining — class and modifiers are combined via bitwise OR for precise configuration.
  • Impact — correct InputType speeds up input, reduces errors, and improves form UX.

What is InputType in Android

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.

kotlin
// 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

InputType Classes: TEXT, NUMBER, PHONE, DATETIME

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.

ClassConstantKeyboardUsage
TEXTTYPE_CLASS_TEXT (1)QWERTY keyboardText, comments, description
NUMBERTYPE_CLASS_NUMBER (2)NumericQuantity, price, age
PHONETYPE_CLASS_PHONE (3)PhonePhone number
DATETIMETYPE_CLASS_DATETIME (4)Date/timeDate, 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).

InputType Modifier Flags

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.

Flags for TEXT

  • TYPE_TEXT_FLAG_CAP_CHARACTERS — all letters uppercase.
  • TYPE_TEXT_FLAG_CAP_WORDS — each word capitalized.
  • TYPE_TEXT_FLAG_CAP_SENTENCES — capital letter at the start of a sentence (default).
  • TYPE_TEXT_FLAG_AUTO_CORRECT — automatic typo correction.
  • TYPE_TEXT_FLAG_AUTO_COMPLETE — autocomplete (for AutoCompleteTextView).
  • TYPE_TEXT_FLAG_MULTI_LINE — multiline input.
  • TYPE_TEXT_FLAG_NO_SUGGESTIONS — disable suggestions.

Flags for NUMBER

  • TYPE_NUMBER_FLAG_SIGNED — allows negative numbers (minus sign).
  • TYPE_NUMBER_FLAG_DECIMAL — allows decimal point.

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.

InputType Combinations: Examples for Different Scenarios

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.

ScenarioInputTypeKeyboard
NametextCapWordsQWERTY, each word capitalized
EmailtextEmailAddressQWERTY with @ and .
PasswordtextPasswordQWERTY, hidden input
PhonephoneDigits with +, #, *
PricenumberDecimalDigits with decimal point
QuantitynumberDigits only
CommenttextCapSentences|textMultiLineQWERTY, multiline
Searchtext|textNoSuggestionsQWERTY without suggestions
kotlin
// 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

Programmatic Work with InputType

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.

Switching Modes

kotlin
// 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)
}

Extracting Class and Variation

kotlin
// 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
}

Best Practices for Choosing InputType

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.

  • Explicitness — always explicitly set InputType, do not rely on the default value (textMultiLine).
  • Specificity — use the most specific type: textEmailAddress, not text, for email.
  • Security — for passwords, PINs, and card data, use PASSWORD variations.
  • Autofill — combine InputType with autofillHints to support password managers.
  • Testing — test behavior on different keyboards (Gboard, SwiftKey, Samsung Keyboard).

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

How is InputType different from Keyboard Type?

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.

How to reset InputType to the default value?

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.

Can I create a custom InputType?

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.

How does InputType affect the IME (keyboard)?

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.

How to check InputType at runtime?

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

  • InputType — a bitmask consisting of an input class (TEXT, NUMBER, PHONE, DATETIME) and modifiers.
  • Input class defines the basic data type and the type of keyboard displayed.
  • Modifiers refine behavior: multiline, autocorrect, capital letters, hidden input.
  • Combining via bitwise OR allows creating precise configurations for different scenarios.
  • PASSWORD variations disable autocorrect, hide characters, and prevent dictionary storage.
  • Programmatic setting via setInputType() requires restarting the IME to update the keyboard.
  • Best practices — explicitly set InputType, use specific types, and test on different keyboards.

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.

Discuss the project

Read also