Added in API level 1

TextView


open class TextView : View, ViewTreeObserver.OnPreDrawListener
kotlin.Any
   ↳ android.view.View
   ↳ android.widget.TextView

A user interface element that displays text to the user. To provide user-editable text, see EditText.

The following code sample shows a typical use, with an XML layout and code to modify the contents of the text view:

<LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
     <TextView
         android:id="@+id/text_view_id"
         android:layout_height="wrap_content"
         android:layout_width="wrap_content"
         android:text="@string/hello" />
  </LinearLayout>
  

This code sample demonstrates how to modify the contents of the text view defined in the previous XML layout:

public class MainActivity extends Activity {
 
     protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          final TextView helloTextView = (TextView) findViewById(R.id.text_view_id);
          helloTextView.setText(R.string.user_greeting);
      }
  }
  

To customize the appearance of TextView, see Styles and Themes.

XML attributes

See TextView Attributes, View Attributes

Summary

Nested classes

Type of the text buffer that defines the characteristics of the text such as static, styleable, or editable.

abstract

Interface definition for a callback to be invoked when an action is performed on the editor.

open

User interface state that is stored by TextView for implementing View#onSaveInstanceState.

XML attributes
android:allowUndo Whether undo should be allowed for editable text.
android:autoLink Controls whether links such as urls and email addresses are automatically found and converted to clickable links.
android:autoSizeMaxTextSize The maximum text size constraint to be used when auto-sizing text.
android:autoSizeMinTextSize The minimum text size constraint to be used when auto-sizing text.
android:autoSizePresetSizes Resource array of dimensions to be used in conjunction with autoSizeTextType set to uniform .
android:autoSizeStepGranularity Specify the auto-size step size if autoSizeTextType is set to uniform .
android:autoSizeTextType Specify the type of auto-size.
android:autoText If set, specifies that this TextView has a textual input method and automatically corrects some common spelling errors.
android:breakStrategy Break strategy (control over paragraph layout).
android:bufferType Determines the minimum type that getText() will return.
android:capitalize If set, specifies that this TextView has a textual input method and should automatically capitalize what the user types.
android:cursorVisible Makes the cursor visible (the default) or invisible.
android:digits If set, specifies that this TextView has a numeric input method and that these specific characters are the ones that it will accept.
android:drawableBottom The drawable to be drawn below the text.
android:drawableEnd The drawable to be drawn to the end of the text.
android:drawableLeft The drawable to be drawn to the left of the text.
android:drawablePadding The padding between the drawables and the text.
android:drawableRight The drawable to be drawn to the right of the text.
android:drawableStart The drawable to be drawn to the start of the text.
android:drawableTint Tint to apply to the compound (left, top, etc.) drawables.
android:drawableTintMode Blending mode used to apply the compound (left, top, etc.) drawables tint.
android:drawableTop The drawable to be drawn above the text.
android:editable If set, specifies that this TextView has an input method.
android:editorExtras Reference to an <input-extras> XML resource containing additional data to supply to an input method, which is private to the implementation of the input method.
android:elegantTextHeight Elegant text height, especially for less compacted complex script text.
android:ellipsize If set, causes words that are longer than the view is wide to be ellipsized instead of broken in the middle.
android:ems Makes the TextView be exactly this many ems wide.
android:enabled Specifies whether the widget is enabled.
android:fallbackLineSpacing Whether to respect the ascent and descent of the fallback fonts that are used in displaying the text.
android:fontFamily Font family (named by string or as a font resource reference) for the text.
android:fontFeatureSettings Font feature settings.
android:fontVariationSettings Font variation settings.
android:freezesText If set, the text view will include its current complete text inside of its frozen icicle in addition to meta-data such as the current cursor position.
android:gravity Specifies how to align the text by the view's x- and/or y-axis when the text is smaller than the view.
android:height Makes the TextView be exactly this tall.
android:hint Hint text to display when the text is empty.
android:hyphenationFrequency Frequency of automatic hyphenation.
android:imeActionId Supply a value for EditorInfo.
android:imeActionLabel Supply a value for EditorInfo.
android:imeOptions Additional features you can enable in an IME associated with an editor to improve the integration with your application.
android:includeFontPadding Leave enough room for ascenders and descenders instead of using the font ascent and descent strictly.
android:inputMethod If set, specifies that this TextView should use the specified input method (specified by fully-qualified class name).
android:inputType The type of data being placed in a text field, used to help an input method decide how to let the user enter text.
android:justificationMode Mode for justification.
android:letterSpacing Text letter-spacing.
android:lineBreakStyle Specifies the line-break strategies for text wrapping.
android:lineBreakWordStyle Specifies the line-break word strategies for text wrapping.
android:lineSpacingExtra Extra spacing between lines of text.
android:lineSpacingMultiplier Extra spacing between lines of text, as a multiplier.
android:lines Makes the TextView be exactly this many lines tall.
android:linksClickable If set to false, keeps the movement method from being set to the link movement method even if autoLink causes links to be found.
android:marqueeRepeatLimit The number of times to repeat the marquee animation.
android:maxEms Makes the TextView be at most this many ems wide.
android:maxHeight Makes the TextView be at most this many pixels tall.
android:maxLength Set an input filter to constrain the text length to the specified number.
android:maxLines Makes the TextView be at most this many lines tall.
android:maxWidth Makes the TextView be at most this many pixels wide.
android:minEms Makes the TextView be at least this many ems wide.
android:minHeight Makes the TextView be at least this many pixels tall.
android:minLines Makes the TextView be at least this many lines tall.
android:minWidth Makes the TextView be at least this many pixels wide.
android:numeric If set, specifies that this TextView has a numeric input method.
android:password Whether the characters of the field are displayed as password dots instead of themselves.
android:phoneNumber If set, specifies that this TextView has a phone number input method.
android:privateImeOptions An addition content type description to supply to the input method attached to the text view, which is private to the implementation of the input method.
android:scrollHorizontally Whether the text is allowed to be wider than the view (and therefore can be scrolled horizontally).
android:selectAllOnFocus If the text is selectable, select it all when the view takes focus.
android:shadowColor Place a blurred shadow of text underneath the text, drawn with the specified color.
android:shadowDx Horizontal offset of the text shadow.
android:shadowDy Vertical offset of the text shadow.
android:shadowRadius Blur radius of the text shadow.
android:singleLine Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines, and advances focus instead of inserting a newline when you press the enter key.
android:text Text to display.
android:textAppearance Base text color, typeface, size, and style.
android:textColor Text color.
android:textColorHighlight Color of the text selection highlight.
android:textColorHint Color of the hint text.
android:textColorLink Text color for links.
android:textCursorDrawable Reference to a drawable that will be drawn under the insertion cursor.
android:textFontWeight Weight for the font used in the TextView.
android:textScaleX Sets the horizontal scaling factor for the text.
android:textSelectHandle Reference to a drawable that will be used to display a text selection anchor for positioning the cursor within text.
android:textSelectHandleLeft Reference to a drawable that will be used to display a text selection anchor on the left side of a selection region.
android:textSelectHandleRight Reference to a drawable that will be used to display a text selection anchor on the right side of a selection region.
android:textSize Size of the text.
android:textStyle Style (normal, bold, italic, bold|italic) for the text.
android:typeface Typeface (normal, sans, serif, monospace) for the text.
android:width Makes the TextView be exactly this wide.
Inherited XML attributes
Constants
static Int

The TextView does not auto-size text (default).

static Int

The TextView scales text size both horizontally and vertically to fit within the container.

static Int

A special index used for setFocusedSearchResultIndex(int) and getFocusedSearchResultIndex() inidicating there is no focused search result.

Inherited constants
Public constructors
TextView(context: Context!)

TextView(context: Context!, attrs: AttributeSet?)

TextView(context: Context!, attrs: AttributeSet?, defStyleAttr: Int)

TextView(context: Context!, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Unit

open Unit

Adds a TextWatcher to the list of those whose methods are called whenever this TextView's text changes.

Unit

Convenience method to append the specified text to the TextView's display buffer, upgrading it to android.widget.TextView.BufferType#EDITABLE if it was not already editable.

open Unit
append(text: CharSequence!, start: Int, end: Int)

Convenience method to append the specified text slice to the TextView's display buffer, upgrading it to android.widget.TextView.BufferType#EDITABLE if it was not already editable.

open Unit

open Unit

open Boolean

Move the point, specified by the offset, into the view if it is needed.

open Boolean
bringPointIntoView(offset: Int, requestRectWithoutFocus: Boolean)

Move the insertion position of the given offset into visible area of the View.

open Unit

open Unit

Use BaseInputConnection.removeComposingSpans() to remove any IME composing state from this text view.

open Unit

open Unit
debug(depth: Int)

open Boolean

Returns true, only while processing a touch gesture, if the initial touch down event caused focus to move to the text view and as a result its selection changed.

open Unit

open Unit

open Boolean

If this TextView contains editable content, extract a portion of it based on the information in request in to outText.

open Unit
findViewsWithText(outViews: ArrayList<View!>!, searched: CharSequence!, flags: Int)

open CharSequence!

Int

Gets the autolink mask of the text.

open Int

open Int

open Int

open IntArray!

open Int

Returns the type of auto-size set for this widget.

open Array<String!>?

open Int

Describes the autofill type of this view, so an android.service.autofill.AutofillService can create the proper AutofillValue when autofilling the view.

open AutofillValue?

Gets the TextView's current text for AutoFill.

open Int

open Int

Gets the current strategy for breaking paragraphs into lines.

open Int

Returns the padding between the compound drawables and the text.

open BlendMode?

Returns the blending mode used to apply the tint to the compound drawables, if specified.

open ColorStateList!

open PorterDuff.Mode!

Returns the blending mode used to apply the tint to the compound drawables, if specified.

open Array<Drawable!>

Returns drawables for the left, top, right, and bottom borders.

open Array<Drawable!>

Returns drawables for the start, top, end, and bottom borders.

open Int

Returns the bottom padding of the view, plus space for the bottom Drawable if any.

open Int

Returns the end padding of the view, plus space for the end Drawable if any.

open Int

Returns the left padding of the view, plus space for the left Drawable if any.

open Int

Returns the right padding of the view, plus space for the right Drawable if any.

open Int

Returns the start padding of the view, plus space for the start Drawable if any.

open Int

Returns the top padding of the view, plus space for the top Drawable if any.

Int

Return the current color selected to paint the hint text.

Int

Return the current color selected for normal text.

open ActionMode.Callback!

Retrieves the value set in setCustomInsertionActionModeCallback.

open ActionMode.Callback!

Retrieves the value set in setCustomSelectionActionModeCallback.

open Editable!

Return the text that TextView is displaying as an Editable object.

open TextUtils.TruncateAt!

Returns where, if anywhere, words that are longer than the view is wide should be ellipsized.

open CharSequence!

Returns the error message that was set to be displayed with #setError, or null if no error was set or if it the error was cleared by the widget after user input.

open Int

Returns the extended bottom padding of the view, including both the bottom Drawable if any and any extra space to keep more than maxLines of text from showing.

open Int

Returns the extended top padding of the view, including both the top Drawable if any and any extra space to keep more than maxLines of text from showing.

open Array<InputFilter!>!

Returns the current list of input filters.

open Int

Returns the distance between the first text baseline and the top of this TextView.

open Unit

open Int

Gets focused search result highlight color.

open Int

Gets the focused search result index.

open String?

Returns the font feature settings.

open String?

Returns the font variation settings.

open Boolean

Return whether this text view is including its entire text contents in frozen icicles.

open Int

Returns the horizontal and vertical alignment of this TextView.

open Int

open Highlights?

Returns highlights

open CharSequence!

Returns the hint that is displayed when the text of the TextView is empty.

ColorStateList!

open Int

Gets the current frequency of automatic hyphenation to be used when determining word breaks.

open Int

Get the IME action ID previous set with setImeActionLabel.

open CharSequence!

Get the IME action label previous set with setImeActionLabel.

open LocaleList?

open Int

Get the type of the Input Method Editor (IME).

open Boolean

Gets whether the TextView includes extra top and bottom padding to make room for accents that go above the normal ascent and descent.

open Bundle!

Retrieve the input extras currently associated with the text view, which can be viewed as well as modified.

open Int

Get the type of the editable content.

open Int

KeyListener!

Gets the current KeyListener for the TextView.

open Int

Returns the distance between the last text baseline and the bottom of this TextView.

Layout!

Gets the android.text.Layout that is currently being used to display the text.

open Float

Gets the text letter-space value, which determines the spacing between characters.

open Int
getLineBounds(line: Int, bounds: Rect!)

Return the baseline for the specified line (0...getLineCount() - 1) If bounds is not null, return the top, left, right, bottom extents of the specified line in it.

open Int

Gets the current line-break style for text wrapping.

open Int

Gets the current line-break word style for text wrapping.

open Int

Return the number of lines of text, or 0 if the internal Layout has not been built.

open Int

Gets the vertical distance between lines of text, in pixels.

open Float

Gets the line spacing extra space

open Float

Gets the line spacing multiplier

ColorStateList!

Boolean

Returns whether the movement method will automatically be set to LinkMovementMethod if setAutoLinkMask has been set to nonzero and links are detected in #setText.

open Int

Gets the number of times the marquee animation is repeated.

open Int

Returns the maximum width of TextView in terms of ems or -1 if the maximum width was set using setMaxWidth(int) or setWidth(int).

open Int

Returns the maximum height of TextView in terms of pixels or -1 if the maximum height was set using setMaxLines(int) or setLines(int).

open Int

Returns the maximum height of TextView in terms of number of lines or -1 if the maximum height was set using setMaxHeight(int) or setHeight(int).

open Int

Returns the maximum width of TextView in terms of pixels or -1 if the maximum width was set using setMaxEms(int) or setEms(int).

open Int

Returns the minimum width of TextView in terms of ems or -1 if the minimum width was set using setMinWidth(int) or setWidth(int).

open Int

Returns the minimum height of TextView in terms of pixels or -1 if the minimum height was set using setMinLines(int) or setLines(int).

open Int

Returns the minimum height of TextView in terms of number of lines or -1 if the minimum height was set using setMinHeight(int) or setHeight(int).

open Int

Returns the minimum width of TextView in terms of pixels or -1 if the minimum width was set using setMinEms(int) or setEms(int).

open Paint.FontMetrics?

Get the minimum font metrics used for line spacing.

MovementMethod!

Gets the android.text.method.MovementMethod being used for this TextView, which provides positioning, scrolling, and text selection functionality.

open Int

Get the character offset closest to the specified absolute position.

open TextPaint!

Gets the TextPaint used for the text.

open Int

Gets the flags on the Paint being used to display the text.

open String!

Get the private type of the content.

open Int

Gets the search result highlight color.

open IntArray?

Gets the current search result ranges.

open Int

Convenience for Selection#getSelectionEnd.

open Int

Convenience for Selection#getSelectionStart.

open Int

Gets the color of the shadow layer.

open Float

open Float

Gets the vertical offset of the shadow layer.

open Float

Gets the radius of the shadow layer.

open Boolean

Returns true if shifting the drawing x offset for start overhang.

Boolean

Returns whether the soft input method will be made visible when this TextView gets focused.

open CharSequence!

Return the text that TextView is displaying.

open TextClassifier

Returns the TextClassifier used by this TextView.

ColorStateList!

Gets the text colors for the different states (normal, selected, focused) of the TextView.

open Drawable?

Returns the Drawable corresponding to the text cursor.

open TextDirectionHeuristic

Returns resolved TextDirectionHeuristic that will be used for text layout.

open Locale

Get the default primary Locale of the text in this TextView.

open LocaleList

Get the default LocaleList of the text in this TextView.

open PrecomputedText.Params

Gets the parameters for text layout precomputation, for use with PrecomputedText.

open Float

Gets the extent by which text should be stretched horizontally.

open Drawable?

Returns the Drawable corresponding to the selection handle used for positioning the cursor within text.

open Drawable?

Returns the Drawable corresponding to the left handle used for selecting text.

open Drawable?

Returns the Drawable corresponding to the right handle used for selecting text.

open Float

open Int

Gets the text size unit defined by the developer.

open Int

Returns the total bottom padding of the view, including the bottom Drawable if any, the extra space to keep more than maxLines from showing, and the vertical offset for gravity, if any.

open Int

Returns the total end padding of the view, including the end Drawable if any.

open Int

Returns the total left padding of the view, including the left Drawable if any.

open Int

Returns the total right padding of the view, including the right Drawable if any.

open Int

Returns the total start padding of the view, including the start Drawable if any.

open Int

Returns the total top padding of the view, including the top Drawable if any, the extra space to keep more than maxLines from showing, and the vertical offset for gravity, if any.

TransformationMethod!

Gets the current android.text.method.TransformationMethod for the TextView.

open Typeface!

Gets the current Typeface that is used to style the text.

open Array<URLSpan!>!

Returns the list of URLSpans attached to the text (by Linkify or otherwise) if any.

open Boolean

Returns true if using bounding box as a width, false for using advance as a width.

open Boolean

open Boolean

Return true iff there is a selection of nonzero length inside this text view.

open Unit

Invalidates the specified Drawable.

open Boolean

Checks whether the transformation method applied to this TextView is set to ALL CAPS.

open Boolean

open Boolean

open Boolean

Get the value of the TextView's elegant height metrics flag.

open Boolean

Boolean

Returns whether the text is allowed to be wider than the View.

open Boolean

Returns whether this text view is a current input method target.

open Boolean

Returns true if the locale preferred line height is used for the minimum line height.

open Boolean

Returns if the text is constrained to a single horizontally scrolling line ignoring new line characters instead of letting it wrap onto multiple lines.

open Boolean

Return whether or not suggestions are enabled on this TextView.

open Boolean

Returns the state of the textIsSelectable flag (See setTextIsSelectable()).

open Unit

open Int

Returns the length, in characters, of the text managed by this TextView

open Boolean

Move the cursor, if needed, so that it is at an offset that is visible to the user.

open Unit

Called by the framework in response to a request to begin a batch of edit operations through a call to link beginBatchEdit().

open Boolean

open Unit

Called by the framework in response to a text completion from the current input method, provided by it calling InputConnection.commitCompletion().

open Unit

Called by the framework in response to a text auto-correction (such as fixing a typo using a dictionary) from the current input method, provided by it calling InputConnection.commitCorrection().

open InputConnection!

open Unit
onCreateViewTranslationRequest(supportedFormats: IntArray, requestsCollector: Consumer<ViewTranslationRequest!>)

Collects a ViewTranslationRequest which represents the content to be translated in the view.

open Boolean

Handles drag events sent by the system following a call to startDragAndDrop().

open Unit
onEditorAction(actionCode: Int)

Called when an attached input method calls InputConnection.performEditorAction() for this text view.

open Unit

Called by the framework in response to a request to end a batch of edit operations through a call to link endBatchEdit.

open Boolean

open Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)

open Boolean
onKeyMultiple(keyCode: Int, repeatCount: Int, event: KeyEvent!)

open Boolean
onKeyPreIme(keyCode: Int, event: KeyEvent!)

open Boolean
onKeyShortcut(keyCode: Int, event: KeyEvent!)

open Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)

open Boolean

Callback method to be invoked when the view tree is about to be drawn.

open Boolean
onPrivateIMECommand(action: String!, data: Bundle!)

Called by the framework in response to a private command from the current method, provided by it calling InputConnection.performPrivateCommand().

open ContentInfo?

Default TextView implementation for receiving content.

open PointerIcon!
onResolvePointerIcon(event: MotionEvent!, pointerIndex: Int)

open Unit

open Unit
onRtlPropertiesChanged(layoutDirection: Int)

open Parcelable?

open Unit
onScreenStateChanged(screenState: Int)

open Boolean

Called when a context menu option for the text view is selected.

open Boolean

open Boolean

open Unit

open Unit
onWindowFocusChanged(hasWindowFocus: Boolean)

open Boolean

open Unit

Removes the specified TextWatcher from the list of those whose methods are called whenever this TextView's text changes.

open Unit

open Unit
setAllCaps(allCaps: Boolean)

Sets the properties of this field to transform input to ALL CAPS display.

Unit

Sets the autolink mask of the text.

open Unit
setAutoSizeTextTypeUniformWithConfiguration(autoSizeMinTextSize: Int, autoSizeMaxTextSize: Int, autoSizeStepGranularity: Int, unit: Int)

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds.

open Unit

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds.

open Unit

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds by using the default auto-size configuration.

open Unit
setBreakStrategy(breakStrategy: Int)

Sets the break strategy for breaking paragraphs into lines.

open Unit

Sets the size of the padding between the compound drawables and the text.

open Unit

Specifies the blending mode used to apply the tint specified by setCompoundDrawableTintList(android.content.res.ColorStateList) to the compound drawables.

open Unit

Applies a tint to the compound drawables.

open Unit

Specifies the blending mode used to apply the tint specified by setCompoundDrawableTintList(android.content.res.ColorStateList) to the compound drawables.

open Unit
setCompoundDrawables(left: Drawable?, top: Drawable?, right: Drawable?, bottom: Drawable?)

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.

open Unit
setCompoundDrawablesRelative(start: Drawable?, top: Drawable?, end: Drawable?, bottom: Drawable?)

Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text.

open Unit

Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text.

open Unit

Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text.

open Unit
setCompoundDrawablesWithIntrinsicBounds(left: Int, top: Int, right: Int, bottom: Int)

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.

open Unit

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.

open Unit

Set whether the cursor is visible.

open Unit

If provided, this ActionMode.

open Unit

If provided, this ActionMode.

Unit

Sets the Factory used to create new Editables.

open Unit

Set the TextView's elegant height metrics flag.

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
setEms(ems: Int)

Sets the width of the TextView to be exactly ems wide.

open Unit
setEnabled(enabled: Boolean)

open Unit

Sets the right-hand compound drawable of the TextView to the "error" icon and sets an error message that will be displayed in a popup when the TextView has focus.

open Unit
setError(error: CharSequence!, icon: Drawable!)

Sets the right-hand compound drawable of the TextView to the specified icon and sets an error message that will be displayed in a popup when the TextView has focus.

open Unit

Apply to this text view the given extracted text, as previously returned by extractText(android.view.inputmethod.ExtractedTextRequest,android.view.inputmethod.ExtractedText).

open Unit

Set whether to respect the ascent and descent of the fallback fonts that are used in displaying the text (which is needed to avoid text from consecutive lines running into each other).

open Unit

Sets the list of input filters that will be used if the buffer is Editable.

open Unit
setFirstBaselineToTopHeight(firstBaselineToTopHeight: Int)

Updates the top padding of the TextView so that is the distance between the top of the TextView and first line's baseline.

open Unit

Sets focused search result highlight color.

open Unit

Sets the focused search result index.

open Unit
setFontFeatureSettings(fontFeatureSettings: String?)

Sets font feature settings.

open Boolean
setFontVariationSettings(fontVariationSettings: String?)

Sets TrueType or OpenType font variation settings.

open Unit
setFreezesText(freezesText: Boolean)

Control whether this text view saves its entire text contents when freezing to an icicle, in addition to dynamic state such as cursor position.

open Unit
setGravity(gravity: Int)

Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself.

open Unit
setHeight(pixels: Int)

Sets the height of the TextView to be exactly pixels tall.

open Unit

Sets the color used to display the selection highlight.

open Unit
setHighlights(highlights: Highlights?)

Set Highlights

Unit

Sets the text to be displayed when the text of the TextView is empty.

Unit
setHint(resid: Int)

Sets the text to be displayed when the text of the TextView is empty, from a resource.

Unit

Sets the color of the hint text for all the states (disabled, focussed, selected...) of this TextView.

Unit

Sets the color of the hint text.

open Unit

Sets whether the text should be allowed to be wider than the View is.

open Unit
setHyphenationFrequency(hyphenationFrequency: Int)

Sets the frequency of automatic hyphenation to use when determining word breaks.

open Unit
setImeActionLabel(label: CharSequence!, actionId: Int)

Change the custom IME action associated with the text view, which will be reported to an IME with EditorInfo#actionLabel and EditorInfo#actionId when it has focus.

open Unit

Change "hint" locales associated with the text view, which will be reported to an IME with EditorInfo#hintLocales when it has focus.

open Unit
setImeOptions(imeOptions: Int)

Change the editor type integer associated with the text view, which is reported to an Input Method Editor (IME) with EditorInfo#imeOptions when it has focus.

open Unit

Set whether the TextView includes extra top and bottom padding to make room for accents that go above the normal ascent and descent.

open Unit
setInputExtras(xmlResId: Int)

Set the extra input data of the text, which is the TextBoxAttribute.extras Bundle that will be filled in when creating an input connection.

open Unit

Set the type of the content with a constant as defined for EditorInfo#inputType.

open Unit
setJustificationMode(justificationMode: Int)

Set justification mode.

open Unit

Sets the key listener to be used with this TextView.

open Unit
setLastBaselineToBottomHeight(lastBaselineToBottomHeight: Int)

Updates the bottom padding of the TextView so that is the distance between the bottom of the TextView and the last line's baseline.

open Unit
setLetterSpacing(letterSpacing: Float)

Sets text letter-spacing in em units.

open Unit
setLineBreakStyle(lineBreakStyle: Int)

Sets the line-break style for text wrapping.

open Unit
setLineBreakWordStyle(lineBreakWordStyle: Int)

Sets the line-break word style for text wrapping.

open Unit
setLineHeight(lineHeight: Int)

Sets an explicit line height for this TextView.

open Unit
setLineHeight(unit: Int, lineHeight: Float)

Sets an explicit line height to a given unit and value for this TextView.

open Unit
setLineSpacing(add: Float, mult: Float)

Sets line spacing for this TextView.

open Unit
setLines(lines: Int)

Sets the height of the TextView to be exactly lines tall.

Unit

Sets the color of links in the text.

Unit

Sets the color of links in the text.

Unit

Sets whether the movement method will automatically be set to LinkMovementMethod if setAutoLinkMask has been set to nonzero and links are detected in #setText.

open Unit

Set true if the locale preferred line height is used for the minimum line height.

open Unit
setMarqueeRepeatLimit(marqueeLimit: Int)

Sets how many times to repeat the marquee animation.

open Unit
setMaxEms(maxEms: Int)

Sets the width of the TextView to be at most maxEms wide.

open Unit
setMaxHeight(maxPixels: Int)

Sets the height of the TextView to be at most maxPixels tall.

open Unit
setMaxLines(maxLines: Int)

Sets the height of the TextView to be at most maxLines tall.

open Unit
setMaxWidth(maxPixels: Int)

Sets the width of the TextView to be at most maxPixels wide.

open Unit
setMinEms(minEms: Int)

Sets the width of the TextView to be at least minEms wide.

open Unit
setMinHeight(minPixels: Int)

Sets the height of the TextView to be at least minPixels tall.

open Unit
setMinLines(minLines: Int)

Sets the height of the TextView to be at least minLines tall.

open Unit
setMinWidth(minPixels: Int)

Sets the width of the TextView to be at least minPixels wide.

open Unit

Set the minimum font metrics used for line spacing.

Unit

Sets the android.text.method.MovementMethod for handling arrow key movement for this TextView.

open Unit

Set a special listener to be called when an action is performed on the text view.

open Unit
setPadding(left: Int, top: Int, right: Int, bottom: Int)

open Unit
setPaddingRelative(start: Int, top: Int, end: Int, bottom: Int)

open Unit

Sets flags on the Paint being used to display the text and reflows the text if they are different from the old flags.

open Unit

Set the private content type of the text, which is the EditorInfo.privateImeOptions field that will be filled in when creating an input connection.

open Unit

Directly change the content type integer of the text view, without modifying any other state.

open Unit

Sets the Scroller used for producing a scrolling animation

open Unit

Sets the search result highlight color.

open Unit

Sets the search result ranges with flatten range representation.

open Unit
setSelectAllOnFocus(selectAllOnFocus: Boolean)

Set the TextView so that when it takes focus, all the text is selected.

open Unit
setSelected(selected: Boolean)

open Unit
setShadowLayer(radius: Float, dx: Float, dy: Float, color: Int)

Gives the text a shadow of the specified blur radius and color, the specified distance from its drawn position.

open Unit
setShiftDrawingOffsetForStartOverhang(shiftDrawingOffsetForStartOverhang: Boolean)

Set true for shifting the drawing x offset for showing overhang at the start position.

Unit

Sets whether the soft input method will be made visible when this TextView gets focused.

open Unit

Sets the properties of this field (lines, horizontally scrolling, transformation method) to be for a single-line input.

open Unit
setSingleLine(singleLine: Boolean)

If true, sets the properties of this field (number of lines, horizontally scrolling, transformation method) to be for a single-line input; if false, restores these to the default conditions.

Unit

Sets the Factory used to create new Spannables.

Unit

Sets the text to be displayed.

open Unit

Sets the text to be displayed and the android.widget.TextView.BufferType.

Unit
setText(text: CharArray, start: Int, len: Int)

Sets the TextView to display the specified slice of the specified char array.

Unit
setText(resid: Int)

Sets the text to be displayed using a string resource identifier.

Unit
setText(resid: Int, type: TextView.BufferType!)

Sets the text to be displayed using a string resource identifier and the android.widget.TextView.BufferType.

open Unit

Sets the text appearance from the specified style resource.

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

Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.

open Unit

Sets the TextClassifier for this TextView.

open Unit
setTextColor(color: Int)

Sets the text color for all the states (normal, selected, focused) to be this color.

open Unit

Sets the text color.

open Unit
setTextCursorDrawable(textCursorDrawable: Drawable?)

Sets the Drawable corresponding to the text cursor.

open Unit
setTextCursorDrawable(textCursorDrawable: Int)

Sets the Drawable corresponding to the text cursor.

open Unit

Sets whether the content of this view is selectable by the user.

Unit

Sets the text to be displayed but retains the cursor position.

Unit

Sets the text to be displayed and the android.widget.TextView.BufferType but retains the cursor position.

open Unit

Set the default Locale of the text in this TextView to a one-member LocaleList containing just the given Locale.

open Unit

Set the default LocaleList of the text in this TextView to the given value.

open Unit

Apply the text layout parameter.

open Unit

Sets the horizontal scale factor for text.

open Unit
setTextSelectHandle(textSelectHandle: Drawable)

Sets the Drawable corresponding to the selection handle used for positioning the cursor within text.

open Unit
setTextSelectHandle(textSelectHandle: Int)

Sets the Drawable corresponding to the selection handle used for positioning the cursor within text.

open Unit
setTextSelectHandleLeft(textSelectHandleLeft: Drawable)

Sets the Drawable corresponding to the left handle used for selecting text.

open Unit
setTextSelectHandleLeft(textSelectHandleLeft: Int)

Sets the Drawable corresponding to the left handle used for selecting text.

open Unit
setTextSelectHandleRight(textSelectHandleRight: Drawable)

Sets the Drawable corresponding to the right handle used for selecting text.

open Unit
setTextSelectHandleRight(textSelectHandleRight: Int)

Sets the Drawable corresponding to the right handle used for selecting text.

open Unit

Set the default text size to the given value, interpreted as "scaled pixel" units.

open Unit
setTextSize(unit: Int, size: Float)

Set the default text size to a given unit and value.

Unit

Sets the transformation that is applied to the text that this TextView is displaying.

open Unit
setTypeface(tf: Typeface?, style: Int)

Sets the typeface and style in which the text should be displayed, and turns on the fake bold and italic bits in the Paint if the Typeface that you provided does not have all the bits in the style that you specified.

open Unit

Sets the typeface and style in which the text should be displayed.

open Unit
setUseBoundsForWidth(useBoundsForWidth: Boolean)

Set true for using width of bounding box as a source of automatic line breaking and drawing.

open Unit
setWidth(pixels: Int)

Sets the width of the TextView to be exactly pixels wide.

open Boolean

open Boolean

Protected methods
open Int

open Int

open Int

open Unit

open Int

open Boolean

Subclasses override this to specify that they have a KeyListener by default even if not specifically called for in the XML options.

open MovementMethod!

Subclasses override this to specify a default movement method.

open Float

open Int

open Float

open Int

open Int

open Boolean

open Unit

open Unit

open Unit

open IntArray!

open Unit
onDraw(canvas: Canvas)

open Unit
onFocusChanged(focused: Boolean, direction: Int, previouslyFocusedRect: Rect?)

open Unit
onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int)

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

open Unit
onScrollChanged(horiz: Int, vert: Int, oldHoriz: Int, oldVert: Int)

open Unit
onSelectionChanged(selStart: Int, selEnd: Int)

This method is called when the selection has changed, in case any subclasses would like to know.

open Unit
onTextChanged(text: CharSequence!, start: Int, lengthBefore: Int, lengthAfter: Int)

This method is called when the text is changed, in case any subclasses would like to know.

open Unit
onVisibilityChanged(changedView: View, visibility: Int)

open Boolean
setFrame(l: Int, t: Int, r: Int, b: Int)

open Boolean

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying.

Inherited functions
Inherited properties

XML attributes

android:allowUndo

android:allowUndo
Whether undo should be allowed for editable text. Defaults to true.

May be a boolean value, such as "true" or "false".

android:autoLink
Controls whether links such as urls and email addresses are automatically found and converted to clickable links. The default value is "none", disabling this feature.

Must be one or more (separated by '|') of the following constant values.

Constant Value Description
all f Match all patterns (equivalent to web|email|phone|map).
email 2 Match email addresses.
map 8 Match map addresses. Deprecated: see android.text.util.Linkify#MAP_ADDRESSES.
none 0 Match no patterns (default).
phone 4 Match phone numbers.
web 1 Match Web URLs.

android:autoSizeMaxTextSize

android:autoSizeMaxTextSize
The maximum text size constraint to be used when auto-sizing text.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:autoSizeMinTextSize

android:autoSizeMinTextSize
The minimum text size constraint to be used when auto-sizing text.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:autoSizePresetSizes

android:autoSizePresetSizes
Resource array of dimensions to be used in conjunction with autoSizeTextType set to uniform. Overrides autoSizeStepGranularity if set.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

May be an integer value, such as "100".

May be a boolean value, such as "true" or "false".

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

May be a floating point value, such as "1.2".

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

May be a fractional value, which is a floating point number appended with either % or %p, such as "14.5%". The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.

android:autoSizeStepGranularity

android:autoSizeStepGranularity
Specify the auto-size step size if autoSizeTextType is set to uniform. The default is 1px. Overwrites autoSizePresetSizes if set.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:autoSizeTextType

android:autoSizeTextType
Specify the type of auto-size. Note that this feature is not supported by EditText, works only for TextView.

Must be one of the following constant values.

Constant Value Description
none 0 No auto-sizing (default).
uniform 1 Uniform horizontal and vertical text size scaling to fit within the container.

android:autoText

android:autoText
If set, specifies that this TextView has a textual input method and automatically corrects some common spelling errors. The default is "false". {@deprecated Use inputType instead.}

May be a boolean value, such as "true" or "false".

android:breakStrategy

android:breakStrategy
Break strategy (control over paragraph layout).

Must be one of the following constant values.

Constant Value Description
balanced 2 Line breaking strategy balances line lengths.
high_quality 1 Line breaking uses high-quality strategy, including hyphenation.
simple 0 Line breaking uses simple strategy.

android:bufferType

android:bufferType
Determines the minimum type that getText() will return. The default is "normal". Note that EditText and LogTextBox always return Editable, even if you specify something less powerful here.

Must be one of the following constant values.

Constant Value Description
editable 2 Can only return Spannable and Editable.
normal 0 Can return any CharSequence, possibly a Spanned one if the source text was Spanned.
spannable 1 Can only return Spannable.

android:capitalize

android:capitalize
If set, specifies that this TextView has a textual input method and should automatically capitalize what the user types. The default is "none". {@deprecated Use inputType instead.}

Must be one of the following constant values.

Constant Value Description
characters 3 Capitalize every character.
none 0 Don't automatically capitalize anything.
sentences 1 Capitalize the first word of each sentence.
words 2 Capitalize the first letter of every word.

android:cursorVisible

android:cursorVisible
Makes the cursor visible (the default) or invisible.

May be a boolean value, such as "true" or "false".

android:digits

android:digits
If set, specifies that this TextView has a numeric input method and that these specific characters are the ones that it will accept. If this is set, numeric is implied to be true. The default is false.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:drawableBottom

android:drawableBottom
The drawable to be drawn below the text.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:drawableEnd

android:drawableEnd
The drawable to be drawn to the end of the text.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:drawableLeft

android:drawableLeft
The drawable to be drawn to the left of the text.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:drawablePadding

android:drawablePadding
The padding between the drawables and the text.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:drawableRight

android:drawableRight
The drawable to be drawn to the right of the text.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:drawableStart

android:drawableStart
The drawable to be drawn to the start of the text.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:drawableTint

android:drawableTint
Tint to apply to the compound (left, top, etc.) drawables.

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:drawableTintMode

android:drawableTintMode
Blending mode used to apply the compound (left, top, etc.) drawables tint.

Must be one of the following constant values.

Constant Value Description
add 10 Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)
multiply e Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screen f [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
src_atop 9 The tint is drawn above the drawable, but with the drawable’s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
src_in 5 The tint is masked by the alpha channel of the drawable. The drawable’s color channels are thrown out. [Sa * Da, Sc * Da]
src_over 3 The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]

android:drawableTop

android:drawableTop
The drawable to be drawn above the text.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:editable

android:editable
If set, specifies that this TextView has an input method. It will be a textual one unless it has otherwise been specified. For TextView, this is false by default. For EditText, it is true by default. {@deprecated Use inputType instead.}

May be a boolean value, such as "true" or "false".

android:editorExtras

android:editorExtras
Reference to an <input-extras> XML resource containing additional data to supply to an input method, which is private to the implementation of the input method. This simply fills in the EditorInfo.extras field when the input method is connected.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:elegantTextHeight

android:elegantTextHeight
Elegant text height, especially for less compacted complex script text.

May be a boolean value, such as "true" or "false".

android:ellipsize

android:ellipsize
If set, causes words that are longer than the view is wide to be ellipsized instead of broken in the middle. You will often also want to set scrollHorizontally or singleLine as well so that the text as a whole is also constrained to a single line instead of still allowed to be broken onto multiple lines.

Must be one of the following constant values.

Constant Value Description
end 3
marquee 4
middle 2
none 0
start 1

android:ems

android:ems
Makes the TextView be exactly this many ems wide.

May be an integer value, such as "100".

android:enabled

android:enabled
Specifies whether the widget is enabled. The interpretation of the enabled state varies by subclass. For example, a non-enabled EditText prevents the user from editing the contained text, and a non-enabled Button prevents the user from tapping the button. The appearance of enabled and non-enabled widgets may differ, if the drawables referenced from evaluating state_enabled differ.

May be a boolean value, such as "true" or "false".

android:fallbackLineSpacing

android:fallbackLineSpacing
Whether to respect the ascent and descent of the fallback fonts that are used in displaying the text. When true, fallback fonts that end up getting used can increase the ascent and descent of the lines that they are used on.

May be a boolean value, such as "true" or "false".

android:fontFamily

android:fontFamily
Font family (named by string or as a font resource reference) for the text.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:fontFeatureSettings

android:fontFeatureSettings
Font feature settings.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:fontVariationSettings

android:fontVariationSettings
Font variation settings.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:freezesText

android:freezesText
If set, the text view will include its current complete text inside of its frozen icicle in addition to meta-data such as the current cursor position. By default this is disabled; it can be useful when the contents of a text view is not stored in a persistent place such as a content provider. For android.widget.EditText it is always enabled, regardless of the value of the attribute.

May be a boolean value, such as "true" or "false".

android:gravity

android:gravity
Specifies how to align the text by the view's x- and/or y-axis when the text is smaller than the view.

Must be one or more (separated by '|') of the following constant values.

Constant Value Description
bottom 50 Push object to the bottom of its container, not changing its size.
center 11 Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
center_horizontal 1 Place object in the horizontal center of its container, not changing its size.
center_vertical 10 Place object in the vertical center of its container, not changing its size.
clip_horizontal 8 Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip will be based on the horizontal gravity: a left gravity will clip the right edge, a right gravity will clip the left edge, and neither will clip both edges.
clip_vertical 80 Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip will be based on the vertical gravity: a top gravity will clip the bottom edge, a bottom gravity will clip the top edge, and neither will clip both edges.
end 800005 Push object to the end of its container, not changing its size.
fill 77 Grow the horizontal and vertical size of the object if needed so it completely fills its container.
fill_horizontal 7 Grow the horizontal size of the object if needed so it completely fills its container.
fill_vertical 70 Grow the vertical size of the object if needed so it completely fills its container.
left 3 Push object to the left of its container, not changing its size.
right 5 Push object to the right of its container, not changing its size.
start 800003 Push object to the beginning of its container, not changing its size.
top 30 Push object to the top of its container, not changing its size.

android:height

android:height
Makes the TextView be exactly this tall. You could get the same effect by specifying this number in the layout parameters.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:hint

android:hint
Hint text to display when the text is empty.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:hyphenationFrequency

android:hyphenationFrequency
Frequency of automatic hyphenation.

Must be one of the following constant values.

Constant Value Description
full 2 Standard amount of hyphenation, useful for running text and for screens with limited space for text.
fullFast 4 Same to hyphenationFrequency="full" but using faster algorithm for measuring hyphenation break points. To make text rendering faster with hyphenation, this algorithm ignores some hyphen character related typographic features, e.g. kerning.
none 0 No hyphenation.
normal 1 Less frequent hyphenation, useful for informal use cases, such as chat messages.
normalFast 3 Same to hyphenationFrequency="normal" but using faster algorithm for measuring hyphenation break points. To make text rendering faster with hyphenation, this algorithm ignores some hyphen character related typographic features, e.g. kerning.

android:imeActionId

android:imeActionId
Supply a value for EditorInfo.actionId used when an input method is connected to the text view.

May be an integer value, such as "100".

android:imeActionLabel

android:imeActionLabel
Supply a value for EditorInfo.actionLabel used when an input method is connected to the text view.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:imeOptions

android:imeOptions
Additional features you can enable in an IME associated with an editor to improve the integration with your application. The constants here correspond to those defined by android.view.inputmethod.EditorInfo#imeOptions.

Must be one or more (separated by '|') of the following constant values.

Constant Value Description
actionDone 6 The action key performs a "done" operation, closing the soft input method. Corresponds to android.view.inputmethod.EditorInfo#IME_ACTION_DONE.
actionGo 2 The action key performs a "go" operation to take the user to the target of the text they typed. Typically used, for example, when entering a URL. Corresponds to android.view.inputmethod.EditorInfo#IME_ACTION_GO.
actionNext 5 The action key performs a "next" operation, taking the user to the next field that will accept text. Corresponds to android.view.inputmethod.EditorInfo#IME_ACTION_NEXT.
actionNone 1 This editor has no action associated with it. Corresponds to android.view.inputmethod.EditorInfo#IME_ACTION_NONE.
actionPrevious 7 The action key performs a "previous" operation, taking the user to the previous field that will accept text. Corresponds to android.view.inputmethod.EditorInfo#IME_ACTION_PREVIOUS.
actionSearch 3 The action key performs a "search" operation, taking the user to the results of searching for the text the have typed (in whatever context is appropriate). Corresponds to android.view.inputmethod.EditorInfo#IME_ACTION_SEARCH.
actionSend 4 The action key performs a "send" operation, delivering the text to its target. This is typically used when composing a message. Corresponds to android.view.inputmethod.EditorInfo#IME_ACTION_SEND.
actionUnspecified 0 There is no specific action associated with this editor, let the editor come up with its own if it can. Corresponds to android.view.inputmethod.EditorInfo#IME_NULL.
flagForceAscii 80000000 Used to request that the IME should be capable of inputting ASCII characters. The intention of this flag is to ensure that the user can type Roman alphabet characters in a android.widget.TextView used for, typically, account ID or password input. It is expected that IMEs normally are able to input ASCII even without being told so (such IMEs already respect this flag in a sense), but there could be some cases they aren't when, for instance, only non-ASCII input languages like Arabic, Greek, Hebrew, Russian are enabled in the IME. Applications need to be aware that the flag is not a guarantee, and not all IMEs will respect it. However, it is strongly recommended for IME authors to respect this flag especially when their IME could end up with a state that has only non-ASCII input languages enabled.

Corresponds to android.view.inputmethod.EditorInfo#IME_FLAG_FORCE_ASCII.

flagNavigateNext 8000000 Used to specify that there is something interesting that a forward navigation can focus on. This is like using actionNext, except allows the IME to be multiline (with an enter key) as well as provide forward navigation. Note that some IMEs may not be able to do this, especially when running on a small screen where there is little space. In that case it does not need to present a UI for this option. Like actionNext, if the user selects the IME's facility to forward navigate, this will show up in the application at InputConnection.performEditorAction(int).

Corresponds to android.view.inputmethod.EditorInfo#IME_FLAG_NAVIGATE_NEXT.

flagNavigatePrevious 4000000 Like flagNavigateNext, but specifies there is something interesting that a backward navigation can focus on. If the user selects the IME's facility to backward navigate, this will show up in the application as an actionPrevious at InputConnection.performEditorAction(int).

Corresponds to android.view.inputmethod.EditorInfo#IME_FLAG_NAVIGATE_PREVIOUS.

flagNoAccessoryAction 20000000 Used in conjunction with a custom action, this indicates that the action should not be available as an accessory button when the input method is full-screen. Note that by setting this flag, there can be cases where the action is simply never available to the user. Setting this generally means that you think showing text being edited is more important than the action you have supplied.

Corresponds to android.view.inputmethod.EditorInfo#IME_FLAG_NO_ACCESSORY_ACTION.

flagNoEnterAction 40000000 Used in conjunction with a custom action, this indicates that the action should not be available in-line as a replacement for the "enter" key. Typically this is because the action has such a significant impact or is not recoverable enough that accidentally hitting it should be avoided, such as sending a message. Note that android.widget.TextView will automatically set this flag for you on multi-line text views.

Corresponds to android.view.inputmethod.EditorInfo#IME_FLAG_NO_ENTER_ACTION.

flagNoExtractUi 10000000 Used to specify that the IME does not need to show its extracted text UI. For input methods that may be fullscreen, often when in landscape mode, this allows them to be smaller and let part of the application be shown behind. Though there will likely be limited access to the application available from the user, it can make the experience of a (mostly) fullscreen IME less jarring. Note that when this flag is specified the IME may not be set up to be able to display text, so it should only be used in situations where this is not needed.

Corresponds to android.view.inputmethod.EditorInfo#IME_FLAG_NO_EXTRACT_UI.

flagNoFullscreen 2000000 Used to request that the IME never go into fullscreen mode. Applications need to be aware that the flag is not a guarantee, and not all IMEs will respect it.

Corresponds to android.view.inputmethod.EditorInfo#IME_FLAG_NO_FULLSCREEN.

flagNoPersonalizedLearning 1000000 Used to request that the IME should not update any personalized data such as typing history and personalized language model based on what the user typed on this text editing object. Typical use cases are:
  • When the application is in a special mode, where user's activities are expected to be not recorded in the application's history. Some web browsers and chat applications may have this kind of modes.
  • When storing typing history does not make much sense. Specifying this flag in typing games may help to avoid typing history from being filled up with words that the user is less likely to type in their daily life. Another example is that when the application already knows that the expected input is not a valid word (e.g. a promotion code that is not a valid word in any natural language).

Applications need to be aware that the flag is not a guarantee, and some IMEs may not respect it.

normal 0 There are no special semantics associated with this editor.

android:includeFontPadding

android:includeFontPadding
Leave enough room for ascenders and descenders instead of using the font ascent and descent strictly. (Normally true).

May be a boolean value, such as "true" or "false".

android:inputMethod

android:inputMethod
If set, specifies that this TextView should use the specified input method (specified by fully-qualified class name). {@deprecated Use inputType instead.}

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:inputType

android:inputType
The type of data being placed in a text field, used to help an input method decide how to let the user enter text. The constants here correspond to those defined by android.text.InputType. Generally you can select a single value, though some can be combined together as indicated. Setting this attribute to anything besides none also implies that the text is editable.

Must be one or more (separated by '|') of the following constant values.

Constant Value Description
date 14 For entering a date. Corresponds to android.text.InputType#TYPE_CLASS_DATETIME | android.text.InputType#TYPE_DATETIME_VARIATION_DATE.
datetime 4 For entering a date and time. Corresponds to android.text.InputType#TYPE_CLASS_DATETIME | android.text.InputType#TYPE_DATETIME_VARIATION_NORMAL.
none 0 There is no content type. The text is not editable.
number 2 A numeric only field. Corresponds to android.text.InputType#TYPE_CLASS_NUMBER | android.text.InputType#TYPE_NUMBER_VARIATION_NORMAL.
numberDecimal 2002 Can be combined with number and its other options to allow a decimal (fractional) number. Corresponds to android.text.InputType#TYPE_CLASS_NUMBER | android.text.InputType#TYPE_NUMBER_FLAG_DECIMAL.
numberPassword 12 A numeric password field. Corresponds to android.text.InputType#TYPE_CLASS_NUMBER | android.text.InputType#TYPE_NUMBER_VARIATION_PASSWORD.
numberSigned 1002 Can be combined with number and its other options to allow a signed number. Corresponds to android.text.InputType#TYPE_CLASS_NUMBER | android.text.InputType#TYPE_NUMBER_FLAG_SIGNED.
phone 3 For entering a phone number. Corresponds to android.text.InputType#TYPE_CLASS_PHONE.
text 1 Just plain old text. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_NORMAL.
textAutoComplete 10001 Can be combined with text and its variations to specify that this field will be doing its own auto-completion and talking with the input method appropriately. Corresponds to android.text.InputType#TYPE_TEXT_FLAG_AUTO_COMPLETE.
textAutoCorrect 8001 Can be combined with text and its variations to request auto-correction of text being input. Corresponds to android.text.InputType#TYPE_TEXT_FLAG_AUTO_CORRECT.
textCapCharacters 1001 Can be combined with text and its variations to request capitalization of all characters. Corresponds to android.text.InputType#TYPE_TEXT_FLAG_CAP_CHARACTERS.
textCapSentences 4001 Can be combined with text and its variations to request capitalization of the first character of every sentence. Corresponds to android.text.InputType#TYPE_TEXT_FLAG_CAP_SENTENCES.
textCapWords 2001 Can be combined with text and its variations to request capitalization of the first character of every word. Corresponds to android.text.InputType#TYPE_TEXT_FLAG_CAP_WORDS.
textEmailAddress 21 Text that will be used as an e-mail address. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_EMAIL_ADDRESS.
textEmailSubject 31 Text that is being supplied as the subject of an e-mail. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_EMAIL_SUBJECT.
textEnableTextConversionSuggestions 100001 Can be combined with text and its variations to indicate that if there is extra information, the IME should provide android.view.inputmethod.TextAttribute. Corresponds to android.text.InputType#TYPE_TEXT_FLAG_ENABLE_TEXT_CONVERSION_SUGGESTIONS.
textFilter b1 Text that is filtering some other data. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_FILTER.
textImeMultiLine 40001 Can be combined with text and its variations to indicate that though the regular text view should not be multiple lines, the IME should provide multiple lines if it can. Corresponds to android.text.InputType#TYPE_TEXT_FLAG_IME_MULTI_LINE.
textLongMessage 51 Text that is the content of a long message. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_LONG_MESSAGE.
textMultiLine 20001 Can be combined with text and its variations to allow multiple lines of text in the field. If this flag is not set, the text field will be constrained to a single line. Corresponds to android.text.InputType#TYPE_TEXT_FLAG_MULTI_LINE. Note: If this flag is not set and the text field doesn't have max length limit, the framework automatically set maximum length of the characters to 5000 for the performance reasons.
textNoSuggestions 80001 Can be combined with text and its variations to indicate that the IME should not show any dictionary-based word suggestions. Corresponds to android.text.InputType#TYPE_TEXT_FLAG_NO_SUGGESTIONS.
textPassword 81 Text that is a password. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_PASSWORD.
textPersonName 61 Text that is the name of a person. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_PERSON_NAME.
textPhonetic c1 Text that is for phonetic pronunciation, such as a phonetic name field in a contact entry. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_PHONETIC.
textPostalAddress 71 Text that is being supplied as a postal mailing address. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_POSTAL_ADDRESS.
textShortMessage 41 Text that is the content of a short message. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_SHORT_MESSAGE.
textUri 11 Text that will be used as a URI. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_URI.
textVisiblePassword 91 Text that is a password that should be visible. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_VISIBLE_PASSWORD.
textWebEditText a1 Text that is being supplied as text in a web form. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_WEB_EDIT_TEXT.
textWebEmailAddress d1 Text that will be used as an e-mail address on a web form. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS.
textWebPassword e1 Text that will be used as a password on a web form. Corresponds to android.text.InputType#TYPE_CLASS_TEXT | android.text.InputType#TYPE_TEXT_VARIATION_WEB_PASSWORD.
time 24 For entering a time. Corresponds to android.text.InputType#TYPE_CLASS_DATETIME | android.text.InputType#TYPE_DATETIME_VARIATION_TIME.

android:justificationMode

android:justificationMode
Mode for justification.

Must be one of the following constant values.

Constant Value Description
inter_character 2 @FlaggedApi("com.android.text.flags.inter_character_justification")
inter_word 1 Justification by stretching word spacing.
none 0 No justification.

android:letterSpacing

android:letterSpacing
Text letter-spacing.

May be a floating point value, such as "1.2".

android:lineBreakStyle

android:lineBreakStyle
Specifies the line-break strategies for text wrapping.

Must be one of the following constant values.

Constant Value Description
loose 1 The least restrictive line-break rules are used for line breaking.
none 0 No line-break rules are used for line breaking.
normal 2 The most common line-break rules are used for line breaking.
strict 3 The most strict line-break rules are used for line breaking.

android:lineBreakWordStyle

android:lineBreakWordStyle
Specifies the line-break word strategies for text wrapping.

Must be one of the following constant values.

Constant Value Description
none 0 No line-break word style is used for line breaking.
phrase 1 Line breaking is based on phrases, which results in text wrapping only on meaningful words.

android:lineSpacingExtra

android:lineSpacingExtra
Extra spacing between lines of text. The value will not be applied for the last line of text.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:lineSpacingMultiplier

android:lineSpacingMultiplier
Extra spacing between lines of text, as a multiplier. The value will not be applied for the last line of text.

May be a floating point value, such as "1.2".

android:lines

android:lines
Makes the TextView be exactly this many lines tall.

May be an integer value, such as "100".

android:linksClickable

android:linksClickable
If set to false, keeps the movement method from being set to the link movement method even if autoLink causes links to be found.

May be a boolean value, such as "true" or "false".

android:marqueeRepeatLimit

android:marqueeRepeatLimit
The number of times to repeat the marquee animation. Only applied if the TextView has marquee enabled.

May be an integer value, such as "100".

Must be one of the following constant values.

Constant Value Description
marquee_forever ffffffff Indicates that marquee should repeat indefinitely.

android:maxEms

android:maxEms
Makes the TextView be at most this many ems wide.

May be an integer value, such as "100".

android:maxHeight

android:maxHeight
Makes the TextView be at most this many pixels tall.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:maxLength

android:maxLength
Set an input filter to constrain the text length to the specified number.

May be an integer value, such as "100".

android:maxLines

android:maxLines
Makes the TextView be at most this many lines tall. When used on an editable text, the inputType attribute's value must be combined with the textMultiLine flag for the maxLines attribute to apply.

May be an integer value, such as "100".

android:maxWidth

android:maxWidth
Makes the TextView be at most this many pixels wide.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:minEms

android:minEms
Makes the TextView be at least this many ems wide.

May be an integer value, such as "100".

android:minHeight

android:minHeight
Makes the TextView be at least this many pixels tall.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:minLines

android:minLines
Makes the TextView be at least this many lines tall. When used on an editable text, the inputType attribute's value must be combined with the textMultiLine flag for the minLines attribute to apply.

May be an integer value, such as "100".

android:minWidth

android:minWidth
Makes the TextView be at least this many pixels wide.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:numeric

android:numeric
If set, specifies that this TextView has a numeric input method. The default is false. {@deprecated Use inputType instead.}

Must be one or more (separated by '|') of the following constant values.

Constant Value Description
decimal 5 Input is numeric, with decimals allowed.
integer 1 Input is numeric.
signed 3 Input is numeric, with sign allowed.

android:password

android:password
Whether the characters of the field are displayed as password dots instead of themselves. {@deprecated Use inputType instead.}

May be a boolean value, such as "true" or "false".

android:phoneNumber

android:phoneNumber
If set, specifies that this TextView has a phone number input method. The default is false. {@deprecated Use inputType instead.}

May be a boolean value, such as "true" or "false".

android:privateImeOptions

android:privateImeOptions
An addition content type description to supply to the input method attached to the text view, which is private to the implementation of the input method. This simply fills in the EditorInfo.privateImeOptions field when the input method is connected.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:scrollHorizontally

android:scrollHorizontally
Whether the text is allowed to be wider than the view (and therefore can be scrolled horizontally).

May be a boolean value, such as "true" or "false".

android:selectAllOnFocus

android:selectAllOnFocus
If the text is selectable, select it all when the view takes focus.

May be a boolean value, such as "true" or "false".

android:shadowColor

android:shadowColor
Place a blurred shadow of text underneath the text, drawn with the specified color. The text shadow produced does not interact with properties on View that are responsible for real time shadows, elevation and translationZ.

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:shadowDx

android:shadowDx
Horizontal offset of the text shadow.

May be a floating point value, such as "1.2".

android:shadowDy

android:shadowDy
Vertical offset of the text shadow.

May be a floating point value, such as "1.2".

android:shadowRadius

android:shadowRadius
Blur radius of the text shadow.

May be a floating point value, such as "1.2".

android:singleLine

android:singleLine
Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines, and advances focus instead of inserting a newline when you press the enter key. The default value is false (multi-line wrapped text mode) for non-editable text, but if you specify any value for inputType, the default is true (single-line input field mode). {@deprecated This attribute is deprecated. Use maxLines instead to change * the layout of a static text, and use the textMultiLine flag in the * inputType attribute instead for editable text views (if both singleLine and inputType * are supplied, the inputType flags will override the value of singleLine). }

May be a boolean value, such as "true" or "false".

android:text

android:text
Text to display.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:textAppearance

android:textAppearance
Base text color, typeface, size, and style.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:textColor

android:textColor
Text color.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:textColorHighlight

android:textColorHighlight
Color of the text selection highlight.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:textColorHint

android:textColorHint
Color of the hint text.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:textColorLink
Text color for links.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:textCursorDrawable

android:textCursorDrawable
Reference to a drawable that will be drawn under the insertion cursor.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:textFontWeight

android:textFontWeight
Weight for the font used in the TextView.

May be an integer value, such as "100".

android:textScaleX

android:textScaleX
Sets the horizontal scaling factor for the text.

May be a floating point value, such as "1.2".

android:textSelectHandle

android:textSelectHandle
Reference to a drawable that will be used to display a text selection anchor for positioning the cursor within text.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:textSelectHandleLeft

android:textSelectHandleLeft
Reference to a drawable that will be used to display a text selection anchor on the left side of a selection region.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:textSelectHandleRight

android:textSelectHandleRight
Reference to a drawable that will be used to display a text selection anchor on the right side of a selection region.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:textSize

android:textSize
Size of the text. Recommended dimension type for text is "sp" for scaled-pixels (example: 15sp).

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:textStyle

android:textStyle
Style (normal, bold, italic, bold|italic) for the text.

Must be one or more (separated by '|') of the following constant values.

Constant Value Description
bold 1
italic 2
normal 0

android:typeface

android:typeface
Typeface (normal, sans, serif, monospace) for the text.

Must be one of the following constant values.

Constant Value Description
monospace 3
normal 0
sans 1
serif 2

android:width

android:width
Makes the TextView be exactly this wide. You could get the same effect by specifying this number in the layout parameters.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

Constants

AUTO_SIZE_TEXT_TYPE_NONE

Added in API level 26
static val AUTO_SIZE_TEXT_TYPE_NONE: Int

The TextView does not auto-size text (default).

Value: 0

AUTO_SIZE_TEXT_TYPE_UNIFORM

Added in API level 26
static val AUTO_SIZE_TEXT_TYPE_UNIFORM: Int

The TextView scales text size both horizontally and vertically to fit within the container.

Value: 1

FOCUSED_SEARCH_RESULT_INDEX_NONE

Added in API level 34
static val FOCUSED_SEARCH_RESULT_INDEX_NONE: Int

A special index used for setFocusedSearchResultIndex(int) and getFocusedSearchResultIndex() inidicating there is no focused search result.

Value: -1

Public constructors

TextView

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

TextView

Added in API level 1
TextView(
    context: Context!,
    attrs: AttributeSet?)
Parameters
attrs AttributeSet?: This value may be null.

TextView

Added in API level 1
TextView(
    context: Context!,
    attrs: AttributeSet?,
    defStyleAttr: Int)
Parameters
attrs AttributeSet?: This value may be null.

TextView

Added in API level 21
TextView(
    context: Context!,
    attrs: AttributeSet?,
    defStyleAttr: Int,
    defStyleRes: Int)
Parameters
attrs AttributeSet?: This value may be null.

Public methods

addExtraDataToAccessibilityNodeInfo

Added in API level 26
open fun addExtraDataToAccessibilityNodeInfo(
    info: AccessibilityNodeInfo,
    extraDataKey: String,
    arguments: Bundle?
): Unit
Parameters
info AccessibilityNodeInfo: The info to which to add the extra data. Never null.
extraDataKey String: A key specifying the type of extra data to add to the info. The extra data should be added to the Bundle returned by the info's AccessibilityNodeInfo#getExtras method. Never null.
arguments Bundle?: A Bundle holding any arguments relevant for this request. May be null if the service provided no arguments.

addTextChangedListener

Added in API level 1
open fun addTextChangedListener(watcher: TextWatcher!): Unit

Adds a TextWatcher to the list of those whose methods are called whenever this TextView's text changes.

In 1.0, the TextWatcher#afterTextChanged method was erroneously not called after #setText calls. Now, doing #setText if there are any text changed listeners forces the buffer type to Editable if it would not otherwise be and does call this method.

append

Added in API level 1
fun append(text: CharSequence!): Unit

Convenience method to append the specified text to the TextView's display buffer, upgrading it to android.widget.TextView.BufferType#EDITABLE if it was not already editable.

Parameters
text CharSequence!: text to be appended to the already displayed text

append

Added in API level 1
open fun append(
    text: CharSequence!,
    start: Int,
    end: Int
): Unit

Convenience method to append the specified text slice to the TextView's display buffer, upgrading it to android.widget.TextView.BufferType#EDITABLE if it was not already editable.

Parameters
text CharSequence!: text to be appended to the already displayed text
start Int: the index of the first character in the text
end Int: the index of the character following the last character in the text

autofill

Added in API level 26
open fun autofill(value: AutofillValue!): Unit
Parameters
value AutofillValue!: value to be autofilled.

beginBatchEdit

Added in API level 3
open fun beginBatchEdit(): Unit

bringPointIntoView

Added in API level 3
open fun bringPointIntoView(offset: Int): Boolean

Move the point, specified by the offset, into the view if it is needed. This has to be called after layout. Returns true if anything changed.

bringPointIntoView

Added in API level 34
open fun bringPointIntoView(
    offset: Int,
    requestRectWithoutFocus: Boolean
): Boolean

Move the insertion position of the given offset into visible area of the View. If the View is focused or requestRectWithoutFocus is set to true, this API may call View#requestRectangleOnScreen(Rect) to bring the point to the visible area if necessary.

Parameters
offset Int: an offset of the character. Value is 0 or greater
requestRectWithoutFocus Boolean: True for calling View#requestRectangleOnScreen(Rect) in the unfocused state. False for calling it only the View has the focus.
Return
Boolean true if anything changed, otherwise false.

cancelLongPress

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

clearComposingText

Added in API level 3
open fun clearComposingText(): Unit

Use BaseInputConnection.removeComposingSpans() to remove any IME composing state from this text view.

computeScroll

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

debug

Added in API level 1
open fun debug(depth: Int): Unit

didTouchFocusSelect

Added in API level 3
open fun didTouchFocusSelect(): Boolean

Returns true, only while processing a touch gesture, if the initial touch down event caused focus to move to the text view and as a result its selection changed. Only valid while processing the touch gesture of interest, in an editable text view.

drawableHotspotChanged

Added in API level 21
open fun drawableHotspotChanged(
    x: Float,
    y: Float
): Unit
Parameters
x Float: hotspot x coordinate
y Float: hotspot y coordinate

endBatchEdit

Added in API level 3
open fun endBatchEdit(): Unit

extractText

Added in API level 3
open fun extractText(
    request: ExtractedTextRequest!,
    outText: ExtractedText!
): Boolean

If this TextView contains editable content, extract a portion of it based on the information in request in to outText.

Return
Boolean Returns true if the text was successfully extracted, else false.

findViewsWithText

Added in API level 14
open fun findViewsWithText(
    outViews: ArrayList<View!>!,
    searched: CharSequence!,
    flags: Int
): Unit
Parameters
outViews ArrayList<View!>!: The output list of matching Views.
searched CharSequence!: The text to match against.
flags Int: Value is either 0 or a combination of android.view.View#FIND_VIEWS_WITH_TEXT, and android.view.View#FIND_VIEWS_WITH_CONTENT_DESCRIPTION

getAccessibilityClassName

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

getAutoLinkMask

Added in API level 1
fun getAutoLinkMask(): Int

Gets the autolink mask of the text. See Linkify#ALL and peers for possible values.

getAutoSizeMaxTextSize

Added in API level 26
open fun getAutoSizeMaxTextSize(): Int
Return
Int the current auto-size maximum text size in pixels (the default is 112sp). Note that if auto-size has not been configured this function returns -1.

getAutoSizeMinTextSize

Added in API level 26
open fun getAutoSizeMinTextSize(): Int
Return
Int the current auto-size minimum text size in pixels (the default is 12sp). Note that if auto-size has not been configured this function returns -1.

getAutoSizeStepGranularity

Added in API level 26
open fun getAutoSizeStepGranularity(): Int
Return
Int the current auto-size step granularity in pixels.

getAutoSizeTextAvailableSizes

Added in API level 26
open fun getAutoSizeTextAvailableSizes(): IntArray!
Return
IntArray! the current auto-size int sizes array (in pixels).

getAutofillHints

Added in API level 26
open fun getAutofillHints(): Array<String!>?
Return
Array<String!>? The hints set via the attribute or setAutofillHints(java.lang.String...), or null if no hints were set.

getAutofillType

Added in API level 26
open fun getAutofillType(): Int

Describes the autofill type of this view, so an android.service.autofill.AutofillService can create the proper AutofillValue when autofilling the view.

By default returns AUTOFILL_TYPE_NONE, but views should override it to properly support the Autofill Framework.

Return
Int Value is android.view.View#AUTOFILL_TYPE_NONE, android.view.View#AUTOFILL_TYPE_TEXT, android.view.View#AUTOFILL_TYPE_TOGGLE, android.view.View#AUTOFILL_TYPE_LIST, or android.view.View#AUTOFILL_TYPE_DATE

getAutofillValue

Added in API level 26
open fun getAutofillValue(): AutofillValue?

Gets the TextView's current text for AutoFill. The value is trimmed to 100K chars if longer.

Return
AutofillValue? current text, null if the text is not editable

getBaseline

Added in API level 1
open fun getBaseline(): Int
Return
Int the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported

getBreakStrategy

Added in API level 23
open fun getBreakStrategy(): Int

Gets the current strategy for breaking paragraphs into lines.

Return
Int the current strategy for breaking paragraphs into lines. Value is android.graphics.text.LineBreaker#BREAK_STRATEGY_SIMPLE, android.graphics.text.LineBreaker#BREAK_STRATEGY_HIGH_QUALITY, or android.graphics.text.LineBreaker#BREAK_STRATEGY_BALANCED

getCompoundDrawablePadding

Added in API level 1
open fun getCompoundDrawablePadding(): Int

Returns the padding between the compound drawables and the text.

getCompoundDrawableTintBlendMode

Added in API level 29
open fun getCompoundDrawableTintBlendMode(): BlendMode?

Returns the blending mode used to apply the tint to the compound drawables, if specified.

Return
BlendMode? the blending mode used to apply the tint to the compound drawables This value may be null.

getCompoundDrawableTintList

Added in API level 23
open fun getCompoundDrawableTintList(): ColorStateList!
Return
ColorStateList! the tint applied to the compound drawables

getCompoundDrawableTintMode

Added in API level 23
open fun getCompoundDrawableTintMode(): PorterDuff.Mode!

Returns the blending mode used to apply the tint to the compound drawables, if specified.

Return
PorterDuff.Mode! the blending mode used to apply the tint to the compound drawables

getCompoundDrawables

Added in API level 1
open fun getCompoundDrawables(): Array<Drawable!>

Returns drawables for the left, top, right, and bottom borders.

Return
Array<Drawable!> This value cannot be null.

getCompoundDrawablesRelative

Added in API level 17
open fun getCompoundDrawablesRelative(): Array<Drawable!>

Returns drawables for the start, top, end, and bottom borders.

Return
Array<Drawable!> This value cannot be null.

getCompoundPaddingBottom

Added in API level 1
open fun getCompoundPaddingBottom(): Int

Returns the bottom padding of the view, plus space for the bottom Drawable if any.

getCompoundPaddingEnd

Added in API level 17
open fun getCompoundPaddingEnd(): Int

Returns the end padding of the view, plus space for the end Drawable if any.

getCompoundPaddingLeft

Added in API level 1
open fun getCompoundPaddingLeft(): Int

Returns the left padding of the view, plus space for the left Drawable if any.

getCompoundPaddingRight

Added in API level 1
open fun getCompoundPaddingRight(): Int

Returns the right padding of the view, plus space for the right Drawable if any.

getCompoundPaddingStart

Added in API level 17
open fun getCompoundPaddingStart(): Int

Returns the start padding of the view, plus space for the start Drawable if any.

getCompoundPaddingTop

Added in API level 1
open fun getCompoundPaddingTop(): Int

Returns the top padding of the view, plus space for the top Drawable if any.

getCurrentHintTextColor

Added in API level 1
fun getCurrentHintTextColor(): Int

Return the current color selected to paint the hint text.

Return
Int Returns the current hint text color.

getCurrentTextColor

Added in API level 1
fun getCurrentTextColor(): Int

Return the current color selected for normal text.

Return
Int Returns the current text color.

getCustomInsertionActionModeCallback

Added in API level 23
open fun getCustomInsertionActionModeCallback(): ActionMode.Callback!

Retrieves the value set in setCustomInsertionActionModeCallback. Default is null.

Return
ActionMode.Callback! The current custom insertion callback.

getCustomSelectionActionModeCallback

Added in API level 11
open fun getCustomSelectionActionModeCallback(): ActionMode.Callback!

Retrieves the value set in setCustomSelectionActionModeCallback. Default is null.

Return
ActionMode.Callback! The current custom selection callback.

getEditableText

Added in API level 3
open fun getEditableText(): Editable!

Return the text that TextView is displaying as an Editable object. If the text is not editable, null is returned.

See Also

getEllipsize

Added in API level 1
open fun getEllipsize(): TextUtils.TruncateAt!

Returns where, if anywhere, words that are longer than the view is wide should be ellipsized.

getError

Added in API level 1
open fun getError(): CharSequence!

Returns the error message that was set to be displayed with #setError, or null if no error was set or if it the error was cleared by the widget after user input.

getExtendedPaddingBottom

Added in API level 1
open fun getExtendedPaddingBottom(): Int

Returns the extended bottom padding of the view, including both the bottom Drawable if any and any extra space to keep more than maxLines of text from showing. It is only valid to call this after measuring.

getExtendedPaddingTop

Added in API level 1
open fun getExtendedPaddingTop(): Int

Returns the extended top padding of the view, including both the top Drawable if any and any extra space to keep more than maxLines of text from showing. It is only valid to call this after measuring.

getFilters

Added in API level 1
open fun getFilters(): Array<InputFilter!>!

Returns the current list of input filters.

getFirstBaselineToTopHeight

Added in API level 28
open fun getFirstBaselineToTopHeight(): Int

Returns the distance between the first text baseline and the top of this TextView.

getFocusedRect

Added in API level 1
open fun getFocusedRect(r: Rect!): Unit
Parameters
r Rect!: The rectangle to fill in, in this view's coordinates.

getFocusedSearchResultHighlightColor

Added in API level 34
open fun getFocusedSearchResultHighlightColor(): Int

Gets focused search result highlight color.

Return
Int a focused search result highlight color.

getFontFeatureSettings

Added in API level 21
open fun getFontFeatureSettings(): String?

Returns the font feature settings. The format is the same as the CSS font-feature-settings attribute: https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop

Return
String? the currently set font feature settings. Default is null.

getFontVariationSettings

Added in API level 26
open fun getFontVariationSettings(): String?

Returns the font variation settings.

Return
String? the currently set font variation settings. Returns null if no variation is specified.

getFreezesText

Added in API level 1
open fun getFreezesText(): Boolean

Return whether this text view is including its entire text contents in frozen icicles. For android.widget.EditText it always returns true.

Return
Boolean Returns true if text is included, false if it isn't.

See Also

getGravity

Added in API level 1
open fun getGravity(): Int

Returns the horizontal and vertical alignment of this TextView.

getHighlightColor

Added in API level 16
open fun getHighlightColor(): Int
Return
Int the color used to display the selection highlight

getHighlights

Added in API level 34
open fun getHighlights(): Highlights?

Returns highlights

Return
Highlights? a highlight to be drawn. null if no highlight was set.

getHint

Added in API level 1
open fun getHint(): CharSequence!

Returns the hint that is displayed when the text of the TextView is empty.

getHintTextColors

Added in API level 1
fun getHintTextColors(): ColorStateList!
Return
ColorStateList! the color of the hint text, for the different states of this TextView.

getHyphenationFrequency

Added in API level 23
open fun getHyphenationFrequency(): Int

Gets the current frequency of automatic hyphenation to be used when determining word breaks.

Return
Int the current frequency of automatic hyphenation to be used when determining word breaks. Value is android.text.Layout#HYPHENATION_FREQUENCY_NORMAL, android.text.Layout#HYPHENATION_FREQUENCY_NORMAL_FAST, android.text.Layout#HYPHENATION_FREQUENCY_FULL, android.text.Layout#HYPHENATION_FREQUENCY_FULL_FAST, or android.text.Layout#HYPHENATION_FREQUENCY_NONE

getImeActionId

Added in API level 3
open fun getImeActionId(): Int

Get the IME action ID previous set with setImeActionLabel.

getImeActionLabel

Added in API level 3
open fun getImeActionLabel(): CharSequence!

Get the IME action label previous set with setImeActionLabel.

getImeHintLocales

Added in API level 24
open fun getImeHintLocales(): LocaleList?
Return
LocaleList? The current languages list "hint". null when no "hint" is available.

getImeOptions

Added in API level 3
open fun getImeOptions(): Int

Get the type of the Input Method Editor (IME).

Return
Int the type of the IME

getIncludeFontPadding

Added in API level 16
open fun getIncludeFontPadding(): Boolean

Gets whether the TextView includes extra top and bottom padding to make room for accents that go above the normal ascent and descent.

getInputExtras

Added in API level 3
open fun getInputExtras(create: Boolean): Bundle!

Retrieve the input extras currently associated with the text view, which can be viewed as well as modified.

Parameters
create Boolean: If true, the extras will be created if they don't already exist. Otherwise, null will be returned if none have been created.

getInputType

Added in API level 3
open fun getInputType(): Int

Get the type of the editable content.

getKeyListener

Added in API level 1
fun getKeyListener(): KeyListener!

Gets the current KeyListener for the TextView. This will frequently be null for non-EditText TextViews.

Return
KeyListener! the current key listener for this TextView.

getLastBaselineToBottomHeight

Added in API level 28
open fun getLastBaselineToBottomHeight(): Int

Returns the distance between the last text baseline and the bottom of this TextView.

getLayout

Added in API level 1
fun getLayout(): Layout!

Gets the android.text.Layout that is currently being used to display the text. This value can be null if the text or width has recently changed.

Return
Layout! The Layout that is currently being used to display the text.

getLetterSpacing

Added in API level 21
open fun getLetterSpacing(): Float

Gets the text letter-space value, which determines the spacing between characters. The value returned is in ems. Normally, this value is 0.0.

Return
Float The text letter-space value in ems.

getLineBounds

Added in API level 1
open fun getLineBounds(
    line: Int,
    bounds: Rect!
): Int

Return the baseline for the specified line (0...getLineCount() - 1) If bounds is not null, return the top, left, right, bottom extents of the specified line in it. If the internal Layout has not been built, return 0 and set bounds to (0, 0, 0, 0)

Parameters
line Int: which line to examine (0..getLineCount() - 1)
bounds Rect!: Optional. If not null, it returns the extent of the line
Return
Int the Y-coordinate of the baseline

getLineBreakWordStyle

Added in API level 33
open fun getLineBreakWordStyle(): Int

Gets the current line-break word style for text wrapping.

Return
Int The line-break word style to be used for text wrapping. Value is android.graphics.text.LineBreakConfig#LINE_BREAK_WORD_STYLE_NONE, android.graphics.text.LineBreakConfig#LINE_BREAK_WORD_STYLE_PHRASE, android.graphics.text.LineBreakConfig#LINE_BREAK_WORD_STYLE_UNSPECIFIED, or android.graphics.text.LineBreakConfig#LINE_BREAK_WORD_STYLE_AUTO

getLineCount

Added in API level 1
open fun getLineCount(): Int

Return the number of lines of text, or 0 if the internal Layout has not been built.

getLineHeight

Added in API level 1
open fun getLineHeight(): Int

Gets the vertical distance between lines of text, in pixels. Note that markup within the text can cause individual lines to be taller or shorter than this height, and the layout may contain additional first-or last-line padding.

Return
Int The height of one standard line in pixels.

getLineSpacingExtra

Added in API level 16
open fun getLineSpacingExtra(): Float

Gets the line spacing extra space

Return
Float the extra space that is added to the height of each lines of this TextView.

getLineSpacingMultiplier

Added in API level 16
open fun getLineSpacingMultiplier(): Float

Gets the line spacing multiplier

Return
Float the value by which each line's height is multiplied to get its actual height.

getLinkTextColors

Added in API level 1
fun getLinkTextColors(): ColorStateList!
Return
ColorStateList! the list of colors used to paint the links in the text, for the different states of this TextView

getLinksClickable

Added in API level 1
fun getLinksClickable(): Boolean

Returns whether the movement method will automatically be set to LinkMovementMethod if setAutoLinkMask has been set to nonzero and links are detected in #setText. The default is true.

getMarqueeRepeatLimit

Added in API level 16
open fun getMarqueeRepeatLimit(): Int

Gets the number of times the marquee animation is repeated. Only meaningful if the TextView has marquee enabled.

Return
Int the number of times the marquee animation is repeated. -1 if the animation repeats indefinitely

getMaxEms

Added in API level 16
open fun getMaxEms(): Int

Returns the maximum width of TextView in terms of ems or -1 if the maximum width was set using setMaxWidth(int) or setWidth(int).

Return
Int the maximum width of TextView in terms of ems or -1 if the maximum width is not defined in ems

getMaxHeight

Added in API level 16
open fun getMaxHeight(): Int

Returns the maximum height of TextView in terms of pixels or -1 if the maximum height was set using setMaxLines(int) or setLines(int).

Return
Int the maximum height of TextView in terms of pixels or -1 if the maximum height is not defined in pixels

getMaxLines

Added in API level 16
open fun getMaxLines(): Int

Returns the maximum height of TextView in terms of number of lines or -1 if the maximum height was set using setMaxHeight(int) or setHeight(int).

Return
Int the maximum height of TextView in terms of number of lines. -1 if the maximum height is not defined in lines.

getMaxWidth

Added in API level 16
open fun getMaxWidth(): Int

Returns the maximum width of TextView in terms of pixels or -1 if the maximum width was set using setMaxEms(int) or setEms(int).

Return
Int the maximum width of TextView in terms of pixels. -1 if the maximum width is not defined in pixels

getMinEms

Added in API level 16
open fun getMinEms(): Int

Returns the minimum width of TextView in terms of ems or -1 if the minimum width was set using setMinWidth(int) or setWidth(int).

Return
Int the minimum width of TextView in terms of ems. -1 if the minimum width is not defined in ems

getMinHeight

Added in API level 16
open fun getMinHeight(): Int

Returns the minimum height of TextView in terms of pixels or -1 if the minimum height was set using setMinLines(int) or setLines(int).

Return
Int the minimum height of TextView in terms of pixels or -1 if the minimum height is not defined in pixels

getMinLines

Added in API level 16
open fun getMinLines(): Int

Returns the minimum height of TextView in terms of number of lines or -1 if the minimum height was set using setMinHeight(int) or setHeight(int).

Return
Int the minimum height of TextView in terms of number of lines or -1 if the minimum height is not defined in lines

getMinWidth

Added in API level 16
open fun getMinWidth(): Int

Returns the minimum width of TextView in terms of pixels or -1 if the minimum width was set using setMinEms(int) or setEms(int).

Return
Int the minimum width of TextView in terms of pixels or -1 if the minimum width is not defined in pixels

getMovementMethod

Added in API level 1
fun getMovementMethod(): MovementMethod!

Gets the android.text.method.MovementMethod being used for this TextView, which provides positioning, scrolling, and text selection functionality. This will frequently be null for non-EditText TextViews.

Return
MovementMethod! the movement method being used for this TextView.

getOffsetForPosition

Added in API level 14
open fun getOffsetForPosition(
    x: Float,
    y: Float
): Int

Get the character offset closest to the specified absolute position. A typical use case is to pass the result of MotionEvent#getX() and MotionEvent#getY() to this method.

Parameters
x Float: The horizontal absolute position of a point on screen
y Float: The vertical absolute position of a point on screen
Return
Int the character offset for the character whose position is closest to the specified position. Returns -1 if there is no layout.

getPaint

Added in API level 1
open fun getPaint(): TextPaint!

Gets the TextPaint used for the text. Use this only to consult the Paint's properties and not to change them.

Return
TextPaint! The base paint used for the text.

getPaintFlags

Added in API level 1
open fun getPaintFlags(): Int

Gets the flags on the Paint being used to display the text.

Return
Int The flags on the Paint being used to display the text.

getPrivateImeOptions

Added in API level 3
open fun getPrivateImeOptions(): String!

Get the private type of the content.

getSearchResultHighlights

Added in API level 34
open fun getSearchResultHighlights(): IntArray?

Gets the current search result ranges.

Return
IntArray? a flatten search result ranges. null if not available.

getSelectionEnd

Added in API level 1
open fun getSelectionEnd(): Int

Convenience for Selection#getSelectionEnd.

getSelectionStart

Added in API level 1
open fun getSelectionStart(): Int

Convenience for Selection#getSelectionStart.

getShadowColor

Added in API level 16
open fun getShadowColor(): Int

Gets the color of the shadow layer.

Return
Int the color of the shadow layer

getShadowDx

Added in API level 16
open fun getShadowDx(): Float
Return
Float the horizontal offset of the shadow layer

getShadowDy

Added in API level 16
open fun getShadowDy(): Float

Gets the vertical offset of the shadow layer.

Return
Float The vertical offset of the shadow layer.

getShadowRadius

Added in API level 16
open fun getShadowRadius(): Float

Gets the radius of the shadow layer.

Return
Float the radius of the shadow layer. If 0, the shadow layer is not visible

getShiftDrawingOffsetForStartOverhang

Added in API level 35
open fun getShiftDrawingOffsetForStartOverhang(): Boolean

Returns true if shifting the drawing x offset for start overhang.

Return
Boolean True if shifting the drawing x offset for start overhang.

getShowSoftInputOnFocus

Added in API level 21
fun getShowSoftInputOnFocus(): Boolean

Returns whether the soft input method will be made visible when this TextView gets focused. The default is true.

getText

Added in API level 1
open fun getText(): CharSequence!

Return the text that TextView is displaying. If setText(java.lang.CharSequence) was called with an argument of BufferType.SPANNABLE or BufferType.EDITABLE, you can cast the return value from this method to Spannable or Editable, respectively.

The content of the return value should not be modified. If you want a modifiable one, you should make your own copy first.

Return
CharSequence! The text displayed by the text view.

getTextClassifier

Added in API level 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 TextClassificationManager.

Return
TextClassifier This value cannot be null.

getTextColors

Added in API level 1
fun getTextColors(): ColorStateList!

Gets the text colors for the different states (normal, selected, focused) of the TextView.

getTextCursorDrawable

Added in API level 29
open fun getTextCursorDrawable(): Drawable?

Returns the Drawable corresponding to the text cursor. Note that any change applied to the cursor Drawable will not be visible until the cursor is hidden and then drawn again.

Return
Drawable? the text cursor drawable This value may be null.

getTextDirectionHeuristic

Added in API level 29
open fun getTextDirectionHeuristic(): TextDirectionHeuristic

Returns resolved TextDirectionHeuristic that will be used for text layout. The TextDirectionHeuristic that is used by TextView is only available after getTextDirection() and getLayoutDirection() is resolved. Therefore the return value may not be the same as the one TextView uses if the View's layout direction is not resolved or detached from parent root view.

Return
TextDirectionHeuristic This value cannot be null.

getTextLocale

Added in API level 17
open fun getTextLocale(): Locale

Get the default primary Locale of the text in this TextView. This will always be the first member of getTextLocales().

Return
Locale the default primary Locale of the text in this TextView. This value cannot be null.

getTextLocales

Added in API level 24
open fun getTextLocales(): LocaleList

Get the default LocaleList of the text in this TextView.

Return
LocaleList the default LocaleList of the text in this TextView. This value cannot be null.

getTextMetricsParams

Added in API level 28
open fun getTextMetricsParams(): PrecomputedText.Params

Gets the parameters for text layout precomputation, for use with PrecomputedText.

Return
PrecomputedText.Params a current PrecomputedText.Params This value cannot be null.

getTextScaleX

Added in API level 1
open fun getTextScaleX(): Float

Gets the extent by which text should be stretched horizontally. This will usually be 1.0.

Return
Float The horizontal scale factor.

getTextSelectHandle

Added in API level 29
open fun getTextSelectHandle(): Drawable?

Returns the Drawable corresponding to the selection handle used for positioning the cursor within text. Note that any change applied to the handle Drawable will not be visible until the handle is hidden and then drawn again.

Return
Drawable? the text select handle drawable This value may be null.

getTextSelectHandleLeft

Added in API level 29
open fun getTextSelectHandleLeft(): Drawable?

Returns the Drawable corresponding to the left handle used for selecting text. Note that any change applied to the handle Drawable will not be visible until the handle is hidden and then drawn again.

Return
Drawable? the left text selection handle drawable This value may be null.

getTextSelectHandleRight

Added in API level 29
open fun getTextSelectHandleRight(): Drawable?

Returns the Drawable corresponding to the right handle used for selecting text. Note that any change applied to the handle Drawable will not be visible until the handle is hidden and then drawn again.

Return
Drawable? the right text selection handle drawable This value may be null.

getTextSize

Added in API level 1
open fun getTextSize(): Float
Return
Float the size (in pixels) of the default text size in this TextView.

getTextSizeUnit

Added in API level 30
open fun getTextSizeUnit(): Int

Gets the text size unit defined by the developer. It may be specified in resources or be passed as the unit argument of setTextSize(int,float) at runtime.

Return
Int the dimension type of the text size unit originally defined.

getTotalPaddingBottom

Added in API level 1
open fun getTotalPaddingBottom(): Int

Returns the total bottom padding of the view, including the bottom Drawable if any, the extra space to keep more than maxLines from showing, and the vertical offset for gravity, if any.

getTotalPaddingEnd

Added in API level 17
open fun getTotalPaddingEnd(): Int

Returns the total end padding of the view, including the end Drawable if any.

getTotalPaddingLeft

Added in API level 1
open fun getTotalPaddingLeft(): Int

Returns the total left padding of the view, including the left Drawable if any.

getTotalPaddingRight

Added in API level 1
open fun getTotalPaddingRight(): Int

Returns the total right padding of the view, including the right Drawable if any.

getTotalPaddingStart

Added in API level 17
open fun getTotalPaddingStart(): Int

Returns the total start padding of the view, including the start Drawable if any.

getTotalPaddingTop

Added in API level 1
open fun getTotalPaddingTop(): Int

Returns the total top padding of the view, including the top Drawable if any, the extra space to keep more than maxLines from showing, and the vertical offset for gravity, if any.

getTransformationMethod

Added in API level 1
fun getTransformationMethod(): TransformationMethod!

Gets the current android.text.method.TransformationMethod for the TextView. This is frequently null, except for single-line and password fields.

Return
TransformationMethod! the current transformation method for this TextView.

getTypeface

Added in API level 1
open fun getTypeface(): Typeface!

Gets the current Typeface that is used to style the text.

Return
Typeface! The current Typeface.

getUrls

Added in API level 1
open fun getUrls(): Array<URLSpan!>!

Returns the list of URLSpans attached to the text (by Linkify or otherwise) if any. You can call URLSpan#getURL on them to find where they link to or use Spanned#getSpanStart and Spanned#getSpanEnd to find the region of the text they are attached to.

getUseBoundsForWidth

Added in API level 35
open fun getUseBoundsForWidth(): Boolean

Returns true if using bounding box as a width, false for using advance as a width.

Return
Boolean True if using bounding box for width, false if using advance for width.

hasOverlappingRendering

Added in API level 16
open fun hasOverlappingRendering(): Boolean
Return
Boolean true if the content in this view might overlap, false otherwise.

hasSelection

Added in API level 1
open fun hasSelection(): Boolean

Return true iff there is a selection of nonzero length inside this text view.

invalidateDrawable

Added in API level 1
open fun invalidateDrawable(drawable: Drawable): Unit

Invalidates the specified Drawable.

Parameters
who The drawable that is requesting the update. This value cannot be null.
drawable Drawable: This value cannot be null.

isAllCaps

Added in API level 28
open fun isAllCaps(): Boolean

Checks whether the transformation method applied to this TextView is set to ALL CAPS.

Return
Boolean Whether the current transformation method is for ALL CAPS.

isAutoHandwritingEnabled

Added in API level 33
open fun isAutoHandwritingEnabled(): Boolean

isCursorVisible

Added in API level 16
open fun isCursorVisible(): Boolean
Return
Boolean whether or not the cursor is visible (assuming this TextView is editable). This method may return false when the IME is consuming the input even if the mEditor.mCursorVisible attribute is true or setCursorVisible(true) is called.

isElegantTextHeight

Added in API level 28
open fun isElegantTextHeight(): Boolean

Get the value of the TextView's elegant height metrics flag. This setting selects font variants that have not been compacted to fit Latin-based vertical metrics, and also increases top and bottom bounds to provide more space.

Return
Boolean true if the elegant height metrics flag is set.

isFallbackLineSpacing

Added in API level 28
open fun isFallbackLineSpacing(): Boolean
Return
Boolean whether fallback line spacing is enabled, true by default

isHorizontallyScrollable

Added in API level 29
fun isHorizontallyScrollable(): Boolean

Returns whether the text is allowed to be wider than the View. If false, the text will be wrapped to the width of the View.

isInputMethodTarget

Added in API level 3
open fun isInputMethodTarget(): Boolean

Returns whether this text view is a current input method target. The default implementation just checks with InputMethodManager.

Return
Boolean True if the TextView is a current input method target; false otherwise.

isLocalePreferredLineHeightForMinimumUsed

Added in API level 35
open fun isLocalePreferredLineHeightForMinimumUsed(): Boolean

Returns true if the locale preferred line height is used for the minimum line height.

Return
Boolean true if using locale preferred line height for the minimum line height. Otherwise false.

isSingleLine

Added in API level 29
open fun isSingleLine(): Boolean

Returns if the text is constrained to a single horizontally scrolling line ignoring new line characters instead of letting it wrap onto multiple lines.

isSuggestionsEnabled

Added in API level 14
open fun isSuggestionsEnabled(): Boolean

Return whether or not suggestions are enabled on this TextView. The suggestions are generated by the IME or by the spell checker as the user types. This is done by adding SuggestionSpans to the text. When suggestions are enabled (default), this list of suggestions will be displayed when the user asks for them on these parts of the text. This value depends on the inputType of this TextView. The class of the input type must be InputType#TYPE_CLASS_TEXT. In addition, the type variation must be one of InputType#TYPE_TEXT_VARIATION_NORMAL, InputType#TYPE_TEXT_VARIATION_EMAIL_SUBJECT, InputType#TYPE_TEXT_VARIATION_LONG_MESSAGE, InputType#TYPE_TEXT_VARIATION_SHORT_MESSAGE or InputType#TYPE_TEXT_VARIATION_WEB_EDIT_TEXT. And finally, the InputType#TYPE_TEXT_FLAG_NO_SUGGESTIONS flag must not be set.

Return
Boolean true if the suggestions popup window is enabled, based on the inputType.

isTextSelectable

Added in API level 11
open fun isTextSelectable(): Boolean

Returns the state of the textIsSelectable flag (See setTextIsSelectable()). Although you have to set this flag to allow users to select and copy text in a non-editable TextView, the content of an EditText can always be selected, independently of the value of this flag.

Return
Boolean True if the text displayed in this TextView can be selected by the user.

jumpDrawablesToCurrentState

Added in API level 11
open fun jumpDrawablesToCurrentState(): Unit

length

Added in API level 1
open fun length(): Int

Returns the length, in characters, of the text managed by this TextView

Return
Int The length of the text managed by the TextView in characters.

moveCursorToVisibleOffset

Added in API level 3
open fun moveCursorToVisibleOffset(): Boolean

Move the cursor, if needed, so that it is at an offset that is visible to the user. This will not move the cursor if it represents more than one character (a selection range). This will only work if the TextView contains spannable text; otherwise it will do nothing.

Return
Boolean True if the cursor was actually moved, false otherwise.

onBeginBatchEdit

Added in API level 3
open fun onBeginBatchEdit(): Unit

Called by the framework in response to a request to begin a batch of edit operations through a call to link beginBatchEdit().

onCheckIsTextEditor

Added in API level 3
open fun onCheckIsTextEditor(): Boolean
Return
Boolean Returns true if this view is a text editor, else false.

onCommitCompletion

Added in API level 3
open fun onCommitCompletion(text: CompletionInfo!): Unit

Called by the framework in response to a text completion from the current input method, provided by it calling InputConnection.commitCompletion(). The default implementation does nothing; text views that are supporting auto-completion should override this to do their desired behavior.

Parameters
text CompletionInfo!: The auto complete text the user has selected.

onCommitCorrection

Added in API level 11
open fun onCommitCorrection(info: CorrectionInfo!): Unit

Called by the framework in response to a text auto-correction (such as fixing a typo using a dictionary) from the current input method, provided by it calling InputConnection.commitCorrection(). The default implementation flashes the background of the corrected word to provide feedback to the user.

Parameters
info CorrectionInfo!: The auto correct info about the text that was corrected.

onCreateInputConnection

Added in API level 3
open fun onCreateInputConnection(outAttrs: EditorInfo!): InputConnection!
Parameters
outAttrs EditorInfo!: Fill in with attribute information about the connection.

onCreateViewTranslationRequest

Added in API level 31
open fun onCreateViewTranslationRequest(
    supportedFormats: IntArray,
    requestsCollector: Consumer<ViewTranslationRequest!>
): Unit

Collects a ViewTranslationRequest which represents the content to be translated in the view.

NOTE: When overriding the method, it should not collect a request to translate this TextView if it is displaying a password.

Parameters
supportedFormats IntArray: the supported translation format. The value could be android.view.translation.TranslationSpec#DATA_FORMAT_TEXT. This value cannot be null.
requestsCollector Consumer<ViewTranslationRequest!>: Consumer to receiver the ViewTranslationRequest which contains the information to be translated. This value cannot be null.

onDragEvent

Added in API level 11
open fun onDragEvent(event: DragEvent!): Boolean

Handles drag events sent by the system following a call to startDragAndDrop().

If this text view is not editable, delegates to the default View#onDragEvent implementation.

If this text view is editable, accepts all drag actions (returns true for an ACTION_DRAG_STARTED event and all subsequent drag events). While the drag is in progress, updates the cursor position to follow the touch location. Once a drop event is received, handles content insertion via performReceiveContent.

Parameters
event DragEvent!: The android.view.DragEvent sent by the system. The android.view.DragEvent#getAction() method returns an action type constant defined in DragEvent, indicating the type of drag event represented by this object.
Return
Boolean Returns true if this text view is editable and delegates to super otherwise. See View#onDragEvent.

onEditorAction

Added in API level 3
open fun onEditorAction(actionCode: Int): Unit

Called when an attached input method calls InputConnection.performEditorAction() for this text view. The default implementation will call your action listener supplied to setOnEditorActionListener, or perform a standard operation for EditorInfo.IME_ACTION_NEXT, EditorInfo.IME_ACTION_PREVIOUS, or EditorInfo.IME_ACTION_DONE.

For backwards compatibility, if no IME options have been set and the text view would not normally advance focus on enter, then the NEXT and DONE actions received here will be turned into an enter key down/up pair to go through the normal key handling.

Parameters
actionCode Int: The code of the action being performed.

onEndBatchEdit

Added in API level 3
open fun onEndBatchEdit(): Unit

Called by the framework in response to a request to end a batch of edit operations through a call to link endBatchEdit.

onGenericMotionEvent

Added in API level 12
open fun onGenericMotionEvent(event: MotionEvent!): Boolean
Parameters
event MotionEvent!: The generic motion event being processed.
Return
Boolean True if the event was handled, false otherwise.

onKeyDown

Added in API level 1
open fun onKeyDown(
    keyCode: Int,
    event: KeyEvent!
): Boolean
Parameters
keyCode Int: a key code that represents the button pressed, from android.view.KeyEvent
event KeyEvent!: the KeyEvent object that defines the button action
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyMultiple

Added in API level 1
open fun onKeyMultiple(
    keyCode: Int,
    repeatCount: Int,
    event: KeyEvent!
): Boolean
Parameters
keyCode Int: A key code that represents the button pressed, from android.view.KeyEvent.
count Number of pairs as returned by event.getRepeatCount().
event KeyEvent!: The KeyEvent object that defines the button action.
repeatCount Int: The number of times the action was made.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyPreIme

Added in API level 3
open fun onKeyPreIme(
    keyCode: Int,
    event: KeyEvent!
): Boolean
Parameters
keyCode Int: The value in event.getKeyCode().
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyShortcut

Added in API level 1
open fun onKeyShortcut(
    keyCode: Int,
    event: KeyEvent!
): Boolean
Parameters
keyCode Int: The value in event.getKeyCode().
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyUp

Added in API level 1
open fun onKeyUp(
    keyCode: Int,
    event: KeyEvent!
): Boolean
Parameters
keyCode Int: A key code that represents the button pressed, from android.view.KeyEvent.
event KeyEvent!: The KeyEvent object that defines the button action.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onPreDraw

Added in API level 1
open fun onPreDraw(): Boolean

Callback method to be invoked when the view tree is about to be drawn. At this point, all views in the tree have been measured and given a frame. Clients can use this to adjust their scroll bounds or even to request a new layout before drawing occurs.

Return
Boolean Return true to proceed with the current drawing pass, or false to cancel.

onPrivateIMECommand

Added in API level 3
open fun onPrivateIMECommand(
    action: String!,
    data: Bundle!
): Boolean

Called by the framework in response to a private command from the current method, provided by it calling InputConnection.performPrivateCommand().

Parameters
action String!: The action name of the command.
data Bundle!: Any additional data for the command. This may be null.
Return
Boolean Return true if you handled the command, else false.

onReceiveContent

Added in API level 31
open fun onReceiveContent(payload: ContentInfo): ContentInfo?

Default TextView implementation for receiving content. Apps wishing to provide custom behavior should configure a listener via setOnReceiveContentListener.

For non-editable TextViews the default behavior is a no-op (returns the passed-in content without acting on it).

For editable TextViews the default behavior is to insert text into the view, coercing non-text content to text as needed. The MIME types "text/plain" and "text/html" have well-defined behavior for this, while other MIME types have reasonable fallback behavior (see ClipData.Item#coerceToStyledText).

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

onResolvePointerIcon

Added in API level 24
open fun onResolvePointerIcon(
    event: MotionEvent!,
    pointerIndex: Int
): PointerIcon!
Parameters
event MotionEvent!: The MotionEvent that requires a pointer icon to be resolved for one of pointers.
pointerIndex Int: The index of the pointer in event for which to retrieve the PointerIcon. This will be between 0 and MotionEvent#getPointerCount().
Return
PointerIcon! the pointer icon to use for specified pointer, or null if a pointer icon is not specified and the default icon should be used.

onRestoreInstanceState

Added in API level 1
open fun onRestoreInstanceState(state: Parcelable!): Unit
Parameters
state Parcelable!: The frozen state that had previously been returned by onSaveInstanceState.

onRtlPropertiesChanged

Added in API level 17
open fun onRtlPropertiesChanged(layoutDirection: Int): Unit
Parameters
layoutDirection Int: the direction of the layout Value is android.view.View#LAYOUT_DIRECTION_LTR, or android.view.View#LAYOUT_DIRECTION_RTL

onSaveInstanceState

Added in API level 1
open fun onSaveInstanceState(): Parcelable?
Return
Parcelable? Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save.

onScreenStateChanged

Added in API level 16
open fun onScreenStateChanged(screenState: Int): Unit
Parameters
screenState Int: The new state of the screen. Can be either SCREEN_STATE_ON or SCREEN_STATE_OFF

onTextContextMenuItem

Added in API level 3
open fun onTextContextMenuItem(id: Int): Boolean

Called when a context menu option for the text view is selected. Currently this will be one of android.R.id#selectAll, android.R.id#cut, android.R.id#copy, android.R.id#paste, android.R.id#pasteAsPlainText (starting at API level 23) or android.R.id#shareText.

Return
Boolean true if the context menu item action was performed.

onTouchEvent

Added in API level 1
open fun onTouchEvent(event: MotionEvent!): Boolean
Parameters
event MotionEvent!: The motion event.
Return
Boolean True if the event was handled, false otherwise.

onTrackballEvent

Added in API level 1
open fun onTrackballEvent(event: MotionEvent!): Boolean
Parameters
event MotionEvent!: The motion event.
Return
Boolean True if the event was handled, false otherwise.

onVisibilityAggregated

Added in API level 24
open fun onVisibilityAggregated(isVisible: Boolean): Unit
Parameters
isVisible Boolean: true if this view and all of its ancestors are VISIBLE and this view's window is also visible

onWindowFocusChanged

Added in API level 1
open fun onWindowFocusChanged(hasWindowFocus: Boolean): Unit
Parameters
hasWindowFocus Boolean: True if the window containing this view now has focus, false otherwise.

performLongClick

Added in API level 1
open fun performLongClick(): Boolean
Return
Boolean true if one of the above receivers consumed the event, false otherwise

removeTextChangedListener

Added in API level 1
open fun removeTextChangedListener(watcher: TextWatcher!): Unit

Removes the specified TextWatcher from the list of those whose methods are called whenever this TextView's text changes.

sendAccessibilityEventUnchecked

Added in API level 4
open fun sendAccessibilityEventUnchecked(event: AccessibilityEvent!): Unit
Parameters
event AccessibilityEvent!: The event to send.

setAllCaps

Added in API level 14
open fun setAllCaps(allCaps: Boolean): Unit

Sets the properties of this field to transform input to ALL CAPS display. This may use a "small caps" formatting if available. This setting will be ignored if this field is editable or selectable. This call replaces the current transformation method. Disabling this will not necessarily restore the previous behavior from before this was enabled.

setAutoLinkMask

Added in API level 1
fun setAutoLinkMask(mask: Int): Unit

Sets the autolink mask of the text. See Linkify.ALL and peers for possible values.

Note: Linkify.MAP_ADDRESSES is deprecated and should be avoided; see its documentation.

setAutoSizeTextTypeUniformWithConfiguration

Added in API level 26
open fun setAutoSizeTextTypeUniformWithConfiguration(
    autoSizeMinTextSize: Int,
    autoSizeMaxTextSize: Int,
    autoSizeStepGranularity: Int,
    unit: Int
): Unit

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds. If all the configuration params are valid the type of auto-size is set to AUTO_SIZE_TEXT_TYPE_UNIFORM.

Parameters
autoSizeMinTextSize Int: the minimum text size available for auto-size
autoSizeMaxTextSize Int: the maximum text size available for auto-size
autoSizeStepGranularity Int: the auto-size step granularity. It is used in conjunction with the minimum and maximum text size in order to build the set of text sizes the system uses to choose from when auto-sizing
unit Int: the desired dimension unit for all sizes above. See TypedValue for the possible dimension units
Exceptions
java.lang.IllegalArgumentException if any of the configuration params are invalid.

setAutoSizeTextTypeUniformWithPresetSizes

Added in API level 26
open fun setAutoSizeTextTypeUniformWithPresetSizes(
    presetSizes: IntArray,
    unit: Int
): Unit

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds. If at least one value from the presetSizes is valid then the type of auto-size is set to AUTO_SIZE_TEXT_TYPE_UNIFORM.

Parameters
presetSizes IntArray: an int array of sizes in pixels This value cannot be null.
unit Int: the desired dimension unit for the preset sizes above. See TypedValue for the possible dimension units
Exceptions
java.lang.IllegalArgumentException if all of the presetSizes are invalid.

setAutoSizeTextTypeWithDefaults

Added in API level 26
open fun setAutoSizeTextTypeWithDefaults(autoSizeTextType: Int): Unit

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds by using the default auto-size configuration.

Parameters
autoSizeTextType Int: the type of auto-size. Must be one of TextView#AUTO_SIZE_TEXT_TYPE_NONE or TextView#AUTO_SIZE_TEXT_TYPE_UNIFORM Value is android.widget.TextView#AUTO_SIZE_TEXT_TYPE_NONE, or android.widget.TextView#AUTO_SIZE_TEXT_TYPE_UNIFORM
Exceptions
java.lang.IllegalArgumentException if autoSizeTextType is none of the types above.

setBreakStrategy

Added in API level 23
open fun setBreakStrategy(breakStrategy: Int): Unit

Sets the break strategy for breaking paragraphs into lines. The default value for TextView is Layout#BREAK_STRATEGY_HIGH_QUALITY, and the default value for EditText is Layout#BREAK_STRATEGY_SIMPLE, the latter to avoid the text "dancing" when being edited.

Enabling hyphenation with either using Layout#HYPHENATION_FREQUENCY_NORMAL or Layout#HYPHENATION_FREQUENCY_FULL while line breaking is set to one of Layout#BREAK_STRATEGY_BALANCED, Layout#BREAK_STRATEGY_HIGH_QUALITY improves the structure of text layout however has performance impact and requires more time to do the text layout.

Compared with setLineBreakStyle(int), line break style with different strictness is evaluated in the ICU to identify the potential breakpoints. In setBreakStrategy(int), line break strategy handles the post processing of ICU's line break result. It aims to evaluate ICU's breakpoints and break the lines based on the constraint.

Parameters
breakStrategy Int: Value is android.graphics.text.LineBreaker#BREAK_STRATEGY_SIMPLE, android.graphics.text.LineBreaker#BREAK_STRATEGY_HIGH_QUALITY, or android.graphics.text.LineBreaker#BREAK_STRATEGY_BALANCED

setCompoundDrawablePadding

Added in API level 1
open fun setCompoundDrawablePadding(pad: Int): Unit

Sets the size of the padding between the compound drawables and the text.

setCompoundDrawableTintBlendMode

Added in API level 29
open fun setCompoundDrawableTintBlendMode(blendMode: BlendMode?): Unit

Specifies the blending mode used to apply the tint specified by setCompoundDrawableTintList(android.content.res.ColorStateList) to the compound drawables. The default mode is PorterDuff.Mode#SRC_IN.

Parameters
blendMode BlendMode?: the blending mode used to apply the tint, may be null to clear tint

setCompoundDrawableTintList

Added in API level 23
open fun setCompoundDrawableTintList(tint: ColorStateList?): Unit

Applies a tint to the compound drawables. Does not modify the current tint mode, which is BlendMode#SRC_IN by default.

Subsequent calls to setCompoundDrawables(android.graphics.drawable.Drawable,android.graphics.drawable.Drawable,android.graphics.drawable.Drawable,android.graphics.drawable.Drawable) and related methods will automatically mutate the drawables and apply the specified tint and tint mode using Drawable#setTintList(ColorStateList).

Parameters
tint ColorStateList?: the tint to apply, may be null to clear tint

setCompoundDrawableTintMode

Added in API level 23
open fun setCompoundDrawableTintMode(tintMode: PorterDuff.Mode?): Unit

Specifies the blending mode used to apply the tint specified by setCompoundDrawableTintList(android.content.res.ColorStateList) to the compound drawables. The default mode is PorterDuff.Mode#SRC_IN.

Parameters
tintMode PorterDuff.Mode?: the blending mode used to apply the tint, may be null to clear tint

setCompoundDrawables

Added in API level 1
open fun setCompoundDrawables(
    left: Drawable?,
    top: Drawable?,
    right: Drawable?,
    bottom: Drawable?
): Unit

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use null if you do not want a Drawable there. The Drawables must already have had android.graphics.drawable.Drawable#setBounds called.

Calling this method will overwrite any Drawables previously set using setCompoundDrawablesRelative or related methods.

Parameters
left Drawable?: This value may be null.
top Drawable?: This value may be null.
right Drawable?: This value may be null.
bottom Drawable?: This value may be null.

setCompoundDrawablesRelative

Added in API level 17
open fun setCompoundDrawablesRelative(
    start: Drawable?,
    top: Drawable?,
    end: Drawable?,
    bottom: Drawable?
): Unit

Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text. Use null if you do not want a Drawable there. The Drawables must already have had android.graphics.drawable.Drawable#setBounds called.

Calling this method will overwrite any Drawables previously set using setCompoundDrawables or related methods.

Parameters
start Drawable?: This value may be null.
top Drawable?: This value may be null.
end Drawable?: This value may be null.
bottom Drawable?: This value may be null.

setCompoundDrawablesRelativeWithIntrinsicBounds

Added in API level 17
open fun setCompoundDrawablesRelativeWithIntrinsicBounds(
    start: Int,
    top: Int,
    end: Int,
    bottom: Int
): Unit

Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.

Calling this method will overwrite any Drawables previously set using setCompoundDrawables or related methods.

Parameters
start Int: Resource identifier of the start Drawable.
top Int: Resource identifier of the top Drawable.
end Int: Resource identifier of the end Drawable.
bottom Int: Resource identifier of the bottom Drawable.

setCompoundDrawablesRelativeWithIntrinsicBounds

Added in API level 17
open fun setCompoundDrawablesRelativeWithIntrinsicBounds(
    start: Drawable?,
    top: Drawable?,
    end: Drawable?,
    bottom: Drawable?
): Unit

Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text. Use null if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.

Calling this method will overwrite any Drawables previously set using setCompoundDrawables or related methods.

Parameters
start Drawable?: This value may be null.
top Drawable?: This value may be null.
end Drawable?: This value may be null.
bottom Drawable?: This value may be null.

setCompoundDrawablesWithIntrinsicBounds

Added in API level 3
open fun setCompoundDrawablesWithIntrinsicBounds(
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Unit

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.

Calling this method will overwrite any Drawables previously set using setCompoundDrawablesRelative or related methods.

Parameters
left Int: Resource identifier of the left Drawable.
top Int: Resource identifier of the top Drawable.
right Int: Resource identifier of the right Drawable.
bottom Int: Resource identifier of the bottom Drawable.

setCompoundDrawablesWithIntrinsicBounds

Added in API level 1
open fun setCompoundDrawablesWithIntrinsicBounds(
    left: Drawable?,
    top: Drawable?,
    right: Drawable?,
    bottom: Drawable?
): Unit

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use null if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.

Calling this method will overwrite any Drawables previously set using setCompoundDrawablesRelative or related methods.

Parameters
left Drawable?: This value may be null.
top Drawable?: This value may be null.
right Drawable?: This value may be null.
bottom Drawable?: This value may be null.

setCursorVisible

Added in API level 1
open fun setCursorVisible(visible: Boolean): Unit

Set whether the cursor is visible. The default is true. Note that this property only makes sense for editable TextView. If IME is consuming the input, the cursor will always be invisible, visibility will be updated as the last state when IME does not consume the input anymore.

setCustomInsertionActionModeCallback

Added in API level 23
open fun setCustomInsertionActionModeCallback(actionModeCallback: ActionMode.Callback!): Unit

If provided, this ActionMode.Callback will be used to create the ActionMode when text insertion is initiated in this View. The standard implementation populates the menu with a subset of Select All, Paste and Replace actions, depending on what this View supports.

A custom implementation can add new entries in the default menu in its android.view.ActionMode.Callback#onPrepareActionMode(android.view.ActionMode, * android.view.Menu) method. The default actions can also be removed from the menu using android.view.Menu#removeItem(int) and passing android.R.id#selectAll, android.R.id#paste, android.R.id#pasteAsPlainText (starting at API level 23) or android.R.id#replaceText ids as parameters.

Returning false from android.view.ActionMode.Callback#onCreateActionMode(android.view.ActionMode, * android.view.Menu) will prevent the action mode from being started.

Action click events should be handled by the custom implementation of android.view.ActionMode.Callback#onActionItemClicked(android.view.ActionMode, * android.view.MenuItem).

Note that text insertion mode is not started when a TextView receives focus and the android.R.attr#selectAllOnFocus flag has been set.

setCustomSelectionActionModeCallback

Added in API level 11
open fun setCustomSelectionActionModeCallback(actionModeCallback: ActionMode.Callback!): Unit

If provided, this ActionMode.Callback will be used to create the ActionMode when text selection is initiated in this View.

The standard implementation populates the menu with a subset of Select All, Cut, Copy, Paste, Replace and Share actions, depending on what this View supports.

A custom implementation can add new entries in the default menu in its android.view.ActionMode.Callback#onPrepareActionMode(ActionMode, android.view.Menu) method. The default actions can also be removed from the menu using android.view.Menu#removeItem(int) and passing android.R.id#selectAll, android.R.id#cut, android.R.id#copy, android.R.id#paste, android.R.id#pasteAsPlainText (starting at API level 23), android.R.id#replaceText or android.R.id#shareText ids as parameters.

Returning false from android.view.ActionMode.Callback#onCreateActionMode(ActionMode, android.view.Menu) will prevent the action mode from being started.

Action click events should be handled by the custom implementation of android.view.ActionMode.Callback#onActionItemClicked(ActionMode, * android.view.MenuItem).

Note that text selection mode is not started when a TextView receives focus and the android.R.attr#selectAllOnFocus flag has been set. The content is highlighted in that case, to allow for quick replacement.

setEditableFactory

Added in API level 1
fun setEditableFactory(factory: Editable.Factory!): Unit

Sets the Factory used to create new Editables.

Parameters
factory Editable.Factory!: Editable.Factory to be used

setElegantTextHeight

Added in API level 21
open fun setElegantTextHeight(elegant: Boolean): Unit

Set the TextView's elegant height metrics flag. This setting selects font variants that have not been compacted to fit Latin-based vertical metrics, and also increases top and bottom bounds to provide more space.

Parameters
elegant Boolean: set the paint's elegant metrics flag.

setEllipsize

Added in API level 1
open fun setEllipsize(where: 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. You may also want to #setSingleLine or setHorizontallyScrolling to constrain the text to a single line. Use null to turn off ellipsizing. If setMaxLines has been used to set two or more lines, only android.text.TextUtils.TruncateAt#END and android.text.TextUtils.TruncateAt#MARQUEE are supported (other ellipsizing types will not do anything).

setEms

Added in API level 1
open fun setEms(ems: Int): Unit

Sets the width of the TextView to be exactly ems wide. This value is used for width calculation if LayoutParams does not force TextView to have an exact width. Setting this value overrides previous minimum/maximum configurations such as setMinEms(int) or setMaxEms(int).

Parameters
ems Int: the exact width of the TextView in terms of ems

See Also

setEnabled

Added in API level 1
open fun setEnabled(enabled: Boolean): Unit
Parameters
enabled Boolean: True if this view is enabled, false otherwise.

setError

Added in API level 1
open fun setError(error: CharSequence!): Unit

Sets the right-hand compound drawable of the TextView to the "error" icon and sets an error message that will be displayed in a popup when the TextView has focus. The icon and error message will be reset to null when any key events cause changes to the TextView's text. If the error is null, the error message and icon will be cleared.

setError

Added in API level 1
open fun setError(
    error: CharSequence!,
    icon: Drawable!
): Unit

Sets the right-hand compound drawable of the TextView to the specified icon and sets an error message that will be displayed in a popup when the TextView has focus. The icon and error message will be reset to null when any key events cause changes to the TextView's text. The drawable must already have had android.graphics.drawable.Drawable#setBounds set on it. If the error is null, the error message will be cleared (and you should provide a null icon as well).

setExtractedText

Added in API level 3
open fun setExtractedText(text: ExtractedText!): Unit

Apply to this text view the given extracted text, as previously returned by extractText(android.view.inputmethod.ExtractedTextRequest,android.view.inputmethod.ExtractedText).

setFallbackLineSpacing

Added in API level 28
open fun setFallbackLineSpacing(enabled: Boolean): Unit

Set whether to respect the ascent and descent of the fallback fonts that are used in displaying the text (which is needed to avoid text from consecutive lines running into each other). If set, fallback fonts that end up getting used can increase the ascent and descent of the lines that they are used on.

It is required to be true if text could be in languages like Burmese or Tibetan where text is typically much taller or deeper than Latin text.
Parameters
enabled Boolean: whether to expand linespacing based on fallback fonts, true by default

setFilters

Added in API level 1
open fun setFilters(filters: Array<InputFilter!>!): Unit

Sets the list of input filters that will be used if the buffer is Editable. Has no effect otherwise.

setFirstBaselineToTopHeight

Added in API level 28
open fun setFirstBaselineToTopHeight(firstBaselineToTopHeight: Int): Unit

Updates the top padding of the TextView so that is the distance between the top of the TextView and first line's baseline.

First and last baseline metrics for a TextView. Note that if FontMetrics.top or FontMetrics.ascent was already greater than firstBaselineToTopHeight, the top padding is not updated. Moreover since this function sets the top padding, if the height of the TextView is less than the sum of top padding, line height and bottom padding, top of the line will be pushed down and bottom will be clipped.
Parameters
firstBaselineToTopHeight Int: distance between first baseline to top of the container in pixels The units of this value are pixels. Value is 0 or greater

setFocusedSearchResultHighlightColor

Added in API level 34
open fun setFocusedSearchResultHighlightColor(color: Int): Unit

Sets focused search result highlight color.

Parameters
color Int: a focused search result highlight color.

setFocusedSearchResultIndex

Added in API level 34
open fun setFocusedSearchResultIndex(index: Int): Unit

Sets the focused search result index. The focused search result is drawn in a focused color. Calling FOCUSED_SEARCH_RESULT_INDEX_NONE for clearing focused search result. This method must be called after setting search result ranges by setSearchResultHighlights(int[]).

Parameters
index Int: a focused search index or FOCUSED_SEARCH_RESULT_INDEX_NONE

setFontFeatureSettings

Added in API level 21
open fun setFontFeatureSettings(fontFeatureSettings: String?): Unit

Sets font feature settings. The format is the same as the CSS font-feature-settings attribute: https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop

Parameters
fontFeatureSettings String?: font feature settings represented as CSS compatible string This value may be null.

setFontVariationSettings

Added in API level 26
open fun setFontVariationSettings(fontVariationSettings: String?): Boolean

Sets TrueType or OpenType font variation settings. The settings string is constructed from multiple pairs of axis tag and style values. The axis tag must contain four ASCII characters and must be wrapped with single quotes (U+0027) or double quotes (U+0022). Axis strings that are longer or shorter than four characters, or contain characters outside of U+0020..U+007E are invalid. If a specified axis name is not defined in the font, the settings will be ignored.

Examples,

  • Set font width to 150.
    <code>
        TextView textView = (TextView) findViewById(R.id.textView);
        textView.setFontVariationSettings("'wdth' 150");
      </code>
  • Set the font slant to 20 degrees and ask for italic style.
    <code>
        TextView textView = (TextView) findViewById(R.id.textView);
        textView.setFontVariationSettings("'slnt' 20, 'ital' 1");
      </code>

Parameters
fontVariationSettings String?: font variation settings. You can pass null or empty string as no variation settings.
Return
Boolean true if the given settings is effective to at least one font file underlying this TextView. This function also returns true for empty settings string. Otherwise returns false.
Exceptions
java.lang.IllegalArgumentException If given string is not a valid font variation settings format.

setFreezesText

Added in API level 1
open fun setFreezesText(freezesText: Boolean): Unit

Control whether this text view saves its entire text contents when freezing to an icicle, in addition to dynamic state such as cursor position. By default this is false, not saving the text. Set to true if the text in the text view is not being saved somewhere else in persistent storage (such as in a content provider) so that if the view is later thawed the user will not lose their data. For android.widget.EditText it is always enabled, regardless of the value of the attribute.

Parameters
freezesText Boolean: Controls whether a frozen icicle should include the entire text data: true to include it, false to not.

setGravity

Added in API level 1
open fun setGravity(gravity: Int): Unit

Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself.

setHeight

Added in API level 1
open fun setHeight(pixels: Int): Unit

Sets the height of the TextView to be exactly pixels tall.

This value is used for height calculation if LayoutParams does not force TextView to have an exact height. Setting this value overrides previous minimum/maximum height configurations such as setMinHeight(int) or setMaxHeight(int).

Parameters
pixels Int: the exact height of the TextView in terms of pixels

See Also

setHighlightColor

Added in API level 1
open fun setHighlightColor(color: Int): Unit

Sets the color used to display the selection highlight.

setHighlights

Added in API level 34
open fun setHighlights(highlights: Highlights?): Unit

Set Highlights

Parameters
highlights Highlights?: A highlight object. Call with null for reset.

setHint

Added in API level 1
fun setHint(hint: CharSequence!): Unit

Sets the text to be displayed when the text of the TextView is empty. Null means to use the normal empty text. The hint does not currently participate in determining the size of the view.

setHint

Added in API level 1
fun setHint(resid: Int): Unit

Sets the text to be displayed when the text of the TextView is empty, from a resource.

setHintTextColor

Added in API level 1
fun setHintTextColor(color: Int): Unit

Sets the color of the hint text for all the states (disabled, focussed, selected...) of this TextView.

setHintTextColor

Added in API level 1
fun setHintTextColor(colors: ColorStateList!): Unit

Sets the color of the hint text.

setHorizontallyScrolling

Added in API level 1
open fun setHorizontallyScrolling(whether: Boolean): Unit

Sets whether the text should be allowed to be wider than the View is. If false, it will be wrapped to the width of the View.

setHyphenationFrequency

Added in API level 23
open fun setHyphenationFrequency(hyphenationFrequency: Int): Unit

Sets the frequency of automatic hyphenation to use when determining word breaks. The default value for both TextView and EditText is . Note that the default hyphenation frequency value is set from the theme.

Enabling hyphenation with either using Layout#HYPHENATION_FREQUENCY_NORMAL or Layout#HYPHENATION_FREQUENCY_FULL while line breaking is set to one of Layout#BREAK_STRATEGY_BALANCED, Layout#BREAK_STRATEGY_HIGH_QUALITY improves the structure of text layout however has performance impact and requires more time to do the text layout.

Note: Before Android Q, in the theme hyphenation frequency is set to Layout#HYPHENATION_FREQUENCY_NORMAL. The default value is changed into Layout#HYPHENATION_FREQUENCY_NONE on Q.
Parameters
hyphenationFrequency Int: the hyphenation frequency to use, one of Layout#HYPHENATION_FREQUENCY_NONE, Layout#HYPHENATION_FREQUENCY_NORMAL, Layout#HYPHENATION_FREQUENCY_FULL Value is android.text.Layout#HYPHENATION_FREQUENCY_NORMAL, android.text.Layout#HYPHENATION_FREQUENCY_NORMAL_FAST, android.text.Layout#HYPHENATION_FREQUENCY_FULL, android.text.Layout#HYPHENATION_FREQUENCY_FULL_FAST, or android.text.Layout#HYPHENATION_FREQUENCY_NONE

setImeActionLabel

Added in API level 3
open fun setImeActionLabel(
    label: CharSequence!,
    actionId: Int
): Unit

Change the custom IME action associated with the text view, which will be reported to an IME with EditorInfo#actionLabel and EditorInfo#actionId when it has focus.

setImeHintLocales

Added in API level 24
open fun setImeHintLocales(hintLocales: LocaleList?): Unit

Change "hint" locales associated with the text view, which will be reported to an IME with EditorInfo#hintLocales when it has focus. Starting with Android O, this also causes internationalized listeners to be created (or change locale) based on the first locale in the input locale list.

Note: If you want new "hint" to take effect immediately you need to call InputMethodManager#restartInput(View).

Parameters
hintLocales LocaleList?: List of the languages that the user is supposed to switch to no matter what input method subtype is currently used. Set null to clear the current "hint".

setImeOptions

Added in API level 3
open fun setImeOptions(imeOptions: Int): Unit

Change the editor type integer associated with the text view, which is reported to an Input Method Editor (IME) with EditorInfo#imeOptions when it has focus.

setIncludeFontPadding

Added in API level 1
open fun setIncludeFontPadding(includepad: Boolean): Unit

Set whether the TextView includes extra top and bottom padding to make room for accents that go above the normal ascent and descent. The default is true.

setInputExtras

Added in API level 3
open fun setInputExtras(xmlResId: Int): Unit

Set the extra input data of the text, which is the TextBoxAttribute.extras Bundle that will be filled in when creating an input connection. The given integer is the resource identifier of an XML resource holding an <input-extras> XML tree.

setInputType

Added in API level 3
open fun setInputType(type: Int): Unit

Set the type of the content with a constant as defined for EditorInfo#inputType. This will take care of changing the key listener, by calling setKeyListener(android.text.method.KeyListener), to match the given content type. If the given content type is EditorInfo#TYPE_NULL then a soft keyboard will not be displayed for this text view. Note that the maximum number of displayed lines (see setMaxLines(int)) will be modified if you change the EditorInfo#TYPE_TEXT_FLAG_MULTI_LINE flag of the input type.

setKeyListener

Added in API level 1
open fun setKeyListener(input: KeyListener!): Unit

Sets the key listener to be used with this TextView. This can be null to disallow user input. Note that this method has significant and subtle interactions with soft keyboards and other input method: see KeyListener.getInputType() for important details. Calling this method will replace the current content type of the text view with the content type returned by the key listener.

Be warned that if you want a TextView with a key listener or movement method not to be focusable, or if you want a TextView without a key listener or movement method to be focusable, you must call #setFocusable again after calling this to get the focusability back the way you want it.

setLastBaselineToBottomHeight

Added in API level 28
open fun setLastBaselineToBottomHeight(lastBaselineToBottomHeight: Int): Unit

Updates the bottom padding of the TextView so that is the distance between the bottom of the TextView and the last line's baseline.

First and last baseline metrics for a TextView. Note that if FontMetrics.bottom or FontMetrics.descent was already greater than lastBaselineToBottomHeight, the bottom padding is not updated. Moreover since this function sets the bottom padding, if the height of the TextView is less than the sum of top padding, line height and bottom padding, bottom of the text will be clipped.
Parameters
lastBaselineToBottomHeight Int: distance between last baseline to bottom of the container in pixels The units of this value are pixels. Value is 0 or greater

setLetterSpacing

Added in API level 21
open fun setLetterSpacing(letterSpacing: Float): Unit

Sets text letter-spacing in em units. Typical values for slight expansion will be around 0.05. Negative values tighten text.

Parameters
letterSpacing Float: A text letter-space value in ems.

setLineBreakStyle

Added in API level 33
open fun setLineBreakStyle(lineBreakStyle: Int): Unit

Sets the line-break style for text wrapping.

Line-break style specifies the line-break strategies that can be used for text wrapping. The line-break style affects rule-based line breaking by specifying the strictness of line-breaking rules.

The following are types of line-break styles:

The default line-break style is LineBreakConfig#LINE_BREAK_STYLE_NONE, which specifies that no line-breaking rules are used.

See the line-break property for more information.

Parameters
lineBreakStyle Int: The line-break style for the text. Value is android.graphics.text.LineBreakConfig#LINE_BREAK_STYLE_NONE, android.graphics.text.LineBreakConfig#LINE_BREAK_STYLE_LOOSE, android.graphics.text.LineBreakConfig#LINE_BREAK_STYLE_NORMAL, android.graphics.text.LineBreakConfig#LINE_BREAK_STYLE_STRICT, android.graphics.text.LineBreakConfig#LINE_BREAK_STYLE_UNSPECIFIED, android.graphics.text.LineBreakConfig#LINE_BREAK_STYLE_NO_BREAK, or android.graphics.text.LineBreakConfig#LINE_BREAK_STYLE_AUTO

setLineBreakWordStyle

Added in API level 33
open fun setLineBreakWordStyle(lineBreakWordStyle: Int): Unit

Sets the line-break word style for text wrapping.

The line-break word style affects dictionary-based line breaking by providing phrase-based line-breaking opportunities. Use LineBreakConfig#LINE_BREAK_WORD_STYLE_PHRASE to specify phrase-based line breaking.

The default line-break word style is LineBreakConfig#LINE_BREAK_WORD_STYLE_NONE, which specifies that no line-breaking word style is used.

See the word-break property for more information.

Parameters
lineBreakWordStyle Int: The line-break word style for the text. Value is android.graphics.text.LineBreakConfig#LINE_BREAK_WORD_STYLE_NONE, android.graphics.text.LineBreakConfig#LINE_BREAK_WORD_STYLE_PHRASE, android.graphics.text.LineBreakConfig#LINE_BREAK_WORD_STYLE_UNSPECIFIED, or android.graphics.text.LineBreakConfig#LINE_BREAK_WORD_STYLE_AUTO

setLineHeight

Added in API level 28
open fun setLineHeight(lineHeight: Int): Unit

Sets an explicit line height for this TextView. This is equivalent to the vertical distance between subsequent baselines in the TextView.

Parameters
lineHeight Int: the line height in pixels The units of this value are pixels. Value is 0 or greater

setLineHeight

Added in API level 34
open fun setLineHeight(
    unit: Int,
    lineHeight: Float
): Unit

Sets an explicit line height to a given unit and value for this TextView. This is equivalent to the vertical distance between subsequent baselines in the TextView. See TypedValue for the possible dimension units.

Parameters
unit Int: The desired dimension unit. SP units are strongly recommended so that line height stays proportional to the text size when fonts are scaled up for accessibility. Value is android.util.TypedValue#COMPLEX_UNIT_PX, android.util.TypedValue#COMPLEX_UNIT_DIP, android.util.TypedValue#COMPLEX_UNIT_SP, android.util.TypedValue#COMPLEX_UNIT_PT, android.util.TypedValue#COMPLEX_UNIT_IN, or android.util.TypedValue#COMPLEX_UNIT_MM
lineHeight Float: The desired line height in the given units. Value is 0 or greater

setLineSpacing

Added in API level 1
open fun setLineSpacing(
    add: Float,
    mult: Float
): Unit

Sets line spacing for this TextView. Each line other than the last line will have its height multiplied by mult and have add added to it.

Parameters
add Float: The value in pixels that should be added to each line other than the last line. This will be applied after the multiplier
mult Float: The value by which each line height other than the last line will be multiplied by

setLines

Added in API level 1
open fun setLines(lines: Int): Unit

Sets the height of the TextView to be exactly lines tall.

This value is used for height calculation if LayoutParams does not force TextView to have an exact height. Setting this value overrides previous minimum/maximum height configurations such as setMinLines(int) or setMaxLines(int). setSingleLine() will set this value to 1.

Parameters
lines Int: the exact height of the TextView in terms of lines

See Also

setLinkTextColor

Added in API level 1
fun setLinkTextColor(color: Int): Unit

Sets the color of links in the text.

setLinkTextColor

Added in API level 1
fun setLinkTextColor(colors: ColorStateList!): Unit

Sets the color of links in the text.

setLinksClickable

Added in API level 1
fun setLinksClickable(whether: Boolean): Unit

Sets whether the movement method will automatically be set to LinkMovementMethod if setAutoLinkMask has been set to nonzero and links are detected in #setText. The default is true.

setLocalePreferredLineHeightForMinimumUsed

Added in API level 35
open fun setLocalePreferredLineHeightForMinimumUsed(flag: Boolean): Unit

Set true if the locale preferred line height is used for the minimum line height. By setting this flag to true is equivalenet to call setMinimumFontMetrics(android.graphics.Paint.FontMetrics) with the one obtained by Paint#getFontMetricsForLocale(Paint.FontMetrics). If custom minimum line height was specified by setMinimumFontMetrics(android.graphics.Paint.FontMetrics), this flag will be ignored.

Parameters
flag Boolean: true for using locale preferred line height for the minimum line height.

setMarqueeRepeatLimit

Added in API level 2
open fun setMarqueeRepeatLimit(marqueeLimit: Int): Unit

Sets how many times to repeat the marquee animation. Only applied if the TextView has marquee enabled. Set to -1 to repeat indefinitely.

setMaxEms

Added in API level 1
open fun setMaxEms(maxEms: Int): Unit

Sets the width of the TextView to be at most maxEms wide.

This value is used for width calculation if LayoutParams does not force TextView to have an exact width. Setting this value overrides previous maximum width configurations such as setMaxWidth(int) or setWidth(int).

Parameters
maxEms Int: the maximum width of TextView in terms of ems

setMaxHeight

Added in API level 1
open fun setMaxHeight(maxPixels: Int): Unit

Sets the height of the TextView to be at most maxPixels tall.

This value is used for height calculation if LayoutParams does not force TextView to have an exact height. Setting this value overrides previous maximum height configurations such as setMaxLines(int) or setLines(int).

Parameters
maxPixels Int: the maximum height of TextView in terms of pixels

setMaxLines

Added in API level 1
open fun setMaxLines(maxLines: Int): Unit

Sets the height of the TextView to be at most maxLines tall.

This value is used for height calculation if LayoutParams does not force TextView to have an exact height. Setting this value overrides previous maximum height configurations such as setMaxHeight(int) or setLines(int).

Parameters
maxLines Int: the maximum height of TextView in terms of number of lines

setMaxWidth

Added in API level 1
open fun setMaxWidth(maxPixels: Int): Unit

Sets the width of the TextView to be at most maxPixels wide.

This value is used for width calculation if LayoutParams does not force TextView to have an exact width. Setting this value overrides previous maximum width configurations such as setMaxEms(int) or setEms(int).

Parameters
maxPixels Int: the maximum width of TextView in terms of pixels

setMinEms

Added in API level 1
open fun setMinEms(minEms: Int): Unit

Sets the width of the TextView to be at least minEms wide.

This value is used for width calculation if LayoutParams does not force TextView to have an exact width. Setting this value overrides previous minimum width configurations such as setMinWidth(int) or setWidth(int).

Parameters
minEms Int: the minimum width of TextView in terms of ems

setMinHeight

Added in API level 1
open fun setMinHeight(minPixels: Int): Unit

Sets the height of the TextView to be at least minPixels tall.

This value is used for height calculation if LayoutParams does not force TextView to have an exact height. Setting this value overrides previous minimum height configurations such as setMinLines(int) or setLines(int).

The value given here is different than setMinimumHeight(int). Between minHeight and the value set in setMinimumHeight(int), the greater one is used to decide the final height.

Parameters
minPixels Int: the minimum height of TextView in terms of pixels

setMinLines

Added in API level 1
open fun setMinLines(minLines: Int): Unit

Sets the height of the TextView to be at least minLines tall.

This value is used for height calculation if LayoutParams does not force TextView to have an exact height. Setting this value overrides other previous minimum height configurations such as setMinHeight(int) or setHeight(int). setSingleLine() will set this value to 1.

Parameters
minLines Int: the minimum height of TextView in terms of number of lines

setMinWidth

Added in API level 1
open fun setMinWidth(minPixels: Int): Unit

Sets the width of the TextView to be at least minPixels wide.

This value is used for width calculation if LayoutParams does not force TextView to have an exact width. Setting this value overrides previous minimum width configurations such as setMinEms(int) or setEms(int).

The value given here is different than setMinimumWidth(int). Between minWidth and the value set in setMinimumWidth(int), the greater one is used to decide the final width.

Parameters
minPixels Int: the minimum width of TextView in terms of pixels

setMinimumFontMetrics

Added in API level 35
open fun setMinimumFontMetrics(minimumFontMetrics: Paint.FontMetrics?): Unit

Set the minimum font metrics used for line spacing.

null is the default value. If null is set or left as default, the font metrics obtained by Paint#getFontMetricsForLocale(Paint.FontMetrics) is used.

The minimum meaning here is the minimum value of line spacing: maximum value of Paint#ascent(), minimum value of Paint#descent().

By setting this value, each line will have minimum line spacing regardless of the text rendered. For example, usually Japanese script has larger vertical metrics than Latin script. By setting the metrics obtained by Paint#getFontMetricsForLocale(Paint.FontMetrics) for Japanese or leave it null if the TextView's locale or system locale is Japanese, the line spacing for Japanese is reserved if the TextView contains English text. If the vertical metrics of the text is larger than Japanese, for example Burmese, the bigger font metrics is used.

Parameters
minimumFontMetrics Paint.FontMetrics?: A minimum font metrics. Passing null for using the value obtained by Paint#getFontMetricsForLocale(Paint.FontMetrics)

setMovementMethod

Added in API level 1
fun setMovementMethod(movement: MovementMethod!): Unit

Sets the android.text.method.MovementMethod for handling arrow key movement for this TextView. This can be null to disallow using the arrow keys to move the cursor or scroll the view.

Be warned that if you want a TextView with a key listener or movement method not to be focusable, or if you want a TextView without a key listener or movement method to be focusable, you must call #setFocusable again after calling this to get the focusability back the way you want it.

setOnEditorActionListener

Added in API level 3
open fun setOnEditorActionListener(l: TextView.OnEditorActionListener!): Unit

Set a special listener to be called when an action is performed on the text view. This will be called when the enter key is pressed, or when an action supplied to the IME is selected by the user. Setting this means that the normal hard key event will not insert a newline into the text view, even if it is multi-line; holding down the ALT modifier will, however, allow the user to insert a newline character.

setPadding

Added in API level 1
open fun setPadding(
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Unit
Parameters
left Int: the left padding in pixels
top Int: the top padding in pixels
right Int: the right padding in pixels
bottom Int: the bottom padding in pixels

setPaddingRelative

Added in API level 16
open fun setPaddingRelative(
    start: Int,
    top: Int,
    end: Int,
    bottom: Int
): Unit
Parameters
start Int: the start padding in pixels
top Int: the top padding in pixels
end Int: the end padding in pixels
bottom Int: the bottom padding in pixels

setPaintFlags

Added in API level 1
open fun setPaintFlags(flags: Int): Unit

Sets flags on the Paint being used to display the text and reflows the text if they are different from the old flags.

setPrivateImeOptions

Added in API level 3
open fun setPrivateImeOptions(type: String!): Unit

Set the private content type of the text, which is the EditorInfo.privateImeOptions field that will be filled in when creating an input connection.

setRawInputType

Added in API level 3
open fun setRawInputType(type: Int): Unit

Directly change the content type integer of the text view, without modifying any other state.

setScroller

Added in API level 1
open fun setScroller(s: Scroller!): Unit

Sets the Scroller used for producing a scrolling animation

Parameters
s Scroller!: A Scroller instance

setSearchResultHighlightColor

Added in API level 34
open fun setSearchResultHighlightColor(color: Int): Unit

Sets the search result highlight color.

Parameters
color Int: a search result highlight color.

setSearchResultHighlights

Added in API level 34
open fun setSearchResultHighlights(vararg ranges: Int): Unit

Sets the search result ranges with flatten range representation. Ranges are represented of flattened inclusive start and exclusive end integers array. The inclusive start offset of the i-th range is stored in 2 * i-th of the array. The exclusive end offset of the i-th range is stored in 2* i + 1-th of the array. For example, the two ranges: (1, 2) and (3, 4) are flattened into single int array [1, 2, 3, 4]. TextView will render the search result with the highlights with specified color in the theme. If there is a focused search result, it is rendered with focused color. By calling this method, the focused search index will be cleared.

Parameters
ranges Int: the flatten ranges of the search result. null for clear.

setSelectAllOnFocus

Added in API level 1
open fun setSelectAllOnFocus(selectAllOnFocus: Boolean): Unit

Set the TextView so that when it takes focus, all the text is selected.

setSelected

Added in API level 1
open fun setSelected(selected: Boolean): Unit
Parameters
selected Boolean: true if the view must be selected, false otherwise

setShadowLayer

Added in API level 1
open fun setShadowLayer(
    radius: Float,
    dx: Float,
    dy: Float,
    color: Int
): Unit

Gives the text a shadow of the specified blur radius and color, the specified distance from its drawn position.

The text shadow produced does not interact with the properties on view that are responsible for real time shadows, elevation and translationZ.

setShiftDrawingOffsetForStartOverhang

Added in API level 35
open fun setShiftDrawingOffsetForStartOverhang(shiftDrawingOffsetForStartOverhang: Boolean): Unit

Set true for shifting the drawing x offset for showing overhang at the start position. This flag is ignored if the getUseBoundsForWidth() is false. If this value is false, the TextView draws text from the zero even if there is a glyph stroke in a region where the x coordinate is negative. TextView clips the stroke in the region where the X coordinate is negative unless the parents has ViewGroup#getClipChildren() to true. This is useful for aligning multiple TextViews vertically. If this value is true, the TextView draws text with shifting the x coordinate of the drawing bounding box. This prevents the clipping even if the parents doesn't have ViewGroup#getClipChildren() to true. This value is false by default.

Parameters
shiftDrawingOffsetForStartOverhang Boolean: true for shifting the drawing offset for showing the stroke that is in the region whre the x coorinate is negative.

setShowSoftInputOnFocus

Added in API level 21
fun setShowSoftInputOnFocus(show: Boolean): Unit

Sets whether the soft input method will be made visible when this TextView gets focused. The default is true.

setSingleLine

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

Sets the properties of this field (lines, horizontally scrolling, transformation method) to be for a single-line input.

setSingleLine

Added in API level 1
open fun setSingleLine(singleLine: Boolean): Unit

If true, sets the properties of this field (number of lines, horizontally scrolling, transformation method) to be for a single-line input; if false, restores these to the default conditions. Note that the default conditions are not necessarily those that were in effect prior this method, and you may want to reset these properties to your custom values. Note that due to performance reasons, by setting single line for the EditText, the maximum text length is set to 5000 if no other character limitation are applied.

setSpannableFactory

Added in API level 1
fun setSpannableFactory(factory: Spannable.Factory!): Unit

Sets the Factory used to create new Spannables.

Parameters
factory Spannable.Factory!: Spannable.Factory to be used

setText

Added in API level 1
fun setText(text: CharSequence!): Unit

Sets the text to be displayed. TextView does not accept HTML-like formatting, which you can do with text strings in XML resource files. To style your strings, attach android.text.style.* objects to a android.text.SpannableString, or see the Available Resource Types documentation for an example of setting formatted text in the XML resource file.

When required, TextView will use android.text.Spannable.Factory to create final or intermediate Spannables. Likewise it will use android.text.Editable.Factory to create final or intermediate Editables. If the passed text is a PrecomputedText but the parameters used to create the PrecomputedText mismatches with this TextView, IllegalArgumentException is thrown. To ensure the parameters match, you can call TextView#setTextMetricsParams before calling this.
Parameters
text CharSequence!: text to be displayed
Exceptions
java.lang.IllegalArgumentException if the passed text is a PrecomputedText but the parameters used to create the PrecomputedText mismatches with this TextView.

setText

Added in API level 1
open fun setText(
    text: CharSequence!,
    type: TextView.BufferType!
): Unit

Sets the text to be displayed and the android.widget.TextView.BufferType.

When required, TextView will use android.text.Spannable.Factory to create final or intermediate Spannables. Likewise it will use android.text.Editable.Factory to create final or intermediate Editables. Subclasses overriding this method should ensure that the following post condition holds, in order to guarantee the safety of the view's measurement and layout operations: regardless of the input, after calling #setText both mText and mTransformed will be different from null.
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

setText

Added in API level 1
fun setText(
    text: CharArray,
    start: Int,
    len: Int
): Unit

Sets the TextView to display the specified slice of the specified char array. You must promise that you will not change the contents of the array except for right before another call to setText(), since the TextView has no way to know that the text has changed and that it needs to invalidate and re-layout.

Parameters
text CharArray: char array to be displayed This value cannot be null.
start Int: start index in the char array
len Int: length of char count after start
Exceptions
java.lang.NullPointerException if text is null
java.lang.IndexOutOfBoundsException if start or start+len are not in 0 to text.length

setText

Added in API level 1
fun setText(resid: Int): Unit

Sets the text to be displayed using a string resource identifier.

Parameters
resid Int: the resource identifier of the string resource to be displayed

setText

Added in API level 1
fun setText(
    resid: Int,
    type: TextView.BufferType!
): Unit

Sets the text to be displayed using a string resource identifier and the android.widget.TextView.BufferType.

When required, TextView will use android.text.Spannable.Factory to create final or intermediate Spannables. Likewise it will use android.text.Editable.Factory to create final or intermediate Editables.
Parameters
resid Int: the resource identifier of the string resource 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

setTextAppearance

Added in API level 23
open fun setTextAppearance(resId: Int): Unit

Sets the text appearance from the specified style resource.

Use a framework-defined TextAppearance style like @android:style/TextAppearance.Material.Body1 or see TextAppearance for the set of attributes that can be used in a custom style.

Parameters
resId Int: the resource identifier of the style to apply

setTextAppearance

Added in API level 1
Deprecated in API level 23
open fun setTextAppearance(
    context: Context!,
    resId: Int
): Unit

Deprecated: Use setTextAppearance(int) instead.

Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.

setTextClassifier

Added in API level 26
open fun setTextClassifier(textClassifier: TextClassifier?): Unit

Sets the TextClassifier for this TextView.

Parameters
textClassifier TextClassifier?: This value may be null.

setTextColor

Added in API level 1
open fun setTextColor(color: Int): Unit

Sets the text color for all the states (normal, selected, focused) to be this color.

Parameters
color Int: A color value in the form 0xAARRGGBB. Do not pass a resource ID. To get a color value from a resource ID, call androidx.core.content.ContextCompat#getColor(Context, int).

setTextColor

Added in API level 1
open fun setTextColor(colors: ColorStateList!): Unit

Sets the text color.

setTextCursorDrawable

Added in API level 29
open fun setTextCursorDrawable(textCursorDrawable: Drawable?): Unit

Sets the Drawable corresponding to the text cursor. The Drawable defaults to the value of the textCursorDrawable attribute. Note that any change applied to the cursor Drawable will not be visible until the cursor is hidden and then drawn again.

Parameters
textCursorDrawable Drawable?: This value may be null.

setTextCursorDrawable

Added in API level 29
open fun setTextCursorDrawable(textCursorDrawable: Int): Unit

Sets the Drawable corresponding to the text cursor. The Drawable defaults to the value of the textCursorDrawable attribute. Note that any change applied to the cursor Drawable will not be visible until the cursor is hidden and then drawn again.

setTextIsSelectable

Added in API level 11
open fun setTextIsSelectable(selectable: Boolean): Unit

Sets whether the content of this view is selectable by the user. The default is false, meaning that the content is not selectable.

When you use a TextView to display a useful piece of information to the user (such as a contact's address), make it selectable, so that the user can select and copy its content. You can also use set the XML attribute android.R.styleable#TextView_textIsSelectable to "true".

When you call this method to set the value of textIsSelectable, it sets the flags focusable, focusableInTouchMode, clickable, and longClickable to the same value. These flags correspond to the attributes android:focusable, android:focusableInTouchMode, android:clickable, and android:longClickable. To restore any of these flags to a state you had set previously, call one or more of the following methods: setFocusable(), setFocusableInTouchMode(), setClickable() or setLongClickable().

Parameters
selectable Boolean: Whether the content of this TextView should be selectable.

setTextKeepState

Added in API level 1
fun setTextKeepState(text: CharSequence!): Unit

Sets the text to be displayed but retains the cursor position. Same as setText(java.lang.CharSequence) except that the cursor position (if any) is retained in the new text.

When required, TextView will use android.text.Spannable.Factory to create final or intermediate Spannables. Likewise it will use android.text.Editable.Factory to create final or intermediate Editables.
Parameters
text CharSequence!: text to be displayed

setTextKeepState

Added in API level 1
fun setTextKeepState(
    text: CharSequence!,
    type: TextView.BufferType!
): Unit

Sets the text to be displayed and the android.widget.TextView.BufferType but retains the cursor position. Same as setText(java.lang.CharSequence,android.widget.TextView.BufferType) except that the cursor position (if any) is retained in the new text.

When required, TextView will use android.text.Spannable.Factory to create final or intermediate Spannables. Likewise it will use android.text.Editable.Factory to create final or intermediate Editables.
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

setTextLocale

Added in API level 17
open fun setTextLocale(locale: Locale): Unit

Set the default Locale of the text in this TextView to a one-member LocaleList containing just the given Locale.

Parameters
locale Locale: the Locale for drawing text, must not be null.

See Also

setTextLocales

Added in API level 24
open fun setTextLocales(locales: LocaleList): Unit

Set the default LocaleList of the text in this TextView to the given value. This value is used to choose appropriate typefaces for ambiguous characters (typically used for CJK locales to disambiguate Hanzi/Kanji/Hanja characters). It also affects other aspects of text display, including line breaking.

Parameters
locales LocaleList: the LocaleList for drawing text, must not be null or empty.

setTextMetricsParams

Added in API level 28
open fun setTextMetricsParams(params: PrecomputedText.Params): Unit

Apply the text layout parameter. Update the TextView parameters to be compatible with PrecomputedText.Params.

Parameters
params PrecomputedText.Params: This value cannot be null.

setTextScaleX

Added in API level 1
open fun setTextScaleX(size: Float): Unit

Sets the horizontal scale factor for text. The default value is 1.0. Values greater than 1.0 stretch the text wider. Values less than 1.0 make the text narrower. By default, this value is 1.0.

Parameters
size Float: The horizontal scale factor.

setTextSelectHandle

Added in API level 29
open fun setTextSelectHandle(textSelectHandle: Drawable): Unit

Sets the Drawable corresponding to the selection handle used for positioning the cursor within text. The Drawable defaults to the value of the textSelectHandle attribute. Note that any change applied to the handle Drawable will not be visible until the handle is hidden and then drawn again.

Parameters
textSelectHandle Drawable: This value cannot be null.

setTextSelectHandle

Added in API level 29
open fun setTextSelectHandle(textSelectHandle: Int): Unit

Sets the Drawable corresponding to the selection handle used for positioning the cursor within text. The Drawable defaults to the value of the textSelectHandle attribute. Note that any change applied to the handle Drawable will not be visible until the handle is hidden and then drawn again.

setTextSelectHandleLeft

Added in API level 29
open fun setTextSelectHandleLeft(textSelectHandleLeft: Drawable): Unit

Sets the Drawable corresponding to the left handle used for selecting text. The Drawable defaults to the value of the textSelectHandleLeft attribute. Note that any change applied to the handle Drawable will not be visible until the handle is hidden and then drawn again.

Parameters
textSelectHandleLeft Drawable: This value cannot be null.

setTextSelectHandleLeft

Added in API level 29
open fun setTextSelectHandleLeft(textSelectHandleLeft: Int): Unit

Sets the Drawable corresponding to the left handle used for selecting text. The Drawable defaults to the value of the textSelectHandleLeft attribute. Note that any change applied to the handle Drawable will not be visible until the handle is hidden and then drawn again.

setTextSelectHandleRight

Added in API level 29
open fun setTextSelectHandleRight(textSelectHandleRight: Drawable): Unit

Sets the Drawable corresponding to the right handle used for selecting text. The Drawable defaults to the value of the textSelectHandleRight attribute. Note that any change applied to the handle Drawable will not be visible until the handle is hidden and then drawn again.

Parameters
textSelectHandleRight Drawable: This value cannot be null.

setTextSelectHandleRight

Added in API level 29
open fun setTextSelectHandleRight(textSelectHandleRight: Int): Unit

Sets the Drawable corresponding to the right handle used for selecting text. The Drawable defaults to the value of the textSelectHandleRight attribute. Note that any change applied to the handle Drawable will not be visible until the handle is hidden and then drawn again.

setTextSize

Added in API level 1
open fun setTextSize(size: Float): Unit

Set the default text size to the given value, interpreted as "scaled pixel" units. This size is adjusted based on the current density and user font size preference.

Note: if this TextView has the auto-size feature enabled, then this function is no-op.

Parameters
size Float: The scaled pixel size.

setTextSize

Added in API level 1
open fun setTextSize(
    unit: Int,
    size: Float
): Unit

Set the default text size to a given unit and value. See TypedValue for the possible dimension units.

Note: if this TextView has the auto-size feature enabled, then this function is no-op.

Parameters
unit Int: The desired dimension unit.
size Float: The desired size in the given units.

setTransformationMethod

Added in API level 1
fun setTransformationMethod(method: TransformationMethod!): Unit

Sets the transformation that is applied to the text that this TextView is displaying.

setTypeface

Added in API level 1
open fun setTypeface(
    tf: Typeface?,
    style: Int
): Unit

Sets the typeface and style in which the text should be displayed, and turns on the fake bold and italic bits in the Paint if the Typeface that you provided does not have all the bits in the style that you specified.

Parameters
tf Typeface?: This value may be null.
style Int: Value is android.graphics.Typeface#NORMAL, android.graphics.Typeface#BOLD, android.graphics.Typeface#ITALIC, or android.graphics.Typeface#BOLD_ITALIC

setTypeface

Added in API level 1
open fun setTypeface(tf: Typeface?): Unit

Sets the typeface and style in which the text should be displayed. Note that not all Typeface families actually have bold and italic variants, so you may need to use setTypeface(android.graphics.Typeface,int) to get the appearance that you actually want.

Parameters
tf Typeface?: This value may be null.

See Also

setUseBoundsForWidth

Added in API level 35
open fun setUseBoundsForWidth(useBoundsForWidth: Boolean): Unit

Set true for using width of bounding box as a source of automatic line breaking and drawing. If this value is false, the TextView determines the View width, drawing offset and automatic line breaking based on total advances as text widths. By setting true, use glyph bound's as a source of text width. If the font used for this TextView has glyphs that has negative bearing X or glyph xMax is greater than advance, the glyph clipping can be happened because the drawing area may be bigger than advance. By setting this to true, the TextView will reserve more spaces for drawing are, so clipping can be prevented. This value is true by default if the target API version is 35 or later.

Parameters
useBoundsForWidth Boolean: true for using bounding box for width. false for using advances for width.

setWidth

Added in API level 1
open fun setWidth(pixels: Int): Unit

Sets the width of the TextView to be exactly pixels wide.

This value is used for width calculation if LayoutParams does not force TextView to have an exact width. Setting this value overrides previous minimum/maximum width configurations such as setMinWidth(int) or setMaxWidth(int).

Parameters
pixels Int: the exact width of the TextView in terms of pixels

See Also

showContextMenu

Added in API level 1
open fun showContextMenu(): Boolean
Return
Boolean true if the context menu was shown, false otherwise

showContextMenu

Added in API level 24
open fun showContextMenu(
    x: Float,
    y: Float
): Boolean
Parameters
x Float: the X coordinate in pixels relative to the view to which the menu should be anchored, or Float#NaN to disable anchoring
y Float: the Y coordinate in pixels relative to the view to which the menu should be anchored, or Float#NaN to disable anchoring
Return
Boolean true if the context menu was shown, false otherwise

Protected methods

computeHorizontalScrollRange

Added in API level 1
protected open fun computeHorizontalScrollRange(): Int
Return
Int the total horizontal range represented by the horizontal scrollbar

computeVerticalScrollExtent

Added in API level 1
protected open fun computeVerticalScrollExtent(): Int
Return
Int the vertical extent of the scrollbar's thumb

computeVerticalScrollRange

Added in API level 1
protected open fun computeVerticalScrollRange(): Int
Return
Int the total vertical range represented by the vertical scrollbar

The default range is the drawing height of this view.

drawableStateChanged

Added in API level 1
protected open fun drawableStateChanged(): Unit

getBottomPaddingOffset

Added in API level 2
protected open fun getBottomPaddingOffset(): Int
Return
Int The bottom padding offset in pixels.

getDefaultEditable

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

Subclasses override this to specify that they have a KeyListener by default even if not specifically called for in the XML options.

getDefaultMovementMethod

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

Subclasses override this to specify a default movement method.

getLeftFadingEdgeStrength

Added in API level 1
protected open fun getLeftFadingEdgeStrength(): Float
Return
Float the intensity of the left fade as a float between 0.0f and 1.0f

getLeftPaddingOffset

Added in API level 2
protected open fun getLeftPaddingOffset(): Int
Return
Int The left padding offset in pixels.

getRightFadingEdgeStrength

Added in API level 1
protected open fun getRightFadingEdgeStrength(): Float
Return
Float the intensity of the right fade as a float between 0.0f and 1.0f

getRightPaddingOffset

Added in API level 2
protected open fun getRightPaddingOffset(): Int
Return
Int The right padding offset in pixels.

getTopPaddingOffset

Added in API level 2
protected open fun getTopPaddingOffset(): Int
Return
Int The top padding offset in pixels.

isPaddingOffsetRequired

Added in API level 2
protected open fun isPaddingOffsetRequired(): Boolean
Return
Boolean True if padding offset must be applied, false otherwise.

onAttachedToWindow

Added in API level 1
protected open fun onAttachedToWindow(): Unit

onConfigurationChanged

Added in API level 8
protected open fun onConfigurationChanged(newConfig: Configuration!): Unit
Parameters
newConfig Configuration!: The new resource configuration.

onCreateContextMenu

Added in API level 1
protected open fun onCreateContextMenu(menu: ContextMenu!): Unit
Parameters
menu ContextMenu!: the context menu to populate

onCreateDrawableState

Added in API level 1
protected open fun onCreateDrawableState(extraSpace: Int): IntArray!
Parameters
extraSpace Int: if non-zero, this is the number of extra entries you would like in the returned array in which you can place your own states.
Return
IntArray! Returns an array holding the current Drawable state of the view.

onDraw

Added in API level 1
protected open fun onDraw(canvas: Canvas): Unit
Parameters
canvas Canvas: the canvas on which the background will be drawn This value cannot be null.

onFocusChanged

Added in API level 1
protected open fun onFocusChanged(
    focused: Boolean,
    direction: Int,
    previouslyFocusedRect: Rect?
): Unit
Parameters
gainFocus True if the View has focus; false otherwise.
direction Int: The direction focus has moved when requestFocus() is called to give this view focus. Values are FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, or FOCUS_BACKWARD. It may not always apply, in which case use the default. Value is android.view.View#FOCUS_BACKWARD, android.view.View#FOCUS_FORWARD, android.view.View#FOCUS_LEFT, android.view.View#FOCUS_UP, android.view.View#FOCUS_RIGHT, or android.view.View#FOCUS_DOWN
previouslyFocusedRect Rect?: The rectangle, in this view's coordinate system, of the previously focused view. If applicable, this will be passed in as finer grained information about where the focus is coming from (in addition to direction). Will be null otherwise.

onLayout

Added in API level 1
protected open fun onLayout(
    changed: Boolean,
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Unit
Parameters
changed Boolean: This is a new size or position for this view
left Int: Left position, relative to parent
top Int: Top position, relative to parent
right Int: Right position, relative to parent
bottom Int: Bottom position, relative to parent

onMeasure

Added in API level 1
protected open fun onMeasure(
    widthMeasureSpec: Int,
    heightMeasureSpec: Int
): Unit
Parameters
widthMeasureSpec Int: horizontal space requirements as imposed by the parent. The requirements are encoded with android.view.View.MeasureSpec.
heightMeasureSpec Int: vertical space requirements as imposed by the parent. The requirements are encoded with android.view.View.MeasureSpec.

onScrollChanged

Added in API level 1
protected open fun onScrollChanged(
    horiz: Int,
    vert: Int,
    oldHoriz: Int,
    oldVert: Int
): Unit
Parameters
l Current horizontal scroll origin.
t Current vertical scroll origin.
oldl Previous horizontal scroll origin.
oldt Previous vertical scroll origin.

onSelectionChanged

Added in API level 3
protected open fun onSelectionChanged(
    selStart: Int,
    selEnd: Int
): Unit

This method is called when the selection has changed, in case any subclasses would like to know.

Note: Always call the super implementation, which informs the accessibility subsystem about the selection change.


If you override this method you must call through to the superclass implementation.
Parameters
selStart Int: The new selection start location.
selEnd Int: The new selection end location.

onTextChanged

Added in API level 1
protected open fun onTextChanged(
    text: CharSequence!,
    start: Int,
    lengthBefore: Int,
    lengthAfter: Int
): Unit

This method is called when the text is changed, in case any subclasses would like to know. Within text, the lengthAfter characters beginning at start have just replaced old text that had length lengthBefore. It is an error to attempt to make changes to text from this callback.

Parameters
text CharSequence!: The text the TextView is displaying
start Int: The offset of the start of the range of the text that was modified
lengthBefore Int: The length of the former text that has been replaced
lengthAfter Int: The length of the replacement modified text

onVisibilityChanged

Added in API level 8
protected open fun onVisibilityChanged(
    changedView: View,
    visibility: Int
): Unit
Parameters
changedView View: The view whose visibility changed. May be this or an ancestor view. This value cannot be null.
visibility Int: The new visibility, one of VISIBLE, INVISIBLE or GONE. Value is android.view.View#VISIBLE, android.view.View#INVISIBLE, or android.view.View#GONE

setFrame

Added in API level 1
protected open fun setFrame(
    l: Int,
    t: Int,
    r: Int,
    b: Int
): Boolean

verifyDrawable

Added in API level 1
protected open fun verifyDrawable(who: Drawable): Boolean

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. This allows animations for those drawables to be scheduled.

Be sure to call through to the super class when overriding this function.
If you override this method you must call through to the superclass implementation.

Parameters
who Drawable: This value cannot be null.
Return
Boolean boolean If true then the Drawable is being displayed in the view; else false and it is not allowed to animate.