Java android.widget TextView fields, constructors, methods, implement or subclass

Example usage for Java android.widget TextView fields, constructors, methods, implement or subclass

Introduction

In this page you can find the methods, fields and constructors for android.widget TextView.

The text is from its open source code.

Subclass

android.widget.TextView has subclasses.
Click this link to see all its subclasses.

Constructor

Method

voidaddTextChangedListener(TextWatcher watcher)
Adds a TextWatcher to the list of those whose methods are called whenever this TextView's text changes.
ViewPropertyAnimatoranimate()
This method returns a ViewPropertyAnimator object, which can be used to animate specific properties on this View.
voidannounceForAccessibility(CharSequence text)
Convenience method for sending a AccessibilityEvent#TYPE_ANNOUNCEMENT AccessibilityEvent to make an announcement which is related to some sort of a context change for which none of the events representing UI transitions is a good fit.
voidappend(CharSequence text)
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.
voidbringToFront()
Change the view's z order in the tree, so it's on top of other sibling views.
voidbuildDrawingCache()

Calling this method is equivalent to calling buildDrawingCache(false).

voidbuildDrawingCache(boolean autoScale)

Forces the drawing cache to be built if the drawing cache is invalid.

If you call #buildDrawingCache() manually without calling #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true) , you should cleanup the cache by calling #destroyDrawingCache() afterwards.

Note about auto scaling in compatibility mode: When auto scaling is not enabled, this method will create a bitmap of the same size as this view.

voidclearAnimation()
Cancels any animations for this view.
voidclearFocus()
Called when this view wants to give up focus.
voiddestroyDrawingCache()

Frees the resources used by the drawing cache.

voiddraw(Canvas canvas)
Manually render this view (and all of its children) to the given Canvas.
booleanequals(Object obj)
Indicates whether some other object is "equal to" this one.
TfindViewById(@IdRes int id)
Finds the first descendant view with the given ID, the view itself if the ID matches #getId() , or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.
ViewfocusSearch(@FocusRealDirection int direction)
Find the nearest view in the specified direction that can take focus.
floatgetAlpha()
The opacity of the view.
DrawablegetBackground()
Gets the background drawable
intgetBaseline()
intgetBottom()
Bottom position of this view relative to its parent.
ClassgetClass()
Returns the runtime class of this Object .
intgetCompoundDrawablePadding()
Returns the padding between the compound drawables and the text.
Drawable[]getCompoundDrawables()
Returns drawables for the left, top, right, and bottom borders.
Drawable[]getCompoundDrawablesRelative()
Returns drawables for the start, top, end, and bottom borders.
intgetCompoundPaddingBottom()
Returns the bottom padding of the view, plus space for the bottom Drawable if any.
intgetCompoundPaddingLeft()
Returns the left padding of the view, plus space for the left Drawable if any.
intgetCompoundPaddingRight()
Returns the right padding of the view, plus space for the right Drawable if any.
intgetCompoundPaddingTop()
Returns the top padding of the view, plus space for the top Drawable if any.
CharSequencegetContentDescription()
Returns the View 's content description.
ContextgetContext()
Returns the context the view is running in, through which it can access the current theme, resources, etc.
intgetCurrentHintTextColor()

Return the current color selected to paint the hint text.

intgetCurrentTextColor()
Return the current color selected for normal text.
BitmapgetDrawingCache()

Calling this method is equivalent to calling getDrawingCache(false).

EditablegetEditableText()
Return the text that TextView is displaying as an Editable object.
TextUtils.TruncateAtgetEllipsize()
Returns where, if anywhere, words that are longer than the view is wide should be ellipsized.
CharSequencegetError()
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.
InputFilter[]getFilters()
Returns the current list of input filters.
intgetGravity()
Returns the horizontal and vertical alignment of this TextView.
intgetHeight()
Return the height of your view.
CharSequencegetHint()
Returns the hint that is displayed when the text of the TextView is empty.
ColorStateListgetHintTextColors()
voidgetHitRect(Rect outRect)
Hit rectangle in parent's coordinates
intgetId()
Returns this view's identifier.
intgetInputType()
Get the type of the editable content.
LayoutgetLayout()
Gets the android.text.Layout that is currently being used to display the text.
intgetLayoutDirection()
Returns the resolved layout direction for this view.
ViewGroup.LayoutParamsgetLayoutParams()
Get the LayoutParams associated with this view.
intgetLeft()
Left position of this view relative to its parent.
intgetLineCount()
Return the number of lines of text, or 0 if the internal Layout has not been built.
intgetLineHeight()
Gets the vertical distance between lines of text, in pixels.
booleangetLinksClickable()
Returns whether the movement method will automatically be set to LinkMovementMethod if #setAutoLinkMask has been set to nonzero and links are detected in #setText .
ColorStateListgetLinkTextColors()
booleangetLocalVisibleRect(Rect r)
voidgetLocationInWindow(@Size(2) int[] outLocation)

Computes the coordinates of this view in its window.

voidgetLocationOnScreen(@Size(2) int[] outLocation)

Computes the coordinates of this view on the screen.

intgetMaxHeight()
Returns the maximum height of TextView in terms of pixels or -1 if the maximum height was set using #setMaxLines(int) or #setLines(int) .
intgetMaxLines()
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) .
intgetMaxWidth()
Returns the maximum width of TextView in terms of pixels or -1 if the maximum width was set using #setMaxEms(int) or #setEms(int) .
intgetMeasuredHeight()
Like #getMeasuredHeightAndState() , but only returns the raw height component (that is the result is masked by #MEASURED_SIZE_MASK ).
intgetMeasuredWidth()
Like #getMeasuredWidthAndState() , but only returns the raw width component (that is the result is masked by #MEASURED_SIZE_MASK ).
MovementMethodgetMovementMethod()
Gets the android.text.method.MovementMethod being used for this TextView, which provides positioning, scrolling, and text selection functionality.
intgetPaddingBottom()
Returns the bottom padding of this view.
intgetPaddingEnd()
Returns the end padding of this view depending on its resolved layout direction.
intgetPaddingLeft()
Returns the left padding of this view.
intgetPaddingRight()
Returns the right padding of this view.
intgetPaddingStart()
Returns the start padding of this view depending on its resolved layout direction.
intgetPaddingTop()
Returns the top padding of this view.
TextPaintgetPaint()
Gets the TextPaint used for the text.
intgetPaintFlags()
Gets the flags on the Paint being used to display the text.
ViewParentgetParent()
Gets the parent of this view.
ResourcesgetResources()
Returns the resources associated with this view.
intgetRight()
Right position of this view relative to its parent.
floatgetScaleX()
The amount that the view is scaled in x around the pivot point, as a proportion of the view's unscaled width.
floatgetScaleY()
The amount that the view is scaled in y around the pivot point, as a proportion of the view's unscaled height.
intgetScrollX()
Return the scrolled left position of this view.
intgetScrollY()
Return the scrolled top position of this view.
intgetSelectionEnd()
Convenience for Selection#getSelectionEnd .
intgetSelectionStart()
Convenience for Selection#getSelectionStart .
ObjectgetTag()
Returns this view's tag.
ObjectgetTag(int key)
Returns the tag associated with this view and the specified key.
CharSequencegetText()
Return the text that TextView is displaying.
intgetTextAlignment()
Return the resolved text alignment.
ColorStateListgetTextColors()
Gets the text colors for the different states (normal, selected, focused) of the TextView.
floatgetTextScaleX()
Gets the extent by which text should be stretched horizontally.
floatgetTextSize()
intgetTop()
Top position of this view relative to its parent.
intgetTotalPaddingBottom()
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.
intgetTotalPaddingLeft()
Returns the total left padding of the view, including the left Drawable if any.
intgetTotalPaddingRight()
Returns the total right padding of the view, including the right Drawable if any.
intgetTotalPaddingTop()
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.
TransformationMethodgetTransformationMethod()
Gets the current android.text.method.TransformationMethod for the TextView.
TypefacegetTypeface()
Gets the current Typeface that is used to style the text.
URLSpan[]getUrls()
Returns the list of android.text.style.URLSpan URLSpans attached to the text (by Linkify or otherwise) if any.
ViewTreeObservergetViewTreeObserver()
Returns the ViewTreeObserver for this view's hierarchy.
intgetVisibility()
Returns the visibility status for this view.
intgetWidth()
Return the width of your view.
IBindergetWindowToken()
Retrieve a unique token identifying the window this view is attached to.
floatgetX()
The visual x position of this view, in pixels.
voidinvalidate()
Invalidate the whole view.
booleanisClickable()
Indicates whether this view reacts to click events or not.
booleanisEnabled()
Returns the enabled status for this view.
booleanisInEditMode()
Indicates whether this View is currently in edit mode.
booleanisSelected()
Indicates the selection state of this view.
booleanisShown()
Returns the visibility of this view and all of its ancestors
booleanisTextSelectable()
Returns the state of the textIsSelectable flag (See #setTextIsSelectable setTextIsSelectable() ).
voidlayout(int l, int t, int r, int b)
Assign a size and position to a view and all of its descendants

This is the second phase of the layout mechanism.

intlength()
Returns the length, in characters, of the text managed by this TextView
voidmeasure(int widthMeasureSpec, int heightMeasureSpec)

This is called to find out how big a view should be.

booleanpost(Runnable action)

Causes the Runnable to be added to the message queue.

booleanpostDelayed(Runnable action, long delayMillis)

Causes the Runnable to be added to the message queue, to be run after the specified amount of time elapses.

voidpostInvalidate()

Cause an invalidate to happen on a subsequent cycle through the event loop.

booleanrequestFocus()
Call this to try to give focus to a specific view or to one of its descendants.
voidrequestLayout()
Call this when something has changed which has invalidated the layout of this view.
voidscrollTo(int x, int y)
Set the scrolled position of your view.
voidsendAccessibilityEvent(int eventType)
Sends an accessibility event of the given type.
voidsetActivated(boolean activated)
Changes the activated state of this view.
voidsetAllCaps(boolean allCaps)
Sets the properties of this field to transform input to ALL CAPS display.
voidsetAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha)
Sets the opacity of the view to a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.
voidsetAnimation(Animation animation)
Sets the next animation to play for this view.
voidsetAutoLinkMask(int mask)
Sets the autolink mask of the text.
voidsetBackground(Drawable background)
Set the background to a given Drawable, or remove the background.
voidsetBackgroundColor(@ColorInt int color)
Sets the background color for this view.
voidsetBackgroundDrawable(Drawable background)
voidsetBackgroundResource(@DrawableRes int resid)
Set the background to a given resource.
voidsetBottom(int bottom)
Sets the bottom position of this view relative to its parent.
voidsetClickable(boolean clickable)
Enables or disables click events for this view.
voidsetCompoundDrawablePadding(int pad)
Sets the size of the padding between the compound drawables and the text.
voidsetCompoundDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom)
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.
voidsetCompoundDrawablesRelative(@Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom)
Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text.
voidsetCompoundDrawablesRelativeWithIntrinsicBounds(@DrawableRes int start, @DrawableRes int top, @DrawableRes int end, @DrawableRes int bottom)
Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text.
voidsetCompoundDrawablesRelativeWithIntrinsicBounds(@Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom)
Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text.
voidsetCompoundDrawablesWithIntrinsicBounds(@DrawableRes int left, @DrawableRes int top, @DrawableRes int right, @DrawableRes int bottom)
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.
voidsetCompoundDrawablesWithIntrinsicBounds(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom)
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.
voidsetContentDescription(CharSequence contentDescription)
Sets the View 's content description.
voidsetCursorVisible(boolean visible)
Set whether the cursor is visible.
voidsetCustomSelectionActionModeCallback(ActionMode.Callback actionModeCallback)
If provided, this ActionMode.Callback will be used to create the ActionMode when text selection is initiated in this View.
voidsetDrawingCacheEnabled(boolean enabled)

Enables or disables the drawing cache.

voidsetElevation(float elevation)
Sets the base elevation of this view, in pixels.
voidsetEllipsize(TextUtils.TruncateAt where)
Causes words in the text that are longer than the view's width to be ellipsized instead of broken in the middle.
voidsetEnabled(boolean enabled)
voidsetError(CharSequence error)
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.
voidsetError(CharSequence error, Drawable icon)
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.
voidsetFadingEdgeLength(int length)
Set the size of the faded edge used to indicate that more content in this view is available.
voidsetFilters(InputFilter[] filters)
Sets the list of input filters that will be used if the buffer is Editable.
voidsetFocusable(boolean focusable)
Set whether this view can receive the focus.
voidsetFocusableInTouchMode(boolean focusableInTouchMode)
Set whether this view can receive focus while in touch mode.
voidsetGravity(int gravity)
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.
voidsetHeight(int pixels)
Sets the height of the TextView to be exactly pixels tall.
voidsetHighlightColor(@ColorInt int color)
Sets the color used to display the selection highlight.
voidsetHint(CharSequence hint)
Sets the text to be displayed when the text of the TextView is empty.
voidsetHint(@StringRes int resid)
Sets the text to be displayed when the text of the TextView is empty, from a resource.
voidsetHintTextColor(@ColorInt int color)
Sets the color of the hint text for all the states (disabled, focussed, selected...) of this TextView.
voidsetHintTextColor(ColorStateList colors)
Sets the color of the hint text.
voidsetHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled)

Define whether the horizontal edges should be faded when this view is scrolled horizontally.

voidsetHorizontallyScrolling(boolean whether)
Sets whether the text should be allowed to be wider than the View is.
voidsetId(@IdRes int id)
Sets the identifier for this view.
voidsetImeOptions(int imeOptions)
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.
voidsetIncludeFontPadding(boolean includepad)
Set whether the TextView includes extra top and bottom padding to make room for accents that go above the normal ascent and descent.
voidsetInputType(int type)
Set the type of the content with a constant as defined for EditorInfo#inputType .
voidsetKeyListener(KeyListener input)
Sets the key listener to be used with this TextView.
voidsetLayerType(int layerType, @Nullable Paint paint)

Specifies the type of layer backing this view.

voidsetLayoutParams(ViewGroup.LayoutParams params)
Set the layout parameters associated with this view.
voidsetLeft(int left)
Sets the left position of this view relative to its parent.
voidsetLines(int lines)
Sets the height of the TextView to be exactly lines tall.
voidsetLineSpacing(float add, float mult)
Sets line spacing for this TextView.
voidsetLinksClickable(boolean whether)
Sets whether the movement method will automatically be set to LinkMovementMethod if #setAutoLinkMask has been set to nonzero and links are detected in #setText .
voidsetLinkTextColor(@ColorInt int color)
Sets the color of links in the text.
voidsetLinkTextColor(ColorStateList colors)
Sets the color of links in the text.
voidsetLongClickable(boolean longClickable)
Enables or disables long click events for this view.
voidsetMarqueeRepeatLimit(int marqueeLimit)
Sets how many times to repeat the marquee animation.
voidsetMaxEms(int maxEms)
Sets the width of the TextView to be at most maxEms wide.
voidsetMaxHeight(int maxPixels)
Sets the height of the TextView to be at most maxPixels tall.
voidsetMaxLines(int maxLines)
Sets the height of the TextView to be at most maxLines tall.
voidsetMaxWidth(int maxPixels)
Sets the width of the TextView to be at most maxPixels wide.
voidsetMinHeight(int minPixels)
Sets the height of the TextView to be at least minPixels tall.
voidsetMinimumHeight(int minHeight)
Sets the minimum height of the view.
voidsetMinimumWidth(int minWidth)
Sets the minimum width of the view.
voidsetMinWidth(int minPixels)
Sets the width of the TextView to be at least minPixels wide.
voidsetMovementMethod(MovementMethod movement)
Sets the android.text.method.MovementMethod for handling arrow key movement for this TextView.
voidsetOnClickListener(@Nullable OnClickListener l)
Register a callback to be invoked when this view is clicked.
voidsetOnCreateContextMenuListener(OnCreateContextMenuListener l)
Register a callback to be invoked when the context menu for this view is being built.
voidsetOnEditorActionListener(OnEditorActionListener l)
Set a special listener to be called when an action is performed on the text view.
voidsetOnFocusChangeListener(OnFocusChangeListener l)
Register a callback to be invoked when focus of this view changed.
voidsetOnKeyListener(OnKeyListener l)
Register a callback to be invoked when a hardware key is pressed in this view.
voidsetOnLongClickListener(@Nullable OnLongClickListener l)
Register a callback to be invoked when this view is clicked and held.
voidsetOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l)
Set a listener to receive callbacks when the visibility of the system bar changes.
voidsetOnTouchListener(OnTouchListener l)
Register a callback to be invoked when a touch event is sent to this view.
voidsetPadding(int left, int top, int right, int bottom)
voidsetPaddingRelative(int start, int top, int end, int bottom)
voidsetPaintFlags(int flags)
Sets flags on the Paint being used to display the text and reflows the text if they are different from the old flags.
voidsetRight(int right)
Sets the right position of this view relative to its parent.
voidsetScaleX(float scaleX)
Sets the amount that the view is scaled in x around the pivot point, as a proportion of the view's unscaled width.
voidsetScaleY(float scaleY)
Sets the amount that the view is scaled in Y around the pivot point, as a proportion of the view's unscaled width.
voidsetScrollBarStyle(@ScrollBarStyle int style)

Specify the style of the scrollbars.

voidsetScroller(Scroller s)
Sets the Scroller used for producing a scrolling animation
voidsetScrollX(int value)
Set the horizontal scrolled position of your view.
voidsetSelected(boolean selected)
voidsetShadowLayer(float radius, float dx, float dy, int color)
Gives the text a shadow of the specified blur radius and color, the specified distance from its drawn position.
voidsetSingleLine(boolean singleLine)
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.
voidsetSingleLine()
Sets the properties of this field (lines, horizontally scrolling, transformation method) to be for a single-line input.
voidsetStateListAnimator(StateListAnimator stateListAnimator)
Attaches the provided StateListAnimator to this View.
voidsetTag(final Object tag)
Sets the tag associated with this view.
voidsetTag(int key, final Object tag)
Sets a tag associated with this view and a key.
voidsetText(CharSequence text)
Sets the text to be displayed.
voidsetText(@StringRes int resid)
Sets the text to be displayed using a string resource identifier.
voidsetText(CharSequence text, BufferType type)
Sets the text to be displayed and the android.widget.TextView.BufferType .
voidsetText(@StringRes int resid, BufferType type)
Sets the text to be displayed using a string resource identifier and the android.widget.TextView.BufferType .
voidsetTextAlignment(@TextAlignment int textAlignment)
Set the text alignment.
voidsetTextAppearance(@StyleRes int resId)
Sets the text appearance from the specified style resource.
voidsetTextAppearance(Context context, @StyleRes int resId)
Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.
voidsetTextColor(@ColorInt int color)
Sets the text color for all the states (normal, selected, focused) to be this color.
voidsetTextColor(ColorStateList colors)
Sets the text color.
voidsetTextDirection(int textDirection)
Set the text direction.
voidsetTextIsSelectable(boolean selectable)
Sets whether the content of this view is selectable by the user.
voidsetTextScaleX(float size)
Sets the horizontal scale factor for text.
voidsetTextSize(float size)
Set the default text size to the given value, interpreted as "scaled pixel" units.
voidsetTextSize(int unit, float size)
Set the default text size to a given unit and value.
voidsetTop(int top)
Sets the top position of this view relative to its parent.
voidsetTransformationMethod(TransformationMethod method)
Sets the transformation that is applied to the text that this TextView is displaying.
voidsetTransitionName(String transitionName)
Sets the name of the View to be used to identify Views in Transitions.
voidsetTranslationY(float translationY)
Sets the vertical location of this view relative to its #getTop() top position.
voidsetTypeface(@Nullable Typeface tf, @Typeface.Style int style)
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.
voidsetTypeface(@Nullable Typeface tf)
Sets the typeface and style in which the text should be displayed.
voidsetVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled)

Define whether the vertical edges should be faded when this view is scrolled vertically.

voidsetVerticalScrollBarEnabled(boolean verticalScrollBarEnabled)

Define whether the vertical scrollbar should be drawn or not.

voidsetVisibility(@Visibility int visibility)
Set the visibility state of this view.
voidsetWidth(int pixels)
Sets the width of the TextView to be exactly pixels wide.
voidsetX(float x)
Sets the visual x position of this view, in pixels.
voidsetY(float y)
Sets the visual y position of this view, in pixels.
voidstartAnimation(Animation animation)
Start the specified animation now.
StringtoString()