The Android Developer Challenge is back! Submit your idea before December 2.

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 CharSequence!

open TextClassifier

Returns the TextClassifier used by this TextView.

open PrecomputedTextCompat.Params

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

open InputConnection!

open Unit

open Unit
setBackgroundResource(@DrawableRes resId: Int)

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

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

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

open Unit

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

See TextViewCompat#setCustomSelectionActionModeCallback(TextView, ActionMode.Callback)

open Unit
setFirstBaselineToTopHeight(@Px firstBaselineToTopHeight: Int)

open Unit
setLastBaselineToBottomHeight(@Px lastBaselineToBottomHeight: Int)

open Unit
setLineHeight(@Px lineHeight: Int)

open Unit

Sets the PrecomputedTextCompat to the TextView.

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

open Unit
setTextClassifier(@Nullable textClassifier: TextClassifier?)

Sets the TextClassifier for this TextView.

open Unit

Set the precomputed text future.

open Unit

Apply the text layout parameter.

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

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

Protected methods

open Unit

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

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

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

Public constructors

<init>

AppCompatTextView(context: Context!)

<init>

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

<init>

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

Public methods

getFirstBaselineToTopHeight

open fun getFirstBaselineToTopHeight(): Int

getLastBaselineToBottomHeight

open fun getLastBaselineToBottomHeight(): Int

getText

open fun getText(): CharSequence!

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.

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

onCreateInputConnection

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

setBackgroundDrawable

open fun setBackgroundDrawable(background: Drawable!): Unit

setBackgroundResource

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

setCompoundDrawables

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

setCompoundDrawablesRelative

open fun setCompoundDrawablesRelative(@Nullable start: Drawable?, @Nullable top: Drawable?, @Nullable end: Drawable?, @Nullable bottom: 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

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

setCustomSelectionActionModeCallback

open fun setCustomSelectionActionModeCallback(actionModeCallback: Callback!): Unit

See TextViewCompat#setCustomSelectionActionModeCallback(TextView, ActionMode.Callback)

setFirstBaselineToTopHeight

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

setLastBaselineToBottomHeight

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

setLineHeight

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

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

setTextClassifier

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

Sets the TextClassifier for this TextView.

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

setTextMetricsParamsCompat

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

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

setTextSize

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

setTypeface

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

Protected methods

drawableStateChanged

protected open fun drawableStateChanged(): Unit

onLayout

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

onMeasure

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

onTextChanged

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