Google is committed to advancing racial equity for Black communities. See how.
Added in API level 1

EditText

open class EditText : TextView
kotlin.Any
   ↳ android.view.View
   ↳ android.widget.TextView
   ↳ android.widget.EditText

A user interface element for entering and modifying text. When you define an edit text widget, you must specify the android.R.styleable#TextView_inputType attribute. For example, for plain text input set inputType to "text":

<EditText
      android:id="@+id/plain_text_input"
      android:layout_height="wrap_content"
      android:layout_width="match_parent"
      android:inputType="text"/>
Choosing the input type configures the keyboard type that is shown, acceptable characters, and appearance of the edit text. For example, if you want to accept a secret number, like a unique pin or serial number, you can set inputType to "numericPassword". An inputType of "numericPassword" results in an edit text that accepts numbers only, shows a numeric keyboard when focused, and masks the text that is entered for privacy.

See the Text Fields guide for examples of other android.R.styleable#TextView_inputType settings.

You also can receive callbacks as a user changes text by adding a android.text.TextWatcher to the edit text. This is useful when you want to add auto-save functionality as changes are made, or validate the format of user input, for example. You add a text watcher using the TextView#addTextChangedListener method.

This widget does not support auto-sizing text.

XML attributes

See EditText Attributes, TextView Attributes, View Attributes

Summary

Inherited XML attributes
Inherited constants
Public constructors
<init>(context: Context!)

<init>(context: Context!, attrs: AttributeSet!)

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Unit

Convenience for Selection#extendSelection.

open CharSequence!

open Boolean

open Editable!

open Unit

Convenience for Selection#selectAll.

open Unit

Causes words in the text that are longer than the view's width to be ellipsized instead of broken in the middle.

open Unit
setSelection(start: Int, stop: Int)

Convenience for Selection#setSelection(Spannable, int, int).

open Unit
setSelection(index: Int)

Convenience for Selection#setSelection(Spannable, int).

open Unit

Protected methods
open Boolean

open MovementMethod!

Inherited functions
Inherited properties

Public constructors

<init>

Added in API level 1
EditText(context: Context!)

<init>

Added in API level 1
EditText(
    context: Context!,
    attrs: AttributeSet!)

<init>

Added in API level 1
EditText(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

<init>

Added in API level 21
EditText(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

Public methods

extendSelection

Added in API level 1
open fun extendSelection(index: Int): Unit

Convenience for Selection#extendSelection.

getAccessibilityClassName

Added in API level 23
open fun getAccessibilityClassName(): CharSequence!

getFreezesText

Added in API level 1
open fun getFreezesText(): Boolean
Return
Boolean Returns true if text is included, false if it isn't.

getText

Added in API level 1
open fun getText(): Editable!
Return
Editable! The text displayed by the text view.

selectAll

Added in API level 1
open fun selectAll(): Unit

Convenience for Selection#selectAll.

setEllipsize

Added in API level 1
open fun setEllipsize(ellipsis: TextUtils.TruncateAt!): Unit

Causes words in the text that are longer than the view's width to be ellipsized instead of broken in the middle. TextUtils.TruncateAt#MARQUEE is not supported.

Parameters
ellipsis TextUtils.TruncateAt!: Type of ellipsis to be applied.
Exceptions
java.lang.IllegalArgumentException When the value of ellipsis parameter is TextUtils.TruncateAt#MARQUEE.

setSelection

Added in API level 1
open fun setSelection(
    start: Int,
    stop: Int
): Unit

Convenience for Selection#setSelection(Spannable, int, int).

setSelection

Added in API level 1
open fun setSelection(index: Int): Unit

Convenience for Selection#setSelection(Spannable, int).

setText

Added in API level 1
open fun setText(
    text: CharSequence!,
    type: TextView.BufferType!
): Unit
Parameters
text CharSequence!: text to be displayed
type TextView.BufferType!: a android.widget.TextView.BufferType which defines whether the text is stored as a static text, styleable/spannable text, or editable text

Protected methods

getDefaultEditable

Added in API level 1
protected open fun getDefaultEditable(): Boolean

getDefaultMovementMethod

Added in API level 1
protected open fun getDefaultMovementMethod(): MovementMethod!