TextInputLayout

public class TextInputLayout


Layout which wraps a TextInputEditText, android.widget.EditText, or descendant to show a floating label when the hint is hidden while the user inputs text.

Also supports:

  • Showing an error via setErrorEnabled and setError, along with showing an error icon via setErrorIconDrawable
  • Showing helper text via setHelperTextEnabled and setHelperText
  • Showing placeholder text via setPlaceholderText
  • Showing prefix text via setPrefixText
  • Showing suffix text via setSuffixText
  • Showing a character counter via setCounterEnabled and setCounterMaxLength
  • Password visibility toggling via setEndIconMode API and related attribute. If set, a button is displayed to toggle between the password being displayed as plain-text or disguised, when your EditText is set to display a password.
  • Clearing text functionality via setEndIconMode API and related attribute. If set, a button is displayed when text is present and clicking it clears the EditText field.
  • Showing a custom icon specified via setEndIconMode API and related attribute. You should specify a drawable and content description for the icon. Optionally, you can also specify an android.view.View.OnClickListener, an and an OnEndIconChangedListener.

    Note: When using an end icon, the 'end' compound drawable of the EditText will be overridden while the end icon view is visible. To ensure that any existing drawables are restored correctly, you should set those compound drawables relatively (start/end), as opposed to absolutely (left/right).

  • Showing a start icon via setStartIconDrawable API and related attribute. You should specify a content description for the icon. Optionally, you can also specify an android.view.View.OnClickListener for it.

    Note: Use the setStartIconDrawable API in place of setting a start/left compound drawable on the EditText. When using a start icon, the 'start/left' compound drawable of the EditText will be overridden.

  • Showing a button that when clicked displays a dropdown menu. The selected option is displayed above the dropdown. You need to use an AutoCompleteTextView instead of a TextInputEditText as the input text child, and a Widget.MaterialComponents.TextInputLayout.(...).ExposedDropdownMenu style.

    To disable user input you should set

    android:editable="false"
    on the AutoCompleteTextView.

The TextInputEditText class is provided to be used as the input text child of this layout. Using TextInputEditText instead of an EditText provides accessibility support for the text field and allows TextInputLayout greater control over the visual aspects of the text field. This is an example usage:

<com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/form_username">

    <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout>
The hint should be set on the TextInputLayout, rather than the EditText. If a hint is specified on the child EditText in XML, the TextInputLayout might still work correctly; TextInputLayout will use the EditText's hint as its floating label. However, future calls to modify the hint will not update TextInputLayout's hint. To avoid unintended behavior, call setHint and getHint on TextInputLayout, instead of on EditText.

If you construct the TextInputEditText child of a TextInputLayout programmatically, you should use TextInputLayout's context to create the view. This will allow TextInputLayout to pass along the appropriate styling to the .

If the EditText child is not a TextInputEditText, make sure to set the 's android:background to null when using an outlined or filled text field. This allows TextInputLayout to set the EditText's background to an outlined or filled box, respectively.

Note: The actual view hierarchy present under TextInputLayout is NOT guaranteed to match the view hierarchy as written in XML. As a result, calls to getParent() on children of the TextInputLayout -- such as a TextInputEditText -- may not return the TextInputLayout itself, but rather an intermediate View. If you need to access a View directly, set an android:id and use findViewById.

For more information, see the component developer guidance and design guidelines.

Summary

Nested types

An AccessibilityDelegate intended to be set on an EditText or with setTextInputAccessibilityDelegate to provide attributes for accessibility that are managed by TextInputLayout.

@Retention(value = RetentionPolicy.SOURCE)
public annotation TextInputLayout.BoxBackgroundMode

Values for box background mode.

Interface definition for a length counter.

Callback interface invoked when the view's EditText is attached, or from addOnEditTextAttachedListener if the edit text is already present.

Callback interface invoked when the view's end icon changes.

Constants

static final int
static final int
static final int
static final int

The TextInputLayout will show a clear text button while there is input in the EditText.

static final int

The TextInputLayout will show a custom icon specified by the user.

static final int

The TextInputLayout will show a dropdown button if the EditText is an and a Widget.MaterialComponents.TextInputLayout.(...).ExposedDropdownMenu style is being used.

static final int

Default for the TextInputLayout.

static final int

The TextInputLayout will show a password toggle button if its EditText displays a password.

Public constructors

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

Public methods

void

Add a OnEditTextAttachedListener that will be invoked when the edit text is attached, or from this method if the EditText is already present.

void

Add a TextInputLayout.OnEndIconChangedListener that will be invoked when the end icon gets changed.

void
addView(View child, int index, LayoutParams params)
void

Remove all previously added OnEditTextAttachedListeners.

void

Remove all previously added TextInputLayout.OnEndIconChangedListeners.

void
dispatchProvideAutofillStructure(ViewStructure structure, int flags)
void
draw(Canvas canvas)
int
int

Returns the filled box's default background color.

int

Get the box background mode (filled, outline, or none).

int

Returns the EditText's collapsed top padding

float

Returns the box's bottom end corner radius.

float

Returns the box's bottom start corner radius.

float

Returns the box's top end corner radius.

float

Returns the box's top start corner radius.

int

Returns the box's stroke focused color.

ColorStateList

Returns the box's stroke color when an error is being displayed.

int

Returns the box's stroke width.

int

Returns the box's stroke focused width.

int

Returns the max length shown at the character counter.

ColorStateList

Returns the text color used for the overflowed character counter, or null if one has not been set.

ColorStateList

Returns the text color used for the character counter, or null if one has not been set.

ColorStateList

Returns the cursor color.

ColorStateList

Returns the cursor error color.

ColorStateList

Returns the text color used by the hint in both the collapsed and expanded states, or null if no color has been set.

EditText

Returns the android.widget.EditText used for text input.

CharSequence

Returns the currently configured content description for the end icon.

Drawable

Returns the drawable currently used for the end icon.

int

Returns the minimum size of the end icon.

int

Returns the current end icon mode.

ScaleType

Returns the ScaleType for the end icon's ImageButton.

CharSequence

Returns the error message that was set to be displayed with setError, or null if no error was set or if error displaying is not enabled.

int

Returns the accessibility live region of the error message.

CharSequence

Returns the content description of the error message, or null if not set.

int

Returns the text color used by the error message in current state.

Drawable

Returns the drawable currently used for the error icon.

CharSequence

Returns the helper message that was set to be displayed with setHelperText, or null if no helper text was set or if helper text functionality is not enabled.

int

Returns the text color used by the helper text in the current states.

CharSequence

Returns the hint which is displayed in the floating label, if enabled.

int

Gets the max number of lines for the hint text.

ColorStateList

Gets the collapsed hint text color.

TextInputLayout.LengthCounter

Returns the counting method used to count the length of the text.

int

Returns the text field's maximum width in terms of ems, or -1 if no maximum width is set.

int

Returns the text field's maximum width, or -1 if no maximum width is set.

int

Returns the text field's minimum width in terms of ems, or -1 if no minimum width is set.

int

Returns the text field's minimum width, or -1 if no minimum width is set.

CharSequence

This method is deprecated.

Use getEndIconContentDescription instead.

Drawable

This method is deprecated.

Use getEndIconDrawable instead.

CharSequence

Returns the placeholder text that was set to be displayed with setPlaceholderText, or null if there is no placeholder text.

int

Returns the TextAppearance resource used for the placeholder text color.

ColorStateList

Returns the ColorStateList used for the placeholder text.

CharSequence

Returns the prefix text that was set to be displayed with setPrefixText, or null if there is no prefix text.

ColorStateList

Returns the ColorStateList used for the prefix text.

TextView

Returns the prefix text view.

ShapeAppearanceModel

Returns the ShapeAppearanceModel of the text field's box background.

CharSequence

Returns the currently configured content description for the start icon.

Drawable

Returns the start icon.

int

Returns the size of the start icon.

ScaleType

Returns the ScaleType for the start icon's ImageButton.

CharSequence

Returns the suffix text that was set to be displayed with setSuffixText, or null if there is no suffix text.

ColorStateList

Returns the ColorStateList used for the suffix text.

TextView

Returns the suffix text view.

Typeface

Returns the typeface used for the hint and any label views (such as counter and error views).

boolean

Returns whether the character counter functionality is enabled or not in this layout.

boolean

Returns whether the end icon is checkable.

boolean

Returns whether the current end icon is visible.

boolean

Returns whether the error functionality is enabled or not in this layout.

boolean

Returns whether the hint expands to occupy the input area when the text field is unpopulated and not focused.

boolean

Returns whether the helper text functionality is enabled or not in this layout.

boolean

Returns whether any hint state changes, due to being focused or non-empty text, are animated.

boolean

Returns whether the floating label functionality is enabled or not in this layout.

boolean

This method is deprecated.

Use getEndIconMode instead.

boolean

Returns whether the start icon is checkable.

boolean

Returns whether the current start icon is visible.

void
void
onRtlPropertiesChanged(int layoutDirection)
Parcelable
void
passwordVisibilityToggleRequested(boolean shouldSkipAnimations)

This method is deprecated.

The password toggle will show as checked or unchecked depending on whether the EditText's android.text.method.TransformationMethod is of type

void

This method should be called from within your icon's click listener if your icon's tint list has a color for a state that depends on a click (such as checked state).

void

This method should be called from within your icon's click listener if your icon's tint list has a color for a state that depends on a click (such as checked state).

void

This method should be called from within your icon's click listener if your icon's tint list has a color for a state that depends on a click (such as checked state).

void

Remove the given OnEditTextAttachedListener that was previously added via addOnEditTextAttachedListener.

void

Remove the given TextInputLayout.OnEndIconChangedListener that was previously added via addOnEndIconChangedListener.

void
setBoxBackgroundColor(int boxBackgroundColor)

Sets the filled box's default background color.

void
setBoxBackgroundColorResource(int boxBackgroundColorId)

Set the resource used for the filled box's background color.

void
setBoxBackgroundColorStateList(
    ColorStateList boxBackgroundColorStateList
)

Sets the box's background color state list.

void

Set the box background mode (filled, outline, or none).

void
setBoxCollapsedPaddingTop(int boxCollapsedPaddingTop)

Set the value to use for the EditText's collapsed top padding in box mode.

void
setBoxCornerFamily(@CornerFamily int cornerFamily)

Sets the box's corner family for all corners of the text field.

void
setBoxCornerRadii(
    float boxCornerRadiusTopStart,
    float boxCornerRadiusTopEnd,
    float boxCornerRadiusBottomStart,
    float boxCornerRadiusBottomEnd
)

Set the box's corner radii.

void
setBoxCornerRadiiResources(
    int boxCornerRadiusTopStartId,
    int boxCornerRadiusTopEndId,
    int boxCornerRadiusBottomEndId,
    int boxCornerRadiusBottomStartId
)

Set the resources used for the box's corner radii.

void
setBoxStrokeColor(int boxStrokeColor)

Set the outline box's stroke focused color.

void
setBoxStrokeColorStateList(ColorStateList boxStrokeColorStateList)

Set the box's stroke color state list.

void
setBoxStrokeErrorColor(ColorStateList strokeErrorColor)

Set the outline box's stroke color when an error is being displayed.

void
setBoxStrokeWidth(int boxStrokeWidth)

Set the value to use for the box's stroke when in outline box mode, or for the underline stroke in filled mode.

void
setBoxStrokeWidthFocused(int boxStrokeWidthFocused)

Set the value to use for the focused box's stroke when in outline box mode, or for the focused underline stroke in filled mode.

void
setBoxStrokeWidthFocusedResource(int boxStrokeWidthFocusedResId)

Set the resource dimension to use for the focused box's stroke when in outline box mode, or for the focused underline stroke in filled mode.

void
setBoxStrokeWidthResource(int boxStrokeWidthResId)

Set the resource dimension to use for the box's stroke when in outline box mode, or for the underline stroke in filled mode.

void
setCounterEnabled(boolean enabled)

Whether the character counter functionality is enabled or not in this layout.

void
setCounterMaxLength(int maxLength)

Sets the max length to display at the character counter.

void
setCounterOverflowTextAppearance(int counterOverflowTextAppearance)

Sets the text color and size for the overflowed character counter using the specified TextAppearance resource.

void
setCounterOverflowTextColor(ColorStateList counterOverflowTextColor)

Sets the text color for the overflowed character counter using a ColorStateList.

void
setCounterTextAppearance(int counterTextAppearance)

Sets the text color and size for the character counter using the specified TextAppearance resource.

void
setCounterTextColor(ColorStateList counterTextColor)

Sets the text color for the character counter using a ColorStateList.

void
setCursorColor(ColorStateList cursorColor)

Sets the cursor color.

void
setCursorErrorColor(ColorStateList cursorErrorColor)

Sets the cursor color when an error is being displayed.

void
setDefaultHintTextColor(ColorStateList textColor)

Sets the text color used by the hint in both the collapsed and expanded states.

void
setEnabled(boolean enabled)
void
setEndIconActivated(boolean endIconActivated)

Sets the current end icon's state to be activated or not.

void
setEndIconCheckable(boolean endIconCheckable)

Sets the current end icon to be checkable or not.

void
setEndIconContentDescription(CharSequence endIconContentDescription)

Set a content description for the end icon.

void

Set a content description for the end icon.

void
setEndIconDrawable(Drawable endIconDrawable)

Set the icon to use for the end icon.

void
setEndIconDrawable(int resId)

Set the icon to use for the end icon.

void
setEndIconMinSize(int iconSize)

Sets the width and height of the end icon.

void
setEndIconMode(int endIconMode)

Set up the end icon mode.

void
setEndIconOnClickListener(OnClickListener endIconOnClickListener)

Sets the end icon's functionality that is performed when the icon is clicked.

void
setEndIconOnLongClickListener(
    OnLongClickListener endIconOnLongClickListener
)

Sets the end icon's functionality that is performed when the end icon is long clicked.

void
setEndIconScaleType(ScaleType scaleType)

Sets ScaleType for the end icon's ImageButton.

void
setEndIconTintList(ColorStateList endIconTintList)

Applies a tint to the end icon drawable.

void
setEndIconTintMode(Mode endIconTintMode)

Specifies the blending mode used to apply the tint specified by setEndIconTintList to the end icon drawable.

void
setEndIconVisible(boolean visible)

Sets the current end icon to be VISIBLE or GONE.

void

Sets an error message that will be displayed below our EditText.

void
setErrorAccessibilityLiveRegion(int errorAccessibilityLiveRegion)

Sets an accessibility live region for the error message.

void
setErrorContentDescription(CharSequence errorContentDescription)

Sets a content description for the error message.

void
setErrorEnabled(boolean enabled)

Whether the error functionality is enabled or not in this layout.

void
setErrorIconDrawable(Drawable errorIconDrawable)

Set the drawable to use for the error icon.

void

Set the drawable to use for the error icon.

void
setErrorIconOnClickListener(OnClickListener errorIconOnClickListener)

Sets the error icon's functionality that is performed when the icon is clicked.

void
setErrorIconOnLongClickListener(
    OnLongClickListener errorIconOnLongClickListener
)

Sets the error icon's functionality that is performed when the end icon is long clicked.

void
setErrorIconTintList(ColorStateList errorIconTintList)

Applies a tint to the error icon drawable.

void
setErrorIconTintMode(Mode errorIconTintMode)

Specifies the blending mode used to apply tint to the end icon drawable.

void
setErrorTextAppearance(int errorTextAppearance)

Sets the text color and size for the error message from the specified TextAppearance resource.

void
setErrorTextColor(ColorStateList errorTextColor)

Sets the text color used by the error message in all states.

void
setExpandedHintEnabled(boolean enabled)

Sets whether the hint should expand to occupy the input area when the text field is unpopulated and not focused.

void

Sets a helper message that will be displayed below the EditText.

void
setHelperTextColor(ColorStateList helperTextColor)

Sets the text color used by the helper text in all states.

void
setHelperTextEnabled(boolean enabled)

Whether the helper text functionality is enabled or not in this layout.

void
setHelperTextTextAppearance(int helperTextTextAppearance)

Sets the text color and size for the helper text from the specified TextAppearance resource.

void

Set the hint to be displayed in the floating label, if enabled.

void
setHint(int textHintId)

Set the hint to be displayed in the floating label, if enabled, using the given resource id.

void
setHintAnimationEnabled(boolean enabled)

Set whether any hint state changes, due to being focused or non-empty text, are animated.

void
setHintEnabled(boolean enabled)

Sets whether the floating label functionality is enabled or not in this layout.

void
setHintMaxLines(int hintMaxLines)

Sets the max number of lines for the hint text.

void

Sets the collapsed hint text color, size, style from the specified TextAppearance resource.

void
setHintTextColor(ColorStateList hintTextColor)

Sets the collapsed hint text color from the specified ColorStateList resource.

void

Set the counting method used to count the length of a text.

void
setMaxEms(int maxEms)

Sets the maximum width in terms of ems of the text field.

void
setMaxWidth(int maxWidth)

Sets the maximum width of the text field.

void
setMaxWidthResource(int maxWidthId)

Sets the maximum width of the text field.

void
setMinEms(int minEms)

Sets the minimum width in terms of ems of the text field.

void
setMinWidth(int minWidth)

Sets the minimum width of the text field.

void
setMinWidthResource(int minWidthId)

Sets the minimum width of the text field.

void

This method is deprecated.

Use setEndIconContentDescription instead.

void

This method is deprecated.

Use setEndIconContentDescription instead.

void

This method is deprecated.

Use setEndIconDrawable instead.

void

This method is deprecated.

Use setEndIconDrawable instead.

void

This method is deprecated.

Use setEndIconMode instead.

void
setPasswordVisibilityToggleTintList(ColorStateList tintList)

This method is deprecated.

Use setEndIconTintList instead.

void

This method is deprecated.

Use setEndIconTintMode instead.

void

Sets placeholder text that will be displayed in the input area when the hint is collapsed before text is entered.

void
setPlaceholderTextAppearance(int placeholderTextAppearance)

Sets the text color and size for the placeholder text from the specified TextAppearance resource.

void
setPlaceholderTextColor(ColorStateList placeholderTextColor)

Sets the text color used by the placeholder text in all states.

void

Sets prefix text that will be displayed in the input area when the hint is collapsed before text is entered.

void
setPrefixTextAppearance(int prefixTextAppearance)

Sets the text color and size for the prefix text from the specified TextAppearance resource.

void
setPrefixTextColor(ColorStateList prefixTextColor)

Sets the text color used by the prefix text in all states.

void

Sets the ShapeAppearanceModel of the text field's box background.

void
setStartIconCheckable(boolean startIconCheckable)

Sets the current start icon to be checkable or not.

void

Set a content description for the start icon.

void
setStartIconContentDescription(
    CharSequence startIconContentDescription
)

Set a content description for the start icon.

void

Sets the start icon.

void
setStartIconDrawable(Drawable startIconDrawable)

Sets the start icon.

void
setStartIconMinSize(int iconSize)

Sets the width and height of the start icon.

void
setStartIconOnClickListener(OnClickListener startIconOnClickListener)

Sets the start icon's functionality that is performed when the start icon is clicked.

void
setStartIconOnLongClickListener(
    OnLongClickListener startIconOnLongClickListener
)

Sets the start icon's functionality that is performed when the start icon is long clicked.

void
setStartIconScaleType(ScaleType scaleType)

Sets ScaleType for the start icon's ImageButton.

void
setStartIconTintList(ColorStateList startIconTintList)

Applies a tint to the start icon drawable.

void
setStartIconTintMode(Mode startIconTintMode)

Specifies the blending mode used to apply the tint specified by setEndIconTintList to the start icon drawable.

void
setStartIconVisible(boolean visible)

Sets the start icon to be VISIBLE or GONE.

void

Sets suffix text that will be displayed in the input area when the hint is collapsed before text is entered.

void
setSuffixTextAppearance(int suffixTextAppearance)

Sets the text color and size for the suffix text from the specified TextAppearance resource.

void
setSuffixTextColor(ColorStateList suffixTextColor)

Sets the text color used by the suffix text in all states.

void

Sets an TextInputLayout.AccessibilityDelegate providing an accessibility implementation for the EditText used by this layout.

void
setTypeface(Typeface typeface)

Set the typeface to use for the hint and any label views (such as counter and error views).

Protected methods

void
dispatchRestoreInstanceState(SparseArray<Parcelable> container)
void
void
onConfigurationChanged(Configuration newConfig)
void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void
onRestoreInstanceState(Parcelable state)

Constants

BOX_BACKGROUND_FILLED

public static final int BOX_BACKGROUND_FILLED = 1

BOX_BACKGROUND_NONE

public static final int BOX_BACKGROUND_NONE = 0

BOX_BACKGROUND_OUTLINE

public static final int BOX_BACKGROUND_OUTLINE = 2

END_ICON_CLEAR_TEXT

public static final int END_ICON_CLEAR_TEXT = 2

The TextInputLayout will show a clear text button while there is input in the EditText. Clicking it will clear out the text and hide the icon.

END_ICON_CUSTOM

public static final int END_ICON_CUSTOM = -1

The TextInputLayout will show a custom icon specified by the user.

END_ICON_DROPDOWN_MENU

public static final int END_ICON_DROPDOWN_MENU = 3

The TextInputLayout will show a dropdown button if the EditText is an and a Widget.MaterialComponents.TextInputLayout.(...).ExposedDropdownMenu style is being used.

Clicking the button will display a popup with a list of options. The current selected option is displayed on the EditText.

END_ICON_NONE

public static final int END_ICON_NONE = 0

Default for the TextInputLayout. It will not display an end icon.

END_ICON_PASSWORD_TOGGLE

public static final int END_ICON_PASSWORD_TOGGLE = 1

The TextInputLayout will show a password toggle button if its EditText displays a password. When this end icon is clicked, the password is shown as plain-text if it was disguised, or vice-versa.

Public fields

boxBackgroundColor

public int boxBackgroundColor

boxBackgroundMode

@TextInputLayout.BoxBackgroundMode
public int boxBackgroundMode

boxStrokeColor

public int boxStrokeColor

counterMaxLength

public int counterMaxLength

counterOverflowTextColor

public ColorStateList counterOverflowTextColor

counterTextColor

public ColorStateList counterTextColor

cursorColor

public ColorStateList cursorColor

cursorErrorColor

public ColorStateList cursorErrorColor

defaultHintTextColor

public ColorStateList defaultHintTextColor

editText

public EditText editText

hint

public CharSequence hint

maxEms

public int maxEms

maxWidth

public int maxWidth

minEms

public int minEms

minWidth

public int minWidth

placeholderText

public CharSequence placeholderText

placeholderTextAppearance

public int placeholderTextAppearance

placeholderTextColor

public ColorStateList placeholderTextColor

shapeAppearanceModel

public ShapeAppearanceModel shapeAppearanceModel

typeface

public Typeface typeface

Public constructors

TextInputLayout

public TextInputLayout(Context context)

TextInputLayout

public TextInputLayout(Context context, AttributeSet attrs)

TextInputLayout

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

Public methods

addOnEditTextAttachedListener

public void addOnEditTextAttachedListener(
    TextInputLayout.OnEditTextAttachedListener listener
)

Add a OnEditTextAttachedListener that will be invoked when the edit text is attached, or from this method if the EditText is already present.

Components that add a listener should take care to remove it when finished via removeOnEditTextAttachedListener.

Parameters
TextInputLayout.OnEditTextAttachedListener listener

listener to add

addOnEndIconChangedListener

public void addOnEndIconChangedListener(
    TextInputLayout.OnEndIconChangedListener listener
)

Add a TextInputLayout.OnEndIconChangedListener that will be invoked when the end icon gets changed.

Components that add a listener should take care to remove it when finished via removeOnEndIconChangedListener.

Parameters
TextInputLayout.OnEndIconChangedListener listener

listener to add

addView

public void addView(View child, int index, LayoutParams params)

clearOnEditTextAttachedListeners

public void clearOnEditTextAttachedListeners()

Remove all previously added OnEditTextAttachedListeners.

clearOnEndIconChangedListeners

public void clearOnEndIconChangedListeners()

Remove all previously added TextInputLayout.OnEndIconChangedListeners.

dispatchProvideAutofillStructure

public void dispatchProvideAutofillStructure(ViewStructure structure, int flags)

draw

public void draw(Canvas canvas)

getBaseline

public int getBaseline()

getBoxBackgroundColor

public int getBoxBackgroundColor()

Returns the filled box's default background color.

Returns
int

the color used for the filled box's background

getBoxBackgroundMode

@TextInputLayout.BoxBackgroundMode
public int getBoxBackgroundMode()

Get the box background mode (filled, outline, or none).

May be one of BOX_BACKGROUND_NONE, BOX_BACKGROUND_FILLED, or BOX_BACKGROUND_OUTLINE.

getBoxCollapsedPaddingTop

public int getBoxCollapsedPaddingTop()

Returns the EditText's collapsed top padding

Returns
int

the value used for the box's padding top when collapsed

getBoxCornerRadiusBottomEnd

public float getBoxCornerRadiusBottomEnd()

Returns the box's bottom end corner radius.

Returns
float

the value used for the box's bottom end corner radius

getBoxCornerRadiusBottomStart

public float getBoxCornerRadiusBottomStart()

Returns the box's bottom start corner radius.

Returns
float

the value used for the box's bottom start corner radius

getBoxCornerRadiusTopEnd

public float getBoxCornerRadiusTopEnd()

Returns the box's top end corner radius.

Returns
float

the value used for the box's top end corner radius

getBoxCornerRadiusTopStart

public float getBoxCornerRadiusTopStart()

Returns the box's top start corner radius.

Returns
float

the value used for the box's top start corner radius

getBoxStrokeColor

public int getBoxStrokeColor()

Returns the box's stroke focused color.

Returns
int

the color used for the box's stroke when focused

getBoxStrokeErrorColor

public ColorStateList getBoxStrokeErrorColor()

Returns the box's stroke color when an error is being displayed.

ref com.google.android.material.R.styleable#TextInputLayout_boxStrokeErrorColor

getBoxStrokeWidth

public int getBoxStrokeWidth()

Returns the box's stroke width.

Returns
int

the value used for the box's stroke width

getBoxStrokeWidthFocused

public int getBoxStrokeWidthFocused()

Returns the box's stroke focused width.

Returns
int

the value used for the box's stroke width when focused

getCounterMaxLength

public int getCounterMaxLength()

Returns the max length shown at the character counter.

ref com.google.android.material.R.styleable#TextInputLayout_counterMaxLength

getCounterOverflowTextColor

public ColorStateList getCounterOverflowTextColor()

Returns the text color used for the overflowed character counter, or null if one has not been set.

ref com.google.android.material.R.styleable#TextInputLayout_counterOverflowTextColor

Returns
ColorStateList

the text color used for the overflowed character counter

getCounterTextColor

public ColorStateList getCounterTextColor()

Returns the text color used for the character counter, or null if one has not been set.

ref com.google.android.material.R.styleable#TextInputLayout_counterTextColor

Returns
ColorStateList

the text color used for the character counter

getCursorColor

public ColorStateList getCursorColor()

Returns the cursor color. It will return the value of app:cursorColor if set, or null otherwise.

Note: This value only has effect on API levels 28+. On lower API levels ?attr/colorControlActivated will be used for the cursor color.

ref com.google.android.material.R.styleable#TextInputLayout_cursorColor

See also
setCursorColor

getCursorErrorColor

public ColorStateList getCursorErrorColor()

Returns the cursor error color.

Note: This value only has effect on API levels 28+. On lower API levels ?attr/colorControlActivated will be used for the cursor color.

ref com.google.android.material.R.styleable#TextInputLayout_cursorErrorColor

getDefaultHintTextColor

public ColorStateList getDefaultHintTextColor()

Returns the text color used by the hint in both the collapsed and expanded states, or null if no color has been set.

getEditText

public EditText getEditText()

Returns the android.widget.EditText used for text input.

getEndIconContentDescription

public CharSequence getEndIconContentDescription()

Returns the currently configured content description for the end icon.

This will be used to describe the navigation action to users through mechanisms such as screen readers.

getEndIconDrawable

public Drawable getEndIconDrawable()

Returns the drawable currently used for the end icon.

ref com.google.android.material.R.styleable#TextInputLayout_endIconDrawable

getEndIconMinSize

public int getEndIconMinSize()

Returns the minimum size of the end icon.

ref android.support.design.button.R.styleable#TextInputLayout_endIconSize

Returns
int

Returns the size of the end icon in pixels.

getEndIconMode

public int getEndIconMode()

Returns the current end icon mode.

ref com.google.android.material.R.styleable#TextInputLayout_endIconMode

Returns
int

the end icon mode enum

See also
setEndIconMode

getEndIconScaleType

public ScaleType getEndIconScaleType()

Returns the ScaleType for the end icon's ImageButton.

ref android.support.design.button.R.styleable#TextInputLayout_endIconScaleType

Returns
ScaleType

Returns the ScaleType for the end icon's ImageButton.

getError

public CharSequence getError()

Returns the error message that was set to be displayed with setError, or null if no error was set or if error displaying is not enabled.

See also
setError

getErrorAccessibilityLiveRegion

public int getErrorAccessibilityLiveRegion()

Returns the accessibility live region of the error message.

getErrorContentDescription

public CharSequence getErrorContentDescription()

Returns the content description of the error message, or null if not set.

getErrorCurrentTextColors

public int getErrorCurrentTextColors()

Returns the text color used by the error message in current state.

getErrorIconDrawable

public Drawable getErrorIconDrawable()

Returns the drawable currently used for the error icon.

ref com.google.android.material.R.styleable#TextInputLayout_errorIconDrawable

getHelperText

public CharSequence getHelperText()

Returns the helper message that was set to be displayed with setHelperText, or null if no helper text was set or if helper text functionality is not enabled.

See also
setHelperText

getHelperTextCurrentTextColor

public int getHelperTextCurrentTextColor()

Returns the text color used by the helper text in the current states.

getHint

public CharSequence getHint()

Returns the hint which is displayed in the floating label, if enabled.

ref com.google.android.material.R.styleable#TextInputLayout_android_hint

Returns
CharSequence

the hint, or null if there isn't one set, or the hint is not enabled.

getHintMaxLines

public int getHintMaxLines()

Gets the max number of lines for the hint text.

getHintTextColor

public ColorStateList getHintTextColor()

Gets the collapsed hint text color.

ref com.google.android.material.R.styleable#TextInputLayout_hintTextColor

getLengthCounter

public TextInputLayout.LengthCounter getLengthCounter()

Returns the counting method used to count the length of the text. The default counter will count the number of characters.

getMaxEms

public int getMaxEms()

Returns the text field's maximum width in terms of ems, or -1 if no maximum width is set.

ref com.google.android.material.R.styleable#TextInputLayout_android_maxEms

See also
setMaxEms

getMaxWidth

public int getMaxWidth()

Returns the text field's maximum width, or -1 if no maximum width is set.

ref com.google.android.material.R.styleable#TextInputLayout_android_maxWidth

getMinEms

public int getMinEms()

Returns the text field's minimum width in terms of ems, or -1 if no minimum width is set.

ref com.google.android.material.R.styleable#TextInputLayout_android_minEms

See also
setMinEms

getMinWidth

public int getMinWidth()

Returns the text field's minimum width, or -1 if no minimum width is set.

ref com.google.android.material.R.styleable#TextInputLayout_android_minWidth

getPasswordVisibilityToggleContentDescription

public CharSequence getPasswordVisibilityToggleContentDescription()

Returns the currently configured content description for the password visibility toggle button.

This will be used to describe the navigation action to users through mechanisms such as screen readers.

getPasswordVisibilityToggleDrawable

public Drawable getPasswordVisibilityToggleDrawable()

Returns the icon currently used for the password visibility toggle button.

ref com.google.android.material.R.styleable#TextInputLayout_passwordToggleDrawable

getPlaceholderText

public CharSequence getPlaceholderText()

Returns the placeholder text that was set to be displayed with setPlaceholderText, or null if there is no placeholder text.

getPlaceholderTextAppearance

public int getPlaceholderTextAppearance()

Returns the TextAppearance resource used for the placeholder text color.

ref com.google.android.material.R.styleable#TextInputLayout_placeholderTextAppearance

getPlaceholderTextColor

public ColorStateList getPlaceholderTextColor()

Returns the ColorStateList used for the placeholder text.

ref com.google.android.material.R.styleable#TextInputLayout_placeholderTextColor

getPrefixText

public CharSequence getPrefixText()

Returns the prefix text that was set to be displayed with setPrefixText, or null if there is no prefix text.

See also
setPrefixText

getPrefixTextColor

public ColorStateList getPrefixTextColor()

Returns the ColorStateList used for the prefix text.

ref com.google.android.material.R.styleable#TextInputLayout_prefixTextColor

getPrefixTextView

public TextView getPrefixTextView()

Returns the prefix text view.

Note: In order for the prefix to work correctly, text should always be set only via setPrefixText, instead of on the TextView directly.

See also
setPrefixText

getShapeAppearanceModel

public ShapeAppearanceModel getShapeAppearanceModel()

Returns the ShapeAppearanceModel of the text field's box background.

getStartIconContentDescription

public CharSequence getStartIconContentDescription()

Returns the currently configured content description for the start icon.

This will be used to describe the navigation action to users through mechanisms such as screen readers.

getStartIconDrawable

public Drawable getStartIconDrawable()

Returns the start icon.

ref com.google.android.material.R.styleable#TextInputLayout_startIconDrawable

Returns
Drawable

the drawable used for the start icon

getStartIconMinSize

public int getStartIconMinSize()

Returns the size of the start icon.

ref android.support.design.button.R.styleable#TextInputLayout_startIconSize

Returns
int

Returns the size of the start icon in pixels.

getStartIconScaleType

public ScaleType getStartIconScaleType()

Returns the ScaleType for the start icon's ImageButton.

ref android.support.design.button.R.styleable#TextInputLayout_startIconScaleType

Returns
ScaleType

Returns the ScaleType for the start icon's ImageButton.

getSuffixText

public CharSequence getSuffixText()

Returns the suffix text that was set to be displayed with setSuffixText, or null if there is no suffix text.

See also
setSuffixText

getSuffixTextColor

public ColorStateList getSuffixTextColor()

Returns the ColorStateList used for the suffix text.

ref com.google.android.material.R.styleable#TextInputLayout_suffixTextColor

getSuffixTextView

public TextView getSuffixTextView()

Returns the suffix text view.

Note: In order for the suffix to work correctly, text should always be set only via setSuffixText, instead of on the TextView directly.

See also
setSuffixText

getTypeface

public Typeface getTypeface()

Returns the typeface used for the hint and any label views (such as counter and error views).

isCounterEnabled

public boolean isCounterEnabled()

Returns whether the character counter functionality is enabled or not in this layout.

ref com.google.android.material.R.styleable#TextInputLayout_counterEnabled

isEndIconCheckable

public boolean isEndIconCheckable()

Returns whether the end icon is checkable.

isEndIconVisible

public boolean isEndIconVisible()

Returns whether the current end icon is visible.

isErrorEnabled

public boolean isErrorEnabled()

Returns whether the error functionality is enabled or not in this layout.

ref com.google.android.material.R.styleable#TextInputLayout_errorEnabled

See also
setErrorEnabled

isExpandedHintEnabled

public boolean isExpandedHintEnabled()

Returns whether the hint expands to occupy the input area when the text field is unpopulated and not focused.

ref com.google.android.material.R.styleable#TextInputLayout_hintExpandedEnabled

isHelperTextEnabled

public boolean isHelperTextEnabled()

Returns whether the helper text functionality is enabled or not in this layout.

ref com.google.android.material.R.styleable#TextInputLayout_helperTextEnabled

isHintAnimationEnabled

public boolean isHintAnimationEnabled()

Returns whether any hint state changes, due to being focused or non-empty text, are animated.

ref com.google.android.material.R.styleable#TextInputLayout_hintAnimationEnabled

isHintEnabled

public boolean isHintEnabled()

Returns whether the floating label functionality is enabled or not in this layout.

ref com.google.android.material.R.styleable#TextInputLayout_hintEnabled

See also
setHintEnabled

isPasswordVisibilityToggleEnabled

public boolean isPasswordVisibilityToggleEnabled()

Returns whether the password visibility toggle functionality is currently enabled.

isStartIconCheckable

public boolean isStartIconCheckable()

Returns whether the start icon is checkable.

isStartIconVisible

public boolean isStartIconVisible()

Returns whether the current start icon is visible.

onGlobalLayout

public void onGlobalLayout()

onRtlPropertiesChanged

public void onRtlPropertiesChanged(int layoutDirection)

onSaveInstanceState

public Parcelable onSaveInstanceState()

passwordVisibilityToggleRequested

public void passwordVisibilityToggleRequested(boolean shouldSkipAnimations)

Handles visibility for a password toggle icon when changing obfuscation in a password edit text. Public so that clients can override this method for custom UI changes when toggling the display of password text

Parameters
boolean shouldSkipAnimations

true if the password toggle indicator icon should not animate changes

refreshEndIconDrawableState

public void refreshEndIconDrawableState()

This method should be called from within your icon's click listener if your icon's tint list has a color for a state that depends on a click (such as checked state).

refreshErrorIconDrawableState

public void refreshErrorIconDrawableState()

This method should be called from within your icon's click listener if your icon's tint list has a color for a state that depends on a click (such as checked state).

refreshStartIconDrawableState

public void refreshStartIconDrawableState()

This method should be called from within your icon's click listener if your icon's tint list has a color for a state that depends on a click (such as checked state).

removeOnEditTextAttachedListener

public void removeOnEditTextAttachedListener(
    TextInputLayout.OnEditTextAttachedListener listener
)

Remove the given OnEditTextAttachedListener that was previously added via addOnEditTextAttachedListener.

Parameters
TextInputLayout.OnEditTextAttachedListener listener

listener to remove

removeOnEndIconChangedListener

public void removeOnEndIconChangedListener(
    TextInputLayout.OnEndIconChangedListener listener
)

Remove the given TextInputLayout.OnEndIconChangedListener that was previously added via addOnEndIconChangedListener.

Parameters
TextInputLayout.OnEndIconChangedListener listener

listener to remove

setBoxBackgroundColor

public void setBoxBackgroundColor(int boxBackgroundColor)

Sets the filled box's default background color. Calling this method will make the background color not be stateful, if it was before.

Note: The background color is only supported for filled boxes. When used with box variants other than BOX_BACKGROUND_FILLED, the box background color may not work as intended.

Parameters
int boxBackgroundColor

the color to use for the filled box's background

setBoxBackgroundColorResource

public void setBoxBackgroundColorResource(int boxBackgroundColorId)

Set the resource used for the filled box's background color.

Note: The background color is only supported for filled boxes. When used with box variants other than BOX_BACKGROUND_FILLED, the box background color may not work as intended.

Parameters
int boxBackgroundColorId

the resource to use for the box's background color

setBoxBackgroundColorStateList

public void setBoxBackgroundColorStateList(
    ColorStateList boxBackgroundColorStateList
)

Sets the box's background color state list.

Note: The background color is only supported for filled boxes. When used with box variants other than BOX_BACKGROUND_FILLED, the box background color may not work as intended.

Parameters
ColorStateList boxBackgroundColorStateList

the color state list to use for the box's background color

setBoxBackgroundMode

public void setBoxBackgroundMode(
    @TextInputLayout.BoxBackgroundMode int boxBackgroundMode
)

Set the box background mode (filled, outline, or none).

May be one of BOX_BACKGROUND_NONE, BOX_BACKGROUND_FILLED, or BOX_BACKGROUND_OUTLINE.

Note: This method defines TextInputLayout's internal behavior (for example, it allows the hint to be displayed inline with the stroke in a cutout), but doesn't set all attributes that are set in the styles provided for the box background modes. To achieve the look of an outlined or filled text field, supplement this method with other methods that modify the box, such as setBoxStrokeColor and setBoxBackgroundColor.

Parameters
@TextInputLayout.BoxBackgroundMode int boxBackgroundMode

box's background mode

Throws
java.lang.IllegalArgumentException

if boxBackgroundMode is not a @BoxBackgroundMode constant

setBoxCollapsedPaddingTop

public void setBoxCollapsedPaddingTop(int boxCollapsedPaddingTop)

Set the value to use for the EditText's collapsed top padding in box mode.

Customized boxCollapsedPaddingTop will be disabled if the font scale is larger than 1.3.

ref com.google.android.material.R.styleable#TextInputLayout_boxCollapsedPaddingTop

Parameters
int boxCollapsedPaddingTop

the value to use for the EditText's collapsed top padding

setBoxCornerFamily

public void setBoxCornerFamily(@CornerFamily int cornerFamily)

Sets the box's corner family for all corners of the text field.

Parameters
@CornerFamily int cornerFamily

the CornerFamily to be used. May be one of ROUNDED or CUT.

setBoxCornerRadii

public void setBoxCornerRadii(
    float boxCornerRadiusTopStart,
    float boxCornerRadiusTopEnd,
    float boxCornerRadiusBottomStart,
    float boxCornerRadiusBottomEnd
)

Set the box's corner radii.

Parameters
float boxCornerRadiusTopStart

the value to use for the box's top start corner radius

float boxCornerRadiusTopEnd

the value to use for the box's top end corner radius

float boxCornerRadiusBottomStart

the value to use for the box's bottom start corner radius

float boxCornerRadiusBottomEnd

the value to use for the box's bottom end corner radius

setBoxCornerRadiiResources

public void setBoxCornerRadiiResources(
    int boxCornerRadiusTopStartId,
    int boxCornerRadiusTopEndId,
    int boxCornerRadiusBottomEndId,
    int boxCornerRadiusBottomStartId
)

Set the resources used for the box's corner radii.

Parameters
int boxCornerRadiusTopStartId

the resource to use for the box's top start corner radius

int boxCornerRadiusTopEndId

the resource to use for the box's top end corner radius

int boxCornerRadiusBottomEndId

the resource to use for the box's bottom end corner radius

int boxCornerRadiusBottomStartId

the resource to use for the box's bottom start corner radius

setBoxStrokeColor

public void setBoxStrokeColor(int boxStrokeColor)

Set the outline box's stroke focused color.

Calling this method when not in outline box mode will do nothing.

Parameters
int boxStrokeColor

the color to use for the box's stroke when focused

setBoxStrokeColorStateList

public void setBoxStrokeColorStateList(ColorStateList boxStrokeColorStateList)

Set the box's stroke color state list.

Parameters
ColorStateList boxStrokeColorStateList

the color state list to use for the box's stroke

setBoxStrokeErrorColor

public void setBoxStrokeErrorColor(ColorStateList strokeErrorColor)

Set the outline box's stroke color when an error is being displayed.

Calling this method when not in outline box mode will do nothing.

Parameters
ColorStateList strokeErrorColor

the error color to use for the box's stroke

setBoxStrokeWidth

public void setBoxStrokeWidth(int boxStrokeWidth)

Set the value to use for the box's stroke when in outline box mode, or for the underline stroke in filled mode.

ref com.google.android.material.R.styleable#TextInputLayout_boxStrokeWidth

Parameters
int boxStrokeWidth

the value to use for the box's stroke

setBoxStrokeWidthFocused

public void setBoxStrokeWidthFocused(int boxStrokeWidthFocused)

Set the value to use for the focused box's stroke when in outline box mode, or for the focused underline stroke in filled mode.

ref com.google.android.material.R.styleable#TextInputLayout_boxStrokeWidthFocused

Parameters
int boxStrokeWidthFocused

the value to use for the box's stroke when focused

setBoxStrokeWidthFocusedResource

public void setBoxStrokeWidthFocusedResource(int boxStrokeWidthFocusedResId)

Set the resource dimension to use for the focused box's stroke when in outline box mode, or for the focused underline stroke in filled mode.

ref com.google.android.material.R.styleable#TextInputLayout_boxStrokeWidthFocused

Parameters
int boxStrokeWidthFocusedResId

the resource dimension to use for the box's stroke width when focused

setBoxStrokeWidthResource

public void setBoxStrokeWidthResource(int boxStrokeWidthResId)

Set the resource dimension to use for the box's stroke when in outline box mode, or for the underline stroke in filled mode.

ref com.google.android.material.R.styleable#TextInputLayout_boxStrokeWidth

Parameters
int boxStrokeWidthResId

the resource dimension to use for the box's stroke width

setCounterEnabled

public void setCounterEnabled(boolean enabled)

Whether the character counter functionality is enabled or not in this layout.

ref com.google.android.material.R.styleable#TextInputLayout_counterEnabled

setCounterMaxLength

public void setCounterMaxLength(int maxLength)

Sets the max length to display at the character counter.

ref com.google.android.material.R.styleable#TextInputLayout_counterMaxLength

Parameters
int maxLength

maxLength to display. Any value less than or equal to 0 will not be shown.

setCounterOverflowTextAppearance

public void setCounterOverflowTextAppearance(int counterOverflowTextAppearance)

Sets the text color and size for the overflowed character counter using the specified TextAppearance resource.

ref com.google.android.material.R.styleable#TextInputLayout_counterOverflowTextAppearance

setCounterOverflowTextColor

public void setCounterOverflowTextColor(ColorStateList counterOverflowTextColor)

Sets the text color for the overflowed character counter using a ColorStateList.

This text color takes precedence over a text color set in counterOverflowTextAppearance.

ref com.google.android.material.R.styleable#TextInputLayout_counterOverflowTextColor

Parameters
ColorStateList counterOverflowTextColor

the text color used for the overflowed character counter

setCounterTextAppearance

public void setCounterTextAppearance(int counterTextAppearance)

Sets the text color and size for the character counter using the specified TextAppearance resource.

ref com.google.android.material.R.styleable#TextInputLayout_counterTextAppearance

setCounterTextColor

public void setCounterTextColor(ColorStateList counterTextColor)

Sets the text color for the character counter using a ColorStateList.

This text color takes precedence over a text color set in counterTextAppearance.

ref com.google.android.material.R.styleable#TextInputLayout_counterTextColor

Parameters
ColorStateList counterTextColor

text color used for the character counter

setCursorColor

public void setCursorColor(ColorStateList cursorColor)

Sets the cursor color. Using this method will take precedence over using the value of ?attr/colorControlActivated.

Note: This method only has effect on API levels 28+. On lower API levels ?attr/colorControlActivated will be used for the cursor color.

ref com.google.android.material.R.styleable#TextInputLayout_cursorColor

Parameters
ColorStateList cursorColor

the cursor color to be set

setCursorErrorColor

public void setCursorErrorColor(ColorStateList cursorErrorColor)

Sets the cursor color when an error is being displayed. If null, the cursor doesn't change its color when the text field is in an error state.

Note: This method only has effect on API levels 28+. On lower API levels ?attr/colorControlActivated will be used for the cursor color.

ref com.google.android.material.R.styleable#TextInputLayout_cursorErrorColor

Parameters
ColorStateList cursorErrorColor

the error color to use for the cursor

setDefaultHintTextColor

public void setDefaultHintTextColor(ColorStateList textColor)

Sets the text color used by the hint in both the collapsed and expanded states.

setEnabled

public void setEnabled(boolean enabled)

setEndIconActivated

public void setEndIconActivated(boolean endIconActivated)

Sets the current end icon's state to be activated or not.

Parameters
boolean endIconActivated

whether the icon should be activated

setEndIconCheckable

public void setEndIconCheckable(boolean endIconCheckable)

Sets the current end icon to be checkable or not.

If the icon works just as a button and the fact that it's checked or not doesn't affect its behavior, such as the clear text end icon, calling this method is encouraged so that screen readers will not announce the icon's checked state.

ref com.google.android.material.R.styleable#TextInputLayout_endIconCheckable

Parameters
boolean endIconCheckable

whether the icon should be checkable

setEndIconContentDescription

public void setEndIconContentDescription(CharSequence endIconContentDescription)

Set a content description for the end icon.

The content description will be read via screen readers or other accessibility systems to explain the action of the icon.

ref com.google.android.material.R.styleable#TextInputLayout_endIconContentDescription

Parameters
CharSequence endIconContentDescription

Content description to set, or null to clear the content description

setEndIconContentDescription

public void setEndIconContentDescription(int resId)

Set a content description for the end icon.

The content description will be read via screen readers or other accessibility systems to explain the action of the icon.

ref com.google.android.material.R.styleable#TextInputLayout_endIconContentDescription

Parameters
int resId

Resource ID of a content description string to set, or 0 to clear the description

setEndIconDrawable

public void setEndIconDrawable(Drawable endIconDrawable)

Set the icon to use for the end icon. This method should be called after specifying an via setEndIconMode.

If you use an icon you should also set a description for its action using setEndIconContentDescription. This is used for accessibility.

ref com.google.android.material.R.styleable#TextInputLayout_endIconDrawable

Parameters
Drawable endIconDrawable

Drawable to set, may be null to clear the icon

setEndIconDrawable

public void setEndIconDrawable(int resId)

Set the icon to use for the end icon. This method should be called after specifying an via setEndIconMode.

If you use an icon you should also set a description for its action using setEndIconContentDescription. This is used for accessibility.

ref com.google.android.material.R.styleable#TextInputLayout_endIconDrawable

Parameters
int resId

resource id of the drawable to set, or 0 to clear the icon

setEndIconMinSize

public void setEndIconMinSize(int iconSize)

Sets the width and height of the end icon.

ref android.support.design.button.R.styleable#TextInputLayout_endIconSize

Parameters
int iconSize

new dimension for width and height of the end icon in pixels.

setEndIconMode

public void setEndIconMode(int endIconMode)

Set up the end icon mode. When set, a button is placed at the end of the EditText which enables the user to perform the specific icon's functionality.

ref com.google.android.material.R.styleable#TextInputLayout_endIconMode

Parameters
int endIconMode

the end icon mode to be set: END_ICON_PASSWORD_TOGGLE, END_ICON_CLEAR_TEXT, or END_ICON_CUSTOM; or END_ICON_NONE to clear the current icon if any

setEndIconOnClickListener

public void setEndIconOnClickListener(OnClickListener endIconOnClickListener)

Sets the end icon's functionality that is performed when the icon is clicked. The icon will not be clickable if its click and long click listeners are null.

Parameters
OnClickListener endIconOnClickListener

the android.view.View.OnClickListener the end icon view will have

setEndIconOnLongClickListener

public void setEndIconOnLongClickListener(
    OnLongClickListener endIconOnLongClickListener
)

Sets the end icon's functionality that is performed when the end icon is long clicked. The icon will not be clickable if its click and long click listeners are null.

Parameters
OnLongClickListener endIconOnLongClickListener

the android.view.View.OnLongClickListener the end icon view will have, or null to clear it.

setEndIconScaleType

public void setEndIconScaleType(ScaleType scaleType)

Sets ScaleType for the end icon's ImageButton.

ref android.support.design.button.R.styleable#TextInputLayout_endIconScaleType

Parameters
ScaleType scaleType

ScaleType for the end icon's ImageButton.

setEndIconTintList

public void setEndIconTintList(ColorStateList endIconTintList)

Applies a tint to the end icon drawable. Does not modify the current tint mode, which is SRC_IN by default.

Subsequent calls to setEndIconDrawable will automatically mutate the drawable and apply the specified tint and tint mode using setTintList.

ref com.google.android.material.R.styleable#TextInputLayout_endIconTint

Parameters
ColorStateList endIconTintList

the tint to apply, may be null to clear tint

setEndIconTintMode

public void setEndIconTintMode(Mode endIconTintMode)

Specifies the blending mode used to apply the tint specified by setEndIconTintList to the end icon drawable. The default mode is SRC_IN.

ref com.google.android.material.R.styleable#TextInputLayout_endIconTintMode

Parameters
Mode endIconTintMode

the blending mode used to apply the tint, may be null to clear tint

setEndIconVisible

public void setEndIconVisible(boolean visible)

Sets the current end icon to be VISIBLE or GONE.

Parameters
boolean visible

whether the icon should be set to visible

setError

public void setError(CharSequence errorText)

Sets an error message that will be displayed below our EditText. If the error is null, the error message will be cleared.

If the error functionality has not been enabled via setErrorEnabled, then it will be automatically enabled if error is not empty.

Parameters
CharSequence errorText

Error message to display, or null to clear

See also
getError

setErrorAccessibilityLiveRegion

public void setErrorAccessibilityLiveRegion(int errorAccessibilityLiveRegion)

Sets an accessibility live region for the error message.

ref com.google.android.material.R.styleable#TextInputLayout_errorAccessibilityLiveRegion

Parameters
int errorAccessibilityLiveRegion

Accessibility live region to set

setErrorContentDescription

public void setErrorContentDescription(CharSequence errorContentDescription)

Sets a content description for the error message.

A content description should be set when the error message contains special characters that screen readers or other accessibility systems are not able to read, so that they announce the content description instead.

ref com.google.android.material.R.styleable#TextInputLayout_errorContentDescription

Parameters
CharSequence errorContentDescription

Content description to set, or null to clear it

setErrorEnabled

public void setErrorEnabled(boolean enabled)

Whether the error functionality is enabled or not in this layout. Enabling this functionality before setting an error message via setError, will mean that this layout will not change size when an error is displayed.

ref com.google.android.material.R.styleable#TextInputLayout_errorEnabled

setErrorIconDrawable

public void setErrorIconDrawable(Drawable errorIconDrawable)

Set the drawable to use for the error icon.

ref com.google.android.material.R.styleable#TextInputLayout_errorIconDrawable

Parameters
Drawable errorIconDrawable

Drawable to set, may be null to clear the icon

setErrorIconDrawable

public void setErrorIconDrawable(int resId)

Set the drawable to use for the error icon.

ref com.google.android.material.R.styleable#TextInputLayout_errorIconDrawable

Parameters
int resId

resource id of the drawable to set, or 0 to clear the icon

setErrorIconOnClickListener

public void setErrorIconOnClickListener(OnClickListener errorIconOnClickListener)

Sets the error icon's functionality that is performed when the icon is clicked. The icon will not be clickable if its click and long click listeners are null.

Parameters
OnClickListener errorIconOnClickListener

the android.view.View.OnClickListener the error icon view will have

setErrorIconOnLongClickListener

public void setErrorIconOnLongClickListener(
    OnLongClickListener errorIconOnLongClickListener
)

Sets the error icon's functionality that is performed when the end icon is long clicked. The icon will not be clickable if its click and long click listeners are null.

Parameters
OnLongClickListener errorIconOnLongClickListener

the android.view.View.OnLongClickListener the error icon view will have, or null to clear it.

setErrorIconTintList

public void setErrorIconTintList(ColorStateList errorIconTintList)

Applies a tint to the error icon drawable.

ref com.google.android.material.R.styleable#TextInputLayout_errorIconTint

Parameters
ColorStateList errorIconTintList

the tint to apply, may be null to clear tint

setErrorIconTintMode

public void setErrorIconTintMode(Mode errorIconTintMode)

Specifies the blending mode used to apply tint to the end icon drawable. The default mode is SRC_IN.

ref com.google.android.material.R.styleable#TextInputLayout_errorIconTintMode

Parameters
Mode errorIconTintMode

the blending mode used to apply the tint, may be null to clear tint

setErrorTextAppearance

public void setErrorTextAppearance(int errorTextAppearance)

Sets the text color and size for the error message from the specified TextAppearance resource.

ref com.google.android.material.R.styleable#TextInputLayout_errorTextAppearance

setErrorTextColor

public void setErrorTextColor(ColorStateList errorTextColor)

Sets the text color used by the error message in all states.

setExpandedHintEnabled

public void setExpandedHintEnabled(boolean enabled)

Sets whether the hint should expand to occupy the input area when the text field is unpopulated and not focused.

ref com.google.android.material.R.styleable#TextInputLayout_hintExpandedEnabled

setHelperText

public void setHelperText(CharSequence helperText)

Sets a helper message that will be displayed below the EditText. If the helper is null, the helper text functionality will be disabled and the helper message will be hidden.

If the helper text functionality has not been enabled via setHelperTextEnabled, then it will be automatically enabled if helper is not empty.

Parameters
CharSequence helperText

Helper text to display

See also
getHelperText

setHelperTextColor

public void setHelperTextColor(ColorStateList helperTextColor)

Sets the text color used by the helper text in all states.

setHelperTextEnabled

public void setHelperTextEnabled(boolean enabled)

Whether the helper text functionality is enabled or not in this layout. Enabling this functionality before setting a helper message via setHelperText will mean that this layout will not change size when a helper message is displayed.

ref com.google.android.material.R.styleable#TextInputLayout_helperTextEnabled

setHelperTextTextAppearance

public void setHelperTextTextAppearance(int helperTextTextAppearance)

Sets the text color and size for the helper text from the specified TextAppearance resource.

ref com.google.android.material.R.styleable#TextInputLayout_helperTextTextAppearance

setHint

public void setHint(CharSequence hint)

Set the hint to be displayed in the floating label, if enabled.

ref com.google.android.material.R.styleable#TextInputLayout_android_hint

See also
setHintEnabled

setHint

public void setHint(int textHintId)

Set the hint to be displayed in the floating label, if enabled, using the given resource id.

Parameters
int textHintId

The resource id of the text to display in the floating label

setHintAnimationEnabled

public void setHintAnimationEnabled(boolean enabled)

Set whether any hint state changes, due to being focused or non-empty text, are animated.

ref com.google.android.material.R.styleable#TextInputLayout_hintAnimationEnabled

setHintEnabled

public void setHintEnabled(boolean enabled)

Sets whether the floating label functionality is enabled or not in this layout.

If enabled, any non-empty hint in the child EditText will be moved into the floating hint, and its existing hint will be cleared. If disabled, then any non-empty floating hint in this layout will be moved into the EditText, and this layout's hint will be cleared.

ref com.google.android.material.R.styleable#TextInputLayout_hintEnabled

setHintMaxLines

public void setHintMaxLines(int hintMaxLines)

Sets the max number of lines for the hint text.

Parameters
int hintMaxLines

the number of lines to limit the hint text to

setHintTextAppearance

public void setHintTextAppearance(int resId)

Sets the collapsed hint text color, size, style from the specified TextAppearance resource.

ref com.google.android.material.R.styleable#TextInputLayout_hintTextAppearance

setHintTextColor

public void setHintTextColor(ColorStateList hintTextColor)

Sets the collapsed hint text color from the specified ColorStateList resource.

ref com.google.android.material.R.styleable#TextInputLayout_hintTextColor

setLengthCounter

public void setLengthCounter(TextInputLayout.LengthCounter lengthCounter)

Set the counting method used to count the length of a text.

Parameters
TextInputLayout.LengthCounter lengthCounter

the length counter to use.

setMaxEms

public void setMaxEms(int maxEms)

Sets the maximum width in terms of ems of the text field. The layout will be at most maxEms wide if its layout_width is set to wrap_content.

ref com.google.android.material.R.styleable#TextInputLayout_android_maxEms

Parameters
int maxEms

The maximum width in terms of ems to be set

See also
getMaxEms

setMaxWidth

public void setMaxWidth(int maxWidth)

Sets the maximum width of the text field. The layout will be at most this dimension wide if its layout_width is set to wrap_content.

ref com.google.android.material.R.styleable#TextInputLayout_android_maxWidth

Parameters
int maxWidth

The maximum width to be set

setMaxWidthResource

public void setMaxWidthResource(int maxWidthId)

Sets the maximum width of the text field. The layout will be at most this dimension wide if its layout_width is set to wrap_content.

ref com.google.android.material.R.styleable#TextInputLayout_android_maxWidth

Parameters
int maxWidthId

The id of the maximum width dimension resource to be set

setMinEms

public void setMinEms(int minEms)

Sets the minimum width in terms of ems of the text field. The layout will be at least minEms wide if its layout_width is set to wrap_content.

ref com.google.android.material.R.styleable#TextInputLayout_android_minEms

Parameters
int minEms

The minimum width in terms of ems to be set

See also
getMinEms

setMinWidth

public void setMinWidth(int minWidth)

Sets the minimum width of the text field. The layout will be at least this dimension wide if its layout_width is set to wrap_content.

ref com.google.android.material.R.styleable#TextInputLayout_android_minWidth

Parameters
int minWidth

The minimum width to be set

setMinWidthResource

public void setMinWidthResource(int minWidthId)

Sets the minimum width of the text field. The layout will be at least this dimension wide if its layout_width is set to wrap_content.

ref com.google.android.material.R.styleable#TextInputLayout_android_minWidth

Parameters
int minWidthId

The id of the minimum width dimension resource to be set

setPasswordVisibilityToggleContentDescription

public void setPasswordVisibilityToggleContentDescription(
    CharSequence description
)

Set a content description for the navigation button if one is present.

The content description will be read via screen readers or other accessibility systems to explain the action of the password visibility toggle.

ref com.google.android.material.R.styleable#TextInputLayout_passwordToggleContentDescription

Parameters
CharSequence description

Content description to set, or null to clear the content description

setPasswordVisibilityToggleContentDescription

public void setPasswordVisibilityToggleContentDescription(int resId)

Set a content description for the navigation button if one is present.

The content description will be read via screen readers or other accessibility systems to explain the action of the password visibility toggle.

ref com.google.android.material.R.styleable#TextInputLayout_passwordToggleContentDescription

Parameters
int resId

Resource ID of a content description string to set, or 0 to clear the description

setPasswordVisibilityToggleDrawable

public void setPasswordVisibilityToggleDrawable(Drawable icon)

Set the icon to use for the password visibility toggle button.

If you use an icon you should also set a description for its action using setPasswordVisibilityToggleContentDescription. This is used for accessibility.

ref com.google.android.material.R.styleable#TextInputLayout_passwordToggleDrawable

Parameters
Drawable icon

Drawable to set, may be null to clear the icon

setPasswordVisibilityToggleDrawable

public void setPasswordVisibilityToggleDrawable(int resId)

Set the icon to use for the password visibility toggle button.

If you use an icon you should also set a description for its action using setPasswordVisibilityToggleContentDescription. This is used for accessibility.

ref com.google.android.material.R.styleable#TextInputLayout_passwordToggleDrawable

Parameters
int resId

resource id of the drawable to set, or 0 to clear the icon

setPasswordVisibilityToggleEnabled

public void setPasswordVisibilityToggleEnabled(boolean enabled)

Enables or disable the password visibility toggle functionality.

When enabled, a button is placed at the end of the EditText which enables the user to switch between the field's input being visibly disguised or not.

ref com.google.android.material.R.styleable#TextInputLayout_passwordToggleEnabled

Parameters
boolean enabled

true to enable the functionality

setPasswordVisibilityToggleTintList

public void setPasswordVisibilityToggleTintList(ColorStateList tintList)

Applies a tint to the password visibility toggle drawable. Does not modify the current tint mode, which is SRC_IN by default.

Subsequent calls to setPasswordVisibilityToggleDrawable will automatically mutate the drawable and apply the specified tint and tint mode using setTintList.

ref com.google.android.material.R.styleable#TextInputLayout_passwordToggleTint

Parameters
ColorStateList tintList

the tint to apply, may be null to clear tint

setPasswordVisibilityToggleTintMode

public void setPasswordVisibilityToggleTintMode(Mode mode)

Specifies the blending mode used to apply the tint specified by setPasswordVisibilityToggleTintList to the password visibility toggle drawable. The default mode is SRC_IN.

ref com.google.android.material.R.styleable#TextInputLayout_passwordToggleTintMode

Parameters
Mode mode

the blending mode used to apply the tint, may be null to clear tint

setPlaceholderText

public void setPlaceholderText(CharSequence placeholderText)

Sets placeholder text that will be displayed in the input area when the hint is collapsed before text is entered. If the placeholder is null, any previous placeholder text will be hidden and no placeholder text will be shown.

Parameters
CharSequence placeholderText

Placeholder text to display

setPlaceholderTextAppearance

public void setPlaceholderTextAppearance(int placeholderTextAppearance)

Sets the text color and size for the placeholder text from the specified TextAppearance resource.

ref com.google.android.material.R.styleable#TextInputLayout_placeholderTextAppearance

setPlaceholderTextColor

public void setPlaceholderTextColor(ColorStateList placeholderTextColor)

Sets the text color used by the placeholder text in all states.

ref com.google.android.material.R.styleable#TextInputLayout_placeholderTextColor

setPrefixText

public void setPrefixText(CharSequence prefixText)

Sets prefix text that will be displayed in the input area when the hint is collapsed before text is entered. If the prefix is null, any previous prefix text will be hidden and no prefix text will be shown.

Parameters
CharSequence prefixText

Prefix text to display

See also
getPrefixText

setPrefixTextAppearance

public void setPrefixTextAppearance(int prefixTextAppearance)

Sets the text color and size for the prefix text from the specified TextAppearance resource.

ref com.google.android.material.R.styleable#TextInputLayout_prefixTextAppearance

setPrefixTextColor

public void setPrefixTextColor(ColorStateList prefixTextColor)

Sets the text color used by the prefix text in all states.

ref com.google.android.material.R.styleable#TextInputLayout_prefixTextColor

setShapeAppearanceModel

public void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel)

Sets the ShapeAppearanceModel of the text field's box background.

Parameters
ShapeAppearanceModel shapeAppearanceModel

the desired shape appearance model.

setStartIconCheckable

public void setStartIconCheckable(boolean startIconCheckable)

Sets the current start icon to be checkable or not.

If the icon works just as a button and the fact that it's checked or not doesn't affect its behavior, such as the clear text end icon, calling this method is encouraged so that screen readers will not announce the icon's checked state.

ref com.google.android.material.R.styleable#TextInputLayout_startIconCheckable

Parameters
boolean startIconCheckable

whether the icon should be checkable

setStartIconContentDescription

public void setStartIconContentDescription(int resId)

Set a content description for the start icon.

The content description will be read via screen readers or other accessibility systems to explain the purpose or action of the icon.

ref com.google.android.material.R.styleable#TextInputLayout_startIconContentDescription

Parameters
int resId

Resource ID of a content description string to set, or 0 to clear the description

setStartIconContentDescription

public void setStartIconContentDescription(
    CharSequence startIconContentDescription
)

Set a content description for the start icon.

The content description will be read via screen readers or other accessibility systems to explain the purpose or action of the icon.

ref com.google.android.material.R.styleable#TextInputLayout_startIconContentDescription

Parameters
CharSequence startIconContentDescription

Content description to set, or null to clear the content description

setStartIconDrawable

public void setStartIconDrawable(int resId)

Sets the start icon.

If you use an icon you should also set a description for its action using setStartIconContentDescription. This is used for accessibility.

ref com.google.android.material.R.styleable#TextInputLayout_startIconDrawable

Parameters
int resId

resource id of the drawable to set, or 0 to clear and remove the icon

setStartIconDrawable

public void setStartIconDrawable(Drawable startIconDrawable)

Sets the start icon.

If you use an icon you should also set a description for its action using setStartIconContentDescription. This is used for accessibility.

ref com.google.android.material.R.styleable#TextInputLayout_startIconDrawable

Parameters
Drawable startIconDrawable

Drawable to set, may be null to clear and remove the icon

setStartIconMinSize

public void setStartIconMinSize(int iconSize)

Sets the width and height of the start icon.

ref android.support.design.button.R.styleable#TextInputLayout_startIconSize

Parameters
int iconSize

new dimension for width and height of the start icon in pixels.

setStartIconOnClickListener

public void setStartIconOnClickListener(OnClickListener startIconOnClickListener)

Sets the start icon's functionality that is performed when the start icon is clicked. The icon will not be clickable if its click and long click listeners are null.

Parameters
OnClickListener startIconOnClickListener

the android.view.View.OnClickListener the start icon view will have, or null to clear it.

setStartIconOnLongClickListener

public void setStartIconOnLongClickListener(
    OnLongClickListener startIconOnLongClickListener
)

Sets the start icon's functionality that is performed when the start icon is long clicked. The icon will not be clickable if its click and long click listeners are null.

Parameters
OnLongClickListener startIconOnLongClickListener

the android.view.View.OnLongClickListener the start icon view will have, or null to clear it.

setStartIconScaleType

public void setStartIconScaleType(ScaleType scaleType)

Sets ScaleType for the start icon's ImageButton.

ref android.support.design.button.R.styleable#TextInputLayout_startIconScaleType

Parameters
ScaleType scaleType

ScaleType for the start icon's ImageButton.

setStartIconTintList

public void setStartIconTintList(ColorStateList startIconTintList)

Applies a tint to the start icon drawable. Does not modify the current tint mode, which is SRC_IN by default.

Subsequent calls to setStartIconDrawable will automatically mutate the drawable and apply the specified tint and tint mode using setTintList.

ref com.google.android.material.R.styleable#TextInputLayout_startIconTint

Parameters
ColorStateList startIconTintList

the tint to apply, may be null to clear tint

setStartIconTintMode

public void setStartIconTintMode(Mode startIconTintMode)

Specifies the blending mode used to apply the tint specified by setEndIconTintList to the start icon drawable. The default mode is SRC_IN.

ref com.google.android.material.R.styleable#TextInputLayout_startIconTintMode

Parameters
Mode startIconTintMode

the blending mode used to apply the tint, may be null to clear tint

setStartIconVisible

public void setStartIconVisible(boolean visible)

Sets the start icon to be VISIBLE or GONE.

Parameters
boolean visible

whether the icon should be set to visible

setSuffixText

public void setSuffixText(CharSequence suffixText)

Sets suffix text that will be displayed in the input area when the hint is collapsed before text is entered. If the suffix is null, any previous suffix text will be hidden and no suffix text will be shown.

Parameters
CharSequence suffixText

Suffix text to display

See also
getSuffixText

setSuffixTextAppearance

public void setSuffixTextAppearance(int suffixTextAppearance)

Sets the text color and size for the suffix text from the specified TextAppearance resource.

ref com.google.android.material.R.styleable#TextInputLayout_suffixTextAppearance

setSuffixTextColor

public void setSuffixTextColor(ColorStateList suffixTextColor)

Sets the text color used by the suffix text in all states.

ref com.google.android.material.R.styleable#TextInputLayout_suffixTextColor

setTextInputAccessibilityDelegate

public void setTextInputAccessibilityDelegate(
    TextInputLayout.AccessibilityDelegate delegate
)

Sets an TextInputLayout.AccessibilityDelegate providing an accessibility implementation for the EditText used by this layout.

Note: This method should be used in place of providing an AccessibilityDelegate directly on the EditText.

setTypeface

public void setTypeface(Typeface typeface)

Set the typeface to use for the hint and any label views (such as counter and error views).

Parameters
Typeface typeface

typeface to use, or null to use the default.

Protected methods

dispatchRestoreInstanceState

protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container)

drawableStateChanged

protected void drawableStateChanged()

onConfigurationChanged

protected void onConfigurationChanged(Configuration newConfig)

onLayout

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

onMeasure

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

onRestoreInstanceState

protected void onRestoreInstanceState(Parcelable state)