Google 致力于为黑人社区推动种族平等。查看具体举措

AppCompatEditText

open class AppCompatEditText : EditText, TintableBackgroundView
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 receiver callback in order to handle insertion of content (e.g. pasting text or an image from the clipboard). This callback 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 RichContentReceiverCompat<TextView!>?

Returns the callback that handles insertion of content into this view (e.g. pasting from the clipboard).

open Editable?

Return the text that the view is displaying.

open TextClassifier

Returns the TextClassifier used by this TextView.

open InputConnection!

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

open Boolean

If a receiver callback 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

Sets the callback to handle insertion of content into this view.

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

getRichContentReceiverCompat

@Nullable open fun getRichContentReceiverCompat(): RichContentReceiverCompat<TextView!>?

Returns the callback that handles insertion of content into this view (e.g. pasting from the clipboard). See setRichContentReceiverCompat for more info.

Return
RichContentReceiverCompat<TextView!>? The callback that this view is using to handle insertion of content. Returns null if no callback is configured, in which case the platform behavior of the EditText component will be used for content insertion.

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

open fun onCreateInputConnection(outAttrs: EditorInfo!): InputConnection!

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

onTextContextMenuItem

open fun onTextContextMenuItem(id: Int): Boolean

If a receiver callback 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)

setRichContentReceiverCompat

open fun setRichContentReceiverCompat(@Nullable receiver: RichContentReceiverCompat<TextView!>?): Unit

Sets the callback to handle insertion of content into this view.

"Content" and "rich content" here refers to both text and non-text: plain text, styled text, HTML, images, videos, audio files, etc. The callback configured here should typically extend from androidx.core.widget.TextViewRichContentReceiverCompat to provide consistent behavior for text content.

This callback will be invoked for the following scenarios:

  1. Paste from the clipboard (e.g. "Paste" or "Paste as plain text" action in the insertion/selection menu)
  2. Content insertion from the keyboard (InputConnection#commitContent)
Parameters
receiver RichContentReceiverCompat<TextView!>?: The callback to use. This can be null to clear any previously set callback (the platform behavior of the EditText component will then be used).

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