to top
Android APIs
public class

TextView

extends View
implements ViewTreeObserver.OnPreDrawListener
java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing; see EditText for a subclass that configures the text view for editing.

To allow users to copy some or all of the TextView's value and paste it somewhere else, set the XML attribute android:textIsSelectable to "true" or call setTextIsSelectable(true). The textIsSelectable flag allows users to make selection gestures in the TextView, which in turn triggers the system's built-in copy/paste controls.

XML attributes

See TextView Attributes, View Attributes

Summary

Nested Classes
enum TextView.BufferType  
interface TextView.OnEditorActionListener Interface definition for a callback to be invoked when an action is performed on the editor. 
class TextView.SavedState User interface state that is stored by TextView for implementing onSaveInstanceState()
XML Attributes
Attribute Name Related Method Description
android:autoLink setAutoLinkMask(int) Controls whether links such as urls and email addresses are automatically found and converted to clickable links. 
android:autoText setKeyListener(KeyListener) If set, specifies that this TextView has a textual input method and automatically corrects some common spelling errors. 
android:bufferType setText(CharSequence,TextView.BufferType) Determines the minimum type that getText() will return. 
android:capitalize setKeyListener(KeyListener) If set, specifies that this TextView has a textual input method and should automatically capitalize what the user types. 
android:cursorVisible setCursorVisible(boolean) Makes the cursor visible (the default) or invisible. 
android:digits setKeyListener(KeyListener) 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 setCompoundDrawablesWithIntrinsicBounds(int,int,int,int) The drawable to be drawn below the text. 
android:drawableEnd setCompoundDrawablesRelativeWithIntrinsicBounds(int,int,int,int) The drawable to be drawn to the end of the text. 
android:drawableLeft setCompoundDrawablesWithIntrinsicBounds(int,int,int,int) The drawable to be drawn to the left of the text. 
android:drawablePadding setCompoundDrawablePadding(int) The padding between the drawables and the text. 
android:drawableRight setCompoundDrawablesWithIntrinsicBounds(int,int,int,int) The drawable to be drawn to the right of the text. 
android:drawableStart setCompoundDrawablesRelativeWithIntrinsicBounds(int,int,int,int) The drawable to be drawn to the start of the text. 
android:drawableTop setCompoundDrawablesWithIntrinsicBounds(int,int,int,int) The drawable to be drawn above the text. 
android:editable If set, specifies that this TextView has an input method. 
android:editorExtras setInputExtras(int) 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:ellipsize setEllipsize(TextUtils.TruncateAt) If set, causes words that are longer than the view is wide to be ellipsized instead of broken in the middle. 
android:ems setEms(int) Makes the TextView be exactly this many ems wide. 
android:fontFamily setTypeface(Typeface) Font family (named by string) for the text. 
android:freezesText setFreezesText(boolean) 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 setGravity(int) 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 setHeight(int) Makes the TextView be exactly this many pixels tall. 
android:hint setHint(int) Hint text to display when the text is empty. 
android:imeActionId setImeActionLabel(CharSequence,int) Supply a value for EditorInfo.actionId used when an input method is connected to the text view. 
android:imeActionLabel setImeActionLabel(CharSequence,int) Supply a value for EditorInfo.actionLabel used when an input method is connected to the text view. 
android:imeOptions setImeOptions(int) Additional features you can enable in an IME associated with an editor to improve the integration with your application. 
android:includeFontPadding setIncludeFontPadding(boolean) Leave enough room for ascenders and descenders instead of using the font ascent and descent strictly. 
android:inputMethod setKeyListener(KeyListener) If set, specifies that this TextView should use the specified input method (specified by fully-qualified class name). 
android:inputType setRawInputType(int) 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:lineSpacingExtra setLineSpacing(float,float) Extra spacing between lines of text. 
android:lineSpacingMultiplier setLineSpacing(float,float) Extra spacing between lines of text, as a multiplier. 
android:lines setLines(int) Makes the TextView be exactly this many lines tall. 
android:linksClickable setLinksClickable(boolean) 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 setMarqueeRepeatLimit(int) The number of times to repeat the marquee animation. 
android:maxEms setMaxEms(int) Makes the TextView be at most this many ems wide. 
android:maxHeight setMaxHeight(int) Makes the TextView be at most this many pixels tall. 
android:maxLength setFilters(InputFilter) Set an input filter to constrain the text length to the specified number. 
android:maxLines setMaxLines(int) Makes the TextView be at most this many lines tall. 
android:maxWidth setMaxWidth(int) Makes the TextView be at most this many pixels wide. 
android:minEms setMinEms(int) Makes the TextView be at least this many ems wide. 
android:minHeight setMinHeight(int) Makes the TextView be at least this many pixels tall. 
android:minLines setMinLines(int) Makes the TextView be at least this many lines tall. 
android:minWidth setMinWidth(int) Makes the TextView be at least this many pixels wide. 
android:numeric setKeyListener(KeyListener) If set, specifies that this TextView has a numeric input method. 
android:password setTransformationMethod(TransformationMethod) Whether the characters of the field are displayed as password dots instead of themselves. 
android:phoneNumber setKeyListener(KeyListener) If set, specifies that this TextView has a phone number input method. 
android:privateImeOptions setPrivateImeOptions(String) 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 setHorizontallyScrolling(boolean) Whether the text is allowed to be wider than the view (and therefore can be scrolled horizontally). 
android:selectAllOnFocus setSelectAllOnFocus(boolean) If the text is selectable, select it all when the view takes focus. 
android:shadowColor setShadowLayer(float,float,float,int) Place a shadow of the specified color behind the text. 
android:shadowDx setShadowLayer(float,float,float,int) Horizontal offset of the shadow. 
android:shadowDy setShadowLayer(float,float,float,int) Vertical offset of the shadow. 
android:shadowRadius setShadowLayer(float,float,float,int) Radius of the shadow. 
android:singleLine setTransformationMethod(TransformationMethod) 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 setText(CharSequence,TextView.BufferType) Text to display. 
android:textAllCaps setAllCaps(boolean) Present the text in ALL CAPS. 
android:textAppearance Base text color, typeface, size, and style. 
android:textColor setTextColor(int) Text color. 
android:textColorHighlight setHighlightColor(int) Color of the text selection highlight. 
android:textColorHint setHintTextColor(int) Color of the hint text. 
android:textColorLink setLinkTextColor(int) Text color for links. 
android:textIsSelectable isTextSelectable() Indicates that the content of a non-editable text can be selected. 
android:textScaleX setTextScaleX(float) Sets the horizontal scaling factor for the text. 
android:textSize setTextSize(int,float) Size of the text. 
android:textStyle setTypeface(Typeface) Style (bold, italic, bolditalic) for the text. 
android:typeface setTypeface(Typeface) Typeface (normal, sans, serif, monospace) for the text. 
android:width setWidth(int) Makes the TextView be exactly this many pixels wide. 
[Expand]
Inherited XML Attributes
From class android.view.View
[Expand]
Inherited Constants
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
TextView(Context context)
TextView(Context context, AttributeSet attrs)
TextView(Context context, AttributeSet attrs, int defStyle)
Public Methods
void addTextChangedListener(TextWatcher watcher)
Adds a TextWatcher to the list of those whose methods are called whenever this TextView's text changes.
final void append(CharSequence text)
Convenience method: Append the specified text to the TextView's display buffer, upgrading it to BufferType.EDITABLE if it was not already editable.
void append(CharSequence text, int start, int end)
Convenience method: Append the specified text slice to the TextView's display buffer, upgrading it to BufferType.EDITABLE if it was not already editable.
void beginBatchEdit()
boolean bringPointIntoView(int offset)
Move the point, specified by the offset, into the view if it is needed.
void cancelLongPress()
Cancels a pending long press.
void clearComposingText()
Use BaseInputConnection.removeComposingSpans() to remove any IME composing state from this text view.
void computeScroll()
Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary.
void debug(int depth)
Prints information about this view in the log output, with the tag VIEW_LOG_TAG.
boolean didTouchFocusSelect()
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.
void endBatchEdit()
boolean extractText(ExtractedTextRequest request, ExtractedText outText)
If this TextView contains editable content, extract a portion of it based on the information in request in to outText.
void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags)
Finds the Views that contain given text.
final int getAutoLinkMask()
Gets the autolink mask of the text.
int getBaseline()

Return the offset of the widget's text baseline from the widget's top boundary.

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 getCompoundPaddingEnd()
Returns the end padding of the view, plus space for the end 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 getCompoundPaddingStart()
Returns the start padding of the view, plus space for the start Drawable if any.
int getCompoundPaddingTop()
Returns the top padding of the view, plus space for the top Drawable if any.
final int getCurrentHintTextColor()

Return the current color selected to paint the hint text.

final int getCurrentTextColor()

Return the current color selected for normal text.

ActionMode.Callback getCustomSelectionActionModeCallback()
Editable getEditableText()
Return the text the 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(CharSequence), or null if no error was set or if it the error was cleared by the widget after user input.
int getExtendedPaddingBottom()
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.
int getExtendedPaddingTop()
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.
InputFilter[] getFilters()
Returns the current list of input filters.
void getFocusedRect(Rect r)
When a view has focus and the user navigates away from it, the next view is searched for starting from the rectangle filled in by this method.
boolean getFreezesText()
Return whether this text view is including its entire text contents in frozen icicles.
int getGravity()
Returns the horizontal and vertical alignment of this TextView.
int getHighlightColor()
CharSequence getHint()
Returns the hint that is displayed when the text of the TextView is empty.
final ColorStateList getHintTextColors()
int getImeActionId()
Get the IME action ID previous set with setImeActionLabel(CharSequence, int).
CharSequence getImeActionLabel()
Get the IME action label previous set with setImeActionLabel(CharSequence, int).
int getImeOptions()
Get the type of the IME editor.
boolean getIncludeFontPadding()
Gets whether the TextView includes extra top and bottom padding to make room for accents that go above the normal ascent and descent.
Bundle getInputExtras(boolean create)
Retrieve the input extras currently associated with the text view, which can be viewed as well as modified.
int getInputType()
Get the type of the editable content.
final KeyListener getKeyListener()
final Layout getLayout()
int getLineBounds(int line, Rect bounds)
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.
int getLineCount()
Return the number of lines of text, or 0 if the internal Layout has not been built.
int getLineHeight()
float getLineSpacingExtra()
Gets the line spacing extra space
float getLineSpacingMultiplier()
Gets the line spacing multiplier
final ColorStateList getLinkTextColors()
final boolean getLinksClickable()
Returns whether the movement method will automatically be set to LinkMovementMethod if setAutoLinkMask(int) has been set to nonzero and links are detected in setText(char[], int, int).
int getMarqueeRepeatLimit()
Gets the number of times the marquee animation is repeated.
int getMaxEms()
int getMaxHeight()
int getMaxLines()
int getMaxWidth()
int getMinEms()
int getMinHeight()
int getMinLines()
int getMinWidth()
final MovementMethod getMovementMethod()
int getOffsetForPosition(float x, float y)
Get the character offset closest to the specified absolute position.
TextPaint getPaint()
int getPaintFlags()
String getPrivateImeOptions()
Get the private type of the content.
int getSelectionEnd()
int getSelectionStart()
int getShadowColor()
float getShadowDx()
float getShadowDy()
float getShadowRadius()
Gets the radius of the shadow layer.
CharSequence getText()
Return the text the TextView is displaying.
static int getTextColor(Context context, TypedArray attrs, int def)
Returns the default color from the TextView_textColor attribute from the AttributeSet, if set, or the default color from the TextAppearance_textColor from the TextView_textAppearance attribute, if TextView_textColor was not set directly.
final ColorStateList getTextColors()
Gets the text colors for the different states (normal, selected, focused) of the TextView.
static ColorStateList getTextColors(Context context, TypedArray attrs)
Returns the TextView_textColor attribute from the TypedArray, if set, or the TextAppearance_textColor from the TextView_textAppearance attribute, if TextView_textColor was not set directly.
Locale getTextLocale()
Get the default Locale of the text in this TextView.
float getTextScaleX()
float getTextSize()
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 getTotalPaddingEnd()
Returns the total end padding of the view, including the end Drawable 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 getTotalPaddingStart()
Returns the total start padding of the view, including the start 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.
final TransformationMethod getTransformationMethod()
Typeface getTypeface()
URLSpan[] getUrls()
Returns the list of URLSpans attached to the text (by Linkify or otherwise) if any.
boolean hasOverlappingRendering()
Returns whether this View has content which overlaps.
boolean hasSelection()
Return true iff there is a selection inside this text view.
void invalidateDrawable(Drawable drawable)
Invalidates the specified Drawable.
boolean isCursorVisible()
boolean isInputMethodTarget()
Returns whether this text view is a current input method target.
boolean isSuggestionsEnabled()
Return whether or not suggestions are enabled on this TextView.
boolean isTextSelectable()
Returns the state of the textIsSelectable flag (See setTextIsSelectable()).
void jumpDrawablesToCurrentState()
Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.
int length()
Returns the length, in characters, of the text managed by this TextView
boolean moveCursorToVisibleOffset()
Move the cursor, if needed, so that it is at an offset that is visible to the user.
void onBeginBatchEdit()
Called by the framework in response to a request to begin a batch of edit operations through a call to link beginBatchEdit().
boolean onCheckIsTextEditor()
Check whether the called view is a text editor, in which case it would make sense to automatically display a soft input window for it.
void onCommitCompletion(CompletionInfo text)
Called by the framework in response to a text completion from the current input method, provided by it calling InputConnection.commitCompletion().
void onCommitCorrection(CorrectionInfo info)
Called by the framework in response to a text auto-correction (such as fixing a typo using a a dictionnary) from the current input method, provided by it calling commitCorrection(CorrectionInfo) InputConnection.commitCorrection()}.
InputConnection onCreateInputConnection(EditorInfo outAttrs)
Create a new InputConnection for an InputMethod to interact with the view.
boolean onDragEvent(DragEvent event)
Handles drag events sent by the system following a call to startDrag().
void onEditorAction(int actionCode)
Called when an attached input method calls InputConnection.performEditorAction() for this text view.
void onEndBatchEdit()
Called by the framework in response to a request to end a batch of edit operations through a call to link endBatchEdit().
void onFinishTemporaryDetach()
Called after onStartTemporaryDetach() when the container is done changing the view.
boolean onGenericMotionEvent(MotionEvent event)
Implement this method to handle generic motion events.
void onInitializeAccessibilityEvent(AccessibilityEvent event)
Initializes an AccessibilityEvent with information about this View which is the event source.
void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo with information about this view.
boolean onKeyDown(int keyCode, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KEYCODE_DPAD_CENTER or KEYCODE_ENTER is released, if the view is enabled and clickable.
boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle the event).
boolean onKeyPreIme(int keyCode, KeyEvent event)
Handle a key event before it is processed by any input method associated with the view hierarchy.
boolean onKeyShortcut(int keyCode, KeyEvent event)
Called on the focused view when a key shortcut event is not handled.
boolean onKeyUp(int keyCode, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyUp(): perform clicking of the view when KEYCODE_DPAD_CENTER or KEYCODE_ENTER is released.
void onPopulateAccessibilityEvent(AccessibilityEvent event)
Called from dispatchPopulateAccessibilityEvent(AccessibilityEvent) giving a chance to this View to populate the accessibility event with its text content.
boolean onPreDraw()
Callback method to be invoked when the view tree is about to be drawn.
boolean onPrivateIMECommand(String action, Bundle data)
Called by the framework in response to a private command from the current method, provided by it calling InputConnection.performPrivateCommand().
void onRestoreInstanceState(Parcelable state)
Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().
void onRtlPropertiesChanged(int layoutDirection)
Called when any RTL property (layout direction or text direction or text alignment) has been changed.
Parcelable onSaveInstanceState()
Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state.
void onScreenStateChanged(int screenState)
This method is called whenever the state of the screen this view is attached to changes.
void onStartTemporaryDetach()
This is called when a container is going to temporarily detach a child, with ViewGroup.detachViewFromParent.
boolean onTextContextMenuItem(int id)
Called when a context menu option for the text view is selected.
boolean onTouchEvent(MotionEvent event)
Implement this method to handle touch screen motion events.
boolean onTrackballEvent(MotionEvent event)
Implement this method to handle trackball motion events.
void onWindowFocusChanged(boolean hasWindowFocus)
Called when the window containing this view gains or loses focus.
boolean performAccessibilityAction(int action, Bundle arguments)
Performs the specified accessibility action on the view.
boolean performLongClick()
Call this view's OnLongClickListener, if it is defined.
void removeTextChangedListener(TextWatcher watcher)
Removes the specified TextWatcher from the list of those whose methods are called whenever this TextView's text changes.
void sendAccessibilityEvent(int eventType)
Sends an accessibility event of the given type.
void setAllCaps(boolean allCaps)
Sets the properties of this field to transform input to ALL CAPS display.
final void setAutoLinkMask(int mask)
Sets the autolink mask of the text.
void setCompoundDrawablePadding(int pad)
Sets the size of the padding between the compound drawables and the text.
void setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom)
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.
void setCompoundDrawablesRelative(Drawable start, Drawable top, Drawable end, Drawable bottom)
Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text.
void setCompoundDrawablesRelativeWithIntrinsicBounds(Drawable start, Drawable top, Drawable end, Drawable bottom)
Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text.
void setCompoundDrawablesRelativeWithIntrinsicBounds(int start, int top, int end, int bottom)
Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text.
void setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom)
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.
void setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom)
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.
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.
final void setEditableFactory(Editable.Factory factory)
Sets the Factory used to create new Editables.
void setEllipsize(TextUtils.TruncateAt where)
Causes words in the text that are longer than the view is wide to be ellipsized instead of broken in the middle.
void setEms(int ems)
Makes the TextView exactly this many ems wide
void setEnabled(boolean enabled)
Set the enabled state of this view.
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 setExtractedText(ExtractedText text)
Apply to this text view the given extracted text, as previously returned by extractText(ExtractedTextRequest, ExtractedText).
void setFilters(InputFilter[] filters)
Sets the list of input filters that will be used if the buffer is Editable.
void setFreezesText(boolean freezesText)
Control whether this text view saves its entire text contents when freezing to an icicle, in addition to dynamic state such as cursor position.
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)
Makes the TextView exactly this many pixels tall.
void setHighlightColor(int color)
Sets the color used to display the selection highlight.
final void setHint(CharSequence hint)
Sets the text to be displayed when the text of the TextView is empty.
final void setHint(int resid)
Sets the text to be displayed when the text of the TextView is empty, from a resource.
final void setHintTextColor(ColorStateList colors)
Sets the color of the hint text.
final void setHintTextColor(int color)
Sets the color of the hint text for all the states (disabled, focussed, selected...) of this TextView.
void setHorizontallyScrolling(boolean whether)
Sets whether the text should be allowed to be wider than the View is.
void setImeActionLabel(CharSequence label, int actionId)
Change the custom IME action associated with the text view, which will be reported to an IME with actionLabel and actionId when it has focus.
void setImeOptions(int imeOptions)
Change the editor type integer associated with the text view, which will be reported to an IME with 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 setInputExtras(int xmlResId)
Set the extra input data of the text, which is the TextBoxAttribute.extras Bundle that will be filled in when creating an input connection.
void setInputType(int type)
Set the type of the content with a constant as defined for inputType.
void setKeyListener(KeyListener input)
Sets the key listener to be used with this TextView.
void setLineSpacing(float add, float mult)
Sets line spacing for this TextView.
void setLines(int lines)
Makes the TextView exactly this many lines tall.
final void setLinkTextColor(ColorStateList colors)
Sets the color of links in the text.
final void setLinkTextColor(int color)
Sets the color of links in the text.
final void setLinksClickable(boolean whether)
Sets whether the movement method will automatically be set to LinkMovementMethod if setAutoLinkMask(int) has been set to nonzero and links are detected in setText(char[], int, int).
void setMarqueeRepeatLimit(int marqueeLimit)
Sets how many times to repeat the marquee animation.
void setMaxEms(int maxems)
Makes the TextView at most this many ems wide
void setMaxHeight(int maxHeight)
Makes the TextView at most this many pixels tall.
void setMaxLines(int maxlines)
Makes the TextView at most this many lines tall.
void setMaxWidth(int maxpixels)
Makes the TextView at most this many pixels wide
void setMinEms(int minems)
Makes the TextView at least this many ems wide
void setMinHeight(int minHeight)
Makes the TextView at least this many pixels tall.
void setMinLines(int minlines)
Makes the TextView at least this many lines tall.
void setMinWidth(int minpixels)
Makes the TextView at least this many pixels wide
final void setMovementMethod(MovementMethod movement)
Sets the movement method (arrow key handler) to be used for this TextView.
void setOnEditorActionListener(TextView.OnEditorActionListener l)
Set a special listener to be called when an action is performed on the text view.
void setPadding(int left, int top, int right, int bottom)
Sets the padding.
void setPaddingRelative(int start, int top, int end, int bottom)
Sets the relative padding.
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 setPrivateImeOptions(String type)
Set the private content type of the text, which is the EditorInfo.privateImeOptions field that will be filled in when creating an input connection.
void setRawInputType(int type)
Directly change the content type integer of the text view, without modifying any other state.
void setScroller(Scroller s)
void setSelectAllOnFocus(boolean selectAllOnFocus)
Set the TextView so that when it takes focus, all the text is selected.
void setSelected(boolean selected)
Changes the selection state of this view.
void setShadowLayer(float radius, float dx, float dy, int color)
Gives the text a shadow of the specified radius and color, the specified distance from its normal position.
void setSingleLine()
Sets the properties of this field (lines, horizontally scrolling, transformation method) to be for a single-line input.
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.
final void setSpannableFactory(Spannable.Factory factory)
Sets the Factory used to create new Spannables.
final void setText(int resid)
final void setText(char[] text, int start, int len)
Sets the TextView to display the specified slice of the specified char array.
final void setText(int resid, TextView.BufferType type)
final void setText(CharSequence text)
Sets the string value of the TextView.
void setText(CharSequence text, TextView.BufferType type)
Sets the text that this TextView is to display (see setText(CharSequence)) and also sets whether it is stored in a styleable/spannable buffer and whether it is editable.
void setTextAppearance(Context context, int resid)
Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.
void setTextColor(ColorStateList colors)
Sets the text color.
void setTextColor(int color)
Sets the text color for all the states (normal, selected, focused) to be this color.
void setTextIsSelectable(boolean selectable)
Sets whether the content of this view is selectable by the user.
final void setTextKeepState(CharSequence text)
Like setText(CharSequence), except that the cursor position (if any) is retained in the new text.
final void setTextKeepState(CharSequence text, TextView.BufferType type)
Like setText(CharSequence, android.widget.TextView.BufferType), except that the cursor position (if any) is retained in the new text.
void setTextLocale(Locale locale)
Set the default Locale of the text in this TextView to the given value.
void setTextScaleX(float size)
Sets the extent by which text should be stretched horizontally.
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.
final void setTransformationMethod(TransformationMethod method)
Sets the transformation that is applied to the text that this TextView is displaying.
void setTypeface(Typeface tf, 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(Typeface tf)
Sets the typeface and style in which the text should be displayed.
void setWidth(int pixels)
Makes the TextView exactly this many pixels wide.
Protected Methods
int computeHorizontalScrollRange()

Compute the horizontal range that the horizontal scrollbar represents.

int computeVerticalScrollExtent()

Compute the vertical extent of the horizontal scrollbar's thumb within the vertical range.

int computeVerticalScrollRange()

Compute the vertical range that the vertical scrollbar represents.

void drawableStateChanged()
This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.
int getBottomPaddingOffset()
Amount by which to extend the bottom fading region.
boolean getDefaultEditable()
Subclasses override this to specify that they have a KeyListener by default even if not specifically called for in the XML options.
MovementMethod getDefaultMovementMethod()
Subclasses override this to specify a default movement method.
float getLeftFadingEdgeStrength()
Returns the strength, or intensity, of the left faded edge.
int getLeftPaddingOffset()
Amount by which to extend the left fading region.
float getRightFadingEdgeStrength()
Returns the strength, or intensity, of the right faded edge.
int getRightPaddingOffset()
Amount by which to extend the right fading region.
int getTopPaddingOffset()
Amount by which to extend the top fading region.
boolean isPaddingOffsetRequired()
If the View draws content inside its padding and enables fading edges, it needs to support padding offsets.
void onAttachedToWindow()
This is called when the view is attached to a window.
int[] onCreateDrawableState(int extraSpace)
Generate the new Drawable state for this view.
void onDetachedFromWindow()
This is called when the view is detached from a window.
void onDraw(Canvas canvas)
Implement this to do your drawing.
void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect)
Called by the view system when the focus state of this view changes.
void onLayout(boolean changed, int left, int top, int right, int bottom)
Called from layout when this view should assign a size and position to each of its children.
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert)
This is called in response to an internal scroll in this view (i.e., the view scrolled its own contents).
void onSelectionChanged(int selStart, int selEnd)
This method is called when the selection has changed, in case any subclasses would like to know.
void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter)
This method is called when the text is changed, in case any subclasses would like to know.
void onVisibilityChanged(View changedView, int visibility)
Called when the visibility of the view or an ancestor of the view is changed.
boolean setFrame(int l, int t, int r, int b)
Assign a size and position to this view.
boolean verifyDrawable(Drawable who)
If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying.
[Expand]
Inherited Methods
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewTreeObserver.OnPreDrawListener
From interface android.view.accessibility.AccessibilityEventSource

XML Attributes

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.

ConstantValueDescription
none0x00 Match no patterns (default).
web0x01 Match Web URLs.
email0x02 Match email addresses.
phone0x04 Match phone numbers.
map0x08 Match map addresses.
all0x0f Match all patterns (equivalent to web|email|phone|map).

This corresponds to the global attribute resource symbol autoLink.

Related Methods

android:autoText

If set, specifies that this TextView has a textual input method and automatically corrects some common spelling errors. The default is "false".

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol autoText.

Related Methods

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.

ConstantValueDescription
normal0 Can return any CharSequence, possibly a Spanned one if the source text was Spanned.
spannable1 Can only return Spannable.
editable2 Can only return Spannable and Editable.

This corresponds to the global attribute resource symbol bufferType.

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".

Must be one of the following constant values.

ConstantValueDescription
none0 Don't automatically capitalize anything.
sentences1 Capitalize the first word of each sentence.
words2 Capitalize the first letter of every word.
characters3 Capitalize every character.

This corresponds to the global attribute resource symbol capitalize.

Related Methods

android:cursorVisible

Makes the cursor visible (the default) or invisible.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol cursorVisible.

Related Methods

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.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol digits.

Related Methods

android:drawableBottom

The drawable to be drawn below the text.

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

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

This corresponds to the global attribute resource symbol drawableBottom.

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 to a theme attribute in the form "?[package:][type:]name".

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

This corresponds to the global attribute resource symbol drawableEnd.

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 to a theme attribute in the form "?[package:][type:]name".

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

This corresponds to the global attribute resource symbol drawableLeft.

android:drawablePadding

The padding between the drawables and the text.

Must 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), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol drawablePadding.

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 to a theme attribute in the form "?[package:][type:]name".

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

This corresponds to the global attribute resource symbol drawableRight.

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 to a theme attribute in the form "?[package:][type:]name".

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

This corresponds to the global attribute resource symbol drawableStart.

android:drawableTop

The drawable to be drawn above the text.

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

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

This corresponds to the global attribute resource symbol drawableTop.

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.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol editable.

Related Methods

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.

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

This corresponds to the global attribute resource symbol editorExtras.

Related Methods

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.

ConstantValueDescription
none0
start1
middle2
end3
marquee4

This corresponds to the global attribute resource symbol ellipsize.

android:ems

Makes the TextView be exactly this many ems wide.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol ems.

Related Methods

android:fontFamily

Font family (named by string) for the text.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol fontFamily.

Related Methods

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.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol freezesText.

Related Methods

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.

ConstantValueDescription
top0x30 Push object to the top of its container, not changing its size.
bottom0x50 Push object to the bottom of its container, not changing its size.
left0x03 Push object to the left of its container, not changing its size.
right0x05 Push object to the right of its container, not changing its size.
center_vertical0x10 Place object in the vertical center of its container, not changing its size.
fill_vertical0x70 Grow the vertical size of the object if needed so it completely fills its container.
center_horizontal0x01 Place object in the horizontal center of its container, not changing its size.
fill_horizontal0x07 Grow the horizontal size of the object if needed so it completely fills its container.
center0x11 Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
fill0x77 Grow the horizontal and vertical size of the object if needed so it completely fills its container.
clip_vertical0x80 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.
clip_horizontal0x08 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.
start0x00800003 Push object to the beginning of its container, not changing its size.
end0x00800005 Push object to the end of its container, not changing its size.

This corresponds to the global attribute resource symbol gravity.

Related Methods

android:height

Makes the TextView be exactly this many pixels tall. You could get the same effect by specifying this number in the layout parameters.

Must 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), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol height.

Related Methods

android:hint

Hint text to display when the text is empty.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol hint.

Related Methods

android:imeActionId

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

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol imeActionId.

android:imeActionLabel

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

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol imeActionLabel.

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 imeOptions.

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

ConstantValueDescription
normal0x00000000 There are no special semantics associated with this editor.
actionUnspecified0x00000000 There is no specific action associated with this editor, let the editor come up with its own if it can. Corresponds to IME_NULL.
actionNone0x00000001 This editor has no action associated with it. Corresponds to IME_ACTION_NONE.
actionGo0x00000002 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 IME_ACTION_GO.
actionSearch0x00000003 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 IME_ACTION_SEARCH.
actionSend0x00000004 The action key performs a "send" operation, delivering the text to its target. This is typically used when composing a message. Corresponds to IME_ACTION_SEND.
actionNext0x00000005 The action key performs a "next" operation, taking the user to the next field that will accept text. Corresponds to IME_ACTION_NEXT.
actionDone0x00000006 The action key performs a "done" operation, closing the soft input method. Corresponds to IME_ACTION_DONE.
actionPrevious0x00000007 The action key performs a "previous" operation, taking the user to the previous field that will accept text. Corresponds to IME_ACTION_PREVIOUS.
flagNoFullscreen0x2000000 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 IME_FLAG_NO_FULLSCREEN.

flagNavigatePrevious0x4000000 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 IME_FLAG_NO_FULLSCREEN.

flagNavigateNext0x8000000 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 IME_FLAG_NAVIGATE_NEXT.

flagNoExtractUi0x10000000 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 IME_FLAG_NO_EXTRACT_UI.

flagNoAccessoryAction0x20000000 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 IME_FLAG_NO_ACCESSORY_ACTION.

flagNoEnterAction0x40000000 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 TextView will automatically set this flag for you on multi-line text views.

Corresponds to IME_FLAG_NO_ENTER_ACTION.

flagForceAscii0x80000000 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 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 languagaes 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 IME_FLAG_FORCE_ASCII.

This corresponds to the global attribute resource symbol imeOptions.

Related Methods

android:includeFontPadding

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

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol includeFontPadding.

android:inputMethod

If set, specifies that this TextView should use the specified input method (specified by fully-qualified class name).

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol inputMethod.

Related Methods

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 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.

ConstantValueDescription
none0x00000000 There is no content type. The text is not editable.
text0x00000001 Just plain old text. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_NORMAL.
textCapCharacters0x00001001 Can be combined with text and its variations to request capitalization of all characters. Corresponds to TYPE_TEXT_FLAG_CAP_CHARACTERS.
textCapWords0x00002001 Can be combined with text and its variations to request capitalization of the first character of every word. Corresponds to TYPE_TEXT_FLAG_CAP_WORDS.
textCapSentences0x00004001 Can be combined with text and its variations to request capitalization of the first character of every sentence. Corresponds to TYPE_TEXT_FLAG_CAP_SENTENCES.
textAutoCorrect0x00008001 Can be combined with text and its variations to request auto-correction of text being input. Corresponds to TYPE_TEXT_FLAG_AUTO_CORRECT.
textAutoComplete0x00010001 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 TYPE_TEXT_FLAG_AUTO_COMPLETE.
textMultiLine0x00020001 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 TYPE_TEXT_FLAG_MULTI_LINE.
textImeMultiLine0x00040001 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 TYPE_TEXT_FLAG_IME_MULTI_LINE.
textNoSuggestions0x00080001 Can be combined with text and its variations to indicate that the IME should not show any dictionary-based word suggestions. Corresponds to TYPE_TEXT_FLAG_NO_SUGGESTIONS.
textUri0x00000011 Text that will be used as a URI. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_URI.
textEmailAddress0x00000021 Text that will be used as an e-mail address. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS.
textEmailSubject0x00000031 Text that is being supplied as the subject of an e-mail. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_SUBJECT.
textShortMessage0x00000041 Text that is the content of a short message. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_SHORT_MESSAGE.
textLongMessage0x00000051 Text that is the content of a long message. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_LONG_MESSAGE.
textPersonName0x00000061 Text that is the name of a person. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PERSON_NAME.
textPostalAddress0x00000071 Text that is being supplied as a postal mailing address. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_POSTAL_ADDRESS.
textPassword0x00000081 Text that is a password. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD.
textVisiblePassword0x00000091 Text that is a password that should be visible. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD.
textWebEditText0x000000a1 Text that is being supplied as text in a web form. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_EDIT_TEXT.
textFilter0x000000b1 Text that is filtering some other data. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_FILTER.
textPhonetic0x000000c1 Text that is for phonetic pronunciation, such as a phonetic name field in a contact entry. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PHONETIC.
textWebEmailAddress0x000000d1 Text that will be used as an e-mail address on a web form. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS.
textWebPassword0x000000e1 Text that will be used as a password on a web form. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_PASSWORD.
number0x00000002 A numeric only field. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_NORMAL.
numberSigned0x00001002 Can be combined with number and its other options to allow a signed number. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_FLAG_SIGNED.
numberDecimal0x00002002 Can be combined with number and its other options to allow a decimal (fractional) number. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_FLAG_DECIMAL.
numberPassword0x00000012 A numeric password field. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_PASSWORD.
phone0x00000003 For entering a phone number. Corresponds to TYPE_CLASS_PHONE.
datetime0x00000004 For entering a date and time. Corresponds to TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_NORMAL.
date0x00000014 For entering a date. Corresponds to TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_DATE.
time0x00000024 For entering a time. Corresponds to TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_TIME.

This corresponds to the global attribute resource symbol inputType.

Related Methods

android:lineSpacingExtra

Extra spacing between lines of text.

Must 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), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol lineSpacingExtra.

Related Methods

android:lineSpacingMultiplier

Extra spacing between lines of text, as a multiplier.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol lineSpacingMultiplier.

Related Methods

android:lines

Makes the TextView be exactly this many lines tall.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol lines.

Related Methods

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.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol linksClickable.

Related Methods

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".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

May be one of the following constant values.

ConstantValueDescription
marquee_forever-1 Indicates that marquee should repeat indefinitely.

This corresponds to the global attribute resource symbol marqueeRepeatLimit.

Related Methods

android:maxEms

Makes the TextView be at most this many ems wide.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol maxEms.

Related Methods

android:maxHeight

Makes the TextView be at most this many pixels tall.

Must 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), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol maxHeight.

Related Methods

android:maxLength

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

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol maxLength.

Related Methods

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.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol maxLines.

Related Methods

android:maxWidth

Makes the TextView be at most this many pixels wide.

Must 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), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol maxWidth.

Related Methods

android:minEms

Makes the TextView be at least this many ems wide.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol minEms.

Related Methods

android:minHeight

Makes the TextView be at least this many pixels tall.

Must 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), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol minHeight.

Related Methods

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.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol minLines.

Related Methods

android:minWidth

Makes the TextView be at least this many pixels wide.

Must 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), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol minWidth.

Related Methods

android:numeric

If set, specifies that this TextView has a numeric input method. The default is false.

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

ConstantValueDescription
integer0x01 Input is numeric.
signed0x03 Input is numeric, with sign allowed.
decimal0x05 Input is numeric, with decimals allowed.

This corresponds to the global attribute resource symbol numeric.

Related Methods

android:password

Whether the characters of the field are displayed as password dots instead of themselves.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol password.

android:phoneNumber

If set, specifies that this TextView has a phone number input method. The default is false.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol phoneNumber.

Related Methods

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.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol privateImeOptions.

android:scrollHorizontally

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

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollHorizontally.

android:selectAllOnFocus

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

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol selectAllOnFocus.

android:shadowColor

Place a shadow of the specified color behind the text.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol shadowColor.

android:shadowDx

Horizontal offset of the shadow.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol shadowDx.

android:shadowDy

Vertical offset of the shadow.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol shadowDy.

android:shadowRadius

Radius of the shadow.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol shadowRadius.

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).

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol singleLine.

android:text

Text to display.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol text.

android:textAllCaps

Present the text in ALL CAPS. This may use a small-caps form when available.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol textAllCaps.

Related Methods

android:textAppearance

Base text color, typeface, size, and style.

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

This corresponds to the global attribute resource symbol textAppearance.

Related Methods

android:textColor

Text color.

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

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

This corresponds to the global attribute resource symbol textColor.

Related Methods

android:textColorHighlight

Color of the text selection highlight.

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

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

This corresponds to the global attribute resource symbol textColorHighlight.

Related Methods

android:textColorHint

Color of the hint text.

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

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

This corresponds to the global attribute resource symbol textColorHint.

Related Methods

android:textColorLink

Text color for links.

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

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

This corresponds to the global attribute resource symbol textColorLink.

Related Methods

android:textIsSelectable

Indicates that the content of a non-editable text can be selected.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol textIsSelectable.

Related Methods

android:textScaleX

Sets the horizontal scaling factor for the text.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol textScaleX.

Related Methods

android:textSize

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

Must 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), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol textSize.

Related Methods

android:textStyle

Style (bold, italic, bolditalic) for the text.

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

ConstantValueDescription
normal0
bold1
italic2

This corresponds to the global attribute resource symbol textStyle.

Related Methods

android:typeface

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

Must be one of the following constant values.

ConstantValueDescription
normal0
sans1
serif2
monospace3

This corresponds to the global attribute resource symbol typeface.

Related Methods

android:width

Makes the TextView be exactly this many pixels wide. You could get the same effect by specifying this number in the layout parameters.

Must 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), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol width.

Related Methods

Public Constructors

public TextView (Context context)

Added in API level 1

public TextView (Context context, AttributeSet attrs)

Added in API level 1

public TextView (Context context, AttributeSet attrs, int defStyle)

Added in API level 1

Public Methods

public void addTextChangedListener (TextWatcher watcher)

Added in API level 1

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

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

public final void append (CharSequence text)

Added in API level 1

Convenience method: Append the specified text to the TextView's display buffer, upgrading it to BufferType.EDITABLE if it was not already editable.

public void append (CharSequence text, int start, int end)

Added in API level 1

Convenience method: Append the specified text slice to the TextView's display buffer, upgrading it to BufferType.EDITABLE if it was not already editable.

public void beginBatchEdit ()

Added in API level 3

public boolean bringPointIntoView (int offset)

Added in API level 3

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.

public void cancelLongPress ()

Added in API level 1

Cancels a pending long press. Your subclass can use this if you want the context menu to come up if the user presses and holds at the same place, but you don't want it to come up if they press and then move around enough to cause scrolling.

public void clearComposingText ()

Added in API level 3

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

public void computeScroll ()

Added in API level 1

Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary. This will typically be done if the child is animating a scroll using a Scroller object.

public void debug (int depth)

Added in API level 1

Prints information about this view in the log output, with the tag VIEW_LOG_TAG. Each line in the output is preceded with an indentation defined by the depth.

Parameters
depth the indentation level

public boolean didTouchFocusSelect ()

Added in API level 3

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.

public void endBatchEdit ()

Added in API level 3

public boolean extractText (ExtractedTextRequest request, ExtractedText outText)

Added in API level 3

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

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

public void findViewsWithText (ArrayList<View> outViews, CharSequence searched, int flags)

Added in API level 14

Finds the Views that contain given text. The containment is case insensitive. The search is performed by either the text that the View renders or the content description that describes the view for accessibility purposes and the view does not render or both. Clients can specify how the search is to be performed via passing the FIND_VIEWS_WITH_TEXT and FIND_VIEWS_WITH_CONTENT_DESCRIPTION flags.

Parameters
outViews The output list of matching Views.
searched The text to match against.

public final int getAutoLinkMask ()

Added in API level 1

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

Related XML Attributes

public int getBaseline ()

Added in API level 1

Return the offset of the widget's text baseline from the widget's top boundary. If this widget does not support baseline alignment, this method returns -1.

Returns
  • the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported

public int getCompoundDrawablePadding ()

Added in API level 1

Returns the padding between the compound drawables and the text.

Related XML Attributes

public Drawable[] getCompoundDrawables ()

Added in API level 1

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

public Drawable[] getCompoundDrawablesRelative ()

Added in API level 17

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

public int getCompoundPaddingBottom ()

Added in API level 1

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

public int getCompoundPaddingEnd ()

Added in API level 17

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

public int getCompoundPaddingLeft ()

Added in API level 1

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

public int getCompoundPaddingRight ()

Added in API level 1

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

public int getCompoundPaddingStart ()

Added in API level 17

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

public int getCompoundPaddingTop ()

Added in API level 1

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

public final int getCurrentHintTextColor ()

Added in API level 1

Return the current color selected to paint the hint text.

Returns
  • Returns the current hint text color.

public final int getCurrentTextColor ()

Added in API level 1

Return the current color selected for normal text.

Returns
  • Returns the current text color.

public ActionMode.Callback getCustomSelectionActionModeCallback ()

Added in API level 11

Retrieves the value set in setCustomSelectionActionModeCallback(ActionMode.Callback). Default is null.

Returns
  • The current custom selection callback.

public Editable getEditableText ()

Added in API level 3

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

See Also

public TextUtils.TruncateAt getEllipsize ()

Added in API level 1

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

public CharSequence getError ()

Added in API level 1

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

public int getExtendedPaddingBottom ()

Added in API level 1

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.

public int getExtendedPaddingTop ()

Added in API level 1

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.

public InputFilter[] getFilters ()

Added in API level 1

Returns the current list of input filters.

Related XML Attributes

public void getFocusedRect (Rect r)

Added in API level 1

When a view has focus and the user navigates away from it, the next view is searched for starting from the rectangle filled in by this method. By default, the rectangle is the getDrawingRect(android.graphics.Rect)) of the view. However, if your view maintains some idea of internal selection, such as a cursor, or a selected row or column, you should override this method and fill in a more specific rectangle.

Parameters
r The rectangle to fill in, in this view's coordinates.

public boolean getFreezesText ()

Added in API level 1

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

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

public int getGravity ()

Added in API level 1

Returns the horizontal and vertical alignment of this TextView.

Related XML Attributes
See Also

public int getHighlightColor ()

Added in API level 16

Related XML Attributes
Returns
  • the color used to display the selection highlight

public CharSequence getHint ()

Added in API level 1

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

Related XML Attributes

public final ColorStateList getHintTextColors ()

Added in API level 1

Related XML Attributes
Returns
  • the color of the hint text, for the different states of this TextView.

public int getImeActionId ()

Added in API level 3

public CharSequence getImeActionLabel ()

Added in API level 3

Get the IME action label previous set with setImeActionLabel(CharSequence, int).

public int getImeOptions ()

Added in API level 3

Get the type of the IME editor.

public boolean getIncludeFontPadding ()

Added in API level 16

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

Related XML Attributes

public Bundle getInputExtras (boolean create)

Added in API level 3

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

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

public int getInputType ()

Added in API level 3

Get the type of the editable content.

public final KeyListener getKeyListener ()

Added in API level 1

Returns
  • the current key listener for this TextView. This will frequently be null for non-EditText TextViews.

public final Layout getLayout ()

Added in API level 1

Returns
  • the Layout that is currently being used to display the text. This can be null if the text or width has recently changes.

public int getLineBounds (int line, Rect bounds)

Added in API level 1

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 which line to examine (0..getLineCount() - 1)
bounds Optional. If not null, it returns the extent of the line
Returns
  • the Y-coordinate of the baseline

public int getLineCount ()

Added in API level 1

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

public int getLineHeight ()

Added in API level 1

Returns
  • the height of one standard line 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.

public float getLineSpacingExtra ()

Added in API level 16

Gets the line spacing extra space

Related XML Attributes
Returns
  • the extra space that is added to the height of each lines of this TextView.

public float getLineSpacingMultiplier ()

Added in API level 16

Gets the line spacing multiplier

Related XML Attributes
Returns
  • the value by which each line's height is multiplied to get its actual height.

public final ColorStateList getLinkTextColors ()

Added in API level 1

Related XML Attributes
Returns
  • the list of colors used to paint the links in the text, for the different states of this TextView

public final boolean getLinksClickable ()

Added in API level 1

Returns whether the movement method will automatically be set to LinkMovementMethod if setAutoLinkMask(int) has been set to nonzero and links are detected in setText(char[], int, int). The default is true.

Related XML Attributes

public int getMarqueeRepeatLimit ()

Added in API level 16

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

Related XML Attributes
Returns
  • the number of times the marquee animation is repeated. -1 if the animation repeats indefinitely

public int getMaxEms ()

Added in API level 16

Related XML Attributes
Returns
  • the maximum width of the TextView, expressed in ems or -1 if the maximum width was set in pixels instead (using setMaxWidth(int) or setWidth(int)).

public int getMaxHeight ()

Added in API level 16

Related XML Attributes
Returns
  • the maximum height of this TextView expressed in pixels, or -1 if the maximum height was set in number of lines instead using or #setLines(int).

public int getMaxLines ()

Added in API level 16

Related XML Attributes
Returns
  • the maximum number of lines displayed in this TextView, or -1 if the maximum height was set in pixels instead using or #setHeight(int).
See Also

public int getMaxWidth ()

Added in API level 16

Related XML Attributes
Returns
  • the maximum width of the TextView, in pixels or -1 if the maximum width was set in ems instead (using setMaxEms(int) or setEms(int)).

public int getMinEms ()

Added in API level 16

Related XML Attributes
Returns
  • the minimum width of the TextView, expressed in ems or -1 if the minimum width was set in pixels instead (using setMinWidth(int) or setWidth(int)).

public int getMinHeight ()

Added in API level 16

Related XML Attributes
Returns
  • the minimum height of this TextView expressed in pixels, or -1 if the minimum height was set in number of lines instead using or #setLines(int).

public int getMinLines ()

Added in API level 16

Related XML Attributes
Returns
  • the minimum number of lines displayed in this TextView, or -1 if the minimum height was set in pixels instead using or #setHeight(int).
See Also

public int getMinWidth ()

Added in API level 16

Related XML Attributes
Returns
  • the minimum width of the TextView, in pixels or -1 if the minimum width was set in ems instead (using setMinEms(int) or setEms(int)).

public final MovementMethod getMovementMethod ()

Added in API level 1

Returns
  • the movement method being used for this TextView. This will frequently be null for non-EditText TextViews.

public int getOffsetForPosition (float x, float y)

Added in API level 14

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

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

public TextPaint getPaint ()

Added in API level 1

Returns
  • the base paint used for the text. Please use this only to consult the Paint's properties and not to change them.

public int getPaintFlags ()

Added in API level 1

Returns
  • the flags on the Paint being used to display the text.
See Also

public String getPrivateImeOptions ()

Added in API level 3

Get the private type of the content.

public int getSelectionEnd ()

Added in API level 1

public int getSelectionStart ()

Added in API level 1

public int getShadowColor ()

Added in API level 16

Related XML Attributes
Returns
  • the color of the shadow layer

public float getShadowDx ()

Added in API level 16

Related XML Attributes
Returns
  • the horizontal offset of the shadow layer

public float getShadowDy ()

Added in API level 16

Related XML Attributes
Returns
  • the vertical offset of the shadow layer

public float getShadowRadius ()

Added in API level 16

Gets the radius of the shadow layer.

Related XML Attributes
Returns
  • the radius of the shadow layer. If 0, the shadow layer is not visible

public CharSequence getText ()

Added in API level 1

Return the text the TextView is displaying. If setText() 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. Note: The content of the return value should not be modified. If you want a modifiable one, you should make your own copy first.

Related XML Attributes

public static int getTextColor (Context context, TypedArray attrs, int def)

Added in API level 1

Returns the default color from the TextView_textColor attribute from the AttributeSet, if set, or the default color from the TextAppearance_textColor from the TextView_textAppearance attribute, if TextView_textColor was not set directly.

public final ColorStateList getTextColors ()

Added in API level 1

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

Related XML Attributes

public static ColorStateList getTextColors (Context context, TypedArray attrs)

Added in API level 1

Returns the TextView_textColor attribute from the TypedArray, if set, or the TextAppearance_textColor from the TextView_textAppearance attribute, if TextView_textColor was not set directly.

public Locale getTextLocale ()

Added in API level 17

Get the default Locale of the text in this TextView.

Returns
  • the default Locale of the text in this TextView.

public float getTextScaleX ()

Added in API level 1

Returns
  • the extent by which text is currently being stretched horizontally. This will usually be 1.

public float getTextSize ()

Added in API level 1

Returns
  • the size (in pixels) of the default text size in this TextView.

public int getTotalPaddingBottom ()

Added in API level 1

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.

public int getTotalPaddingEnd ()

Added in API level 17

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

public int getTotalPaddingLeft ()

Added in API level 1

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

public int getTotalPaddingRight ()

Added in API level 1

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

public int getTotalPaddingStart ()

Added in API level 17

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

public int getTotalPaddingTop ()

Added in API level 1

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.

public final TransformationMethod getTransformationMethod ()

Added in API level 1

Related XML Attributes
Returns
  • the current transformation method for this TextView. This will frequently be null except for single-line and password fields.

public Typeface getTypeface ()

Added in API level 1

Returns
  • the current typeface and style in which the text is being displayed.

public URLSpan[] getUrls ()

Added in API level 1

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

public boolean hasOverlappingRendering ()

Added in API level 16

Returns whether this View has content which overlaps.

This function, intended to be overridden by specific View types, is an optimization when alpha is set on a view. If rendering overlaps in a view with alpha < 1, that view is drawn to an offscreen buffer and then composited into place, which can be expensive. If the view has no overlapping rendering, the view can draw each primitive with the appropriate alpha value directly. An example of overlapping rendering is a TextView with a background image, such as a Button. An example of non-overlapping rendering is a TextView with no background, or an ImageView with only the foreground image. The default implementation returns true; subclasses should override if they have cases which can be optimized.

The current implementation of the saveLayer and saveLayerAlpha methods in Canvas necessitates that a View return true if it uses the methods internally without passing the CLIP_TO_LAYER_SAVE_FLAG.

Returns
  • true if the content in this view might overlap, false otherwise.

public boolean hasSelection ()

Added in API level 1

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

public void invalidateDrawable (Drawable drawable)

Added in API level 1

Invalidates the specified Drawable.

Parameters
drawable the drawable to invalidate

public boolean isCursorVisible ()

Added in API level 16

Related XML Attributes
Returns
  • whether or not the cursor is visible (assuming this TextView is editable)

public boolean isInputMethodTarget ()

Added in API level 3

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

public boolean isSuggestionsEnabled ()

Added in API level 14

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 TYPE_CLASS_TEXT. In addition, the type variation must be one of TYPE_TEXT_VARIATION_NORMAL, TYPE_TEXT_VARIATION_EMAIL_SUBJECT, TYPE_TEXT_VARIATION_LONG_MESSAGE, TYPE_TEXT_VARIATION_SHORT_MESSAGE or TYPE_TEXT_VARIATION_WEB_EDIT_TEXT. And finally, the TYPE_TEXT_FLAG_NO_SUGGESTIONS flag must not be set.

Returns
  • true if the suggestions popup window is enabled, based on the inputType.

public boolean isTextSelectable ()

Added in API level 11

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.

Related XML Attributes
Returns
  • True if the text displayed in this TextView can be selected by the user.

public void jumpDrawablesToCurrentState ()

Added in API level 11

Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

public int length ()

Added in API level 1

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

public boolean moveCursorToVisibleOffset ()

Added in API level 3

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.

Returns
  • True if the cursor was actually moved, false otherwise.

public void onBeginBatchEdit ()

Added in API level 3

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

public boolean onCheckIsTextEditor ()

Added in API level 3

Check whether the called view is a text editor, in which case it would make sense to automatically display a soft input window for it. Subclasses should override this if they implement onCreateInputConnection(EditorInfo) to return true if a call on that method would return a non-null InputConnection, and they are really a first-class editor that the user would normally start typing on when the go into a window containing your view.

The default implementation always returns false. This does not mean that its onCreateInputConnection(EditorInfo) will not be called or the user can not otherwise perform edits on your view; it is just a hint to the system that this is not the primary purpose of this view.

Returns
  • Returns true if this view is a text editor, else false.

public void onCommitCompletion (CompletionInfo text)

Added in API level 3

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 The auto complete text the user has selected.

public void onCommitCorrection (CorrectionInfo info)

Added in API level 11

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

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

public InputConnection onCreateInputConnection (EditorInfo outAttrs)

Added in API level 3

Create a new InputConnection for an InputMethod to interact with the view. The default implementation returns null, since it doesn't support input methods. You can override this to implement such support. This is only needed for views that take focus and text input.

When implementing this, you probably also want to implement onCheckIsTextEditor() to indicate you will return a non-null InputConnection.

Parameters
outAttrs Fill in with attribute information about the connection.

public boolean onDragEvent (DragEvent event)

Added in API level 11

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

When the system calls this method, it passes a DragEvent object. A call to getAction() returns one of the action type constants defined in DragEvent. The method uses these to determine what is happening in the drag and drop operation.

Parameters
event The DragEvent sent by the system. The getAction() method returns an action type constant defined in DragEvent, indicating the type of drag event represented by this object.
Returns
  • true if the method was successful, otherwise false.

    The method should return true in response to an action type of ACTION_DRAG_STARTED to receive drag events for the current operation.

    The method should also return true in response to an action type of ACTION_DROP if it consumed the drop, or false if it didn't.

public void onEditorAction (int actionCode)

Added in API level 3

Called when an attached input method calls InputConnection.performEditorAction() for this text view. The default implementation will call your action listener supplied to setOnEditorActionListener(TextView.OnEditorActionListener), 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 The code of the action being performed.

public void onEndBatchEdit ()

Added in API level 3

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

public void onFinishTemporaryDetach ()

Added in API level 3

Called after onStartTemporaryDetach() when the container is done changing the view.

public boolean onGenericMotionEvent (MotionEvent event)

Added in API level 12

Implement this method to handle generic motion events.

Generic motion events describe joystick movements, mouse hovers, track pad touches, scroll wheel movements and other input events. The source of the motion event specifies the class of input that was received. Implementations of this method must examine the bits in the source before processing the event. The following code example shows how this is done.

Generic motion events with source class SOURCE_CLASS_POINTER are delivered to the view under the pointer. All other generic motion events are delivered to the focused view.

 public boolean onGenericMotionEvent(MotionEvent event) {
     if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) {
         if (event.getAction() == MotionEvent.ACTION_MOVE) {
             // process the joystick movement...
             return true;
         }
     }
     if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {
         switch (event.getAction()) {
             case MotionEvent.ACTION_HOVER_MOVE:
                 // process the mouse hover movement...
                 return true;
             case MotionEvent.ACTION_SCROLL:
                 // process the scroll wheel movement...
                 return true;
         }
     }
     return super.onGenericMotionEvent(event);
 }

Parameters
event The generic motion event being processed.
Returns
  • True if the event was handled, false otherwise.

public void onInitializeAccessibilityEvent (AccessibilityEvent event)

Added in API level 14

Initializes an AccessibilityEvent with information about this View which is the event source. In other words, the source of an accessibility event is the view whose state change triggered firing the event.

Example: Setting the password property of an event in addition to properties set by the super implementation:

 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     super.onInitializeAccessibilityEvent(event);
     event.setPassword(true);
 }

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.

Parameters
event The event to initialize.

public void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info)

Added in API level 14

Initializes an AccessibilityNodeInfo with information about this view. The base implementation sets:

Subclasses should override this method, call the super implementation, and set additional attributes.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo) is responsible for handling this call.

Parameters
info The instance to initialize.

public boolean onKeyDown (int keyCode, KeyEvent event)

Added in API level 1

Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KEYCODE_DPAD_CENTER or KEYCODE_ENTER is released, if the view is enabled and clickable.

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters
keyCode A key code that represents the button pressed, from KeyEvent.
event The KeyEvent object that defines the button action.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public boolean onKeyMultiple (int keyCode, int repeatCount, KeyEvent event)

Added in API level 1

Default implementation of KeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle the event).

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters
keyCode A key code that represents the button pressed, from KeyEvent.
repeatCount The number of times the action was made.
event The KeyEvent object that defines the button action.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public boolean onKeyPreIme (int keyCode, KeyEvent event)

Added in API level 3

Handle a key event before it is processed by any input method associated with the view hierarchy. This can be used to intercept key events in special situations before the IME consumes them; a typical example would be handling the BACK key to update the application's UI instead of allowing the IME to see it and close itself.

Parameters
keyCode The value in event.getKeyCode().
event Description of the key event.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public boolean onKeyShortcut (int keyCode, KeyEvent event)

Added in API level 1

Called on the focused view when a key shortcut event is not handled. Override this method to implement local key shortcuts for the View. Key shortcuts can also be implemented by setting the shortcut property of menu items.

Parameters
keyCode The value in event.getKeyCode().
event Description of the key event.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public boolean onKeyUp (int keyCode, KeyEvent event)

Added in API level 1

Default implementation of KeyEvent.Callback.onKeyUp(): perform clicking of the view when KEYCODE_DPAD_CENTER or KEYCODE_ENTER is released.

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters
keyCode A key code that represents the button pressed, from KeyEvent.
event The KeyEvent object that defines the button action.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public void onPopulateAccessibilityEvent (AccessibilityEvent event)

Added in API level 14

Called from dispatchPopulateAccessibilityEvent(AccessibilityEvent) giving a chance to this View to populate the accessibility event with its text content. While this method is free to modify event attributes other than text content, doing so should normally be performed in onInitializeAccessibilityEvent(AccessibilityEvent).

Example: Adding formatted date string to an accessibility event in addition to the text added by the super implementation:

 public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
     super.onPopulateAccessibilityEvent(event);
     final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY;
     String selectedDateUtterance = DateUtils.formatDateTime(mContext,
         mCurrentDate.getTimeInMillis(), flags);
     event.getText().add(selectedDateUtterance);
 }

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onPopulateAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.

Parameters
event The accessibility event which to populate.

public boolean onPreDraw ()

Added in API level 1

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.

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

public boolean onPrivateIMECommand (String action, Bundle data)

Added in API level 3

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

Parameters
action The action name of the command.
data Any additional data for the command. This may be null.
Returns
  • Return true if you handled the command, else false.

public void onRestoreInstanceState (Parcelable state)

Added in API level 1

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(). This function will never be called with a null state.

Parameters
state The frozen state that had previously been returned by onSaveInstanceState().

public void onRtlPropertiesChanged (int layoutDirection)

Added in API level 17

Called when any RTL property (layout direction or text direction or text alignment) has been changed. Subclasses need to override this method to take care of cached information that depends on the resolved layout direction, or to inform child views that inherit their layout direction. The default implementation does nothing.

Parameters
layoutDirection the direction of the layout

public Parcelable onSaveInstanceState ()

Added in API level 1

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.

Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.

Returns
  • Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save. The default implementation returns null.

public void onScreenStateChanged (int screenState)

Added in API level 16

This method is called whenever the state of the screen this view is attached to changes. A state change will usually occurs when the screen turns on or off (whether it happens automatically or the user does it manually.)

Parameters
screenState The new state of the screen. Can be either SCREEN_STATE_ON or SCREEN_STATE_OFF

public void onStartTemporaryDetach ()

Added in API level 3

This is called when a container is going to temporarily detach a child, with ViewGroup.detachViewFromParent. It will either be followed by onFinishTemporaryDetach() or onDetachedFromWindow() when the container is done.

public boolean onTextContextMenuItem (int id)

Added in API level 3

Called when a context menu option for the text view is selected. Currently this will be one of selectAll, cut, copy or paste.

Returns
  • true if the context menu item action was performed.

public boolean onTouchEvent (MotionEvent event)

Added in API level 1

Implement this method to handle touch screen motion events.

If this method is used to detect click actions, it is recommended that the actions be performed by implementing and calling performClick(). This will ensure consistent system behavior, including:

  • obeying click sound preferences
  • dispatching OnClickListener calls
  • handling ACTION_CLICK when accessibility features are enabled

Parameters
event The motion event.
Returns
  • True if the event was handled, false otherwise.

public boolean onTrackballEvent (MotionEvent event)

Added in API level 1

Implement this method to handle trackball motion events. The relative movement of the trackball since the last event can be retrieve with MotionEvent.getX() and MotionEvent.getY(). These are normalized so that a movement of 1 corresponds to the user pressing one DPAD key (so they will often be fractional values, representing the more fine-grained movement information available from a trackball).

Parameters
event The motion event.
Returns
  • True if the event was handled, false otherwise.

public void onWindowFocusChanged (boolean hasWindowFocus)

Added in API level 1

Called when the window containing this view gains or loses focus. Note that this is separate from view focus: to receive key events, both your view and its window must have focus. If a window is displayed on top of yours that takes input focus, then your own window will lose focus but the view focus will remain unchanged.

Parameters
hasWindowFocus True if the window containing this view now has focus, false otherwise.

public boolean performAccessibilityAction (int action, Bundle arguments)

Added in API level 16

Performs the specified accessibility action on the view. For possible accessibility actions look at AccessibilityNodeInfo.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its performAccessibilityAction(View, int, Bundle) is responsible for handling this call.

Parameters
action The action to perform.
arguments Optional action arguments.
Returns
  • Whether the action was performed.

public boolean performLongClick ()

Added in API level 1

Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the OnLongClickListener did not consume the event.

Returns
  • True if one of the above receivers consumed the event, false otherwise.

public void removeTextChangedListener (TextWatcher watcher)

Added in API level 1

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

public void sendAccessibilityEvent (int eventType)

Added in API level 4

Sends an accessibility event of the given type. If accessibility is not enabled this method has no effect. The default implementation calls onInitializeAccessibilityEvent(AccessibilityEvent) first to populate information about the event source (this View), then calls dispatchPopulateAccessibilityEvent(AccessibilityEvent) to populate the text content of the event source including its descendants, and last calls requestSendAccessibilityEvent(View, AccessibilityEvent) on its parent to resuest sending of the event to interested parties.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its sendAccessibilityEvent(View, int) is responsible for handling this call.

Parameters
eventType The type of the event to send, as defined by several types from AccessibilityEvent, such as TYPE_VIEW_CLICKED or TYPE_VIEW_HOVER_ENTER.

public void setAllCaps (boolean allCaps)

Added in API level 14

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.

Related XML Attributes

public final void setAutoLinkMask (int mask)

Added in API level 1

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

Related XML Attributes

public void setCompoundDrawablePadding (int pad)

Added in API level 1

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

Related XML Attributes

public void setCompoundDrawables (Drawable left, Drawable top, Drawable right, Drawable bottom)

Added in API level 1

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 setBounds(Rect) called.

public void setCompoundDrawablesRelative (Drawable start, Drawable top, Drawable end, Drawable bottom)

Added in API level 17

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 setBounds(Rect) called.

public void setCompoundDrawablesRelativeWithIntrinsicBounds (Drawable start, Drawable top, Drawable end, Drawable bottom)

Added in API level 17

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.

public void setCompoundDrawablesRelativeWithIntrinsicBounds (int start, int top, int end, int bottom)

Added in API level 17

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.

Parameters
start Resource identifier of the start Drawable.
top Resource identifier of the top Drawable.
end Resource identifier of the end Drawable.
bottom Resource identifier of the bottom Drawable.

public void setCompoundDrawablesWithIntrinsicBounds (Drawable left, Drawable top, Drawable right, Drawable bottom)

Added in API level 1

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.

public void setCompoundDrawablesWithIntrinsicBounds (int left, int top, int right, int bottom)

Added in API level 3

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.

Parameters
left Resource identifier of the left Drawable.
top Resource identifier of the top Drawable.
right Resource identifier of the right Drawable.
bottom Resource identifier of the bottom Drawable.

public void setCursorVisible (boolean visible)

Added in API level 1

Set whether the cursor is visible. The default is true. Note that this property only makes sense for editable TextView.

Related XML Attributes

public void setCustomSelectionActionModeCallback (ActionMode.Callback actionModeCallback)

Added in API level 11

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 and Paste actions, depending on what this View supports. A custom implementation can add new entries in the default menu in its onPrepareActionMode(ActionMode, Menu) method. The default actions can also be removed from the menu using removeItem(int) and passing selectAll, cut, copy or paste ids as parameters. Returning false from onCreateActionMode(ActionMode, Menu) will prevent the action mode from being started. Action click events should be handled by the custom implementation of onActionItemClicked(ActionMode, MenuItem). Note that text selection mode is not started when a TextView receives focus and the selectAllOnFocus flag has been set. The content is highlighted in that case, to allow for quick replacement.

public final void setEditableFactory (Editable.Factory factory)

Added in API level 1

Sets the Factory used to create new Editables.

public void setEllipsize (TextUtils.TruncateAt where)

Added in API level 1

Causes words in the text that are longer than the view is wide to be ellipsized instead of broken in the middle. You may also want to setSingleLine() or setHorizontallyScrolling(boolean) to constrain the text to a single line. Use null to turn off ellipsizing. If setMaxLines(int) has been used to set two or more lines, END and MARQUEE* are only supported (other ellipsizing types will not do anything).

Related XML Attributes

public void setEms (int ems)

Added in API level 1

Makes the TextView exactly this many ems wide

Related XML Attributes

public void setEnabled (boolean enabled)

Added in API level 1

Set the enabled state of this view. The interpretation of the enabled state varies by subclass.

Parameters
enabled True if this view is enabled, false otherwise.

public void setError (CharSequence error)

Added in API level 1

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.

public void setError (CharSequence error, Drawable icon)

Added in API level 1

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 setBounds(Rect) set on it. If the error is null, the error message will be cleared (and you should provide a null icon as well).

public void setExtractedText (ExtractedText text)

Added in API level 3

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

public void setFilters (InputFilter[] filters)

Added in API level 1

Sets the list of input filters that will be used if the buffer is Editable. Has no effect otherwise.

Related XML Attributes

public void setFreezesText (boolean freezesText)

Added in API level 1

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.

Related XML Attributes
Parameters
freezesText Controls whether a frozen icicle should include the entire text data: true to include it, false to not.

public void setGravity (int gravity)

Added in API level 1

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.

Related XML Attributes
See Also

public void setHeight (int pixels)

Added in API level 1

Makes the TextView exactly this many pixels tall. You could do the same thing by specifying this number in the LayoutParams. Note that setting this value overrides any other (minimum / maximum) number of lines or height setting.

Related XML Attributes

public void setHighlightColor (int color)

Added in API level 1

Sets the color used to display the selection highlight.

Related XML Attributes

public final void setHint (CharSequence hint)

Added in API level 1

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.

Related XML Attributes

public final void setHint (int resid)

Added in API level 1

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

Related XML Attributes

public final void setHintTextColor (ColorStateList colors)

Added in API level 1

public final void setHintTextColor (int color)

Added in API level 1

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

Related XML Attributes

public void setHorizontallyScrolling (boolean whether)

Added in API level 1

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.

Related XML Attributes

public void setImeActionLabel (CharSequence label, int actionId)

Added in API level 3

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

public void setImeOptions (int imeOptions)

Added in API level 3

Change the editor type integer associated with the text view, which will be reported to an IME with imeOptions when it has focus.

Related XML Attributes

public void setIncludeFontPadding (boolean includepad)

Added in API level 1

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.

Related XML Attributes

public void setInputExtras (int xmlResId)

Added in API level 3

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 ID of an XML resource holding an <input-extras> XML tree.

Related XML Attributes

public void setInputType (int type)

Added in API level 3

Set the type of the content with a constant as defined for inputType. This will take care of changing the key listener, by calling setKeyListener(KeyListener), to match the given content type. If the given content type is 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 TYPE_TEXT_FLAG_MULTI_LINE flag of the input type.

Related XML Attributes

public void setKeyListener (KeyListener input)

Added in API level 1

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.getContentType() 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(boolean) again after calling this to get the focusability back the way you want it.

public void setLineSpacing (float add, float mult)

Added in API level 1

Sets line spacing for this TextView. Each line will have its height multiplied by mult and have add added to it.

public void setLines (int lines)

Added in API level 1

Makes the TextView exactly this many lines tall. Note that setting this value overrides any other (minimum / maximum) number of lines or height setting. A single line TextView will set this value to 1.

Related XML Attributes

public final void setLinkTextColor (ColorStateList colors)

Added in API level 1

public final void setLinkTextColor (int color)

Added in API level 1

Sets the color of links in the text.

Related XML Attributes

public final void setLinksClickable (boolean whether)

Added in API level 1

Sets whether the movement method will automatically be set to LinkMovementMethod if setAutoLinkMask(int) has been set to nonzero and links are detected in setText(char[], int, int). The default is true.

Related XML Attributes

public void setMarqueeRepeatLimit (int marqueeLimit)

Added in API level 2

Sets how many times to repeat the marquee animation. Only applied if the TextView has marquee enabled. Set to -1 to repeat indefinitely.

Related XML Attributes

public void setMaxEms (int maxems)

Added in API level 1

Makes the TextView at most this many ems wide

Related XML Attributes

public void setMaxHeight (int maxHeight)

Added in API level 1

Makes the TextView at most this many pixels tall. This option is mutually exclusive with the setMaxLines(int) method. Setting this value overrides any other (maximum) number of lines setting.

Related XML Attributes

public void setMaxLines (int maxlines)

Added in API level 1

Makes the TextView at most this many lines tall. Setting this value overrides any other (maximum) height setting.

Related XML Attributes

public void setMaxWidth (int maxpixels)

Added in API level 1

Makes the TextView at most this many pixels wide

Related XML Attributes

public void setMinEms (int minems)

Added in API level 1

Makes the TextView at least this many ems wide

Related XML Attributes

public void setMinHeight (int minHeight)

Added in API level 1

Makes the TextView at least this many pixels tall. Setting this value overrides any other (minimum) number of lines setting.

Related XML Attributes

public void setMinLines (int minlines)

Added in API level 1

Makes the TextView at least this many lines tall. Setting this value overrides any other (minimum) height setting. A single line TextView will set this value to 1.

Related XML Attributes
See Also

public void setMinWidth (int minpixels)

Added in API level 1

Makes the TextView at least this many pixels wide

Related XML Attributes

public final void setMovementMethod (MovementMethod movement)

Added in API level 1

Sets the movement method (arrow key handler) to be used 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(boolean) again after calling this to get the focusability back the way you want it.

public void setOnEditorActionListener (TextView.OnEditorActionListener l)

Added in API level 3

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.

public void setPadding (int left, int top, int right, int bottom)

Added in API level 1

Sets the padding. The view may add on the space required to display the scrollbars, depending on the style and visibility of the scrollbars. So the values returned from getPaddingLeft(), getPaddingTop(), getPaddingRight() and getPaddingBottom() may be different from the values set in this call.

Parameters
left the left padding in pixels
top the top padding in pixels
right the right padding in pixels
bottom the bottom padding in pixels

public void setPaddingRelative (int start, int top, int end, int bottom)

Added in API level 16

Sets the relative padding. The view may add on the space required to display the scrollbars, depending on the style and visibility of the scrollbars. So the values returned from getPaddingStart(), getPaddingTop(), getPaddingEnd() and getPaddingBottom() may be different from the values set in this call.

Parameters
start the start padding in pixels
top the top padding in pixels
end the end padding in pixels
bottom the bottom padding in pixels

public void setPaintFlags (int flags)

Added in API level 1

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

See Also

public void setPrivateImeOptions (String type)

Added in API level 3

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

Related XML Attributes

public void setRawInputType (int type)

Added in API level 3

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

Related XML Attributes

public void setScroller (Scroller s)

Added in API level 1

public void setSelectAllOnFocus (boolean selectAllOnFocus)

Added in API level 1

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

Related XML Attributes

public void setSelected (boolean selected)

Added in API level 1

Changes the selection state of this view. A view can be selected or not. Note that selection is not the same as focus. Views are typically selected in the context of an AdapterView like ListView or GridView; the selected view is the view that is highlighted.

Parameters
selected true if the view must be selected, false otherwise

public void setShadowLayer (float radius, float dx, float dy, int color)

Added in API level 1

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

public void setSingleLine ()

Added in API level 1

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

Related XML Attributes

public void setSingleLine (boolean singleLine)

Added in API level 1

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.

Related XML Attributes

public final void setSpannableFactory (Spannable.Factory factory)

Added in API level 1

Sets the Factory used to create new Spannables.

public final void setText (int resid)

Added in API level 1

public final void setText (char[] text, int start, int len)

Added in API level 1

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.

public final void setText (int resid, TextView.BufferType type)

Added in API level 1

public final void setText (CharSequence text)

Added in API level 1

Sets the string value of the TextView. 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 SpannableString, or see the Available Resource Types documentation for an example of setting formatted text in the XML resource file.

Related XML Attributes

public void setText (CharSequence text, TextView.BufferType type)

Added in API level 1

Sets the text that this TextView is to display (see setText(CharSequence)) and also sets whether it is stored in a styleable/spannable buffer and whether it is editable.

Related XML Attributes

public void setTextAppearance (Context context, int resid)

Added in API level 1

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

public void setTextColor (ColorStateList colors)

Added in API level 1

public void setTextColor (int color)

Added in API level 1

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

Related XML Attributes

public void setTextIsSelectable (boolean selectable)

Added in API level 11

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 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 Whether the content of this TextView should be selectable.

public final void setTextKeepState (CharSequence text)

Added in API level 1

Like setText(CharSequence), except that the cursor position (if any) is retained in the new text.

Parameters
text The new text to place in the text view.

public final void setTextKeepState (CharSequence text, TextView.BufferType type)

Added in API level 1

Like setText(CharSequence, android.widget.TextView.BufferType), except that the cursor position (if any) is retained in the new text.

public void setTextLocale (Locale locale)

Added in API level 17

Set the default Locale 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.

Parameters
locale the Locale for drawing text, must not be null.

public void setTextScaleX (float size)

Added in API level 1

Sets the extent by which text should be stretched horizontally.

Related XML Attributes

public void setTextSize (float size)

Added in API level 1

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.

Related XML Attributes
Parameters
size The scaled pixel size.

public void setTextSize (int unit, float size)

Added in API level 1

Set the default text size to a given unit and value. See TypedValue for the possible dimension units.

Related XML Attributes
Parameters
unit The desired dimension unit.
size The desired size in the given units.

public final void setTransformationMethod (TransformationMethod method)

Added in API level 1

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

Related XML Attributes

public void setTypeface (Typeface tf, int style)

Added in API level 1

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.

Related XML Attributes

public void setTypeface (Typeface tf)

Added in API level 1

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(Typeface, int) to get the appearance that you actually want.

See Also

public void setWidth (int pixels)

Added in API level 1

Makes the TextView exactly this many pixels wide. You could do the same thing by specifying this number in the LayoutParams.

Related XML Attributes

Protected Methods

protected int computeHorizontalScrollRange ()

Added in API level 1

Compute the horizontal range that the horizontal scrollbar represents.

The range is expressed in arbitrary units that must be the same as the units used by computeHorizontalScrollExtent() and computeHorizontalScrollOffset().

The default range is the drawing width of this view.

Returns
  • the total horizontal range represented by the horizontal scrollbar

protected int computeVerticalScrollExtent ()

Added in API level 1

Compute the vertical extent of the horizontal scrollbar's thumb within the vertical range. This value is used to compute the length of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by computeVerticalScrollRange() and computeVerticalScrollOffset().

The default extent is the drawing height of this view.

Returns
  • the vertical extent of the scrollbar's thumb

protected int computeVerticalScrollRange ()

Added in API level 1

Compute the vertical range that the vertical scrollbar represents.

The range is expressed in arbitrary units that must be the same as the units used by computeVerticalScrollExtent() and computeVerticalScrollOffset().

Returns
  • the total vertical range represented by the vertical scrollbar

    The default range is the drawing height of this view.

protected void drawableStateChanged ()

Added in API level 1

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

Be sure to call through to the superclass when overriding this function.

protected int getBottomPaddingOffset ()

Added in API level 2

Amount by which to extend the bottom fading region. Called only when isPaddingOffsetRequired() returns true.

Returns
  • The bottom padding offset in pixels.

protected boolean getDefaultEditable ()

Added in API level 1

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

protected MovementMethod getDefaultMovementMethod ()

Added in API level 1

Subclasses override this to specify a default movement method.

protected float getLeftFadingEdgeStrength ()

Added in API level 1

Returns the strength, or intensity, of the left faded edge. The strength is a value between 0.0 (no fade) and 1.0 (full fade). The default implementation returns 0.0 or 1.0 but no value in between. Subclasses should override this method to provide a smoother fade transition when scrolling occurs.

Returns
  • the intensity of the left fade as a float between 0.0f and 1.0f

protected int getLeftPaddingOffset ()

Added in API level 2

Amount by which to extend the left fading region. Called only when isPaddingOffsetRequired() returns true.

Returns
  • The left padding offset in pixels.

protected float getRightFadingEdgeStrength ()

Added in API level 1

Returns the strength, or intensity, of the right faded edge. The strength is a value between 0.0 (no fade) and 1.0 (full fade). The default implementation returns 0.0 or 1.0 but no value in between. Subclasses should override this method to provide a smoother fade transition when scrolling occurs.

Returns
  • the intensity of the right fade as a float between 0.0f and 1.0f

protected int getRightPaddingOffset ()

Added in API level 2

Amount by which to extend the right fading region. Called only when isPaddingOffsetRequired() returns true.

Returns
  • The right padding offset in pixels.

protected int getTopPaddingOffset ()

Added in API level 2

Amount by which to extend the top fading region. Called only when isPaddingOffsetRequired() returns true.

Returns
  • The top padding offset in pixels.

protected boolean isPaddingOffsetRequired ()

Added in API level 2

If the View draws content inside its padding and enables fading edges, it needs to support padding offsets. Padding offsets are added to the fading edges to extend the length of the fade so that it covers pixels drawn inside the padding. Subclasses of this class should override this method if they need to draw content inside the padding.

Returns
  • True if padding offset must be applied, false otherwise.

protected void onAttachedToWindow ()

Added in API level 1

This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).

protected int[] onCreateDrawableState (int extraSpace)

Added in API level 1

Generate the new Drawable state for this view. This is called by the view system when the cached Drawable state is determined to be invalid. To retrieve the current state, you should use getDrawableState().

Parameters
extraSpace 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.
Returns
  • Returns an array holding the current Drawable state of the view.

protected void onDetachedFromWindow ()

Added in API level 1

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.

protected void onDraw (Canvas canvas)

Added in API level 1

Implement this to do your drawing.

Parameters
canvas the canvas on which the background will be drawn

protected void onFocusChanged (boolean focused, int direction, Rect previouslyFocusedRect)

Added in API level 1

Called by the view system when the focus state of this view changes. When the focus change event is caused by directional navigation, direction and previouslyFocusedRect provide insight into where the focus is coming from. When overriding, be sure to call up through to the super class so that the standard focus handling will occur.

Parameters
focused True if the View has focus; false otherwise.
direction 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.
previouslyFocusedRect 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.

protected void onLayout (boolean changed, int left, int top, int right, int bottom)

Added in API level 1

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters
changed This is a new size or position for this view
left Left position, relative to parent
top Top position, relative to parent
right Right position, relative to parent
bottom Bottom position, relative to parent

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Added in API level 1

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overriden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

protected void onScrollChanged (int horiz, int vert, int oldHoriz, int oldVert)

Added in API level 1

This is called in response to an internal scroll in this view (i.e., the view scrolled its own contents). This is typically as a result of scrollBy(int, int) or scrollTo(int, int) having been called.

Parameters
horiz Current horizontal scroll origin.
vert Current vertical scroll origin.
oldHoriz Previous horizontal scroll origin.
oldVert Previous vertical scroll origin.

protected void onSelectionChanged (int selStart, int selEnd)

Added in API level 3

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

Parameters
selStart The new selection start location.
selEnd The new selection end location.

protected void onTextChanged (CharSequence text, int start, int lengthBefore, int lengthAfter)

Added in API level 1

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 The text the TextView is displaying
start The offset of the start of the range of the text that was modified
lengthBefore The length of the former text that has been replaced
lengthAfter The length of the replacement modified text

protected void onVisibilityChanged (View changedView, int visibility)

Added in API level 8

Called when the visibility of the view or an ancestor of the view is changed.

Parameters
changedView The view whose visibility changed. Could be 'this' or an ancestor view.
visibility The new visibility of changedView: VISIBLE, INVISIBLE or GONE.

protected boolean setFrame (int l, int t, int r, int b)

Added in API level 1

Assign a size and position to this view. This is called from layout.

Parameters
l Left position, relative to parent
t Top position, relative to parent
r Right position, relative to parent
b Bottom position, relative to parent
Returns
  • true if the new size and position are different than the previous ones

protected boolean verifyDrawable (Drawable who)

Added in API level 1

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.

Parameters
who The Drawable to verify. Return true if it is one you are displaying, else return the result of calling through to the super class.
Returns
  • boolean If true than the Drawable is being displayed in the view; else false and it is not allowed to animate.