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
andR.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, @Nullable attrs: AttributeSet?) |
|
<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?, defStyleAttr: Int) |
Public methods | |
---|---|
open Editable? |
getText() Return the text that the view is displaying. |
open TextClassifier |
Returns the |
open InputConnection? |
onCreateInputConnection(outAttrs: EditorInfo!) If a |
open Boolean |
onDragEvent(event: DragEvent!) |
open ContentInfoCompat? |
onReceiveContent(@NonNull payload: ContentInfoCompat) Implements the default behavior for receiving content, which coerces all content to text and inserts into the view. |
open Boolean |
onTextContextMenuItem(id: Int) If a |
open Unit |
setBackgroundDrawable(@Nullable background: Drawable?) |
open Unit |
setBackgroundResource(@DrawableRes resId: Int) |
open Unit |
setCustomSelectionActionModeCallback(actionModeCallback: Callback!) See |
open Unit |
setTextAppearance(context: Context!, resId: Int) |
open Unit |
setTextClassifier(@Nullable textClassifier: TextClassifier?) Sets the |
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
.
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.
setCustomSelectionActionModeCallback
open fun setCustomSelectionActionModeCallback(actionModeCallback: Callback!): Unit
See TextViewCompat#setCustomSelectionActionModeCallback(TextView, ActionMode.Callback)
setTextClassifier
@RequiresApi(26) open fun setTextClassifier(@Nullable textClassifier: TextClassifier?): Unit
Sets the TextClassifier
for this TextView.
Protected methods
drawableStateChanged
protected open fun drawableStateChanged(): Unit