Google is committed to advancing racial equity for Black communities. See how.

AppCompatEditText

open class AppCompatEditText : EditText, TintableBackgroundView, OnReceiveContentViewBehavior
kotlin.Any
   ↳ android.view.View
   ↳ android.widget.TextView
   ↳ android.widget.EditText
   ↳ androidx.appcompat.widget.AppCompatEditText

A EditText which supports compatible features on older versions of the platform, including:

  • Allows dynamic tint of its background via the background tint methods in androidx.core.view.ViewCompat.
  • Allows setting of the background tint using R.attr#backgroundTint and R.attr#backgroundTintMode.
  • Allows setting a custom listener to handle insertion of content (e.g. pasting text or an image from the clipboard). This listener provides the opportunity to implement app-specific handling such as creating an attachment when an image is pasted.

This will automatically be used when you use EditText in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.

Summary

Public constructors
<init>(@NonNull context: Context)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?, defStyleAttr: Int)

Public methods
open Editable?

Return the text that the view is displaying.

open TextClassifier

Returns the TextClassifier used by this TextView.

open InputConnection?

If a listener is set, the returned InputConnection will use it to handle calls to InputConnection#commitContent.

open Boolean

open ContentInfoCompat?

Implements the default behavior for receiving content, which coerces all content to text and inserts into the view.

open Boolean

If a listener is set, uses it to execute the "Paste" and "Paste as plain text" menu actions.

open Unit
setBackgroundDrawable(@Nullable background: Drawable?)

open Unit
setBackgroundResource(@DrawableRes resId: Int)

open Unit

See TextViewCompat#setCustomSelectionActionModeCallback(TextView, ActionMode.Callback)

open Unit
setTextAppearance(context: Context!, resId: Int)

open Unit
setTextClassifier(@Nullable textClassifier: TextClassifier?)

Sets the TextClassifier for this TextView.

Protected methods
open Unit

Public constructors

<init>

AppCompatEditText(@NonNull context: Context)

<init>

AppCompatEditText(
    @NonNull context: Context,
    @Nullable attrs: AttributeSet?)

<init>

AppCompatEditText(
    @NonNull context: Context,
    @Nullable attrs: AttributeSet?,
    defStyleAttr: Int)

Public methods

getText

@Nullable open fun getText(): Editable?

Return the text that the view is displaying. If an editable text has not been set yet, this will return null.

getTextClassifier

@NonNull @RequiresApi(26) open fun getTextClassifier(): TextClassifier

Returns the TextClassifier used by this TextView. If no TextClassifier has been set, this TextView uses the default set by the android.view.textclassifier.TextClassificationManager.

onCreateInputConnection

@Nullable open fun onCreateInputConnection(outAttrs: EditorInfo!): InputConnection?

If a listener is set, the returned InputConnection will use it to handle calls to InputConnection#commitContent.

onDragEvent

open fun onDragEvent(event: DragEvent!): Boolean

onReceiveContent

@Nullable open fun onReceiveContent(@NonNull payload: ContentInfoCompat): ContentInfoCompat?

Implements the default behavior for receiving content, which coerces all content to text and inserts into the view.

Subclasses of this widget can override this method to customize the default behavior for receiving content. Apps wishing to provide custom behavior for receiving content should set a listener via ViewCompat#setOnReceiveContentListener.

See ViewCompat#performReceiveContent for more info.

Parameters
payload ContentInfoCompat: The content to insert and related metadata.
Return
ContentInfoCompat? The portion of the passed-in content that was not handled (may be all, some, or none of the passed-in content).

onTextContextMenuItem

open fun onTextContextMenuItem(id: Int): Boolean

If a listener is set, uses it to execute the "Paste" and "Paste as plain text" menu actions.

setBackgroundDrawable

open fun setBackgroundDrawable(@Nullable background: Drawable?): Unit

setBackgroundResource

open fun setBackgroundResource(@DrawableRes resId: Int): Unit

setCustomSelectionActionModeCallback

open fun setCustomSelectionActionModeCallback(actionModeCallback: Callback!): Unit

See TextViewCompat#setCustomSelectionActionModeCallback(TextView, ActionMode.Callback)

setTextAppearance

open fun setTextAppearance(
    context: Context!,
    resId: Int
): Unit

setTextClassifier

@RequiresApi(26) open fun setTextClassifier(@Nullable textClassifier: TextClassifier?): Unit

Sets the TextClassifier for this TextView.

Protected methods

drawableStateChanged

protected open fun drawableStateChanged(): Unit