TextInputLayout
public
class
TextInputLayout
extends LinearLayout
java.lang.Object | ||||
↳ | android.view.View | |||
↳ | android.view.ViewGroup | |||
↳ | android.widget.LinearLayout | |||
↳ | com.google.android.material.textfield.TextInputLayout |
Layout which wraps a TextInputEditText
, 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(boolean)
andsetError(CharSequence)
, along with showing an error icon viasetErrorIconDrawable(Drawable)
- Showing helper text via
setHelperTextEnabled(boolean)
andsetHelperText(CharSequence)
- Showing placeholder text via
setPlaceholderText(CharSequence)
- Showing prefix text via
setPrefixText(CharSequence)
- Showing suffix text via
setSuffixText(CharSequence)
- Showing a character counter via
setCounterEnabled(boolean)
andsetCounterMaxLength(int)
- Password visibility toggling via
setEndIconMode(int)
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(int)
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(int)
API and related attribute. You should specify a drawable and content description for the icon. Optionally, you can also specify anView.OnClickListener
, anTextInputLayout.OnEditTextAttachedListener
and anTextInputLayout.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(Drawable)
API and related attribute. You should specify a content description for the icon. Optionally, you can also specify anView.OnClickListener
for it.Note: Use the
setStartIconDrawable(Drawable)
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 aTextInputEditText
as the input text child, and a Widget.MaterialComponents.TextInputLayout.(...).ExposedDropdownMenu style.To disable user input you should set
android:editable="false"
on theAutoCompleteTextView
.
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.
An example usage is as so:
<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(CharSequence)
and getHint()
on TextInputLayout,
instead of on EditText.
If the EditText
child is not a TextInputEditText
, make sure to set the EditText
'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(int)
.
Summary
Nested classes | |
---|---|
class |
TextInputLayout.AccessibilityDelegate
An |
@interface |
TextInputLayout.BoxBackgroundMode
Values for box background mode. |
interface |
TextInputLayout.OnEditTextAttachedListener
Callback interface invoked when the view's |
interface |
TextInputLayout.OnEndIconChangedListener
Callback interface invoked when the view's end icon changes. |
XML attributes | |
---|---|
TextInputLayout_android_hint |
|
TextInputLayout_boxStrokeErrorColor |
|
TextInputLayout_boxStrokeWidth |
|
TextInputLayout_boxStrokeWidthFocused |
|
TextInputLayout_counterEnabled |
|
TextInputLayout_counterMaxLength |
|
TextInputLayout_counterOverflowTextAppearance |
|
TextInputLayout_counterOverflowTextColor |
|
TextInputLayout_counterTextAppearance |
|
TextInputLayout_counterTextColor |
|
TextInputLayout_endIconCheckable |
|
TextInputLayout_endIconContentDescription |
|
TextInputLayout_endIconDrawable |
|
TextInputLayout_endIconMode |
|
TextInputLayout_endIconTint |
|
TextInputLayout_endIconTintMode |
|
TextInputLayout_errorContentDescription |
|
TextInputLayout_errorEnabled |
|
TextInputLayout_errorIconDrawable |
|
TextInputLayout_errorIconTint |
|
TextInputLayout_errorIconTintMode |
|
TextInputLayout_errorTextAppearance |
|
TextInputLayout_helperTextEnabled |
|
TextInputLayout_helperTextTextAppearance |
|
TextInputLayout_hintAnimationEnabled |
|
TextInputLayout_hintEnabled |
|
TextInputLayout_hintTextAppearance |
|
TextInputLayout_hintTextColor |
|
TextInputLayout_passwordToggleContentDescription |
|
TextInputLayout_passwordToggleDrawable |
|
TextInputLayout_passwordToggleEnabled |
|
TextInputLayout_passwordToggleTint |
|
TextInputLayout_passwordToggleTintMode |
|
TextInputLayout_placeholderTextAppearance |
|
TextInputLayout_placeholderTextColor |
|
TextInputLayout_prefixTextAppearance |
|
TextInputLayout_prefixTextColor |
|
TextInputLayout_startIconCheckable |
|
TextInputLayout_startIconContentDescription |
|
TextInputLayout_startIconDrawable |
|
TextInputLayout_startIconTint |
|
TextInputLayout_startIconTintMode |
|
TextInputLayout_suffixTextAppearance |
|
TextInputLayout_suffixTextColor |
Constants | |
---|---|
int |
BOX_BACKGROUND_FILLED
|
int |
BOX_BACKGROUND_NONE
|
int |
BOX_BACKGROUND_OUTLINE
|
int |
END_ICON_CLEAR_TEXT
The TextInputLayout will show a clear text button while there is input in the EditText. |
int |
END_ICON_CUSTOM
The TextInputLayout will show a custom icon specified by the user. |
int |
END_ICON_DROPDOWN_MENU
The TextInputLayout will show a dropdown button if the EditText is an |
int |
END_ICON_NONE
Default for the TextInputLayout. |
int |
END_ICON_PASSWORD_TOGGLE
The TextInputLayout will show a password toggle button if its EditText displays a password. |
Inherited constants |
---|
![]()
android.widget.LinearLayout
|
![]()
android.view.ViewGroup
|
![]()
android.view.View
|
Inherited fields |
---|
![]()
android.view.View
|
Public constructors | |
---|---|
TextInputLayout(Context context)
|
|
TextInputLayout(Context context, AttributeSet attrs)
|
|
TextInputLayout(Context context, AttributeSet attrs, int defStyleAttr)
|
Public methods | |
---|---|
void
|
addOnEditTextAttachedListener(TextInputLayout.OnEditTextAttachedListener listener)
Add a |
void
|
addOnEndIconChangedListener(TextInputLayout.OnEndIconChangedListener listener)
Add a |
void
|
addView(View child, int index, ViewGroup.LayoutParams params)
|
void
|
clearOnEditTextAttachedListeners()
Remove all previously added |
void
|
clearOnEndIconChangedListeners()
Remove all previously added |
void
|
dispatchProvideAutofillStructure(ViewStructure structure, int flags)
|
void
|
draw(Canvas canvas)
|
int
|
getBaseline()
|
int
|
getBoxBackgroundColor()
Returns the filled box's default background color. |
int
|
getBoxBackgroundMode()
Get the box background mode (filled, outline, or none). |
float
|
getBoxCornerRadiusBottomEnd()
Returns the box's bottom end corner radius. |
float
|
getBoxCornerRadiusBottomStart()
Returns the box's bottom start corner radius. |
float
|
getBoxCornerRadiusTopEnd()
Returns the box's top end corner radius. |
float
|
getBoxCornerRadiusTopStart()
Returns the box's top start corner radius. |
int
|
getBoxStrokeColor()
Returns the box's stroke focused color. |
ColorStateList
|
getBoxStrokeErrorColor()
Returns the box's stroke color when an error is being displayed. |
int
|
getBoxStrokeWidth()
Returns the box's stroke width. |
int
|
getBoxStrokeWidthFocused()
Returns the box's stroke focused width. |
int
|
getCounterMaxLength()
Returns the max length shown at the character counter. |
ColorStateList
|
getCounterOverflowTextColor()
Returns the text color used for the overflowed character counter, or null if one has not been set. |
ColorStateList
|
getCounterTextColor()
Returns the text color used for the character counter, or null if one has not been set. |
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. |
EditText
|
getEditText()
Returns the |
CharSequence
|
getEndIconContentDescription()
Returns the currently configured content description for the end icon. |
Drawable
|
getEndIconDrawable()
Returns the drawable currently used for the end icon. |
int
|
getEndIconMode()
Returns the current end icon mode. |
CharSequence
|
getError()
Returns the error message that was set to be displayed with |
CharSequence
|
getErrorContentDescription()
Returns the content description of the error message, or null if not set. |
int
|
getErrorCurrentTextColors()
Returns the text color used by the error message in current state. |
Drawable
|
getErrorIconDrawable()
Returns the drawable currently used for the error icon. |
CharSequence
|
getHelperText()
Returns the helper message that was set to be displayed with |
int
|
getHelperTextCurrentTextColor()
Returns the text color used by the helper text in the current states. |
CharSequence
|
getHint()
Returns the hint which is displayed in the floating label, if enabled. |
ColorStateList
|
getHintTextColor()
Gets the collapsed hint text color. |
CharSequence
|
getPasswordVisibilityToggleContentDescription()
This method is deprecated.
Use |
Drawable
|
getPasswordVisibilityToggleDrawable()
This method is deprecated.
Use |
CharSequence
|
getPlaceholderText()
Returns the placeholder text that was set to be displayed with |
int
|
getPlaceholderTextAppearance()
Returns the TextAppearance resource used for the placeholder text color. |
ColorStateList
|
getPlaceholderTextColor()
Returns the ColorStateList used for the placeholder text. |
CharSequence
|
getPrefixText()
Returns the prefix text that was set to be displayed with |
ColorStateList
|
getPrefixTextColor()
Returns the ColorStateList used for the prefix text. |
TextView
|
getPrefixTextView()
Returns the prefix text view. |
CharSequence
|
getStartIconContentDescription()
Returns the currently configured content description for the start icon. |
Drawable
|
getStartIconDrawable()
Returns the start icon. |
CharSequence
|
getSuffixText()
Returns the suffix text that was set to be displayed with |
ColorStateList
|
getSuffixTextColor()
Returns the ColorStateList used for the suffix text. |
TextView
|
getSuffixTextView()
Returns the suffix text view. |
Typeface
|
getTypeface()
Returns the typeface used for the hint and any label views (such as counter and error views). |
boolean
|
isCounterEnabled()
Returns whether the character counter functionality is enabled or not in this layout. |
boolean
|
isEndIconCheckable()
Returns whether the end icon is checkable. |
boolean
|
isEndIconVisible()
Returns whether the current end icon is visible. |
boolean
|
isErrorEnabled()
Returns whether the error functionality is enabled or not in this layout. |
boolean
|
isHelperTextEnabled()
Returns whether the helper text functionality is enabled or not in this layout. |
boolean
|
isHintAnimationEnabled()
Returns whether any hint state changes, due to being focused or non-empty text, are animated. |
boolean
|
isHintEnabled()
Returns whether the floating label functionality is enabled or not in this layout. |
boolean
|
isPasswordVisibilityToggleEnabled()
This method is deprecated.
Use |
boolean
|
isStartIconCheckable()
Returns whether the start icon is checkable. |
boolean
|
isStartIconVisible()
Returns whether the current start icon is visible. |
Parcelable
|
onSaveInstanceState()
|
void
|
passwordVisibilityToggleRequested(boolean shouldSkipAnimations)
This method is deprecated.
The password toggle will show as checked or unchecked depending on whether the
|
void
|
removeOnEditTextAttachedListener(TextInputLayout.OnEditTextAttachedListener listener)
Remove the given |
void
|
removeOnEndIconChangedListener(TextInputLayout.OnEndIconChangedListener listener)
Remove the given |
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
|
setBoxBackgroundMode(int boxBackgroundMode)
Set the box background mode (filled, outline, or none). |
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
|
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(int resId)
Set a content description for the end icon. |
void
|
setEndIconContentDescription(CharSequence endIconContentDescription)
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
|
setEndIconMode(int endIconMode)
Set up the end icon mode. |
void
|
setEndIconOnClickListener(View.OnClickListener endIconOnClickListener)
Sets the end icon's functionality that is performed when the icon is clicked. |
void
|
setEndIconOnLongClickListener(View.OnLongClickListener endIconOnLongClickListener)
Sets the end icon's functionality that is performed when the end icon is long clicked. |
void
|
setEndIconTintList(ColorStateList endIconTintList)
Applies a tint to the end icon drawable. |
void
|
setEndIconTintMode(PorterDuff.Mode endIconTintMode)
Specifies the blending mode used to apply the tint specified by |
void
|
setEndIconVisible(boolean visible)
Sets the current end icon to be VISIBLE or GONE. |
void
|
setError(CharSequence errorText)
Sets an error message that will be displayed below our |
void
|
setErrorContentDescription(CharSequence errorContentDecription)
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(int resId)
Set the drawable to use for the error icon. |
void
|
setErrorIconDrawable(Drawable errorIconDrawable)
Set the drawable to use for the error icon. |
void
|
setErrorIconOnClickListener(View.OnClickListener errorIconOnClickListener)
Sets the error icon's functionality that is performed when the icon is clicked. |
void
|
setErrorIconOnLongClickListener(View.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(PorterDuff.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
|
setHelperText(CharSequence helperText)
Sets a helper message that will be displayed below the |
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
|
setHint(CharSequence hint)
Set the hint to be displayed in the floating label, if enabled. |
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
|
setHintTextAppearance(int resId)
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
|
setPasswordVisibilityToggleContentDescription(CharSequence description)
This method is deprecated.
Use |
void
|
setPasswordVisibilityToggleContentDescription(int resId)
This method is deprecated.
Use |
void
|
setPasswordVisibilityToggleDrawable(Drawable icon)
This method is deprecated.
Use |
void
|
setPasswordVisibilityToggleDrawable(int resId)
This method is deprecated.
Use |
void
|
setPasswordVisibilityToggleEnabled(boolean enabled)
This method is deprecated.
Use |
void
|
setPasswordVisibilityToggleTintList(ColorStateList tintList)
This method is deprecated.
Use |
void
|
setPasswordVisibilityToggleTintMode(PorterDuff.Mode mode)
This method is deprecated.
Use |
void
|
setPlaceholderText(CharSequence placeholderText)
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
|
setPrefixText(CharSequence prefixText)
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
|
setStartIconCheckable(boolean startIconCheckable)
Sets the current start icon to be checkable or not. |
void
|
setStartIconContentDescription(CharSequence startIconContentDescription)
Set a content description for the start icon. |
void
|
setStartIconContentDescription(int resId)
Set a content description for the start icon. |
void
|
setStartIconDrawable(Drawable startIconDrawable)
Sets the start icon. |
void
|
setStartIconDrawable(int resId)
Sets the start icon. |
void
|
setStartIconOnClickListener(View.OnClickListener startIconOnClickListener)
Sets the start icon's functionality that is performed when the start icon is clicked. |
void
|
setStartIconOnLongClickListener(View.OnLongClickListener startIconOnLongClickListener)
Sets the start icon's functionality that is performed when the start icon is long clicked. |
void
|
setStartIconTintList(ColorStateList startIconTintList)
Applies a tint to the start icon drawable. |
void
|
setStartIconTintMode(PorterDuff.Mode startIconTintMode)
Specifies the blending mode used to apply the tint specified by |
void
|
setStartIconVisible(boolean visible)
Sets the start icon to be VISIBLE or GONE. |
void
|
setSuffixText(CharSequence suffixText)
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
|
setTextInputAccessibilityDelegate(TextInputLayout.AccessibilityDelegate delegate)
Sets an |
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
|
drawableStateChanged()
|
void
|
onLayout(boolean changed, int left, int top, int right, int bottom)
|
void
|
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
void
|
onRestoreInstanceState(Parcelable state)
|
XML attributes
TextInputLayout_android_hint
Related methods:
TextInputLayout_boxStrokeErrorColor
Related methods:
TextInputLayout_boxStrokeWidth
Related methods:
TextInputLayout_boxStrokeWidthFocused
Related methods:
TextInputLayout_counterEnabled
Related methods:
TextInputLayout_counterMaxLength
Related methods:
TextInputLayout_counterOverflowTextAppearance
Related methods:
TextInputLayout_counterOverflowTextColor
Related methods:
TextInputLayout_counterTextAppearance
Related methods:
TextInputLayout_counterTextColor
Related methods:
TextInputLayout_endIconCheckable
Related methods:
TextInputLayout_endIconContentDescription
Related methods:
TextInputLayout_endIconDrawable
Related methods:
TextInputLayout_endIconMode
Related methods:
TextInputLayout_endIconTint
Related methods:
TextInputLayout_endIconTintMode
Related methods:
TextInputLayout_errorContentDescription
Related methods:
TextInputLayout_errorEnabled
Related methods:
TextInputLayout_errorIconDrawable
Related methods:
TextInputLayout_errorIconTint
Related methods:
TextInputLayout_errorIconTintMode
Related methods:
TextInputLayout_errorTextAppearance
Related methods:
TextInputLayout_helperTextEnabled
Related methods:
TextInputLayout_helperTextTextAppearance
Related methods:
TextInputLayout_hintAnimationEnabled
Related methods:
TextInputLayout_hintEnabled
Related methods:
TextInputLayout_hintTextAppearance
Related methods:
TextInputLayout_hintTextColor
Related methods:
TextInputLayout_passwordToggleContentDescription
Related methods:
TextInputLayout_passwordToggleDrawable
Related methods:
TextInputLayout_passwordToggleEnabled
Related methods:
TextInputLayout_passwordToggleTint
Related methods:
TextInputLayout_passwordToggleTintMode
Related methods:
TextInputLayout_placeholderTextAppearance
Related methods:
TextInputLayout_placeholderTextColor
Related methods:
TextInputLayout_prefixTextAppearance
Related methods:
TextInputLayout_prefixTextColor
Related methods:
TextInputLayout_startIconCheckable
Related methods:
TextInputLayout_startIconContentDescription
Related methods:
TextInputLayout_startIconDrawable
Related methods:
TextInputLayout_startIconTint
Related methods:
TextInputLayout_startIconTintMode
Related methods:
TextInputLayout_suffixTextAppearance
Related methods:
TextInputLayout_suffixTextColor
Related methods:
Constants
BOX_BACKGROUND_FILLED
int BOX_BACKGROUND_FILLED
Constant Value: 1 (0x00000001)
BOX_BACKGROUND_NONE
int BOX_BACKGROUND_NONE
Constant Value: 0 (0x00000000)
BOX_BACKGROUND_OUTLINE
int BOX_BACKGROUND_OUTLINE
Constant Value: 2 (0x00000002)
END_ICON_CLEAR_TEXT
int END_ICON_CLEAR_TEXT
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.
See also:
Constant Value: 2 (0x00000002)
END_ICON_CUSTOM
int END_ICON_CUSTOM
The TextInputLayout will show a custom icon specified by the user.
See also:
Constant Value: -1 (0xffffffff)
END_ICON_DROPDOWN_MENU
int END_ICON_DROPDOWN_MENU
The TextInputLayout will show a dropdown button if the EditText is an AutoCompleteTextView
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.
Constant Value: 3 (0x00000003)
END_ICON_NONE
int END_ICON_NONE
Default for the TextInputLayout. It will not display an end icon.
See also:
Constant Value: 0 (0x00000000)
END_ICON_PASSWORD_TOGGLE
int END_ICON_PASSWORD_TOGGLE
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.
See also:
Constant Value: 1 (0x00000001)
Public constructors
TextInputLayout
TextInputLayout (Context context)
Parameters | |
---|---|
context |
Context |
TextInputLayout
TextInputLayout (Context context, AttributeSet attrs)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
TextInputLayout
TextInputLayout (Context context, AttributeSet attrs, int defStyleAttr)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyleAttr |
int |
Public methods
addOnEditTextAttachedListener
void addOnEditTextAttachedListener (TextInputLayout.OnEditTextAttachedListener listener)
Add a TextInputLayout.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(OnEditTextAttachedListener)
.
Parameters | |
---|---|
listener |
TextInputLayout.OnEditTextAttachedListener : listener to add
|
addOnEndIconChangedListener
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(OnEndIconChangedListener)
.
Parameters | |
---|---|
listener |
TextInputLayout.OnEndIconChangedListener : listener to add
|
addView
void addView (View child, int index, ViewGroup.LayoutParams params)
Parameters | |
---|---|
child |
View |
index |
int |
params |
ViewGroup.LayoutParams |
clearOnEditTextAttachedListeners
void clearOnEditTextAttachedListeners ()
Remove all previously added TextInputLayout.OnEditTextAttachedListener
s.
clearOnEndIconChangedListeners
void clearOnEndIconChangedListeners ()
Remove all previously added TextInputLayout.OnEndIconChangedListener
s.
dispatchProvideAutofillStructure
void dispatchProvideAutofillStructure (ViewStructure structure, int flags)
Parameters | |
---|---|
structure |
ViewStructure |
flags |
int |
draw
void draw (Canvas canvas)
Parameters | |
---|---|
canvas |
Canvas |
getBaseline
int getBaseline ()
Returns | |
---|---|
int |
getBoxBackgroundColor
int getBoxBackgroundColor ()
Returns the filled box's default background color.
Returns | |
---|---|
int |
the color used for the filled box's background |
See also:
getBoxBackgroundMode
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
.
Returns | |
---|---|
int |
getBoxCornerRadiusBottomEnd
float getBoxCornerRadiusBottomEnd ()
Returns the box's bottom end corner radius.
Returns | |
---|---|
float |
the value used for the box's bottom end corner radius |
getBoxCornerRadiusBottomStart
float getBoxCornerRadiusBottomStart ()
Returns the box's bottom start corner radius.
Returns | |
---|---|
float |
the value used for the box's bottom start corner radius |
getBoxCornerRadiusTopEnd
float getBoxCornerRadiusTopEnd ()
Returns the box's top end corner radius.
Returns | |
---|---|
float |
the value used for the box's top end corner radius |
getBoxCornerRadiusTopStart
float getBoxCornerRadiusTopStart ()
Returns the box's top start corner radius.
Returns | |
---|---|
float |
the value used for the box's top start corner radius |
getBoxStrokeColor
int getBoxStrokeColor ()
Returns the box's stroke focused color.
Returns | |
---|---|
int |
the color used for the box's stroke when focused |
See also:
getBoxStrokeErrorColor
ColorStateList getBoxStrokeErrorColor ()
Returns the box's stroke color when an error is being displayed.
Related XML Attributes:
Returns | |
---|---|
ColorStateList |
See also:
getBoxStrokeWidth
int getBoxStrokeWidth ()
Returns the box's stroke width.
Returns | |
---|---|
int |
the value used for the box's stroke width |
See also:
getBoxStrokeWidthFocused
int getBoxStrokeWidthFocused ()
Returns the box's stroke focused width.
Returns | |
---|---|
int |
the value used for the box's stroke width when focused |
See also:
getCounterMaxLength
int getCounterMaxLength ()
Returns the max length shown at the character counter.
Related XML Attributes:
Returns | |
---|---|
int |
getCounterOverflowTextColor
ColorStateList getCounterOverflowTextColor ()
Returns the text color used for the overflowed character counter, or null if one has not been set.
Related XML Attributes:
Returns | |
---|---|
ColorStateList |
the text color used for the overflowed character counter |
See also:
getCounterTextColor
ColorStateList getCounterTextColor ()
Returns the text color used for the character counter, or null if one has not been set.
Related XML Attributes:
Returns | |
---|---|
ColorStateList |
the text color used for the character counter |
See also:
getDefaultHintTextColor
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.
Returns | |
---|---|
ColorStateList |
getEndIconContentDescription
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.
Returns | |
---|---|
CharSequence |
getEndIconDrawable
Drawable getEndIconDrawable ()
Returns the drawable currently used for the end icon.
Related XML Attributes:
Returns | |
---|---|
Drawable |
See also:
getEndIconMode
int getEndIconMode ()
Returns the current end icon mode.
Related XML Attributes:
Returns | |
---|---|
int |
the end icon mode enum |
See also:
getError
CharSequence getError ()
Returns the error message that was set to be displayed with setError(CharSequence)
, or
null
if no error was set or if error displaying is not enabled.
Returns | |
---|---|
CharSequence |
See also:
getErrorContentDescription
CharSequence getErrorContentDescription ()
Returns the content description of the error message, or null if not set.
Returns | |
---|---|
CharSequence |
See also:
getErrorCurrentTextColors
int getErrorCurrentTextColors ()
Returns the text color used by the error message in current state.
Returns | |
---|---|
int |
getErrorIconDrawable
Drawable getErrorIconDrawable ()
Returns the drawable currently used for the error icon.
Related XML Attributes:
Returns | |
---|---|
Drawable |
See also:
getHelperText
CharSequence getHelperText ()
Returns the helper message that was set to be displayed with setHelperText(CharSequence)
, or null
if no helper text was set or if helper text
functionality is not enabled.
Returns | |
---|---|
CharSequence |
See also:
getHelperTextCurrentTextColor
int getHelperTextCurrentTextColor ()
Returns the text color used by the helper text in the current states.
Returns | |
---|---|
int |
getHint
CharSequence getHint ()
Returns the hint which is displayed in the floating label, if enabled.
Related XML Attributes:
Returns | |
---|---|
CharSequence |
the hint, or null if there isn't one set, or the hint is not enabled. |
getHintTextColor
ColorStateList getHintTextColor ()
Gets the collapsed hint text color.
Related XML Attributes:
Returns | |
---|---|
ColorStateList |
getPasswordVisibilityToggleContentDescription
CharSequence getPasswordVisibilityToggleContentDescription ()
This method is deprecated.
Use getEndIconContentDescription()
instead.
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.
Returns | |
---|---|
CharSequence |
getPasswordVisibilityToggleDrawable
Drawable getPasswordVisibilityToggleDrawable ()
This method is deprecated.
Use getEndIconDrawable()
instead.
Returns the icon currently used for the password visibility toggle button.
Related XML Attributes:
Returns | |
---|---|
Drawable |
getPlaceholderText
CharSequence getPlaceholderText ()
Returns the placeholder text that was set to be displayed with setPlaceholderText(CharSequence)
, or null
if there is no placeholder text.
Returns | |
---|---|
CharSequence |
See also:
getPlaceholderTextAppearance
int getPlaceholderTextAppearance ()
Returns the TextAppearance resource used for the placeholder text color.
Related XML Attributes:
Returns | |
---|---|
int |
getPlaceholderTextColor
ColorStateList getPlaceholderTextColor ()
Returns the ColorStateList used for the placeholder text.
Related XML Attributes:
Returns | |
---|---|
ColorStateList |
getPrefixText
CharSequence getPrefixText ()
Returns the prefix text that was set to be displayed with setPrefixText(CharSequence)
,
or null
if there is no prefix text.
Returns | |
---|---|
CharSequence |
See also:
getPrefixTextColor
ColorStateList getPrefixTextColor ()
Returns the ColorStateList used for the prefix text.
Related XML Attributes:
Returns | |
---|---|
ColorStateList |
getPrefixTextView
TextView getPrefixTextView ()
Returns the prefix text view.
Note: In order for the prefix to work correctly, text should always be set only via setPrefixText(CharSequence)
, instead of on the TextView
directly.
Returns | |
---|---|
TextView |
See also:
getStartIconContentDescription
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.
Returns | |
---|---|
CharSequence |
getStartIconDrawable
Drawable getStartIconDrawable ()
Returns the start icon.
Related XML Attributes:
Returns | |
---|---|
Drawable |
the drawable used for the start icon |
See also:
getSuffixText
CharSequence getSuffixText ()
Returns the suffix text that was set to be displayed with setSuffixText(CharSequence)
,
or null
if there is no suffix text.
Returns | |
---|---|
CharSequence |
See also:
getSuffixTextColor
ColorStateList getSuffixTextColor ()
Returns the ColorStateList used for the suffix text.
Related XML Attributes:
Returns | |
---|---|
ColorStateList |
getSuffixTextView
TextView getSuffixTextView ()
Returns the suffix text view.
Note: In order for the suffix to work correctly, text should always be set only via setSuffixText(CharSequence)
, instead of on the TextView
directly.
Returns | |
---|---|
TextView |
See also:
getTypeface
Typeface getTypeface ()
Returns the typeface used for the hint and any label views (such as counter and error views).
Returns | |
---|---|
Typeface |
isCounterEnabled
boolean isCounterEnabled ()
Returns whether the character counter functionality is enabled or not in this layout.
Related XML Attributes:
Returns | |
---|---|
boolean |
See also:
isEndIconCheckable
boolean isEndIconCheckable ()
Returns whether the end icon is checkable.
Returns | |
---|---|
boolean |
See also:
isEndIconVisible
boolean isEndIconVisible ()
Returns whether the current end icon is visible.
Returns | |
---|---|
boolean |
See also:
isErrorEnabled
boolean isErrorEnabled ()
Returns whether the error functionality is enabled or not in this layout.
Related XML Attributes:
Returns | |
---|---|
boolean |
See also:
isHelperTextEnabled
boolean isHelperTextEnabled ()
Returns whether the helper text functionality is enabled or not in this layout.
Related XML Attributes:
Returns | |
---|---|
boolean |
See also:
isHintAnimationEnabled
boolean isHintAnimationEnabled ()
Returns whether any hint state changes, due to being focused or non-empty text, are animated.
Related XML Attributes:
Returns | |
---|---|
boolean |
See also:
isHintEnabled
boolean isHintEnabled ()
Returns whether the floating label functionality is enabled or not in this layout.
Related XML Attributes:
Returns | |
---|---|
boolean |
See also:
isPasswordVisibilityToggleEnabled
boolean isPasswordVisibilityToggleEnabled ()
This method is deprecated.
Use getEndIconMode()
instead.
Returns whether the password visibility toggle functionality is currently enabled.
Returns | |
---|---|
boolean |
isStartIconCheckable
boolean isStartIconCheckable ()
Returns whether the start icon is checkable.
Returns | |
---|---|
boolean |
See also:
isStartIconVisible
boolean isStartIconVisible ()
Returns whether the current start icon is visible.
Returns | |
---|---|
boolean |
See also:
onSaveInstanceState
Parcelable onSaveInstanceState ()
Returns | |
---|---|
Parcelable |
passwordVisibilityToggleRequested
void passwordVisibilityToggleRequested (boolean shouldSkipAnimations)
This method is deprecated.
The password toggle will show as checked or unchecked depending on whether the
EditText
's TransformationMethod
is of type PasswordTransformationMethod
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 | |
---|---|
shouldSkipAnimations |
boolean : true if the password toggle indicator icon should not animate
changes |
removeOnEditTextAttachedListener
void removeOnEditTextAttachedListener (TextInputLayout.OnEditTextAttachedListener listener)
Remove the given TextInputLayout.OnEditTextAttachedListener
that was previously added via addOnEditTextAttachedListener(OnEditTextAttachedListener)
.
Parameters | |
---|---|
listener |
TextInputLayout.OnEditTextAttachedListener : listener to remove
|
removeOnEndIconChangedListener
void removeOnEndIconChangedListener (TextInputLayout.OnEndIconChangedListener listener)
Remove the given TextInputLayout.OnEndIconChangedListener
that was previously added via
addOnEndIconChangedListener(OnEndIconChangedListener)
.
Parameters | |
---|---|
listener |
TextInputLayout.OnEndIconChangedListener : listener to remove
|
setBoxBackgroundColor
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 | |
---|---|
boxBackgroundColor |
int : the color to use for the filled box's background |
See also:
setBoxBackgroundColorResource
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 | |
---|---|
boxBackgroundColorId |
int : the resource to use for the box's background color
|
setBoxBackgroundColorStateList
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 | |
---|---|
boxBackgroundColorStateList |
ColorStateList : the color state list to use for the box's background color
|
setBoxBackgroundMode
void setBoxBackgroundMode (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(int)
and setBoxBackgroundColor(int)
.
Parameters | |
---|---|
boxBackgroundMode |
int : box's background mode |
Throws | |
---|---|
IllegalArgumentException |
if boxBackgroundMode is not a @BoxBackgroundMode constant |
setBoxCornerRadii
void setBoxCornerRadii (float boxCornerRadiusTopStart, float boxCornerRadiusTopEnd, float boxCornerRadiusBottomStart, float boxCornerRadiusBottomEnd)
Set the box's corner radii.
Parameters | |
---|---|
boxCornerRadiusTopStart |
float : the value to use for the box's top start corner radius |
boxCornerRadiusTopEnd |
float : the value to use for the box's top end corner radius |
boxCornerRadiusBottomStart |
float : the value to use for the box's bottom start corner radius |
boxCornerRadiusBottomEnd |
float : the value to use for the box's bottom end corner radius |
setBoxCornerRadiiResources
void setBoxCornerRadiiResources (int boxCornerRadiusTopStartId, int boxCornerRadiusTopEndId, int boxCornerRadiusBottomEndId, int boxCornerRadiusBottomStartId)
Set the resources used for the box's corner radii.
Parameters | |
---|---|
boxCornerRadiusTopStartId |
int : the resource to use for the box's top start corner radius |
boxCornerRadiusTopEndId |
int : the resource to use for the box's top end corner radius |
boxCornerRadiusBottomEndId |
int : the resource to use for the box's bottom end corner radius |
boxCornerRadiusBottomStartId |
int : the resource to use for the box's bottom start corner
radius
|
setBoxStrokeColor
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 | |
---|---|
boxStrokeColor |
int : the color to use for the box's stroke when focused |
See also:
setBoxStrokeColorStateList
void setBoxStrokeColorStateList (ColorStateList boxStrokeColorStateList)
Set the box's stroke color state list.
Parameters | |
---|---|
boxStrokeColorStateList |
ColorStateList : the color state list to use for the box's stroke
|
setBoxStrokeErrorColor
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 | |
---|---|
strokeErrorColor |
ColorStateList : the error color to use for the box's stroke |
See also:
setBoxStrokeWidth
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.
Related XML Attributes:
Parameters | |
---|---|
boxStrokeWidth |
int : the value to use for the box's stroke |
See also:
setBoxStrokeWidthFocused
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.
Related XML Attributes:
Parameters | |
---|---|
boxStrokeWidthFocused |
int : the value to use for the box's stroke when focused |
See also:
setBoxStrokeWidthFocusedResource
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.
Related XML Attributes:
Parameters | |
---|---|
boxStrokeWidthFocusedResId |
int : the resource dimension to use for the box's stroke width
when focused |
setBoxStrokeWidthResource
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.
Related XML Attributes:
Parameters | |
---|---|
boxStrokeWidthResId |
int : the resource dimension to use for the box's stroke width |
setCounterEnabled
void setCounterEnabled (boolean enabled)
Whether the character counter functionality is enabled or not in this layout.
Related XML Attributes:
Parameters | |
---|---|
enabled |
boolean |
setCounterMaxLength
void setCounterMaxLength (int maxLength)
Sets the max length to display at the character counter.
Related XML Attributes:
Parameters | |
---|---|
maxLength |
int : maxLength to display. Any value less than or equal to 0 will not be shown. |
setCounterOverflowTextAppearance
void setCounterOverflowTextAppearance (int counterOverflowTextAppearance)
Sets the text color and size for the overflowed character counter using the specified TextAppearance resource.
Related XML Attributes:
Parameters | |
---|---|
counterOverflowTextAppearance |
int |
setCounterOverflowTextColor
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.
Related XML Attributes:
Parameters | |
---|---|
counterOverflowTextColor |
ColorStateList : the text color used for the overflowed character counter
|
See also:
setCounterTextAppearance
void setCounterTextAppearance (int counterTextAppearance)
Sets the text color and size for the character counter using the specified TextAppearance resource.
Related XML Attributes:
Parameters | |
---|---|
counterTextAppearance |
int |
See also:
setCounterTextColor
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.
Related XML Attributes:
Parameters | |
---|---|
counterTextColor |
ColorStateList : text color used for the character counter
|
setDefaultHintTextColor
void setDefaultHintTextColor (ColorStateList textColor)
Sets the text color used by the hint in both the collapsed and expanded states.
Parameters | |
---|---|
textColor |
ColorStateList |
setEnabled
void setEnabled (boolean enabled)
Parameters | |
---|---|
enabled |
boolean |
setEndIconActivated
void setEndIconActivated (boolean endIconActivated)
Sets the current end icon's state to be activated or not.
Parameters | |
---|---|
endIconActivated |
boolean : whether the icon should be activated
|
setEndIconCheckable
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.
Related XML Attributes:
Parameters | |
---|---|
endIconCheckable |
boolean : whether the icon should be checkable |
setEndIconContentDescription
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.
Related XML Attributes:
Parameters | |
---|---|
resId |
int : Resource ID of a content description string to set, or 0 to clear the description |
setEndIconContentDescription
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.
Related XML Attributes:
Parameters | |
---|---|
endIconContentDescription |
CharSequence : Content description to set, or null to clear the content
description |
setEndIconDrawable
void setEndIconDrawable (Drawable endIconDrawable)
Set the icon to use for the end icon.
If you use an icon you should also set a description for its action using setEndIconContentDescription(CharSequence)
. This is used for accessibility.
Related XML Attributes:
Parameters | |
---|---|
endIconDrawable |
Drawable : Drawable to set, may be null to clear the icon |
setEndIconDrawable
void setEndIconDrawable (int resId)
Set the icon to use for the end icon.
If you use an icon you should also set a description for its action using setEndIconContentDescription(CharSequence)
. This is used for accessibility.
Related XML Attributes:
Parameters | |
---|---|
resId |
int : resource id of the drawable to set, or 0 to clear the icon |
setEndIconMode
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.
Related XML Attributes:
Parameters | |
---|---|
endIconMode |
int : 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
void setEndIconOnClickListener (View.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 | |
---|---|
endIconOnClickListener |
View.OnClickListener : the View.OnClickListener the end icon view
will have
|
setEndIconOnLongClickListener
void setEndIconOnLongClickListener (View.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 | |
---|---|
endIconOnLongClickListener |
View.OnLongClickListener : the View.OnLongClickListener the end
icon view will have, or null to clear it.
|
setEndIconTintList
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(Drawable)
will automatically mutate the
drawable and apply the specified tint and tint mode using setTintList(Drawable, ColorStateList)
.
Related XML Attributes:
Parameters | |
---|---|
endIconTintList |
ColorStateList : the tint to apply, may be null to clear tint |
setEndIconTintMode
void setEndIconTintMode (PorterDuff.Mode endIconTintMode)
Specifies the blending mode used to apply the tint specified by setEndIconTintList(ColorStateList)
to the end icon drawable. The default mode is SRC_IN
.
Related XML Attributes:
Parameters | |
---|---|
endIconTintMode |
PorterDuff.Mode : the blending mode used to apply the tint, may be null to clear tint |
setEndIconVisible
void setEndIconVisible (boolean visible)
Sets the current end icon to be VISIBLE or GONE.
Parameters | |
---|---|
visible |
boolean : whether the icon should be set to visible
|
setError
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(boolean)
, then
it will be automatically enabled if error
is not empty.
Parameters | |
---|---|
errorText |
CharSequence : Error message to display, or null to clear |
See also:
setErrorContentDescription
void setErrorContentDescription (CharSequence errorContentDecription)
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.
Related XML Attributes:
Parameters | |
---|---|
errorContentDecription |
CharSequence : Content description to set, or null to clear it |
setErrorEnabled
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(CharSequence)
, will mean that this layout
will not change size when an error is displayed.
Related XML Attributes:
Parameters | |
---|---|
enabled |
boolean |
setErrorIconDrawable
void setErrorIconDrawable (int resId)
Set the drawable to use for the error icon.
Related XML Attributes:
Parameters | |
---|---|
resId |
int : resource id of the drawable to set, or 0 to clear the icon |
setErrorIconDrawable
void setErrorIconDrawable (Drawable errorIconDrawable)
Set the drawable to use for the error icon.
Related XML Attributes:
Parameters | |
---|---|
errorIconDrawable |
Drawable : Drawable to set, may be null to clear the icon |
setErrorIconOnClickListener
void setErrorIconOnClickListener (View.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 | |
---|---|
errorIconOnClickListener |
View.OnClickListener : the View.OnClickListener the error icon
view will have
|
setErrorIconOnLongClickListener
void setErrorIconOnLongClickListener (View.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 | |
---|---|
errorIconOnLongClickListener |
View.OnLongClickListener : the View.OnLongClickListener the error
icon view will have, or null to clear it.
|
setErrorIconTintList
void setErrorIconTintList (ColorStateList errorIconTintList)
Applies a tint to the error icon drawable.
Related XML Attributes:
Parameters | |
---|---|
errorIconTintList |
ColorStateList : the tint to apply, may be null to clear tint |
setErrorIconTintMode
void setErrorIconTintMode (PorterDuff.Mode errorIconTintMode)
Specifies the blending mode used to apply tint to the end icon drawable. The default mode is
SRC_IN
.
Related XML Attributes:
Parameters | |
---|---|
errorIconTintMode |
PorterDuff.Mode : the blending mode used to apply the tint, may be null to clear tint |
setErrorTextAppearance
void setErrorTextAppearance (int errorTextAppearance)
Sets the text color and size for the error message from the specified TextAppearance resource.
Related XML Attributes:
Parameters | |
---|---|
errorTextAppearance |
int |
setErrorTextColor
void setErrorTextColor (ColorStateList errorTextColor)
Sets the text color used by the error message in all states.
Parameters | |
---|---|
errorTextColor |
ColorStateList |
setHelperText
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(boolean)
, then it will be automatically enabled if helper
is not
empty.
Parameters | |
---|---|
helperText |
CharSequence : Helper text to display |
See also:
setHelperTextColor
void setHelperTextColor (ColorStateList helperTextColor)
Sets the text color used by the helper text in all states.
Parameters | |
---|---|
helperTextColor |
ColorStateList |
setHelperTextEnabled
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(CharSequence)
will
mean that this layout will not change size when a helper message is displayed.
Related XML Attributes:
Parameters | |
---|---|
enabled |
boolean |
setHelperTextTextAppearance
void setHelperTextTextAppearance (int helperTextTextAppearance)
Sets the text color and size for the helper text from the specified TextAppearance resource.
Related XML Attributes:
Parameters | |
---|---|
helperTextTextAppearance |
int |
setHint
void setHint (CharSequence hint)
Set the hint to be displayed in the floating label, if enabled.
Related XML Attributes:
Parameters | |
---|---|
hint |
CharSequence |
See also:
setHintAnimationEnabled
void setHintAnimationEnabled (boolean enabled)
Set whether any hint state changes, due to being focused or non-empty text, are animated.
Related XML Attributes:
Parameters | |
---|---|
enabled |
boolean |
See also:
setHintEnabled
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.
Related XML Attributes:
Parameters | |
---|---|
enabled |
boolean |
See also:
setHintTextAppearance
void setHintTextAppearance (int resId)
Sets the collapsed hint text color, size, style from the specified TextAppearance resource.
Related XML Attributes:
Parameters | |
---|---|
resId |
int |
setHintTextColor
void setHintTextColor (ColorStateList hintTextColor)
Sets the collapsed hint text color from the specified ColorStateList resource.
Related XML Attributes:
Parameters | |
---|---|
hintTextColor |
ColorStateList |
setPasswordVisibilityToggleContentDescription
void setPasswordVisibilityToggleContentDescription (CharSequence description)
This method is deprecated.
Use setEndIconContentDescription(CharSequence)
instead.
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.
Related XML Attributes:
Parameters | |
---|---|
description |
CharSequence : Content description to set, or null to clear the content description |
setPasswordVisibilityToggleContentDescription
void setPasswordVisibilityToggleContentDescription (int resId)
This method is deprecated.
Use setEndIconContentDescription(int)
instead.
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.
Related XML Attributes:
Parameters | |
---|---|
resId |
int : Resource ID of a content description string to set, or 0 to clear the description |
setPasswordVisibilityToggleDrawable
void setPasswordVisibilityToggleDrawable (Drawable icon)
This method is deprecated.
Use setEndIconDrawable(Drawable)
instead.
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(CharSequence)
. This is used for accessibility.
Related XML Attributes:
Parameters | |
---|---|
icon |
Drawable : Drawable to set, may be null to clear the icon |
setPasswordVisibilityToggleDrawable
void setPasswordVisibilityToggleDrawable (int resId)
This method is deprecated.
Use setEndIconDrawable(int)
instead.
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(CharSequence)
. This is used for accessibility.
Related XML Attributes:
Parameters | |
---|---|
resId |
int : resource id of the drawable to set, or 0 to clear the icon |
setPasswordVisibilityToggleEnabled
void setPasswordVisibilityToggleEnabled (boolean enabled)
This method is deprecated.
Use setEndIconMode(int)
instead.
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.
Related XML Attributes:
Parameters | |
---|---|
enabled |
boolean : true to enable the functionality |
setPasswordVisibilityToggleTintList
void setPasswordVisibilityToggleTintList (ColorStateList tintList)
This method is deprecated.
Use setEndIconTintList(ColorStateList)
instead.
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(Drawable)
will
automatically mutate the drawable and apply the specified tint and tint mode using setTintList(Drawable, ColorStateList)
.
Related XML Attributes:
Parameters | |
---|---|
tintList |
ColorStateList : the tint to apply, may be null to clear tint |
setPasswordVisibilityToggleTintMode
void setPasswordVisibilityToggleTintMode (PorterDuff.Mode mode)
This method is deprecated.
Use setEndIconTintMode(PorterDuff.Mode)
instead.
Specifies the blending mode used to apply the tint specified by setPasswordVisibilityToggleTintList(ColorStateList)
to the password visibility toggle
drawable. The default mode is SRC_IN
.
Related XML Attributes:
Parameters | |
---|---|
mode |
PorterDuff.Mode : the blending mode used to apply the tint, may be null to clear tint |
setPlaceholderText
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 | |
---|---|
placeholderText |
CharSequence : Placeholder text to display |
See also:
setPlaceholderTextAppearance
void setPlaceholderTextAppearance (int placeholderTextAppearance)
Sets the text color and size for the placeholder text from the specified TextAppearance resource.
Related XML Attributes:
Parameters | |
---|---|
placeholderTextAppearance |
int |
setPlaceholderTextColor
void setPlaceholderTextColor (ColorStateList placeholderTextColor)
Sets the text color used by the placeholder text in all states.
Related XML Attributes:
Parameters | |
---|---|
placeholderTextColor |
ColorStateList |
setPrefixText
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 | |
---|---|
prefixText |
CharSequence : Prefix text to display |
See also:
setPrefixTextAppearance
void setPrefixTextAppearance (int prefixTextAppearance)
Sets the text color and size for the prefix text from the specified TextAppearance resource.
Related XML Attributes:
Parameters | |
---|---|
prefixTextAppearance |
int |
setPrefixTextColor
void setPrefixTextColor (ColorStateList prefixTextColor)
Sets the text color used by the prefix text in all states.
Related XML Attributes:
Parameters | |
---|---|
prefixTextColor |
ColorStateList |
setStartIconCheckable
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.
Related XML Attributes:
Parameters | |
---|---|
startIconCheckable |
boolean : whether the icon should be checkable |
setStartIconContentDescription
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.
Related XML Attributes:
Parameters | |
---|---|
startIconContentDescription |
CharSequence : Content description to set, or null to clear the content
description |
setStartIconContentDescription
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.
Related XML Attributes:
Parameters | |
---|---|
resId |
int : Resource ID of a content description string to set, or 0 to clear the description |
setStartIconDrawable
void setStartIconDrawable (Drawable startIconDrawable)
Sets the start icon.
If you use an icon you should also set a description for its action using setStartIconContentDescription(CharSequence)
. This is used for accessibility.
Related XML Attributes:
Parameters | |
---|---|
startIconDrawable |
Drawable : Drawable to set, may be null to clear and remove the icon |
setStartIconDrawable
void setStartIconDrawable (int resId)
Sets the start icon.
If you use an icon you should also set a description for its action using setStartIconContentDescription(CharSequence)
. This is used for accessibility.
Related XML Attributes:
Parameters | |
---|---|
resId |
int : resource id of the drawable to set, or 0 to clear and remove the icon |
setStartIconOnClickListener
void setStartIconOnClickListener (View.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 | |
---|---|
startIconOnClickListener |
View.OnClickListener : the View.OnClickListener the start icon
view will have, or null to clear it.
|
setStartIconOnLongClickListener
void setStartIconOnLongClickListener (View.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 | |
---|---|
startIconOnLongClickListener |
View.OnLongClickListener : the View.OnLongClickListener the start
icon view will have, or null to clear it.
|
setStartIconTintList
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(Drawable)
will automatically mutate the
drawable and apply the specified tint and tint mode using setTintList(Drawable, ColorStateList)
.
Related XML Attributes:
Parameters | |
---|---|
startIconTintList |
ColorStateList : the tint to apply, may be null to clear tint |
setStartIconTintMode
void setStartIconTintMode (PorterDuff.Mode startIconTintMode)
Specifies the blending mode used to apply the tint specified by setEndIconTintList(ColorStateList)
to the start icon drawable. The default mode is SRC_IN
.
Related XML Attributes:
Parameters | |
---|---|
startIconTintMode |
PorterDuff.Mode : the blending mode used to apply the tint, may be null to clear tint |
setStartIconVisible
void setStartIconVisible (boolean visible)
Sets the start icon to be VISIBLE or GONE.
Parameters | |
---|---|
visible |
boolean : whether the icon should be set to visible
|
setSuffixText
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 | |
---|---|
suffixText |
CharSequence : Suffix text to display |
See also:
setSuffixTextAppearance
void setSuffixTextAppearance (int suffixTextAppearance)
Sets the text color and size for the suffix text from the specified TextAppearance resource.
Related XML Attributes:
Parameters | |
---|---|
suffixTextAppearance |
int |
setSuffixTextColor
void setSuffixTextColor (ColorStateList suffixTextColor)
Sets the text color used by the suffix text in all states.
Related XML Attributes:
Parameters | |
---|---|
suffixTextColor |
ColorStateList |
setTextInputAccessibilityDelegate
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 TextInputLayout.AccessibilityDelegate
directly on the EditText
.
Parameters | |
---|---|
delegate |
TextInputLayout.AccessibilityDelegate |
setTypeface
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
void dispatchRestoreInstanceState (SparseArray<Parcelable> container)
Parameters | |
---|---|
container |
SparseArray |
drawableStateChanged
void drawableStateChanged ()
onLayout
void onLayout (boolean changed, int left, int top, int right, int bottom)
Parameters | |
---|---|
changed |
boolean |
left |
int |
top |
int |
right |
int |
bottom |
int |
onMeasure
void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
Parameters | |
---|---|
widthMeasureSpec |
int |
heightMeasureSpec |
int |
onRestoreInstanceState
void onRestoreInstanceState (Parcelable state)
Parameters | |
---|---|
state |
Parcelable |
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-07-20 UTC.