AppCompatTextView
public class AppCompatTextView extends TextView implements TintableBackgroundView, TintableCompoundDrawablesView, EmojiCompatConfigurationView
| java.lang.Object | |||
| ↳ | android.view.View | ||
| ↳ | android.widget.TextView | ||
| ↳ | androidx.appcompat.widget.AppCompatTextView |
EmojiAppCompatTextView |
AppCompatTextView widget enhanced with emoji capability by using |
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
backgroundTintandbackgroundTintMode. - Supports auto-sizing via
androidx.core.widget.TextViewCompatby allowing to instruct aTextViewto 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 areautoSizeTextType,autoSizeMinTextSize,autoSizeMaxTextSize,autoSizeStepGranularityandautoSizePresetSizes, all of which work back toIce 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 |
|---|
AppCompatTextView(@NonNull Context context) |
AppCompatTextView(@NonNull Context context, @Nullable AttributeSet attrs) |
AppCompatTextView( |
Public methods |
|
|---|---|
@Nullable ActionMode.Callback |
|
int |
|
@Nullable String |
@RequiresApi(value = 26) |
int |
|
CharSequence |
getText() |
@NonNull TextClassifier |
@RequiresApi(api = 26)Returns the |
@NonNull PrecomputedTextCompat.Params |
Gets the parameters for text layout precomputation, for use with |
@Nullable Typeface |
|
boolean |
|
InputConnection |
onCreateInputConnection(EditorInfo outAttrs) |
void |
setAllCaps(boolean allCaps) |
void |
setBackgroundDrawable(@Nullable Drawable background)This method is deprecated. |
void |
setBackgroundResource(@DrawableRes int resId) |
void |
|
void |
|
void |
|
void |
setCompoundDrawablesRelativeWithIntrinsicBounds( |
void |
|
void |
setCompoundDrawablesWithIntrinsicBounds( |
void |
setCustomSelectionActionModeCallback( |
void |
setEmojiCompatEnabled(boolean enabled)Configure emoji fallback behavior using EmojiCompat. |
void |
setFilters(@NonNull InputFilter[] filters) |
void |
setFirstBaselineToTopHeight( |
boolean |
@RequiresApi(value = 26)Set font variation settings. |
void |
setLastBaselineToBottomHeight( |
void |
setLineHeight(@Px @IntRange(from = 0) int lineHeight) |
void |
setLineHeight(int unit, @FloatRange(from = 0) float lineHeight) |
void |
setPrecomputedText(@NonNull PrecomputedTextCompat precomputed)Sets the PrecomputedTextCompat to the TextView. |
void |
setTextAppearance(Context context, int resId)This method is deprecated. |
void |
@RequiresApi(api = 26)Sets the |
void |
setTextFuture(@Nullable Future<PrecomputedTextCompat> future)Set the precomputed text future. |
void |
Apply the text layout parameter. |
void |
setTextSize(int unit, float size) |
void |
setTypeface(@Nullable Typeface tf) |
void |
setTypeface(@Nullable Typeface tf, int style) |
Protected methods |
|
|---|---|
void |
|
void |
|
void |
onLayout(boolean changed, int left, int top, int right, int bottom) |
void |
onMeasure(int widthMeasureSpec, int heightMeasureSpec) |
void |
onTextChanged( |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited methods |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
AppCompatTextView
public AppCompatTextView(@NonNull Context context, @Nullable AttributeSet attrs)
AppCompatTextView
public AppCompatTextView(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr
)
Public methods
getCustomSelectionActionModeCallback
public @Nullable ActionMode.Callback getCustomSelectionActionModeCallback()
getTextClassifier
@RequiresApi(api = 26)
public @NonNull TextClassifier getTextClassifier()
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
public @NonNull PrecomputedTextCompat.Params getTextMetricsParamsCompat()
Gets the parameters for text layout precomputation, for use with PrecomputedTextCompat.
| Returns | |
|---|---|
@NonNull PrecomputedTextCompat.Params |
a current |
| See also | |
|---|---|
PrecomputedTextCompat |
isEmojiCompatEnabled
public boolean isEmojiCompatEnabled()
| Returns | |
|---|---|
boolean |
the current enabled state, set via |
setBackgroundDrawable
public void setBackgroundDrawable(@Nullable Drawable background)
setCompoundDrawables
public void setCompoundDrawables(
@Nullable Drawable left,
@Nullable Drawable top,
@Nullable Drawable right,
@Nullable Drawable bottom
)
setCompoundDrawablesRelative
public void setCompoundDrawablesRelative(
@Nullable Drawable start,
@Nullable Drawable top,
@Nullable Drawable end,
@Nullable Drawable bottom
)
setCompoundDrawablesRelativeWithIntrinsicBounds
public void setCompoundDrawablesRelativeWithIntrinsicBounds(
@Nullable Drawable start,
@Nullable Drawable top,
@Nullable Drawable end,
@Nullable Drawable bottom
)
setCompoundDrawablesRelativeWithIntrinsicBounds
public void setCompoundDrawablesRelativeWithIntrinsicBounds(
int start,
int top,
int end,
int bottom
)
setCompoundDrawablesWithIntrinsicBounds
public void setCompoundDrawablesWithIntrinsicBounds(
@Nullable Drawable left,
@Nullable Drawable top,
@Nullable Drawable right,
@Nullable Drawable bottom
)
setCompoundDrawablesWithIntrinsicBounds
public void setCompoundDrawablesWithIntrinsicBounds(
int left,
int top,
int right,
int bottom
)
setCustomSelectionActionModeCallback
public void setCustomSelectionActionModeCallback(
@Nullable ActionMode.Callback actionModeCallback
)
setEmojiCompatEnabled
public void setEmojiCompatEnabled(boolean enabled)
Configure emoji fallback behavior using EmojiCompat. When enabled, this View will attempt to use EmojiCompat to enabled missing emojis. When disabled, this View will not display missing emojis using EmojiCompat. EmojiCompat must be correctly configured on a device for this to have an effect, which will happen by default if a correct downloadable fonts provider is installed on the device. If you manually configure EmojiCompat by calling EmojiCompat init after this View is constructed, you may call this method again to enable EmojiCompat on this text view. For more information about EmojiCompat configuration see the emoji2 module.
| Parameters | |
|---|---|
boolean enabled |
if true, display missing emoji using EmojiCompat, otherwise display missing emoji using a fallback glyph "□" (known as tofu) |
setFirstBaselineToTopHeight
public void setFirstBaselineToTopHeight(
@Px @IntRange(from = 0) int firstBaselineToTopHeight
)
setFontVariationSettings
@RequiresApi(value = 26)
public boolean setFontVariationSettings(@Nullable String variationSettings)
Set font variation settings. See setFontVariationSettings for details.
Note: Due to performance optimizations, getPaint().getFontVariationSettings() will be less reliable than if not using AppCompatTextView. You should prefer getFontVariationSettings, which will be more accurate. However, neither approach will work correctly if using Typeface objects with embedded font variation settings.
setLastBaselineToBottomHeight
public void setLastBaselineToBottomHeight(
@Px @IntRange(from = 0) int lastBaselineToBottomHeight
)
setPrecomputedText
public void setPrecomputedText(@NonNull PrecomputedTextCompat precomputed)
Sets the PrecomputedTextCompat to the TextView. If the given PrecomputeTextCompat is not compatible with textView, throws an IllegalArgumentException.
| Parameters | |
|---|---|
@NonNull PrecomputedTextCompat precomputed |
the precomputed text |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if precomputed text is not compatible with textView. |
setTextClassifier
@RequiresApi(api = 26)
public void setTextClassifier(@Nullable TextClassifier textClassifier)
Sets the TextClassifier for this TextView.
setTextFuture
public void setTextFuture(@Nullable 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 getTextFuture for more detail.
| Parameters | |
|---|---|
@Nullable Future<PrecomputedTextCompat> future |
a future for the precomputed text |
| See also | |
|---|---|
getTextFuture |
setTextMetricsParamsCompat
public void setTextMetricsParamsCompat(@NonNull PrecomputedTextCompat.Params params)
Apply the text layout parameter. Update the TextView parameters to be compatible with PrecomputedTextCompat.Params.
| See also | |
|---|---|
PrecomputedTextCompat |
Protected methods
onTextChanged
protected void onTextChanged(
CharSequence text,
int start,
int lengthBefore,
int lengthAfter
)