Class TextView
- All Implemented Interfaces:
Drawable.Callback
,ViewTreeObserver.OnPreDrawListener
EditText
.
To display a styled text, use a Spannable
with markup objects, like CharacterStyle
.
TextView will hold a copy of your text after calling setText(CharSequence, BufferType)
.
After you provide a String, you want it to have styles:
TextView textView = new TextView(); textView.setText(string, TextView.BufferType.SPANNABLE); // add styles Spannable spannable = (Spannable) textView.getText(); spannable.setSpan(new ForegroundColorSpan(0xfff699b4), 0, 8, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);If you want a non-editable text to be selected, see
setTextIsSelectable(boolean)
.
Explore the methods in this class to find more usage
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Type of the text buffer that defines the characteristics of the text such as static, styleable, or editable.Nested classes/interfaces inherited from class icyllis.modernui.view.View
View.DragShadow, View.Focusable, View.FocusableMode, View.FocusDirection, View.FocusRealDirection, View.LayoutDir, View.NestedScrollType, View.OnAttachStateChangeListener, View.OnClickListener, View.OnContextClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnGenericMotionListener, View.OnHoverListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnScrollChangeListener, View.OnTouchListener, View.ResolvedLayoutDir, View.ScrollAxis, View.ScrollBarStyle, View.ScrollIndicators, View.TextAlignment, View.Visibility
-
Field Summary
Fields inherited from class icyllis.modernui.view.View
ALPHA, BOTTOM, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLE, FOCUSABLE_AUTO, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, INVISIBLE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_UNDEFINED, LEFT, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mScrollX, mScrollY, NO_ID, NOT_FOCUSABLE, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, RIGHT, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_NONE, SCROLL_AXIS_VERTICAL, SCROLL_INDICATOR_BOTTOM, SCROLL_INDICATOR_END, SCROLL_INDICATOR_LEFT, SCROLL_INDICATOR_RIGHT, SCROLL_INDICATOR_START, SCROLL_INDICATOR_TOP, SCROLL_X, SCROLL_Y, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_VIEW_END, TEXT_ALIGNMENT_VIEW_START, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_FIRST_STRONG_LTR, TEXT_DIRECTION_FIRST_STRONG_RTL, TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TOP, TRANSLATION_X, TRANSLATION_Y, TRANSLATION_Z, TYPE_NON_TOUCH, TYPE_TOUCH, VIEW_MARKER, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y, Z
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addTextChangedListener
(TextWatcher watcher) Adds a TextWatcher to the list of those whose methods are called whenever this TextView's text changes.boolean
bringPointIntoView
(int offset) Move the point, specified by the offset, into the view if it is needed.void
Cancels a pending long press.protected int
Compute the horizontal range that the horizontal scrollbar represents.protected int
Compute the vertical extent of the vertical scrollbar's thumb within the vertical range.protected int
Compute the vertical range that the vertical scrollbar represents.boolean
Returns true, only while processing a touch gesture, if the initial touch down event caused focus to move to the text view and as a result its selection changed.protected void
This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.final int
Gets the autolink mask of the text.int
Return the offset of the widget's text baseline from the widget's top boundary.int
Returns the padding between the compound drawables and the text.Drawable[]
Returns drawables for the left, top, right, and bottom borders.Drawable[]
Returns drawables for the start, top, end, and bottom borders.int
Returns the bottom padding of the view, plus space for the bottom Drawable if any.int
Returns the end padding of the view, plus space for the end Drawable if any.int
Returns the left padding of the view, plus space for the left Drawable if any.int
Returns the right padding of the view, plus space for the right Drawable if any.int
Returns the start padding of the view, plus space for the start Drawable if any.int
Returns the top padding of the view, plus space for the top Drawable if any.final int
Return the current color selected to paint the hint text.final int
Return the current color selected for normal text.Return the text that TextView is displaying as an Editable object.Returns where, if anywhere, words that are longer than the view is wide should be ellipsized.int
Returns the extended bottom padding of the view, including both the bottom Drawable if any and any extra space to keep more than maxLines of text from showing.int
Returns the extended top padding of the view, including both the top Drawable if any and any extra space to keep more than maxLines of text from showing.Returns the current list of input filters.int
Returns the distance between the first text baseline and the top of this TextView.void
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.int
Returns the horizontal and vertical alignment of this TextView.int
getHint()
Returns the hint that is displayed when the text of the TextView is empty.final ColorStateList
int
boolean
Gets whether the TextView includes extra top and bottom padding to make room for accents that go above the normal ascent and descent.int
Returns the distance between the last text baseline and the bottom of this TextView.final Layout
Gets theLayout
that is currently being used to display the text.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
Get the current line break style for text wrapping.int
Get the current line word break style for text wrapping.int
Return the number of lines of text, or 0 if the internal Layout has not been built.int
Gets the vertical distance between lines of text, in pixels.final boolean
Returns whether the movement method will automatically be set toLinkMovementMethod
ifsetAutoLinkMask(int)
has been set to nonzero and links are detected insetText(java.lang.CharSequence)
.final ColorStateList
int
Returns the maximum height of TextView in terms of pixels or -1 if the maximum height was set usingsetMaxLines(int)
orsetLines(int)
.int
Returns the maximum height of TextView in terms of number of lines or -1 if the maximum height was set usingsetMaxHeight(int)
orsetHeight(int)
.int
Returns the maximum width of TextView in terms of pixels.int
Returns the minimum height of TextView in terms of pixels or -1 if the minimum height was set usingsetMinLines(int)
orsetLines(int)
.int
Returns the minimum height of TextView in terms of number of lines or -1 if the minimum height was set usingsetMinHeight(int)
orsetHeight(int)
.int
Returns the minimum width of TextView in terms of pixels.final MovementMethod
Gets theMovementMethod
being used for this TextView, which provides positioning, scrolling, and text selection functionality.int
getOffsetForPosition
(float x, float y) Get the character offset closest to the specified absolute position.getPaint()
Gets theTextPaint
used for the text.int
Convenience forSelection.getSelectionEnd(java.lang.CharSequence)
.int
Convenience forSelection.getSelectionStart(java.lang.CharSequence)
.getText()
Return the text that TextView is displaying.final ColorStateList
Gets the text colors for the different states (normal, selected, focused) of the TextView.Returns resolvedTextDirectionHeuristic
that will be used for text layout.Get the default primaryLocale
of the text in this TextView.Gets the parameters for text layout pre-computation, for use withPrecomputedText
.float
int
Gets the current text style that is used to style the text.int
Returns the total bottom padding of the view, including the bottom Drawable if any, the extra space to keep more than maxLines from showing, and the vertical offset for gravity, if any.int
Returns the total end padding of the view, including the end Drawable if any.int
Returns the total left padding of the view, including the left Drawable if any.int
Returns the total right padding of the view, including the right Drawable if any.int
Returns the total start padding of the view, including the start Drawable if any.int
Returns the total top padding of the view, including the top Drawable if any, the extra space to keep more than maxLines from showing, and the vertical offset for gravity, if any.final TransformationMethod
Gets the currentTransformationMethod
for the TextView.Gets the currentTypeface
that is used to style the text.This method is used by the ArrowKeyMovementMethod to jump from one word to the other.boolean
Return true iff there is a selection of nonzero length inside this text view.boolean
boolean
final boolean
Returns whether the text is allowed to be wider than the View.boolean
Returns the state of thetextIsSelectable
flag (SeesetTextIsSelectable()
).void
CallDrawable.jumpToCurrentState()
on all Drawable objects associated with this view.final void
makeNewLayout
(int wantWidth, int hintWidth, BoringLayout.Metrics boring, BoringLayout.Metrics hintBoring, int ellipsisWidth, boolean bringIntoView) The width passed in is now the desired layout width, not the full view width with padding.boolean
Move the cursor, if needed, so that it is at an offset that is visible to the user.final void
protected void
This is called when the view is attached to a window.protected void
Views should implement this if the view itself is going to add items to the context menu.protected int[]
onCreateDrawableState
(int extraSpace) Generate the newDrawable
state for this view.protected void
This is called when the view is detached from a window.protected void
Draw the content of this view, implement this to do your drawing.protected void
onFocusChanged
(boolean focused, int direction, Rect previouslyFocusedRect) Called by the view system when the focus state of this view changes.boolean
onGenericMotionEvent
(MotionEvent event) Implement this method to handle generic motion events.boolean
Default implementation: perform press of the view whenKeyEvent.KEY_ENTER
,KeyEvent.KEY_KP_ENTER
orKeyEvent.KEY_SPACE
is released, if the view is enabled and clickable.boolean
onKeyShortcut
(int keyCode, KeyEvent event) Called on the focused view when a key shortcut event is not handled.boolean
Default implementation: perform clicking of the view whenKeyEvent.KEY_ENTER
,KeyEvent.KEY_KP_ENTER
orKeyEvent.KEY_SPACE
is released.protected void
onLayout
(boolean changed, int left, int top, int right, int bottom) Called fromView.layout(int, int, int, int)
when this view should assign a size and position to each of its children.protected void
onMeasure
(int widthMeasureSpec, int heightMeasureSpec) Measure the view and its content to determine the measured width and the measured height.boolean
Callback method to be invoked when the view tree is about to be drawn.void
onResolveDrawables
(int layoutDirection) Called when layout direction has been resolved.onResolvePointerIcon
(MotionEvent event) Returns the pointer icon for the motion event, or null if it doesn't specify the icon.protected void
onRtlPropertiesChanged
(int layoutDirection) Called when any RTL property (layout direction or text direction or text alignment) has been changed.protected 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.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.void
removeTextChangedListener
(TextWatcher watcher) Removes the specified TextWatcher from the list of those whose methods are called whenever this TextView's text changes.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
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
setCursorVisible
(boolean visible) Set whether the cursor is visible.final void
setEditableFactory
(Editable.Factory factory) Sets the Factory used to create newEditables
.void
setEllipsize
(TextUtils.TruncateAt where) Causes words in the text that are longer than the view's width to be ellipsized instead of broken in the middle.void
setEnabled
(boolean enabled) Set the enabled state of this view.void
setFallbackLineSpacing
(boolean enabled) Set whether to respect the ascent and descent of the fallback fonts that are used in displaying the text (which is needed to avoid text from consecutive lines running into each other).void
setFilters
(InputFilter... filters) Sets the list of input filters that will be used if the buffer is Editable.void
setFirstBaselineToTopHeight
(int firstBaselineToTopHeight) Updates the top padding of the TextView so thatfirstBaselineToTopHeight
is the distance between the top of the TextView and first line's baseline.void
setGravity
(int gravity) Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself.void
setHeight
(int pixels) Sets the height of the TextView to be exactlypixels
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
setHintTextColor
(int color) Sets the color of the hint text for all the states (disabled, focussed, selected...) of this TextView.final void
setHintTextColor
(ColorStateList colors) 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
setLastBaselineToBottomHeight
(int lastBaselineToBottomHeight) Updates the bottom padding of the TextView so thatlastBaselineToBottomHeight
is the distance between the bottom of the TextView and the last line's baseline.void
setLineBreakStyle
(int lineBreakStyle) Set the line break style for text wrapping.void
setLineBreakWordStyle
(int lineBreakWordStyle) Set the line break word style for text wrapping.void
setLines
(int lines) Sets the height of the TextView to be exactlylines
tall.final void
setLinksClickable
(boolean whether) Sets whether the movement method will automatically be set toLinkMovementMethod
ifsetAutoLinkMask(int)
has been set to nonzero and links are detected insetText(java.lang.CharSequence)
.final void
setLinkTextColor
(int color) Sets the color of links in the text.final void
setLinkTextColor
(ColorStateList colors) Sets the color of links in the text.void
setMaxHeight
(int maxPixels) Sets the height of the TextView to be at mostmaxPixels
tall.void
setMaxLines
(int maxLines) Sets the height of the TextView to be at mostmaxLines
tall.void
setMaxWidth
(int maxPixels) Sets the width of the TextView to be at mostmaxPixels
wide.void
setMinHeight
(int minPixels) Sets the height of the TextView to be at leastminPixels
tall.void
setMinLines
(int minLines) Sets the height of the TextView to be at leastminLines
tall.void
setMinWidth
(int minPixels) Sets the width of the TextView to be at leastminPixels
wide.final void
setMovementMethod
(MovementMethod movement) Sets theMovementMethod
for handling arrow key movement for this TextView.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
setSelectAllOnFocus
(boolean selectAllOnFocus) Set the TextView so that when it takes focus, all the text is selected.void
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 newSpannables
.final void
setText
(CharSequence text) Sets the text to be displayed.void
setText
(CharSequence text, TextView.BufferType type) Sets the text to be displayed and theTextView.BufferType
.void
setTextColor
(int color) Sets the text color for all the states (normal, selected, focused) to be this color.void
setTextColor
(ColorStateList colors) Sets the text color.void
setTextIsSelectable
(boolean selectable) Sets whether the content of this view is selectable by the user.final void
setTextKeepState
(CharSequence text) Sets the text to be displayed but retains the cursor position.final void
setTextKeepState
(CharSequence text, TextView.BufferType type) Sets the text to be displayed and theTextView.BufferType
but retains the cursor position.void
setTextLocale
(Locale locale) Set the defaultLocale
of the text in this TextView to the given Locale.void
Apply the text layout parameter.void
setTextSize
(float size) Set the default text size to the given value, interpreted as "scaled pixel" units.void
setTextSize
(int unit, float size) Set the default text size to a given unit and value.void
setTextStyle
(int style) Sets the default text style in which the text should be displayed.final void
Sets the transformation that is applied to the text that this TextView is displaying.void
setTypeface
(Typeface tf) Sets the typeface in which the text should be displayed.void
setWidth
(int pixels) Sets the width of the TextView to be exactlypixels
wide.boolean
showContextMenu
(float x, float y) Shows the context menu for this view anchored to the specified view-relative coordinate.final boolean
Returns true if DynamicLayout is requiredprotected 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.Methods inherited from class icyllis.modernui.view.View
addFocusables, addFocusables, addKeyboardNavigationClusters, addOnAttachStateChangeListener, addOnLayoutChangeListener, addTouchables, awakenScrollBars, awakenScrollBars, callOnClick, cancelPendingInputEvents, canReceivePointerEvents, canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, canScrollHorizontally, canScrollVertically, clearFocus, combineMeasuredStates, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeScroll, computeVerticalScrollOffset, createContextMenu, dispatchDraw, dispatchDrawableHotspotChanged, dispatchFinishTemporaryDetach, dispatchGenericMotionEvent, dispatchGenericPointerEvent, dispatchHoverEvent, dispatchKeyEvent, dispatchKeyShortcutEvent, dispatchNestedFling, dispatchNestedPreFling, dispatchNestedPreScroll, dispatchNestedScroll, dispatchPointerEvent, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchTouchEvent, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, dp, draw, drawableHotspotChanged, findFocus, findViewById, findViewByPredicate, findViewByPredicateInsideOut, findViewByPredicateTraversal, findViewTraversal, focusSearch, forceHasOverlappingRendering, forceLayout, generateViewId, getAlpha, getAnimationMatrix, getBackground, getBottom, getBoundsOnScreen, getBoundsOnScreen, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingRect, getElevation, getFadingEdge, getFadingEdgeLength, getFocusable, getFocusables, getForeground, getForegroundGravity, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHasOverlappingRendering, getHeight, getHitRect, getHorizontalScrollbarHeight, getHorizontalScrollbarThumbDrawable, getHorizontalScrollbarTrackDrawable, getId, getInverseMatrix, getKeyDispatcherState, getLayoutDirection, getLayoutParams, getLeft, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextClusterForwardId, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOnLongClickListener, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getPivotX, getPivotY, getRawLayoutDirection, getRawTextAlignment, getRawTextDirection, getRevealOnFocusHint, getRight, getRootView, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollIndicators, getScrollX, getScrollY, getStateListAnimator, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getTag, getTextAlignment, getTextDirection, getTooltipText, getTooltipView, getTop, getTouchables, getTransitionAlpha, getTransitionName, getTranslationX, getTranslationY, getTranslationZ, getVerticalFadingEdgeLength, getVerticalScrollbarThumbDrawable, getVerticalScrollbarTrackDrawable, getVerticalScrollbarWidth, getViewRoot, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowVisibility, getX, getY, getZ, handleScrollBarDragging, hasExplicitFocusable, hasFocus, hasFocusable, hasIdentityMatrix, hasNestedScrollingParent, hasOnClickListeners, hasOnLongClickListeners, hasOverlappingRendering, hasTransientState, hasTranslationTransientState, hasWindowFocus, internalSetPadding, invalidate, invalidateDrawable, isActivated, isAttachedToWindow, isClickable, isContextClickable, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isFocusedByDefault, isForegroundInsidePadding, isHapticFeedbackEnabled, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isInLayout, isInScrollingContainer, isInTouchMode, isKeyboardNavigationCluster, isLaidOut, isLayoutDirectionInherited, isLayoutDirectionResolved, isLayoutRequested, isLayoutRtl, isLongClickable, isNestedScrollingEnabled, isPaddingRelative, isPivotSet, isPressed, isRootNamespace, isScrollbarFadingEnabled, isSelected, isShowingLayoutBounds, isShown, isSoundEffectsEnabled, isTemporarilyDetached, isTextAlignmentInherited, isTextAlignmentResolved, isTextDirectionInherited, isTextDirectionResolved, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVerticalScrollBarHidden, keyboardNavigationClusterSearch, layout, mapRectFromViewToScreenCoords, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onCancelPendingInputEvents, onDragEvent, onDrawForeground, onDrawScrollBars, onFinishTemporaryDetach, onHoverChanged, onHoverEvent, onOverScrolled, onScrollChanged, onSizeChanged, onStartTemporaryDetach, onVisibilityAggregated, onVisibilityChanged, onWindowFocusChanged, onWindowVisibilityChanged, overScrollBy, performButtonActionOnTouchDown, performClick, performContextClick, performContextClick, performHapticFeedback, performHapticFeedback, performLongClick, performLongClick, playSoundEffect, pointInView, post, postDelayed, postInvalidate, postInvalidateDelayed, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, refreshDrawableState, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestFocus, requestFocus, requestFocus, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, requireViewById, resetPivot, resetResolvedDrawables, resolveDrawables, resolveLayoutDirection, resolveLayoutParams, resolvePadding, resolveRtlPropertiesIfNeeded, resolveSize, resolveSizeAndState, resolveTextAlignment, resolveTextDirection, restoreDefaultFocus, scheduleDrawable, scrollBy, scrollTo, setActivated, setAlpha, setAnimationMatrix, setBackground, setBottom, setClickable, setContextClickable, setDuplicateParentStateEnabled, setElevation, setFocusable, setFocusable, setFocusableInTouchMode, setFocusedByDefault, setFocusedInCluster, setForeground, setForegroundGravity, setFrame, setHapticFeedbackEnabled, setHasTransientState, setHasTranslationTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHorizontalScrollbarThumbDrawable, setHorizontalScrollbarTrackDrawable, setHovered, setId, setIsRootNamespace, setKeyboardNavigationCluster, setLayoutDirection, setLayoutParams, setLeft, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNestedScrollingEnabled, setNextClusterForwardId, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnContextClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnScrollChangeListener, setOnTouchListener, setOverScrollMode, setPivotX, setPivotY, setPressed, setRevealOnFocusHint, setRight, setRotation, setRotationX, setRotationY, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollIndicators, setScrollIndicators, setScrollX, setScrollY, setSelected, setSoundEffectsEnabled, setStateListAnimator, setTag, setTextAlignment, setTextDirection, setTooltipText, setTop, setTransitionAlpha, setTransitionName, setTransitionVisibility, setTranslationX, setTranslationY, setTranslationZ, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarThumbDrawable, setVerticalScrollbarTrackDrawable, setVisibility, setWillNotDraw, setX, setY, setZ, showContextMenu, sp, startActionMode, startActionMode, startDragAndDrop, startNestedScroll, stopNestedScroll, toGlobalMotionEvent, toLocalMotionEvent, toString, transformFromViewToWindowSpace, transformMatrixToGlobal, transformMatrixToLocal, unscheduleDrawable, unscheduleDrawable, willNotDraw
-
Field Details
-
UNKNOWN_BORING
-
-
Constructor Details
-
TextView
-
-
Method Details
-
getMovementMethod
Gets theMovementMethod
being used for this TextView, which provides positioning, scrolling, and text selection functionality. This will frequently be null for non-editable TextViews.- Returns:
- the movement method being used for this TextView.
- See Also:
-
setMovementMethod
Sets theMovementMethod
for handling arrow key movement for this TextView. This can be null to disallow using the arrow keys to move the cursor or scroll the view.Be warned that if you want a TextView with a movement method not to be focusable, or if you want a TextView without a movement method to be focusable, you must call
View.setFocusable(boolean)
again after calling this to get the focusability back the way you want it.- Parameters:
movement
- the movement method to set
-
getTransformationMethod
Gets the currentTransformationMethod
for the TextView. This is frequently null, except for single-line and password fields.- Returns:
- the current transformation method for this TextView.
-
setTransformationMethod
Sets the transformation that is applied to the text that this TextView is displaying.- Parameters:
method
- the transformation method to set
-
getCompoundPaddingTop
public int getCompoundPaddingTop()Returns the top padding of the view, plus space for the top Drawable if any. -
getCompoundPaddingBottom
public int getCompoundPaddingBottom()Returns the bottom padding of the view, plus space for the bottom Drawable if any. -
getCompoundPaddingLeft
public int getCompoundPaddingLeft()Returns the left padding of the view, plus space for the left Drawable if any. -
getCompoundPaddingRight
public int getCompoundPaddingRight()Returns the right padding of the view, plus space for the right Drawable if any. -
getCompoundPaddingStart
public int getCompoundPaddingStart()Returns the start padding of the view, plus space for the start Drawable if any. -
getCompoundPaddingEnd
public int getCompoundPaddingEnd()Returns the end padding of the view, plus space for the end Drawable if any. -
getExtendedPaddingTop
public 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. It is only valid to call this after measuring. -
getExtendedPaddingBottom
public 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. It is only valid to call this after measuring. -
getTotalPaddingLeft
public int getTotalPaddingLeft()Returns the total left padding of the view, including the left Drawable if any. -
getTotalPaddingRight
public int getTotalPaddingRight()Returns the total right padding of the view, including the right Drawable if any. -
getTotalPaddingStart
public int getTotalPaddingStart()Returns the total start padding of the view, including the start Drawable if any. -
getTotalPaddingEnd
public int getTotalPaddingEnd()Returns the total end padding of the view, including the end Drawable if any. -
getTotalPaddingTop
public 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. -
getTotalPaddingBottom
public 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. -
setCompoundDrawables
public void setCompoundDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom) Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Usenull
if you do not want a Drawable there. The Drawables must already have hadDrawable.setBounds(int, int, int, int)
called.Calling this method will overwrite any Drawables previously set using
setCompoundDrawablesRelative(icyllis.modernui.graphics.drawable.Drawable, icyllis.modernui.graphics.drawable.Drawable, icyllis.modernui.graphics.drawable.Drawable, icyllis.modernui.graphics.drawable.Drawable)
or related methods. -
setCompoundDrawablesWithIntrinsicBounds
public void setCompoundDrawablesWithIntrinsicBounds(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom) Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Usenull
if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.Calling this method will overwrite any Drawables previously set using
setCompoundDrawablesRelative(icyllis.modernui.graphics.drawable.Drawable, icyllis.modernui.graphics.drawable.Drawable, icyllis.modernui.graphics.drawable.Drawable, icyllis.modernui.graphics.drawable.Drawable)
or related methods. -
setCompoundDrawablesRelative
public void setCompoundDrawablesRelative(@Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom) Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text. Usenull
if you do not want a Drawable there. The Drawables must already have hadDrawable.setBounds(int, int, int, int)
called.Calling this method will overwrite any Drawables previously set using
setCompoundDrawables(icyllis.modernui.graphics.drawable.Drawable, icyllis.modernui.graphics.drawable.Drawable, icyllis.modernui.graphics.drawable.Drawable, icyllis.modernui.graphics.drawable.Drawable)
or related methods. -
setCompoundDrawablesRelativeWithIntrinsicBounds
public void setCompoundDrawablesRelativeWithIntrinsicBounds(@Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom) Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text. Usenull
if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.Calling this method will overwrite any Drawables previously set using
setCompoundDrawables(icyllis.modernui.graphics.drawable.Drawable, icyllis.modernui.graphics.drawable.Drawable, icyllis.modernui.graphics.drawable.Drawable, icyllis.modernui.graphics.drawable.Drawable)
or related methods. -
getCompoundDrawables
Returns drawables for the left, top, right, and bottom borders. -
getCompoundDrawablesRelative
Returns drawables for the start, top, end, and bottom borders. -
setCompoundDrawablePadding
public void setCompoundDrawablePadding(int pad) Sets the size of the padding between the compound drawables and the text. -
getCompoundDrawablePadding
public int getCompoundDrawablePadding()Returns the padding between the compound drawables and the text. -
setPadding
public void setPadding(int left, int top, int right, int bottom) Description copied from class:View
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 fromView.getPaddingLeft()
,View.getPaddingTop()
,View.getPaddingRight()
andView.getPaddingBottom()
may be different from the values set in this call.- Overrides:
setPadding
in classView
- Parameters:
left
- the left padding in pixelstop
- the top padding in pixelsright
- the right padding in pixelsbottom
- the bottom padding in pixels
-
setPaddingRelative
public void setPaddingRelative(int start, int top, int end, int bottom) Description copied from class:View
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 fromView.getPaddingStart()
,View.getPaddingTop()
,View.getPaddingEnd()
andView.getPaddingBottom()
may be different from the values set in this call.- Overrides:
setPaddingRelative
in classView
- Parameters:
start
- the start padding in pixelstop
- the top padding in pixelsend
- the end padding in pixelsbottom
- the bottom padding in pixels
-
setFirstBaselineToTopHeight
public void setFirstBaselineToTopHeight(int firstBaselineToTopHeight) Updates the top padding of the TextView so thatfirstBaselineToTopHeight
is the distance between the top of the TextView and first line's baseline. Note that ifFontMetrics.top
orFontMetrics.ascent
was already greater thanfirstBaselineToTopHeight
, the top padding is not updated. Moreover, since this function sets the top padding, if the height of the TextView is less than the sum of top padding, line height and bottom padding, top of the line will be pushed down and bottom will be clipped.- Parameters:
firstBaselineToTopHeight
- distance between first baseline to top of the container in pixels- See Also:
-
setLastBaselineToBottomHeight
public void setLastBaselineToBottomHeight(int lastBaselineToBottomHeight) Updates the bottom padding of the TextView so thatlastBaselineToBottomHeight
is the distance between the bottom of the TextView and the last line's baseline. Note that ifFontMetrics.bottom
orFontMetrics.descent
was already greater thanlastBaselineToBottomHeight
, the bottom padding is not updated. Moreover, since this function sets the bottom padding, if the height of the TextView is less than the sum of top padding, line height and bottom padding, bottom of the text will be clipped.- Parameters:
lastBaselineToBottomHeight
- distance between last baseline to bottom of the container in pixels- See Also:
-
getFirstBaselineToTopHeight
public int getFirstBaselineToTopHeight()Returns the distance between the first text baseline and the top of this TextView.- See Also:
-
getLastBaselineToBottomHeight
public int getLastBaselineToBottomHeight()Returns the distance between the last text baseline and the bottom of this TextView.- See Also:
-
getTextLocale
Get the default primaryLocale
of the text in this TextView.- Returns:
- the default primary
Locale
of the text in this TextView.
-
setTextLocale
Set the defaultLocale
of the text in this TextView to the given Locale.- Parameters:
locale
- theLocale
for drawing text, must not be null.
-
getTextSize
public float getTextSize()- Returns:
- the size (in pixels) of the default text size in this TextView.
-
setTextSize
public void setTextSize(float size) 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.- Parameters:
size
- The scaled pixel size.
-
setTextSize
public void setTextSize(int unit, float size) Set the default text size to a given unit and value. SeeTypedValue
for the possible dimension units.- Parameters:
unit
- The desired dimension unit.size
- The desired size in the given units.
-
setTextStyle
public void setTextStyle(int style) Sets the default text style in which the text should be displayed.- Parameters:
style
- the text style to set- See Also:
-
getTextStyle
public int getTextStyle()Gets the current text style that is used to style the text.- Returns:
- the current text style
- See Also:
-
setTypeface
Sets the typeface in which the text should be displayed.- See Also:
-
getTypeface
Gets the currentTypeface
that is used to style the text.- Returns:
- The current Typeface.
- See Also:
-
getLineHeight
public int getLineHeight()Gets the vertical distance between lines of text, in pixels. Note that markup within the text can cause individual lines to be taller or shorter than this height, and the layout may contain additional first-or last-line padding.- Returns:
- The height of one standard line in pixels.
-
setFallbackLineSpacing
public void setFallbackLineSpacing(boolean enabled) Set whether to respect the ascent and descent of the fallback fonts that are used in displaying the text (which is needed to avoid text from consecutive lines running into each other). If set, fallback fonts that end up getting used can increase the ascent and descent of the lines that they are used on. It is required to be true if text could be in languages like Burmese or Tibetan where text is typically much taller or deeper than Latin text.- Parameters:
enabled
- whether to expand line spacing based on fallback fonts,true
by default- See Also:
-
isFallbackLineSpacing
public boolean isFallbackLineSpacing()- Returns:
- whether fallback line spacing is enabled,
true
by default - See Also:
-
setLineBreakStyle
public void setLineBreakStyle(int lineBreakStyle) Set the line break style for text wrapping.The line break style to indicates the line break strategies can be used when calculating the text wrapping. The line break style affects rule-based breaking. It specifies the strictness of line-breaking rules. There are several types for the line break style:
LineBreakConfig.LINE_BREAK_STYLE_LOOSE
,LineBreakConfig.LINE_BREAK_STYLE_NORMAL
andLineBreakConfig.LINE_BREAK_STYLE_STRICT
. The default values of the line break style isLineBreakConfig.LINE_BREAK_STYLE_NONE
, indicating no breaking rule is specified. See the line-break property- Parameters:
lineBreakStyle
- the line break style for the text.
-
setLineBreakWordStyle
public void setLineBreakWordStyle(int lineBreakWordStyle) Set the line break word style for text wrapping.The line break word style affects dictionary-based breaking and provide phrase-based breaking opportunities. The type for the line break word style is
LineBreakConfig.LINE_BREAK_WORD_STYLE_PHRASE
. The default values of the line break word style isLineBreakConfig.LINE_BREAK_WORD_STYLE_NONE
, indicating no breaking rule is specified. See the word-break property- Parameters:
lineBreakWordStyle
- the line break word style for the tet
-
getLineBreakStyle
public int getLineBreakStyle()Get the current line break style for text wrapping.- Returns:
- the current line break style to be used for text wrapping.
-
getLineBreakWordStyle
public int getLineBreakWordStyle()Get the current line word break style for text wrapping.- Returns:
- the current line break word style to be used for text wrapping.
-
getTextMetricsParams
Gets the parameters for text layout pre-computation, for use withPrecomputedText
.- Returns:
- a current
PrecomputedText.Params
- See Also:
-
setTextMetricsParams
Apply the text layout parameter.Update the TextView parameters to be compatible with
PrecomputedText.Params
.- See Also:
-
setTextColor
public void setTextColor(int color) Sets the text color for all the states (normal, selected, focused) to be this color.- Parameters:
color
- A color value in the form 0xAARRGGBB.- See Also:
-
setTextColor
Sets the text color.- See Also:
-
getTextColors
Gets the text colors for the different states (normal, selected, focused) of the TextView.- See Also:
-
getCurrentTextColor
public final int getCurrentTextColor()Return the current color selected for normal text.- Returns:
- Returns the current text color.
-
setHighlightColor
public void setHighlightColor(int color) Sets the color used to display the selection highlight. -
getHighlightColor
public int getHighlightColor()- Returns:
- the color used to display the selection highlight
- See Also:
-
getPaint
Gets theTextPaint
used for the text. Use this only to consult the Paint's properties and not to change them.- Returns:
- The base paint used for the text.
-
getLayout
Gets theLayout
that is currently being used to display the text. This value can be null if the text or width has recently changed.- Returns:
- The Layout that is currently being used to display the text.
-
setAutoLinkMask
public final void setAutoLinkMask(int mask) Sets the autolink mask of the text. -
getAutoLinkMask
public final int getAutoLinkMask()Gets the autolink mask of the text. -
setLinksClickable
public final void setLinksClickable(boolean whether) Sets whether the movement method will automatically be set toLinkMovementMethod
ifsetAutoLinkMask(int)
has been set to nonzero and links are detected insetText(java.lang.CharSequence)
. The default is true. -
getLinksClickable
public final boolean getLinksClickable()Returns whether the movement method will automatically be set toLinkMovementMethod
ifsetAutoLinkMask(int)
has been set to nonzero and links are detected insetText(java.lang.CharSequence)
. The default is true. -
setHintTextColor
public final void setHintTextColor(int color) Sets the color of the hint text for all the states (disabled, focussed, selected...) of this TextView.- See Also:
-
setHintTextColor
Sets the color of the hint text.- See Also:
-
getHintTextColors
- Returns:
- the color of the hint text, for the different states of this TextView.
- See Also:
-
getCurrentHintTextColor
public final int getCurrentHintTextColor()Return the current color selected to paint the hint text.
- Returns:
- Returns the current hint text color.
-
setLinkTextColor
public final void setLinkTextColor(int color) Sets the color of links in the text.- See Also:
-
setLinkTextColor
Sets the color of links in the text.- See Also:
-
getLinkTextColors
- Returns:
- the list of colors used to paint the links in the text, for the different states of this TextView
- See Also:
-
setGravity
public 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.- See Also:
-
getGravity
public int getGravity()Returns the horizontal and vertical alignment of this TextView.- See Also:
-
setHorizontallyScrolling
public void setHorizontallyScrolling(boolean whether) 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. -
isHorizontallyScrollable
public final boolean isHorizontallyScrollable()Returns whether the text is allowed to be wider than the View. If false, the text will be wrapped to the width of the View.- See Also:
-
setMinLines
public void setMinLines(int minLines) Sets the height of the TextView to be at leastminLines
tall.This value is used for height calculation if LayoutParams does not force TextView to have an exact height. Setting this value overrides other previous minimum height configurations such as
setMinHeight(int)
orsetHeight(int)
.setSingleLine()
will set this value to 1.- Parameters:
minLines
- the minimum height of TextView in terms of number of lines- See Also:
-
getMinLines
public int getMinLines()Returns the minimum height of TextView in terms of number of lines or -1 if the minimum height was set usingsetMinHeight(int)
orsetHeight(int)
.- Returns:
- the minimum height of TextView in terms of number of lines or -1 if the minimum height is not defined in lines
- See Also:
-
setMinHeight
public void setMinHeight(int minPixels) Sets the height of the TextView to be at leastminPixels
tall.This value is used for height calculation if LayoutParams does not force TextView to have an exact height. Setting this value overrides previous minimum height configurations such as
setMinLines(int)
orsetLines(int)
.The value given here is different than
View.setMinimumHeight(int)
. BetweenminHeight
and the value set inView.setMinimumHeight(int)
, the greater one is used to decide the final height.- Parameters:
minPixels
- the minimum height of TextView in terms of pixels- See Also:
-
getMinHeight
public int getMinHeight()Returns the minimum height of TextView in terms of pixels or -1 if the minimum height was set usingsetMinLines(int)
orsetLines(int)
.- Returns:
- the minimum height of TextView in terms of pixels or -1 if the minimum height is not defined in pixels
- See Also:
-
setMaxLines
public void setMaxLines(int maxLines) Sets the height of the TextView to be at mostmaxLines
tall.This value is used for height calculation if LayoutParams does not force TextView to have an exact height. Setting this value overrides previous maximum height configurations such as
setMaxHeight(int)
orsetLines(int)
.- Parameters:
maxLines
- the maximum height of TextView in terms of number of lines- See Also:
-
getMaxLines
public int getMaxLines()Returns the maximum height of TextView in terms of number of lines or -1 if the maximum height was set usingsetMaxHeight(int)
orsetHeight(int)
.- Returns:
- the maximum height of TextView in terms of number of lines. -1 if the maximum height is not defined in lines.
- See Also:
-
setMaxHeight
public void setMaxHeight(int maxPixels) Sets the height of the TextView to be at mostmaxPixels
tall.This value is used for height calculation if LayoutParams does not force TextView to have an exact height. Setting this value overrides previous maximum height configurations such as
setMaxLines(int)
orsetLines(int)
.- Parameters:
maxPixels
- the maximum height of TextView in terms of pixels- See Also:
-
getMaxHeight
public int getMaxHeight()Returns the maximum height of TextView in terms of pixels or -1 if the maximum height was set usingsetMaxLines(int)
orsetLines(int)
.- Returns:
- the maximum height of TextView in terms of pixels or -1 if the maximum height is not defined in pixels
- See Also:
-
setLines
public void setLines(int lines) Sets the height of the TextView to be exactlylines
tall.This value is used for height calculation if LayoutParams does not force TextView to have an exact height. Setting this value overrides previous minimum/maximum height configurations such as
setMinLines(int)
orsetMaxLines(int)
.setSingleLine()
will set this value to 1.- Parameters:
lines
- the exact height of the TextView in terms of lines- See Also:
-
setHeight
public void setHeight(int pixels) Sets the height of the TextView to be exactlypixels
tall.This value is used for height calculation if LayoutParams does not force TextView to have an exact height. Setting this value overrides previous minimum/maximum height configurations such as
setMinHeight(int)
orsetMaxHeight(int)
.- Parameters:
pixels
- the exact height of the TextView in terms of pixels- See Also:
-
setMinWidth
public void setMinWidth(int minPixels) Sets the width of the TextView to be at leastminPixels
wide.This value is used for width calculation if LayoutParams does not force TextView to have an exact width.
The value given here is different from
View.setMinimumWidth(int)
. BetweenminWidth
and the value set inView.setMinimumWidth(int)
, the greater one is used to decide the final width.- Parameters:
minPixels
- the minimum width of TextView in terms of pixels- See Also:
-
getMinWidth
public int getMinWidth()Returns the minimum width of TextView in terms of pixels.- Returns:
- the minimum width of TextView in terms of pixels.
- See Also:
-
setMaxWidth
public void setMaxWidth(int maxPixels) Sets the width of the TextView to be at mostmaxPixels
wide.This value is used for width calculation if LayoutParams does not force TextView to have an exact width.
- Parameters:
maxPixels
- the maximum width of TextView in terms of pixels- See Also:
-
getMaxWidth
public int getMaxWidth()Returns the maximum width of TextView in terms of pixels.- Returns:
- the maximum width of TextView in terms of pixels.
- See Also:
-
setWidth
public void setWidth(int pixels) Sets the width of the TextView to be exactlypixels
wide.This value is used for width calculation if LayoutParams does not force TextView to have an exact width. Setting this value overrides previous minimum/maximum width configurations such as
setMinWidth(int)
orsetMaxWidth(int)
.- Parameters:
pixels
- the exact width of the TextView in terms of pixels
-
getText
Return the text that TextView is displaying. IfsetText(CharSequence)
was called with an argument ofBufferType.SPANNABLE
orBufferType.EDITABLE
, you can cast the return value from this method to Spannable or Editable, respectively.The content of the return value should not be modified. If you want a modifiable one, you should make your own copy first.
- Returns:
- The text displayed by the text view.
-
getEditableText
Return the text that TextView is displaying as an Editable object. If the text is not editable, null is returned.- See Also:
-
setEditableFactory
Sets the Factory used to create newEditables
.- Parameters:
factory
-Editable.Factory
to be used- See Also:
-
setSpannableFactory
Sets the Factory used to create newSpannables
.- Parameters:
factory
-Spannable.Factory
to be used- See Also:
-
setText
Sets the text to be displayed. To style your strings, attachCharacterStyle
to aSpannableString
.When required, TextView will use
Spannable.Factory
to create final or intermediateSpannables
. Likewise, it will useEditable.Factory
to create final or intermediateEditables
.If the passed text is a
PrecomputedText
but the parameters used to create the PrecomputedText mismatches with this TextView, IllegalArgumentException is thrown.- Parameters:
text
- text to be displayed- Throws:
IllegalArgumentException
- if the passed text is aPrecomputedText
but the parameters used to create the PrecomputedText mismatches with this TextView.
-
setTextKeepState
Sets the text to be displayed but retains the cursor position. Same assetText(CharSequence)
except that the cursor position (if any) is retained in the new text. When required, TextView will useSpannable.Factory
to create final or intermediateSpannables
. Likewise, it will useEditable.Factory
to create final or intermediateEditables
.- Parameters:
text
- text to be displayed- See Also:
-
setTextKeepState
Sets the text to be displayed and theTextView.BufferType
but retains the cursor position. Same assetText(CharSequence, BufferType)
except that the cursor position (if any) is retained in the new text. When required, TextView will useSpannable.Factory
to create final or intermediateSpannables
. Likewise, it will useEditable.Factory
to create final or intermediateEditables
.- Parameters:
text
- text to be displayedtype
- aTextView.BufferType
which defines whether the text is stored as a static text, styleable/spannable text, or editable text- See Also:
-
setText
Sets the text to be displayed and theTextView.BufferType
. When required, TextView will useSpannable.Factory
to create final or intermediateSpannables
. Likewise, it will useEditable.Factory
to create final or intermediateEditables
.Subclasses overriding this method should ensure that the following post condition holds, in order to guarantee the safety of the view's measurement and layout operations: regardless of the input, after calling #setText both
mText
andmTransformed
will be different fromnull
.- Parameters:
text
- text to be displayedtype
- aTextView.BufferType
which defines whether the text is stored as a static text, styleable/spannable text, or editable text- See Also:
-
getHint
Returns the hint that is displayed when the text of the TextView is empty. -
setHint
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. -
setFilters
Sets the list of input filters that will be used if the buffer is Editable. Has no effect otherwise. -
getFilters
Returns the current list of input filters. -
onPreDraw
public boolean onPreDraw()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.- Specified by:
onPreDraw
in interfaceViewTreeObserver.OnPreDrawListener
- Returns:
- Return true to proceed with the current drawing pass, or false to cancel.
- See Also:
-
onAttachedToWindow
protected void onAttachedToWindow()Description copied from class:View
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 beforeView.onDraw(Canvas)
, however it may be called any time before the first onDraw -- including before or afterView.onMeasure(int, int)
.- Overrides:
onAttachedToWindow
in classView
- See Also:
-
onDetachedFromWindow
protected void onDetachedFromWindow()Description copied from class:View
This is called when the view is detached from a window. At this point it no longer has a surface for drawing.- Overrides:
onDetachedFromWindow
in classView
- See Also:
-
verifyDrawable
Description copied from class:View
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.
- Overrides:
verifyDrawable
in classView
- 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 then the Drawable is being displayed in the view; else false and it is not allowed to animate.
- See Also:
-
jumpDrawablesToCurrentState
public void jumpDrawablesToCurrentState()Description copied from class:View
CallDrawable.jumpToCurrentState()
on all Drawable objects associated with this view.Also calls
StateListAnimator.jumpToCurrentState()
if there is a StateListAnimator attached to this view.- Overrides:
jumpDrawablesToCurrentState
in classView
-
isTextSelectable
public boolean isTextSelectable()Returns the state of thetextIsSelectable
flag (SeesetTextIsSelectable()
). 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.- Returns:
- True if the text displayed in this TextView can be selected by the user.
-
setTextIsSelectable
public void setTextIsSelectable(boolean selectable) Sets whether the content of this view is selectable by the user. The default isfalse
, 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.
When you call this method to set the value of
textIsSelectable
, it sets the flagsfocusable
,focusableInTouchMode
,clickable
, andlongClickable
to the same value. To restore any of these flags to a state you had set previously, call one or more of the following methods:setFocusable()
,setFocusableInTouchMode()
,setClickable()
orsetLongClickable()
.The content of an EditText (A editable TextView) can always be selected, and you should not the value of this flag.
- Parameters:
selectable
- Whether the content of this TextView should be selectable.
-
drawableStateChanged
protected void drawableStateChanged()Description copied from class:View
This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.If the View has a StateListAnimator, it will also be called to run necessary state change animations.
Be sure to call through to the superclass when overriding this function.
- Overrides:
drawableStateChanged
in classView
- See Also:
-
onCreateDrawableState
Description copied from class:View
Generate the newDrawable
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 useView.getDrawableState()
.- Overrides:
onCreateDrawableState
in classView
- 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:
- an array holding the current
Drawable
state of the view. - See Also:
-
getHorizontalOffsetForDrawables
public int getHorizontalOffsetForDrawables() -
onDraw
Description copied from class:View
Draw the content of this view, implement this to do your drawing.Note that (0, 0) will be the top left of the bounds, and (width, height) will be the bottom right of the bounds.
-
getFocusedRect
Description copied from class:View
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
View.getDrawingRect(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.- Overrides:
getFocusedRect
in classView
- Parameters:
r
- The rectangle to fill in, in this view's coordinates.
-
getLineCount
public int getLineCount()Return the number of lines of text, or 0 if the internal Layout has not been built. -
getLineBounds
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
-
getBaseline
public int getBaseline()Description copied from class:View
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.
- Overrides:
getBaseline
in classView
- Returns:
- the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported
-
nullLayouts
@VisibleForTesting public final void nullLayouts() -
makeNewLayout
@VisibleForTesting public final void makeNewLayout(int wantWidth, int hintWidth, BoringLayout.Metrics boring, BoringLayout.Metrics hintBoring, int ellipsisWidth, boolean bringIntoView) The width passed in is now the desired layout width, not the full view width with padding. -
useDynamicLayout
@VisibleForTesting public final boolean useDynamicLayout()Returns true if DynamicLayout is required -
setIncludeFontPadding
public 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. The default is true.- See Also:
-
getIncludeFontPadding
public 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.- See Also:
-
onMeasure
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) Description copied from class:View
Measure the view and its content to determine the measured width and the measured height. This method is invoked byView.measure(int, int)
and should be overridden by subclasses to provide accurate and efficient measurement of their contents.CONTRACT: When overriding this method, you must call
View.setMeasuredDimension(int, int)
to store the measured width and height of this view. Failure to do so will trigger anIllegalStateException
, thrown byView.measure(int, int)
. Calling super.onMeasure() 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 the base one to provide better measurements of their content.
- Overrides:
onMeasure
in classView
- Parameters:
widthMeasureSpec
- width measure specification imposed by the parentMeasureSpec
heightMeasureSpec
- height measure specification imposed by the parentMeasureSpec
-
onLayout
protected void onLayout(boolean changed, int left, int top, int right, int bottom) Description copied from class:View
Called fromView.layout(int, int, int, int)
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.
-
bringPointIntoView
public boolean bringPointIntoView(int offset) 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. -
moveCursorToVisibleOffset
public boolean moveCursorToVisibleOffset()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.
-
getSelectionStart
public int getSelectionStart()Convenience forSelection.getSelectionStart(java.lang.CharSequence)
. -
getSelectionEnd
public int getSelectionEnd()Convenience forSelection.getSelectionEnd(java.lang.CharSequence)
. -
hasSelection
public boolean hasSelection()Return true iff there is a selection of nonzero length inside this text view. -
setSingleLine
public void setSingleLine()Sets the properties of this field (lines, horizontally scrolling, transformation method) to be for a single-line input. -
setSingleLine
public 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.Note that the default conditions are not necessarily those that were in effect prior this method, and you may want to reset these properties to your custom values.
Note that due to performance reasons, by setting single line for the EditText, the maximum text length is set to 5000 if no other character limitation are applied.
-
setEllipsize
Causes words in the text that are longer than the view's width to be ellipsized instead of broken in the middle. You may also want tosetSingleLine()
orsetHorizontallyScrolling(boolean)
to constrain the text to a single line. Usenull
to turn off ellipsizing.If
setMaxLines(int)
has been used to set two or more lines, onlyTextUtils.TruncateAt.END
is supported (other ellipsizing types will not do anything). -
getEllipsize
Returns where, if anywhere, words that are longer than the view is wide should be ellipsized. -
setSelectAllOnFocus
public void setSelectAllOnFocus(boolean selectAllOnFocus) Set the TextView so that when it takes focus, all the text is selected. -
setCursorVisible
public void setCursorVisible(boolean visible) Set whether the cursor is visible. The default is true. Note that this property only makes sense for editable TextView. If IME is consuming the input, the cursor will always be invisible, visibility will be updated as the last state when IME does not consume the input anymore.- See Also:
-
isCursorVisible
public boolean isCursorVisible()- Returns:
- whether the cursor is visible (assuming this TextView is editable). This
method may return
false
when the IME is consuming the input even if themEditor.mCursorVisible
attribute istrue
or#setCursorVisible(true)
is called. - See Also:
-
onTextChanged
This method is called when the text is changed, in case any subclasses would like to know.Within
text
, thelengthAfter
characters beginning atstart
have just replaced old text that had lengthlengthBefore
. It is an error to attempt to make changes totext
from this callback.- Parameters:
text
- The text the TextView is displayingstart
- The offset of the start of the range of the text that was modifiedlengthBefore
- The length of the former text that has been replacedlengthAfter
- The length of the replacement modified text
-
addTextChangedListener
Adds a TextWatcher to the list of those whose methods are called whenever this TextView's text changes.In 1.0, the
TextWatcher.afterTextChanged(icyllis.modernui.text.Editable)
method was erroneously not called aftersetText(java.lang.CharSequence)
calls. Now, doingsetText(java.lang.CharSequence)
if there are any text changed listeners forces the buffer type to Editable if it would not otherwise be and does call this method.- Parameters:
watcher
- the watcher to add
-
removeTextChangedListener
Removes the specified TextWatcher from the list of those whose methods are called whenever this TextView's text changes.- Parameters:
watcher
- the watcher to remove
-
onFocusChanged
Description copied from class:View
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.- Overrides:
onFocusChanged
in classView
- 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 areView.FOCUS_UP
,View.FOCUS_DOWN
,View.FOCUS_LEFT
,View.FOCUS_RIGHT
,View.FOCUS_FORWARD
, orView.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 benull
otherwise.
-
onTouchEvent
Description copied from class:View
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
View.performClick()
. This will ensure consistent system behavior.- Overrides:
onTouchEvent
in classView
- Parameters:
event
- the touch event- Returns:
true
if the event was handled by the view,false
otherwise
-
onGenericMotionEvent
Description copied from class:View
Implement this method to handle generic motion events.Implementations of this method should check if this view ENABLED and CLICKABLE.
- Overrides:
onGenericMotionEvent
in classView
- Parameters:
event
- the generic motion event being processed.- Returns:
true
if the event was consumed by the view,false
otherwise
-
onCreateContextMenu
Description copied from class:View
Views should implement this if the view itself is going to add items to the context menu.- Overrides:
onCreateContextMenu
in classView
- Parameters:
menu
- the context menu to populate
-
showContextMenu
public boolean showContextMenu(float x, float y) Description copied from class:View
Shows the context menu for this view anchored to the specified view-relative coordinate.- Overrides:
showContextMenu
in classView
- Parameters:
x
- the X coordinate in pixels relative to the view to which the menu should be anchored, orFloat.NaN
to disable anchoringy
- the Y coordinate in pixels relative to the view to which the menu should be anchored, orFloat.NaN
to disable anchoring- Returns:
true
if the context menu was shown,false
otherwise
-
didTouchFocusSelect
public 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. Only valid while processing the touch gesture of interest, in an editable text view. -
cancelLongPress
public void cancelLongPress()Description copied from class:View
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.- Overrides:
cancelLongPress
in classView
-
computeHorizontalScrollRange
protected int computeHorizontalScrollRange()Description copied from class:View
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
View.computeHorizontalScrollExtent()
andView.computeHorizontalScrollOffset()
.The default range is the drawing width of this view.
- Overrides:
computeHorizontalScrollRange
in classView
- Returns:
- the total horizontal range represented by the horizontal scrollbar
- See Also:
-
computeVerticalScrollRange
protected int computeVerticalScrollRange()Description copied from class:View
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
View.computeVerticalScrollExtent()
andView.computeVerticalScrollOffset()
.- Overrides:
computeVerticalScrollRange
in classView
- Returns:
- the total vertical range represented by the vertical scrollbar
The default range is the drawing height of this view.
- See Also:
-
computeVerticalScrollExtent
protected int computeVerticalScrollExtent()Description copied from class:View
Compute the vertical extent of the vertical 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
View.computeVerticalScrollRange()
andView.computeVerticalScrollOffset()
.The default extent is the drawing height of this view.
- Overrides:
computeVerticalScrollExtent
in classView
- Returns:
- the vertical extent of the scrollbar's thumb
- See Also:
-
onKeyDown
Description copied from class:View
Default implementation: perform press of the view whenKeyEvent.KEY_ENTER
,KeyEvent.KEY_KP_ENTER
orKeyEvent.KEY_SPACE
is released, if the view is enabled and clickable. -
onKeyUp
Description copied from class:View
Default implementation: perform clicking of the view whenKeyEvent.KEY_ENTER
,KeyEvent.KEY_KP_ENTER
orKeyEvent.KEY_SPACE
is released. -
onKeyShortcut
Description copied from class:View
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 theshortcut
property of menu items.- Overrides:
onKeyShortcut
in classView
- 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.
-
getWordIterator
This method is used by the ArrowKeyMovementMethod to jump from one word to the other. Made available to achieve a consistent behavior. -
onTextContextMenuItem
public boolean onTextContextMenuItem(int id) Called when a context menu option for the text view is selected. Currently, this will be one ofR.id.selectAll
,R.id.cut
,R.id.copy
,R.id.paste
.- Returns:
- true if the context menu item action was performed.
-
onRtlPropertiesChanged
protected void onRtlPropertiesChanged(int layoutDirection) Description copied from class:View
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.
- Overrides:
onRtlPropertiesChanged
in classView
- Parameters:
layoutDirection
- the direction of the layout- See Also:
-
getTextDirectionHeuristic
Returns resolvedTextDirectionHeuristic
that will be used for text layout. TheTextDirectionHeuristic
that is used by TextView is only available afterView.getTextDirection()
andView.getLayoutDirection()
is resolved. Therefore the return value may not be the same as the one TextView uses if the View's layout direction is not resolved or detached from parent root view. -
onResolveDrawables
public void onResolveDrawables(int layoutDirection) Description copied from class:View
Called when layout direction has been resolved.The default implementation does nothing.
- Overrides:
onResolveDrawables
in classView
- Parameters:
layoutDirection
- The resolved layout direction.- See Also:
-
onResolvePointerIcon
Description copied from class:View
Returns the pointer icon for the motion event, or null if it doesn't specify the icon. The default implementation does not care the location or event types, but some subclasses may use it (such as WebViews).- Overrides:
onResolvePointerIcon
in classView
- Parameters:
event
- The MotionEvent from a mouse- See Also:
-
setEnabled
public void setEnabled(boolean enabled) Description copied from class:View
Set the enabled state of this view. The interpretation of the enabled state varies by subclass.- Overrides:
setEnabled
in classView
- Parameters:
enabled
- True if this view is enabled, false otherwise.
-
getOffsetForPosition
public int getOffsetForPosition(float x, float y) Get the character offset closest to the specified absolute position. A typical use case is to pass the result ofMotionEvent.getX()
andMotionEvent.getY()
to this method.- Parameters:
x
- The horizontal absolute position of a point on screeny
- 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.
-