TextViewCompat

Added in 1.1.0

public final class TextViewCompat


Helper for accessing features in TextView.

Summary

Constants

static final int

The TextView does not auto-size text (default).

static final int

The TextView scales text size both horizontally and vertically to fit within the container.

Public methods

static int

name android:autoSizeMaxTextSize

static int

name android:autoSizeMinTextSize

static int

name android:autoSizeStepGranularity

static @NonNull int[]

name android:autoSizePresetSizes

static int

Returns the type of auto-size set for this widget.

static @Nullable ColorStateList

Return the tint applied to any compound drawables.

static @Nullable PorterDuff.Mode

Return the tint mode applied to any compound drawables.

static @NonNull Drawable[]
@ReplaceWith(expression = "textView.getCompoundDrawablesRelative()")
getCompoundDrawablesRelative(@NonNull TextView textView)

This method is deprecated.

Call getCompoundDrawablesRelative directly.

static int

Returns the distance between the first text baseline and the top of this TextView.

static int

Returns the distance between the last text baseline and the bottom of this TextView.

static int
@ReplaceWith(expression = "textView.getMaxLines()")
getMaxLines(@NonNull TextView textView)

This method is deprecated.

Call getMaxLines directly.

static int
@ReplaceWith(expression = "textView.getMinLines()")
getMinLines(@NonNull TextView textView)

This method is deprecated.

Call getMinLines directly.

static @NonNull PrecomputedTextCompat.Params

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

static void
setAutoSizeTextTypeUniformWithConfiguration(
    @NonNull TextView textView,
    int autoSizeMinTextSize,
    int autoSizeMaxTextSize,
    int autoSizeStepGranularity,
    int unit
)

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds.

static void
setAutoSizeTextTypeUniformWithPresetSizes(
    @NonNull TextView textView,
    @NonNull int[] presetSizes,
    int unit
)

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds.

static void
setAutoSizeTextTypeWithDefaults(
    @NonNull TextView textView,
    int autoSizeTextType
)

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds by using the default auto-size configuration.

static void

Applies a tint to any compound drawables.

static void

Applies a tint mode to any compound drawables.

static void
@ReplaceWith(expression = "textView.setCompoundDrawablesRelative(start, top, end, bottom)")
setCompoundDrawablesRelative(
    @NonNull TextView textView,
    @Nullable Drawable start,
    @Nullable Drawable top,
    @Nullable Drawable end,
    @Nullable Drawable bottom
)

This method is deprecated.

Call setCompoundDrawablesRelative directly.

static void
@ReplaceWith(expression = "textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom)")
setCompoundDrawablesRelativeWithIntrinsicBounds(
    @NonNull TextView textView,
    @Nullable Drawable start,
    @Nullable Drawable top,
    @Nullable Drawable end,
    @Nullable Drawable bottom
)

This method is deprecated.

Call setCompoundDrawablesRelativeWithIntrinsicBounds directly.

static void
@ReplaceWith(expression = "textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom)")
setCompoundDrawablesRelativeWithIntrinsicBounds(
    @NonNull TextView textView,
    @DrawableRes int start,
    @DrawableRes int top,
    @DrawableRes int end,
    @DrawableRes int bottom
)

This method is deprecated.

Call setCompoundDrawablesRelativeWithIntrinsicBounds directly.

static void
@ReplaceWith(expression = "textView.setCustomSelectionActionModeCallback(callback)")
setCustomSelectionActionModeCallback(
    @NonNull TextView textView,
    @NonNull ActionMode.Callback callback
)

This method is deprecated.

Call setCustomSelectionActionModeCallback directly.

static void
setFirstBaselineToTopHeight(
    @NonNull TextView textView,
    @Px @IntRange(from = 0) int firstBaselineToTopHeight
)

Updates the top padding of the TextView so that firstBaselineToTopHeight is equal to the distance between the first text baseline and the top of this TextView.

static void
setLastBaselineToBottomHeight(
    @NonNull TextView textView,
    @Px @IntRange(from = 0) int lastBaselineToBottomHeight
)

Updates the bottom padding of the TextView so that lastBaselineToBottomHeight is equal to the distance between the last text baseline and the bottom of this TextView.

static void
setLineHeight(
    @NonNull TextView textView,
    @Px @IntRange(from = 0) int lineHeight
)

Sets an explicit line height for this TextView.

static void
setLineHeight(
    @NonNull TextView textView,
    int unit,
    @FloatRange(from = 0) float lineHeight
)

Sets an explicit line height to a given unit and value for the TextView.

static void
setPrecomputedText(
    @NonNull TextView textView,
    @NonNull PrecomputedTextCompat precomputed
)

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

static void
setTextAppearance(@NonNull TextView textView, @StyleRes int resId)

Sets the text appearance from the specified style resource.

static void

Apply the text layout parameter.

Constants

AUTO_SIZE_TEXT_TYPE_NONE

Added in 1.1.0
public static final int AUTO_SIZE_TEXT_TYPE_NONE = 0

The TextView does not auto-size text (default).

AUTO_SIZE_TEXT_TYPE_UNIFORM

Added in 1.1.0
public static final int AUTO_SIZE_TEXT_TYPE_UNIFORM = 1

The TextView scales text size both horizontally and vertically to fit within the container.

Public methods

getAutoSizeMaxTextSize

Added in 1.1.0
public static int getAutoSizeMaxTextSize(@NonNull TextView textView)

name android:autoSizeMaxTextSize

Returns
int

the current auto-size maximum text size in pixels (the default is 112sp). Note that if auto-size has not been configured this function returns -1.

getAutoSizeMinTextSize

Added in 1.1.0
public static int getAutoSizeMinTextSize(@NonNull TextView textView)

name android:autoSizeMinTextSize

Returns
int

the current auto-size minimum text size in pixels (the default is 12sp). Note that if auto-size has not been configured this function returns -1.

getAutoSizeStepGranularity

Added in 1.1.0
public static int getAutoSizeStepGranularity(@NonNull TextView textView)

name android:autoSizeStepGranularity

Returns
int

the current auto-size step granularity in pixels.

getAutoSizeTextAvailableSizes

Added in 1.1.0
public static @NonNull int[] getAutoSizeTextAvailableSizes(@NonNull TextView textView)

name android:autoSizePresetSizes

Returns
@NonNull int[]

the current auto-size int sizes array (in pixels).

getAutoSizeTextType

Added in 1.1.0
public static int getAutoSizeTextType(@NonNull TextView textView)

Returns the type of auto-size set for this widget.

name android:autoSizeTextType

Returns
int

an int corresponding to one of the auto-size types: AUTO_SIZE_TEXT_TYPE_NONE or AUTO_SIZE_TEXT_TYPE_UNIFORM

getCompoundDrawableTintList

Added in 1.1.0
public static @Nullable ColorStateList getCompoundDrawableTintList(@NonNull TextView textView)

Return the tint applied to any compound drawables.

Only returns meaningful info when running on API v24 or newer, or if textView implements the TintableCompoundDrawablesView interface.

getCompoundDrawableTintMode

Added in 1.1.0
public static @Nullable PorterDuff.Mode getCompoundDrawableTintMode(@NonNull TextView textView)

Return the tint mode applied to any compound drawables.

Only returns meaningful info when running on API v24 or newer, or if textView implements the TintableCompoundDrawablesView interface.

getCompoundDrawablesRelative

Added in 1.1.0
Deprecated in 1.15.0
@ReplaceWith(expression = "textView.getCompoundDrawablesRelative()")
public static @NonNull Drawable[] getCompoundDrawablesRelative(@NonNull TextView textView)

Returns drawables for the start, top, end, and bottom borders from the given text view.

getFirstBaselineToTopHeight

Added in 1.1.0
public static int getFirstBaselineToTopHeight(@NonNull TextView textView)

Returns the distance between the first text baseline and the top of this TextView.

name android:firstBaselineToTopHeight

getLastBaselineToBottomHeight

Added in 1.1.0
public static int getLastBaselineToBottomHeight(@NonNull TextView textView)

Returns the distance between the last text baseline and the bottom of this TextView.

name android:lastBaselineToBottomHeight

getMaxLines

Added in 1.1.0
Deprecated in 1.15.0
@ReplaceWith(expression = "textView.getMaxLines()")
public static int getMaxLines(@NonNull TextView textView)

Returns the maximum number of lines displayed in the given TextView, or -1 if the maximum height was set in pixels instead.

getMinLines

Added in <a href="