lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

belongs to Maven artifact androidx.appcompat:appcompat:1.0.0-alpha3

AppCompatTextView

public class AppCompatTextView
extends TextView implements TintableBackgroundView

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ androidx.appcompat.widget.AppCompatTextView


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

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

Inherited constants

Inherited fields

Public constructors

AppCompatTextView(Context context)
AppCompatTextView(Context context, AttributeSet attrs)
AppCompatTextView(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

int getFirstBaselineToTopHeight()
int getLastBaselineToBottomHeight()
CharSequence getText()
PrecomputedTextCompat.Params getTextMetricsParamsCompat()

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

InputConnection onCreateInputConnection(EditorInfo outAttrs)
void setBackgroundDrawable(Drawable background)
void setBackgroundResource(int resId)
void setCustomSelectionActionModeCallback(ActionMode.Callback actionModeCallback)

See TextViewCompat.setCustomSelectionActionModeCallback(TextView, ActionMode.Callback)

void setFirstBaselineToTopHeight(int firstBaselineToTopHeight)
void setLastBaselineToBottomHeight(int lastBaselineToBottomHeight)
void setLineHeight(int lineHeight)
void setPrecomputedText(PrecomputedTextCompat precomputed)

Sets the PrecomputedTextCompat to the TextView.

void setTextAppearance(Context context, int resId)
void setTextFuture(Future<PrecomputedTextCompat> future)

Set the precomputed text future.

void setTextMetricsParamsCompat(PrecomputedTextCompat.Params params)

Apply the text layout parameter.

void setTextSize(int unit, float size)

Protected methods

void drawableStateChanged()
void onLayout(boolean changed, int left, int top, int right, int bottom)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter)

Inherited methods

Public constructors

AppCompatTextView

public AppCompatTextView (Context context)

Parameters
context Context

AppCompatTextView

public AppCompatTextView (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

AppCompatTextView

public AppCompatTextView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

getFirstBaselineToTopHeight

public int getFirstBaselineToTopHeight ()

Returns
int

getLastBaselineToBottomHeight

public int getLastBaselineToBottomHeight ()

Returns
int

getText

public CharSequence getText ()

Returns
CharSequence

getTextMetricsParamsCompat

public PrecomputedTextCompat.Params getTextMetricsParamsCompat ()

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

Returns
PrecomputedTextCompat.Params a current PrecomputedTextCompat.Params

onCreateInputConnection

public InputConnection onCreateInputConnection (EditorInfo outAttrs)

Parameters
outAttrs EditorInfo

Returns
InputConnection

setBackgroundDrawable

public void setBackgroundDrawable (Drawable background)

Parameters
background Drawable

setBackgroundResource

public void setBackgroundResource (int resId)

Parameters
resId int

setCustomSelectionActionModeCallback

public void setCustomSelectionActionModeCallback (ActionMode.Callback actionModeCallback)

See TextViewCompat.setCustomSelectionActionModeCallback(TextView, ActionMode.Callback)

Parameters
actionModeCallback ActionMode.Callback

setFirstBaselineToTopHeight

public void setFirstBaselineToTopHeight (int firstBaselineToTopHeight)

Parameters
firstBaselineToTopHeight int

setLastBaselineToBottomHeight

public void setLastBaselineToBottomHeight (int lastBaselineToBottomHeight)

Parameters
lastBaselineToBottomHeight int

setLineHeight

public void setLineHeight (int lineHeight)

Parameters
lineHeight int

setPrecomputedText

public void setPrecomputedText (PrecomputedTextCompat precomputed)

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

Parameters
precomputed PrecomputedTextCompat: the precomputed text

Throws
IllegalArgumentException if precomputed text is not compatible with textView.

setTextAppearance

public void setTextAppearance (Context context, 
                int resId)

Parameters
context Context

resId int

setTextFuture

public void setTextFuture (Future<PrecomputedTextCompat> future)

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(CharSequence, PrecomputedTextCompat.Params, Executor) for more detail.

Parameters
future Future: a future for the precomputed text

setTextMetricsParamsCompat

public void setTextMetricsParamsCompat (PrecomputedTextCompat.Params params)

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

Parameters
params PrecomputedTextCompat.Params

setTextSize

public void setTextSize (int unit, 
                float size)

Parameters
unit int

size float

Protected methods

drawableStateChanged

protected void drawableStateChanged ()

onLayout

protected void onLayout (boolean changed, 
                int left, 
                int top, 
                int right, 
                int bottom)

Parameters
changed boolean

left int

top int

right int

bottom int

onMeasure

protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int

onTextChanged

protected void onTextChanged (CharSequence text, 
                int start, 
                int lengthBefore, 
                int lengthAfter)

Parameters
text CharSequence

start int

lengthBefore int

lengthAfter int