EditText is a core Android component designed for entering and editing text in the user interface. It inherits from TextView and allows character input via virtual or physical keyboards. EditText supports many modes: single-line and multi-line text, passwords, numbers, email addresses and phone numbers. According to Android Developers (2026), EditText is used in over 90% of Android apps for building forms, search fields, chats and data entry screens.
Key Takeaways
EditText is a class from the android.widget package that implements an interactive text field for user data input. In the Android inheritance hierarchy, EditText extends TextView, so it inherits all properties of a text label, including font, color and alignment management. The main difference between EditText and TextView is the ability to edit content — users can enter, delete and modify text directly in the interface.
Each EditText is associated with an Editable instance that stores the entered text and supports insert, delete and replace operations. When typing, EditText automatically manages cursor position, text selection and an undo/redo change history. According to the Android Developers Guide (2026), EditText also supports autocomplete through the AutoCompleteTextView class, which inherits from EditText.
The EditText architecture is built on the separation of model (Editable), view (TextView) and controller (InputConnection). When gaining focus, EditText creates an InputConnection through which the input system passes characters, key presses and editing commands. This mechanism ensures compatibility with any input method — from virtual keyboards to physical Bluetooth keyboards and voice input.
val editText = EditText(context).apply {
hint = "Enter text"
inputType = InputType.TYPE_CLASS_TEXT
maxLines = 1
setTextColor(Color.parseColor("#000000"))
}
EditText provides dozens of attributes for fine-tuning behavior and appearance. They can be set both in XML layouts and programmatically via Kotlin or Java. Attributes fall into categories: text control, constraints, visual styling and keyboard interaction.
| Attribute | Description | Example Value |
|---|---|---|
| android:hint | Hint text displayed in an empty field | "Enter email" |
| android:inputType | Input mode (text, number, password, etc.) | textEmailAddress |
| android:maxLines | Maximum number of lines | 3 |
| android:maxLength | Maximum text length in characters | 100 |
| android:textColorHint | Hint text color | #999999 |
The android:hint attribute is one of the most important — it tells the user what data is expected in the field. When text is entered, the hint is automatically hidden. The hint does not participate in form submission and is not saved as a field value. Material Design recommends using TextInputLayout with a floating label instead of a plain hint for a more modern look.
<!-- EditText in XML layout -->
@+id/etEmail
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:importantForAutofill="yes" />
The inputType attribute determines which keyboard type will be shown to the user and which characters are allowed for input. It is a bitmask where the input class (TYPE_CLASS_TEXT, TYPE_CLASS_NUMBER, TYPE_CLASS_PHONE) is combined with modifiers.
Each input mode not only changes the keyboard layout but also affects text processing: in numeric mode only digits and decimal separators are allowed, in email mode the @ symbol and domain extensions are available, and in phone mode digits and +, #, * symbols are displayed. Choosing the correct inputType critically affects user experience — an inappropriate keyboard forces users to switch modes, increasing form fill time by 30–50%.
According to the Material Design Guidelines (2025), it is recommended to use the most specific inputType for each field: textPassword for passwords, numberDecimal for prices, phone for phone numbers, textMultiLine for multi-line input. This speeds up form filling and reduces input errors.
// Programmatic inputType setup
editText.inputType = InputType.TYPE_CLASS_TEXT or
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES or
InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
TextWatcher is an interface for tracking text changes in EditText in real time. It contains three methods: beforeTextChanged is called before a change, onTextChanged is called during the change, afterTextChanged is called after the text change completes. TextWatcher is used for input validation, character counting, search and autocomplete.
OnEditorActionListener handles user actions on the keyboard: pressing Done (IME_ACTION_DONE), Search (IME_ACTION_SEARCH), Send (IME_ACTION_SEND), Next field (IME_ACTION_NEXT) and others. This listener is especially useful for organizing form navigation — when pressing Next, focus automatically moves to the next field, and when pressing Done, the keyboard is hidden and submission is performed.
According to the Android Developers Blog (2025), proper use of OnEditorActionListener with the android:imeOptions attribute allows creating intuitive forms without additional submit buttons — the user fills in fields and presses Done on the keyboard, triggering save or search.
// TextWatcher for email validation
editText.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
val isValid = Patterns.EMAIL_ADDRESS.matcher(s).matches()
editText.error = if (isValid) null else "Invalid email format"
}
})
// OnEditorActionListener for form submission
editText.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
submitForm()
true
} else false
}
Let us look at a complete example of creating a login screen using EditText for email and password input. This example demonstrates inputType configuration, validation via TextWatcher and handling of the login button press.
@+id/etLoginEmail
android:layout_width="match_parent"
android:hint="Email"
android:inputType="textEmailAddress"
android:maxLines="1" />
@+id/etLoginPassword
android:layout_width="match_parent"
android:hint="Password"
android:inputType="textPassword"
android:maxLines="1" />
class LoginFragment : Fragment() {
private lateinit var etEmail: EditText
private lateinit var etPassword: EditText
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
etEmail = view.findViewById(R.id.etLoginEmail)
etPassword = view.findViewById(R.id.etLoginPassword)
etEmail.addTextChangedListener(emailWatcher)
etPassword.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
performLogin()
true
} else false
}
}
}
EditText supports customization through XML attributes, themes and styles. You can change text color, hint color, underline color (backgroundTint), font style, text size and much more. Material Components provides the MaterialComponents.EditText theme with custom attributes including boxStrokeColor, boxBackgroundColor and endIconMode.
To change the EditText underline color, use the android:backgroundTint attribute, which sets the color for default and focused states. In Material Design, the underline color is managed through the theme's colorPrimary. For full customization, you can create a custom drawable for the background in the res/drawable folder.
| Style | Attribute | Result |
|---|---|---|
| Text color | android:textColor | Changes the entered text color |
| Hint color | android:textColorHint | Changes the hint text color |
| Underline | android:backgroundTint | Changes the underline color |
| Font size | android:textSize | Sets text size in sp |
| Font | android:fontFamily | Applies a custom font |
To create a consistent style for all EditText fields in your app, it is recommended to define a global style in the theme. Material Design offers the Widget.MaterialComponents.TextInputLayout.OutlinedBox style, which is automatically applied to all input fields using TextInputLayout. This ensures a consistent look without duplicating attributes in every layout.
Frequently Asked Questions
EditText inherits from TextView and adds text editing capabilities. TextView only displays text, while EditText allows users to enter, delete and modify content. EditText also supports inputType, TextWatcher, cursor management and other data input related features.
Use InputFilter — an interface for filtering input characters. EditText supports setting an array of filters via the setFilters() method. For example, InputFilter.LengthFilter limits text length, while a custom InputFilter can restrict specific characters, regular expressions or Unicode ranges.
Call editText.text.toString() in Kotlin or editText.getText().toString() in Java. The text property returns Editable, which is converted to a String via toString(). Always check for null and empty values before using the text, especially in forms with required fields.
Set the android:inputType="textMultiLine" attribute or programmatically add the InputType.TYPE_TEXT_FLAG_MULTI_LINE flag. In multi-line mode, EditText allows line breaks via Enter and automatically expands in height. Use android:maxLines or android:minLines to limit the height.
Set the android:enabled="false" attribute or call editText.isEnabled = false in code. A disabled EditText does not respond to touch, cannot gain focus and appears in gray (disabled state). An alternative is to use android:focusable="false", which disables input but retains the normal appearance.
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