added in version 22.1.0
belongs to Maven artifact com.android.support:support-compat:28.0.0-alpha1

TextViewCompat

public final class TextViewCompat
extends Object

java.lang.Object
   ↳ android.support.v4.widget.TextViewCompat


Helper for accessing features in TextView.

Summary

Constants

int AUTO_SIZE_TEXT_TYPE_NONE

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

int AUTO_SIZE_TEXT_TYPE_UNIFORM

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

Public methods

static int getAutoSizeMaxTextSize(TextView textView)
static int getAutoSizeMinTextSize(TextView textView)
static int getAutoSizeStepGranularity(TextView textView)
static int[] getAutoSizeTextAvailableSizes(TextView textView)
static int getAutoSizeTextType(TextView textView)

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

static Drawable[] getCompoundDrawablesRelative(TextView textView)

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

static int getMaxLines(TextView textView)

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

static int getMinLines(TextView textView)

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

static void setAutoSizeTextTypeUniformWithConfiguration(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(TextView textView, 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(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 setCompoundDrawablesRelative(TextView textView, 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.

static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView textView, 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.

static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView textView, int start, int top, int end, int bottom)

Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text.

static void setCustomSelectionActionModeCallback(TextView textView, ActionMode.Callback callback)

Sets a selection action mode callback on a TextView.

static void setTextAppearance(TextView textView, int resId)

Sets the text appearance from the specified style resource.

Inherited methods

From class java.lang.Object

Constants

AUTO_SIZE_TEXT_TYPE_NONE

added in version 26.1.0
int AUTO_SIZE_TEXT_TYPE_NONE

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

Constant Value: 0 (0x00000000)

AUTO_SIZE_TEXT_TYPE_UNIFORM

added in version 26.1.0
int AUTO_SIZE_TEXT_TYPE_UNIFORM

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

Constant Value: 1 (0x00000001)

Public methods

getAutoSizeMaxTextSize

added in version 26.1.0
int getAutoSizeMaxTextSize (TextView textView)

Parameters
textView TextView

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 version 26.1.0
int getAutoSizeMinTextSize (TextView textView)

Parameters
textView TextView

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 version 26.1.0
int getAutoSizeStepGranularity (TextView textView)

Parameters
textView TextView

Returns
int the current auto-size step granularity in pixels.

getAutoSizeTextAvailableSizes

added in version 26.1.0
int[] getAutoSizeTextAvailableSizes (TextView textView)

Parameters
textView TextView

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

getAutoSizeTextType

added in version 26.1.0
int getAutoSizeTextType (TextView textView)

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

Parameters
textView TextView

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

getCompoundDrawablesRelative

added in version 25.1.0
Drawable[] getCompoundDrawablesRelative (TextView textView)

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

Parameters
textView TextView

Returns
Drawable[]

getMaxLines

added in version 24.1.0
int getMaxLines (TextView textView)

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

Parameters
textView TextView

Returns
int

getMinLines

added in version 24.1.0
int getMinLines (TextView textView)

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

Parameters
textView TextView

Returns
int

setAutoSizeTextTypeUniformWithConfiguration

added in version 26.1.0
void setAutoSizeTextTypeUniformWithConfiguration (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. If all the configuration params are valid the type of auto-size is set to AUTO_SIZE_TEXT_TYPE_UNIFORM.

Parameters
textView TextView

autoSizeMinTextSize int: the minimum text size available for auto-size

autoSizeMaxTextSize int: the maximum text size available for auto-size

autoSizeStepGranularity int: the auto-size step granularity. It is used in conjunction with the minimum and maximum text size in order to build the set of text sizes the system uses to choose from when auto-sizing

unit int: the desired dimension unit for all sizes above. See TypedValue for the possible dimension units

Throws
IllegalArgumentException if any of the configuration params are invalid.

setAutoSizeTextTypeUniformWithPresetSizes

added in version 26.1.0
void setAutoSizeTextTypeUniformWithPresetSizes (TextView textView, 
                int[] presetSizes, 
                int unit)

Specify whether this widget should automatically scale the text to try to perfectly fit within the layout bounds. If at least one value from the presetSizes is valid then the type of auto-size is set to AUTO_SIZE_TEXT_TYPE_UNIFORM.

Parameters
textView TextView

presetSizes int: an int array of sizes in pixels

unit int: the desired dimension unit for the preset sizes above. See TypedValue for the possible dimension units

Throws
IllegalArgumentException if all of the presetSizes are invalid. _

setAutoSizeTextTypeWithDefaults

added in version 26.1.0
void setAutoSizeTextTypeWithDefaults (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.

Parameters
textView TextView

autoSizeTextType int: the type of auto-size. Must be one of AUTO_SIZE_TEXT_TYPE_NONE or AUTO_SIZE_TEXT_TYPE_UNIFORM

setCompoundDrawablesRelative

added in version 22.1.0
void setCompoundDrawablesRelative (TextView textView, 
                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. Use null if you do not want a Drawable there. The Drawables must already have had setBounds(Rect) called.

Calling this method will overwrite any Drawables previously set using setCompoundDrawables(Drawable, Drawable, Drawable, Drawable) or related methods.

Parameters
textView TextView: The TextView against which to invoke the method.

start Drawable

top Drawable

end Drawable

bottom Drawable

setCompoundDrawablesRelativeWithIntrinsicBounds

added in version 22.1.0
void setCompoundDrawablesRelativeWithIntrinsicBounds (TextView textView, 
                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. Use null 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