Example usage for Java android.widget TextView fields, constructors, methods, implement or subclass
The text is from its open source code.
void | addTextChangedListener(TextWatcher watcher) Adds a TextWatcher to the list of those whose methods are called whenever this TextView's text changes. |
ViewPropertyAnimator | animate() This method returns a ViewPropertyAnimator object, which can be used to animate specific properties on this View. |
void | announceForAccessibility(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. |
void | append(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. |
void | bringToFront() Change the view's z order in the tree, so it's on top of other sibling views. |
void | buildDrawingCache() Calling this method is equivalent to calling |
void | buildDrawingCache(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. |
void | clearAnimation() Cancels any animations for this view. |
void | clearFocus() Called when this view wants to give up focus. |
void | destroyDrawingCache() Frees the resources used by the drawing cache. |
void | draw(Canvas canvas) Manually render this view (and all of its children) to the given Canvas. |
boolean | equals(Object obj) Indicates whether some other object is "equal to" this one. |
T | findViewById(@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. |
View | focusSearch(@FocusRealDirection int direction) Find the nearest view in the specified direction that can take focus. |
float | getAlpha() The opacity of the view. |
Drawable | getBackground() Gets the background drawable |
int | getBaseline() |
int | getBottom() Bottom position of this view relative to its parent. |
Class> | getClass() Returns the runtime class of this Object . |
int | getCompoundDrawablePadding() 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. |
int | getCompoundPaddingBottom() Returns the bottom padding of the view, plus space for the bottom Drawable if any. |
int | getCompoundPaddingLeft() Returns the left padding of the view, plus space for the left Drawable if any. |
int | getCompoundPaddingRight() Returns the right padding of the view, plus space for the right Drawable if any. |
int | getCompoundPaddingTop() Returns the top padding of the view, plus space for the top Drawable if any. |
CharSequence | getContentDescription() Returns the View 's content description. |
Context | getContext() Returns the context the view is running in, through which it can access the current theme, resources, etc. |
int | getCurrentHintTextColor() Return the current color selected to paint the hint text. |
int | getCurrentTextColor() Return the current color selected for normal text. |
Bitmap | getDrawingCache() Calling this method is equivalent to calling |
Editable | getEditableText() Return the text that TextView is displaying as an Editable object. |
TextUtils.TruncateAt | getEllipsize() Returns where, if anywhere, words that are longer than the view is wide should be ellipsized. |
CharSequence | getError() 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. |
int | getGravity() Returns the horizontal and vertical alignment of this TextView. |
int | getHeight() Return the height of your view. |
CharSequence | getHint() Returns the hint that is displayed when the text of the TextView is empty. |
ColorStateList | getHintTextColors() |
void | getHitRect(Rect outRect) Hit rectangle in parent's coordinates |
int | getId() Returns this view's identifier. |
int | getInputType() Get the type of the editable content. |
Layout | getLayout() Gets the android.text.Layout that is currently being used to display the text. |
int | getLayoutDirection() Returns the resolved layout direction for this view. |
ViewGroup.LayoutParams | getLayoutParams() Get the LayoutParams associated with this view. |
int | getLeft() Left position of this view relative to its parent. |
int | getLineCount() Return the number of lines of text, or 0 if the internal Layout has not been built. |
int | getLineHeight() Gets the vertical distance between lines of text, in pixels. |
boolean | getLinksClickable() Returns whether the movement method will automatically be set to LinkMovementMethod if #setAutoLinkMask has been set to nonzero and links are detected in #setText . |
ColorStateList | getLinkTextColors() |
boolean | getLocalVisibleRect(Rect r) |
void | getLocationInWindow(@Size(2) int[] outLocation) Computes the coordinates of this view in its window. |
void | getLocationOnScreen(@Size(2) int[] outLocation) Computes the coordinates of this view on the screen. |
int | getMaxHeight() Returns the maximum height of TextView in terms of pixels or -1 if the maximum height was set using #setMaxLines(int) or #setLines(int) . |
int | getMaxLines() 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) . |
int | getMaxWidth() Returns the maximum width of TextView in terms of pixels or -1 if the maximum width was set using #setMaxEms(int) or #setEms(int) . |
int | getMeasuredHeight() Like #getMeasuredHeightAndState() , but only returns the raw height component (that is the result is masked by #MEASURED_SIZE_MASK ). |
int | getMeasuredWidth() Like #getMeasuredWidthAndState() , but only returns the raw width component (that is the result is masked by #MEASURED_SIZE_MASK ). |
MovementMethod | getMovementMethod() Gets the android.text.method.MovementMethod being used for this TextView, which provides positioning, scrolling, and text selection functionality. |
int | getPaddingBottom() Returns the bottom padding of this view. |
int | getPaddingEnd() Returns the end padding of this view depending on its resolved layout direction. |
int | getPaddingLeft() Returns the left padding of this view. |
int | getPaddingRight() Returns the right padding of this view. |
int | getPaddingStart() Returns the start padding of this view depending on its resolved layout direction. |
int | getPaddingTop() Returns the top padding of this view. |
TextPaint | getPaint() Gets the TextPaint used for the text. |
int | getPaintFlags() Gets the flags on the Paint being used to display the text. |
ViewParent | getParent() Gets the parent of this view. |
Resources | getResources() Returns the resources associated with this view. |
int | getRight() Right position of this view relative to its parent. |
float | getScaleX() The amount that the view is scaled in x around the pivot point, as a proportion of the view's unscaled width. |
float | getScaleY() The amount that the view is scaled in y around the pivot point, as a proportion of the view's unscaled height. |
int | getScrollX() Return the scrolled left position of this view. |
int | getScrollY() Return the scrolled top position of this view. |
int | getSelectionEnd() Convenience for Selection#getSelectionEnd . |
int | getSelectionStart() Convenience for Selection#getSelectionStart . |
Object | getTag() Returns this view's tag. |
Object | getTag(int key) Returns the tag associated with this view and the specified key. |
CharSequence | getText() Return the text that TextView is displaying. |
int | getTextAlignment() Return the resolved text alignment. |
ColorStateList | getTextColors() Gets the text colors for the different states (normal, selected, focused) of the TextView. |
float | getTextScaleX() Gets the extent by which text should be stretched horizontally. |
float | getTextSize() |
int | getTop() Top position of this view relative to its parent. |
int | getTotalPaddingBottom() 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. |
int | getTotalPaddingLeft() Returns the total left padding of the view, including the left Drawable if any. |
int | getTotalPaddingRight() Returns the total right padding of the view, including the right Drawable if any. |
int | getTotalPaddingTop() 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 | getTransformationMethod() Gets the current android.text.method.TransformationMethod for the TextView. |
Typeface | getTypeface() 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. |
ViewTreeObserver | getViewTreeObserver() Returns the ViewTreeObserver for this view's hierarchy. |
int | getVisibility() Returns the visibility status for this view. |
int | getWidth() Return the width of your view. |
IBinder | getWindowToken() Retrieve a unique token identifying the window this view is attached to. |
float | getX() The visual x position of this view, in pixels. |
void | invalidate() Invalidate the whole view. |
boolean | isClickable() Indicates whether this view reacts to click events or not. |
boolean | isEnabled() Returns the enabled status for this view. |
boolean | isInEditMode() Indicates whether this View is currently in edit mode. |
boolean | isSelected() Indicates the selection state of this view. |
boolean | isShown() Returns the visibility of this view and all of its ancestors |
boolean | isTextSelectable() Returns the state of the textIsSelectable flag (See #setTextIsSelectable setTextIsSelectable() ). |
void | layout(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. |
int | length() Returns the length, in characters, of the text managed by this TextView |
void | measure(int widthMeasureSpec, int heightMeasureSpec) This is called to find out how big a view should be. |
boolean | post(Runnable action) Causes the Runnable to be added to the message queue. |
boolean | postDelayed(Runnable action, long delayMillis) Causes the Runnable to be added to the message queue, to be run after the specified amount of time elapses. |
void | postInvalidate() Cause an invalidate to happen on a subsequent cycle through the event loop. |
boolean | requestFocus() Call this to try to give focus to a specific view or to one of its descendants. |
void | requestLayout() Call this when something has changed which has invalidated the layout of this view. |
void | scrollTo(int x, int y) Set the scrolled position of your view. |
void | sendAccessibilityEvent(int eventType) Sends an accessibility event of the given type. |
void | setActivated(boolean activated) Changes the activated state of this view. |
void | setAllCaps(boolean allCaps) Sets the properties of this field to transform input to ALL CAPS display. |
void | setAlpha(@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. |
void | setAnimation(Animation animation) Sets the next animation to play for this view. |
void | setAutoLinkMask(int mask) Sets the autolink mask of the text. |
void | setBackground(Drawable background) Set the background to a given Drawable, or remove the background. |
void | setBackgroundColor(@ColorInt int color) Sets the background color for this view. |
void | setBackgroundDrawable(Drawable background) |
void | setBackgroundResource(@DrawableRes int resid) Set the background to a given resource. |
void | setBottom(int bottom) Sets the bottom position of this view relative to its parent. |
void | setClickable(boolean clickable) Enables or disables click events for this view. |
void | setCompoundDrawablePadding(int pad) Sets the size of the padding between the compound drawables and the text. |
void | setCompoundDrawables(@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. |
void | setCompoundDrawablesRelative(@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. |
void | setCompoundDrawablesRelativeWithIntrinsicBounds(@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. |
void | setCompoundDrawablesRelativeWithIntrinsicBounds(@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. |
void | setCompoundDrawablesWithIntrinsicBounds(@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. |
void | setCompoundDrawablesWithIntrinsicBounds(@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. |
void | setContentDescription(CharSequence contentDescription) Sets the View 's content description. |
void | setCursorVisible(boolean visible) Set whether the cursor is visible. |
void | setCustomSelectionActionModeCallback(ActionMode.Callback actionModeCallback) If provided, this ActionMode.Callback will be used to create the ActionMode when text selection is initiated in this View. |
void | setDrawingCacheEnabled(boolean enabled) Enables or disables the drawing cache. |
void | setElevation(float elevation) Sets the base elevation of this view, in pixels. |
void | setEllipsize(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. |
void | setEnabled(boolean enabled) |
void | setError(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. |
void | setError(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. |
void | setFadingEdgeLength(int length) Set the size of the faded edge used to indicate that more content in this view is available. |
void | setFilters(InputFilter[] filters) Sets the list of input filters that will be used if the buffer is Editable. |
void | setFocusable(boolean focusable) Set whether this view can receive the focus. |
void | setFocusableInTouchMode(boolean focusableInTouchMode) Set whether this view can receive focus while in touch mode. |
void | setGravity(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. |
void | setHeight(int pixels) Sets the height of the TextView to be exactly pixels tall. |
void | setHighlightColor(@ColorInt int color) Sets the color used to display the selection highlight. |
void | setHint(CharSequence hint) Sets the text to be displayed when the text of the TextView is empty. |
void | setHint(@StringRes int resid) Sets the text to be displayed when the text of the TextView is empty, from a resource. |
void | setHintTextColor(@ColorInt int color) Sets the color of the hint text for all the states (disabled, focussed, selected...) of this TextView. |
void | setHintTextColor(ColorStateList colors) Sets the color of the hint text. |
void | setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled) Define whether the horizontal edges should be faded when this view is scrolled horizontally. |
void | setHorizontallyScrolling(boolean whether) Sets whether the text should be allowed to be wider than the View is. |
void | setId(@IdRes int id) Sets the identifier for this view. |
void | setImeOptions(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. |
void | setIncludeFontPadding(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. |
void | setInputType(int type) Set the type of the content with a constant as defined for EditorInfo#inputType . |
void | setKeyListener(KeyListener input) Sets the key listener to be used with this TextView. |
void | setLayerType(int layerType, @Nullable Paint paint) Specifies the type of layer backing this view. |
void | setLayoutParams(ViewGroup.LayoutParams params) Set the layout parameters associated with this view. |
void | setLeft(int left) Sets the left position of this view relative to its parent. |
void | setLines(int lines) Sets the height of the TextView to be exactly lines tall. |
void | setLineSpacing(float add, float mult) Sets line spacing for this TextView. |
void | setLinksClickable(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 . |
void | setLinkTextColor(@ColorInt int color) Sets the color of links in the text. |
void | setLinkTextColor(ColorStateList colors) Sets the color of links in the text. |
void | setLongClickable(boolean longClickable) Enables or disables long click events for this view. |
void | setMarqueeRepeatLimit(int marqueeLimit) Sets how many times to repeat the marquee animation. |
void | setMaxEms(int maxEms) Sets the width of the TextView to be at most maxEms wide. |
void | setMaxHeight(int maxPixels) Sets the height of the TextView to be at most maxPixels tall. |
void | setMaxLines(int maxLines) Sets the height of the TextView to be at most maxLines tall. |
void | setMaxWidth(int maxPixels) Sets the width of the TextView to be at most maxPixels wide. |
void | setMinHeight(int minPixels) Sets the height of the TextView to be at least minPixels tall. |
void | setMinimumHeight(int minHeight) Sets the minimum height of the view. |
void | setMinimumWidth(int minWidth) Sets the minimum width of the view. |
void | setMinWidth(int minPixels) Sets the width of the TextView to be at least minPixels wide. |
void | setMovementMethod(MovementMethod movement) Sets the android.text.method.MovementMethod for handling arrow key movement for this TextView. |
void | setOnClickListener(@Nullable OnClickListener l) Register a callback to be invoked when this view is clicked. |
void | setOnCreateContextMenuListener(OnCreateContextMenuListener l) Register a callback to be invoked when the context menu for this view is being built. |
void | setOnEditorActionListener(OnEditorActionListener l) Set a special listener to be called when an action is performed on the text view. |
void | setOnFocusChangeListener(OnFocusChangeListener l) Register a callback to be invoked when focus of this view changed. |
void | setOnKeyListener(OnKeyListener l) Register a callback to be invoked when a hardware key is pressed in this view. |
void | setOnLongClickListener(@Nullable OnLongClickListener l) Register a callback to be invoked when this view is clicked and held. |
void | setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) Set a listener to receive callbacks when the visibility of the system bar changes. |
void | setOnTouchListener(OnTouchListener l) Register a callback to be invoked when a touch event is sent to this view. |
void | setPadding(int left, int top, int right, int bottom) |
void | setPaddingRelative(int start, int top, int end, int bottom) |
void | setPaintFlags(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. |
void | setRight(int right) Sets the right position of this view relative to its parent. |
void | setScaleX(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. |
void | setScaleY(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. |
void | setScrollBarStyle(@ScrollBarStyle int style) Specify the style of the scrollbars. |
void | setScroller(Scroller s) Sets the Scroller used for producing a scrolling animation |
void | setScrollX(int value) Set the horizontal scrolled position of your view. |
void | setSelected(boolean selected) |
void | setShadowLayer(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. |
void | setSingleLine(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. |
void | setSingleLine() Sets the properties of this field (lines, horizontally scrolling, transformation method) to be for a single-line input. |
void | setStateListAnimator(StateListAnimator stateListAnimator) Attaches the provided StateListAnimator to this View. |
void | setTag(final Object tag) Sets the tag associated with this view. |
void | setTag(int key, final Object tag) Sets a tag associated with this view and a key. |
void | setText(CharSequence text) Sets the text to be displayed. |
void | setText(@StringRes int resid) Sets the text to be displayed using a string resource identifier. |
void | setText(CharSequence text, BufferType type) Sets the text to be displayed and the android.widget.TextView.BufferType . |
void | setText(@StringRes int resid, BufferType type) Sets the text to be displayed using a string resource identifier and the android.widget.TextView.BufferType . |
void | setTextAlignment(@TextAlignment int textAlignment) Set the text alignment. |
void | setTextAppearance(@StyleRes int resId) Sets the text appearance from the specified style resource. |
void | setTextAppearance(Context context, @StyleRes int resId) Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource. |
void | setTextColor(@ColorInt int color) Sets the text color for all the states (normal, selected, focused) to be this color. |
void | setTextColor(ColorStateList colors) Sets the text color. |
void | setTextDirection(int textDirection) Set the text direction. |
void | setTextIsSelectable(boolean selectable) Sets whether the content of this view is selectable by the user. |
void | setTextScaleX(float size) Sets the horizontal scale factor for text. |
void | setTextSize(float size) Set the default text size to the given value, interpreted as "scaled pixel" units. |
void | setTextSize(int unit, float size) Set the default text size to a given unit and value. |
void | setTop(int top) Sets the top position of this view relative to its parent. |
void | setTransformationMethod(TransformationMethod method) Sets the transformation that is applied to the text that this TextView is displaying. |
void | setTransitionName(String transitionName) Sets the name of the View to be used to identify Views in Transitions. |
void | setTranslationY(float translationY) Sets the vertical location of this view relative to its #getTop() top position. |
void | setTypeface(@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. |
void | setTypeface(@Nullable Typeface tf) Sets the typeface and style in which the text should be displayed. |
void | setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled) Define whether the vertical edges should be faded when this view is scrolled vertically. |
void | setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) Define whether the vertical scrollbar should be drawn or not. |
void | setVisibility(@Visibility int visibility) Set the visibility state of this view. |
void | setWidth(int pixels) Sets the width of the TextView to be exactly pixels wide. |
void | setX(float x) Sets the visual x position of this view, in pixels. |
void | setY(float y) Sets the visual y position of this view, in pixels. |
void | startAnimation(Animation animation) Start the specified animation now. |
String | toString() |