| java.lang.Object | |||
| android.view.View | Drawable.Callback KeyEvent.Callback | ||
| android.widget.TextView | |||
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.
XML attributes
See TextView Attributes, View Attributes
Nested Classes
Known Direct Subclasses
Known Indirect Subclasses| Attribute name | Related methods | |
|---|---|---|
| android:autoLink | setAutoLinkMask(int) |
Controls whether links such as urls and email addresses are automatically found and converted to clickable links. |
| android:autoText | setInputMethod(InputMethod) |
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 what the minimum type that getText() will return. |
| android:capitalize | setInputMethod(InputMethod) |
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
Must be a boolean value, either " |
| android:digits | setInputMethod(InputMethod) |
If set, specifies that this TextView has a numeric input method and that these specific characters are the ones that it will accept. |
| android:editable | If set, specifies that this TextView has an input method. | |
| android:ems | setEms(int) |
Makes the TextView be exactly this many ems wide
Must be an integer value, such as " |
| 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) |
Vertical gravity (top, center_vertical, bottom) 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:includeFontPadding | setIncludeFontPadding(boolean) |
Leave enough room for ascenders and descenders instead of using the font ascent and descent strictly. |
| android:inputMethod | setInputMethod(InputMethod) |
If set, specifies that this TextView should use the specified input method (specified by fully-qualified class name). |
| android:lines | setLines(int) |
Makes the TextView be exactly this many lines tall
Must be an integer value, such as " |
| android:maxEms | setMaxEms(int) |
Makes the TextView be at most this many ems wide
Must be an integer value, such as " |
| android:maxHeight | setMaxHeight(int) |
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 " |
| 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
Must be an integer value, such as " |
| android:maxWidth | setMaxWidth(int) |
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 " |
| android:minEms | setMinEms(int) |
Makes the TextView be at least this many ems wide
Must be an integer value, such as " |
| android:minHeight | setMinHeight(int) |
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 " |
| android:minLines | setMinLines(int) |
Makes the TextView be at least this many lines tall
Must be an integer value, such as " |
| android:minWidth | setMinWidth(int) |
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 " |
| android:numeric | setInputMethod(InputMethod) |
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 | setInputMethod(InputMethod) |
If set, specifies that this TextView has a phone number 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 instead of moving the cursor to the start or end. |
| 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) |
Text to display. |
| android:textAlign | setAlignment(Layout.Alignment) |
Horizontal text alignment: start (default), center, or end. |
| android:textColor | setTextColor(ColorStateList) |
Text color. |
| android:textColorHighlight | setHiliteColor(int) |
Color of the text selection highlight. |
| android:textColorHint | setHintTextColor(int) |
Color of the hint text. |
| android:textScaleX | setTextScaleX(float) |
Sets the horizontal scaling factor for the text
Must be a floating point value, such as " |
| android:textSize | setTextSize(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. |
XML Attributes inherited
from class
android.view.View
Constants inherited
from class
android.view.View
Fields inherited
from class
android.view.View
| TextView(Context context) | |||||
| TextView(Context context, AttributeSet attrs, Map inflateParams) | |||||
| TextView(Context context, AttributeSet attrs, Map inflateParams, int defStyle) |
| 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 | 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. | |||||
| 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. |
|||||
| final | int | getCurrentHintTextColor() | |||
Return the current color selected to paint the hint text. |
|||||
| final | int | getCurrentTextColor() | |||
Return the current color selected for normal text. |
|||||
| InputFilter[] | getFilters() | ||||
| Returns the current list of input filters. | |||||
| boolean | getFreezesText() | ||||
| Return whether this text view is including its entire text contents in frozen icicles. | |||||
| final | ColorStateList | getHintTextColors() | |||
Return the color used to paint the hint text. |
|||||
| final | InputMethod | getInputMethod() | |||
| 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() | ||||
| final | MovementMethod | getMovementMethod() | |||
| TextPaint | getPaint() | ||||
| int | getPaintFlags() | ||||
| int | getSelectionEnd() | ||||
| Convenience for getSelectionEnd(CharSequence). | |||||
| int | getSelectionStart() | ||||
| Convenience for getSelectionStart(CharSequence). | |||||
| CharSequence | getText() | ||||
| Return the text the TextView is displaying. | |||||
| static | int | getTextColor(Context context, StyledAttributes 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() | |||
| Return the set of text colors. | |||||
| static | ColorStateList | getTextColors(Context context, StyledAttributes attrs) | |||
| Returns the TextView_textColor attribute from the Resources.StyledAttributes, if set, or the TextAppearance_textColor from the TextView_textAppearance attribute, if TextView_textColor was not set directly. | |||||
| float | getTextScaleX() | ||||
| float | getTextSize() | ||||
| final | TransformationMethod | getTransformationMethod() | |||
| Typeface | getTypeface() | ||||
| boolean | hasSelection() | ||||
| Return true iff there is a selection inside this text view. | |||||
| int | length() | ||||
| Returns the length, in characters, of the text managed by this TextView | |||||
| Parcelable | onFreeze() | ||||
| 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. | |||||
| boolean | onKeyDown(int keyCode, KeyEvent event) | ||||
| Default implementation of KeyEvent.Callback.onKeyMultiple(): perform press of the view when KEYCODE_DPAD_CENTER or KEYCODE_NEWLINE is released, if the view is enabled and clickable. | |||||
| boolean | onKeyUp(int keyCode, KeyEvent event) | ||||
| Default implementation of KeyEvent.Callback.onKeyMultiple(): perform clicking of the view when KEYCODE_DPAD_CENTER or KEYCODE_NEWLINE is released. | |||||
| void | onThaw(Parcelable state) | ||||
| Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onFreeze(). | |||||
| 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. | |||||
| void | removeTextChangedListener(TextWatcher watcher) | ||||
| Removes the specified TextWatcher from the list of those whose methods are called whenever this TextView's text changes. | |||||
| void | setAlignment(Alignment align) | ||||
| Sets the alignment of this view's text. | |||||
| final | void | setAutoLinkMask(int mask) | |||
| Sets the autolink mask of the text. | |||||
| void | setCursorVisible(boolean visible) | ||||
| Set whether the cursor is visible. | |||||
| void | setEms(int ems) | ||||
| Makes the TextView exactly this many ems wide | |||||
| 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 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 | setHiliteColor(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. | |||||
| void | setHorizontallyScrolling(boolean whether) | ||||
| Sets whether the text should be allowed to be wider than the View is. | |||||
| 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 | setInputMethod(InputMethod input) | ||||
| Sets the input method 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 | |||||
| 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 | setPadding(int left, int top, int right, int bottom) | ||||
| Sets the 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 | setScroller(Scroller s) | ||||
| void | setSelectAllOnFocus(boolean selectAllOnFocus) | ||||
| Set the TextView so that when it takes focus, all the text is selected. | |||||
| 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 (lines, horizontally scrolling, transformation method) to be for a single-line input; if false, restores these to the default conditions. | |||||
| final | void | setText(int resid) | |||
| final | void | setText(int resid, BufferType type) | |||
| void | setText(CharSequence text, 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. | |||||
| final | void | setText(Cursor cursor, int column, BufferType type) | |||
| Set the text to the contents of a particular column in the cursor, keeping the data in the cursor updated as edits happen in the text. | |||||
| final | void | setText(CharSequence text) | |||
| Sets the string value of the TextView. | |||||
| final | void | setText(Cursor cursor, int column) | |||
| Set the text to the contents of a particular column in the cursor, keeping the data in the cursor updated as edits happen in the text. | |||||
| void | setTextAppearance(Context context, int resid) | ||||