Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

AppCompatTextView

open class AppCompatTextView : TextView, TintableBackgroundView, TintableCompoundDrawablesView, AutoSizeableTextView
kotlin.Any
   ↳ android.view.View
   ↳ android.widget.TextView
   ↳ androidx.appcompat.widget.AppCompatTextView

A TextView which supports compatible features on older versions of the platform, including:

  • Allows dynamic tint of its background via the background tint methods in androidx.core.view.ViewCompat.
  • Allows setting of the background tint using androidx.appcompat.R.attr#backgroundTint and androidx.appcompat.R.attr#backgroundTintMode.
  • Supports auto-sizing via androidx.core.widget.TextViewCompat by allowing to instruct a TextView to let the size of the text expand or contract automatically to fill its layout based on the TextView's characteristics and boundaries. The style attributes associated with auto-sizing are androidx.appcompat.R.attr#autoSizeTextType, androidx.appcompat.R.attr#autoSizeMinTextSize, androidx.appcompat.R.attr#autoSizeMaxTextSize, androidx.appcompat.R.attr#autoSizeStepGranularity and androidx.appcompat.R.attr#autoSizePresetSizes, all of which work back to Ice Cream Sandwich.

This will automatically be used when you use TextView in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.

Summary

Public constructors
<init>(context: Context!)

<init>(context: Context!, attrs: AttributeSet!)

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Public methods
open Int

open Int

open Unit
setCompoundDrawablesWithIntrinsicBounds(@Nullable left: Drawable?, @Nullable top: Drawable?, @Nullable right: Drawable?, @Nullable bottom: Drawable?)

open Unit
setCompoundDrawablesWithIntrinsicBounds(left: Int, top: Int, right: Int, bottom: Int)

open Unit
setBackgroundResource(@DrawableRes resId: Int)

open Unit
setFirstBaselineToTopHeight(@Px firstBaselineToTopHeight: Int)

open Unit

Set the precomputed text future.

open CharSequence!

open Unit

Sets the PrecomputedTextCompat to the TextView.

open Unit
setTextAppearance(context: Context!, resId: Int)

open Unit
setCompoundDrawables(@Nullable left: Drawable?, @Nullable top: Drawable?, @Nullable right: Drawable?, @Nullable bottom: Drawable?)

open Unit

See TextViewCompat#setCustomSelectionActionModeCallback(TextView, ActionMode.Callback)

open Unit
setLineHeight(@Px lineHeight: Int)

open Unit
setLastBaselineToBottomHeight(@Px lastBaselineToBottomHeight: Int)

open Unit

Apply the text layout parameter.

open Unit
setCompoundDrawablesRelative(@Nullable start: Drawable?, @Nullable top: Drawable?, @Nullable end: Drawable?, @Nullable bottom: Drawable?)

open Unit

open Unit
setCompoundDrawablesRelativeWithIntrinsicBounds(@Nullable start: Drawable?, @Nullable top: Drawable?, @Nullable end: Drawable?, @Nullable bottom: Drawable?)

open Unit

open Unit
setTextSize(unit: Int, size: Float)

open InputConnection!

open Unit
setTextClassifier(@Nullable textClassifier: TextClassifier?)

Sets the TextClassifier for this TextView.

open PrecomputedTextCompat.Params

Gets the parameters for text layout precomputation, for use with PrecomputedTextCompat.

open TextClassifier

Returns the TextClassifier used by this TextView.

open Unit
setTypeface(@Nullable tf: Typeface?, style: Int)

Protected methods
open Unit

open Unit
onTextChanged(text: CharSequence!, start: Int, lengthBefore: Int, lengthAfter: Int)

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

open Unit
onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int)

Public constructors

<init>

AppCompatTextView(context: Context!)

<init>

AppCompatTextView(context: Context!, attrs: AttributeSet!)

<init>

AppCompatTextView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Public methods

getLastBaselineToBottomHeight

open fun getLastBaselineToBottomHeight(): Int

getFirstBaselineToTopHeight

open fun getFirstBaselineToTopHeight(): Int

setCompoundDrawablesWithIntrinsicBounds

open fun setCompoundDrawablesWithIntrinsicBounds(@Nullable left: Drawable?, @Nullable top: Drawable?, @Nullable right: Drawable?, @Nullable bottom: Drawable?): Unit

setCompoundDrawablesWithIntrinsicBounds

open fun setCompoundDrawablesWithIntrinsicBounds(left: Int, top: Int, right: Int, bottom: Int): Unit

setBackgroundResource

open fun setBackgroundResource(@DrawableRes resId: Int): Unit

setFirstBaselineToTopHeight

open fun setFirstBaselineToTopHeight(@Px firstBaselineToTopHeight: Int): Unit

setTextFuture

open fun setTextFuture(@Nullable future: Future<PrecomputedTextCompat!>?): Unit

Set the precomputed text future. This method sets future of the precomputed text instead of immediately applying text to the TextView. Anything layout related property changes, text size, typeface, letter spacing, etc after this method call will causes IllegalArgumentException during View measurement. See PrecomputedTextCompat#getTextFuture for more detail.

Parameters
future Future<PrecomputedTextCompat!>?: a future for the precomputed text

getText

open fun getText(): CharSequence!

setPrecomputedText

open fun setPrecomputedText(@NonNull precomputed: PrecomputedTextCompat): Unit

Sets the PrecomputedTextCompat to the TextView. If the given PrecomputeTextCompat is not compatible with textView, throws an IllegalArgumentException.

Parameters
precomputed PrecomputedTextCompat: the precomputed text
Exceptions
IllegalArgumentException if precomputed text is not compatible with textView.

setTextAppearance

open fun setTextAppearance(context: Context!, resId: Int): Unit

setCompoundDrawables

open fun setCompoundDrawables(@Nullable left: Drawable?, @Nullable top: Drawable?, @Nullable right: Drawable?, @Nullable bottom: Drawable?): Unit

setCustomSelectionActionModeCallback

open fun setCustomSelectionActionModeCallback(actionModeCallback: Callback!): Unit

See TextViewCompat#setCustomSelectionActionModeCallback(TextView, ActionMode.Callback)

setLineHeight

open fun setLineHeight(@Px lineHeight: Int): Unit

setLastBaselineToBottomHeight

open fun setLastBaselineToBottomHeight(@Px lastBaselineToBottomHeight: Int): Unit

setTextMetricsParamsCompat

open fun setTextMetricsParamsCompat(@NonNull params: PrecomputedTextCompat.Params): Unit

Apply the text layout parameter. Update the TextView parameters to be compatible with PrecomputedTextCompat.Params.

setCompoundDrawablesRelative

open fun setCompoundDrawablesRelative(@Nullable start: Drawable?, @Nullable top: Drawable?, @Nullable end: Drawable?, @Nullable bottom: Drawable?): Unit

setBackgroundDrawable

open fun setBackgroundDrawable(background: Drawable!): Unit

setCompoundDrawablesRelativeWithIntrinsicBounds

open fun setCompoundDrawablesRelativeWithIntrinsicBounds(@Nullable start: Drawable?, @Nullable top: Drawable?, @Nullable end: Drawable?, @Nullable bottom: Drawable?): Unit

setCompoundDrawablesRelativeWithIntrinsicBounds

open fun setCompoundDrawablesRelativeWithIntrinsicBounds(start: Int, top: Int, end: Int, bottom: Int): Unit

setTextSize

open fun setTextSize(unit: Int, size: Float): Unit

onCreateInputConnection

open fun onCreateInputConnection(outAttrs: EditorInfo!): InputConnection!

setTextClassifier

open fun setTextClassifier(@Nullable textClassifier: TextClassifier?): Unit

Sets the TextClassifier for this TextView.

getTextMetricsParamsCompat

@NonNull open fun getTextMetricsParamsCompat(): PrecomputedTextCompat.Params

Gets the parameters for text layout precomputation, for use with PrecomputedTextCompat.

Return
PrecomputedTextCompat.Params: a current PrecomputedTextCompat.Params

getTextClassifier

@NonNull open fun getTextClassifier(): TextClassifier

Returns the TextClassifier used by this TextView. If no TextClassifier has been set, this TextView uses the default set by the android.view.textclassifier.TextClassificationManager.

setTypeface

open fun setTypeface(@Nullable tf: Typeface?, style: Int): Unit

Protected methods

drawableStateChanged

protected open fun drawableStateChanged(): Unit

onTextChanged

protected open fun onTextChanged(text: CharSequence!, start: Int, lengthBefore: Int, lengthAfter: Int): Unit

onMeasure

protected open fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit

onLayout

protected open fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int): Unit