Android APIs
public class

TextInputLayout

extends LinearLayout
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.LinearLayout
         ↳ android.support.design.widget.TextInputLayout

Class Overview

Layout which wraps an EditText (or descendant) to show a floating label when the hint is hidden due to the user inputting text. Also supports showing an error via setErrorEnabled(boolean) and setError(CharSequence).

Summary

XML Attributes
Attribute Name Related Method Description
android.support.design:errorEnabled setErrorEnabled(boolean) Whether the layout is laid out as if an error will be displayed

Must be a boolean value, either "true" or "false". 

android.support.design:hintAnimationEnabled setHintAnimationEnabled(boolean) Whether to animate hint state changes. 
android.support.design:hintTextAppearance setHintTextAppearance(int)  
android:hint setHint(CharSequence) The hint to display in the floating label

This corresponds to the global attribute resource symbol hint

[Expand]
Inherited XML Attributes
From class android.widget.LinearLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Constants
From class android.widget.LinearLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
TextInputLayout(Context context)
TextInputLayout(Context context, AttributeSet attrs)
TextInputLayout(Context context, AttributeSet attrs, int defStyleAttr)
Public Methods
void addView(View child, int index, ViewGroup.LayoutParams params)
Adds a child view with the specified layout parameters.
void draw(Canvas canvas)
Manually render this view (and all of its children) to the given Canvas.
EditText getEditText()
Returns the EditText used for text input.
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.
CharSequence getHint()
Returns the hint which is displayed in the floating label.
boolean isErrorEnabled()
Returns whether the error 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.
void refreshDrawableState()
Call this to force a view to update its drawable state.
void setError(CharSequence error)
Sets an error message that will be displayed below our EditText.
void setErrorEnabled(boolean enabled)
Whether the error functionality is enabled or not in this layout.
void setHint(CharSequence hint)
Set the hint to be displayed in the floating label
void setHintAnimationEnabled(boolean enabled)
Set whether any hint state changes, due to being focused or non-empty text, are animated.
void setHintTextAppearance(int resId)
Sets the hint text color, size, style from the specified TextAppearance resource.
void setTypeface(Typeface typeface)
Set the typeface to use for the both the expanded and floating hint.
Protected Methods
void onLayout(boolean changed, int left, int top, int right, int bottom)
Called from layout when this view should assign a size and position to each of its children.
[Expand]
Inherited Methods
From class android.widget.LinearLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

XML Attributes

android.support.design:errorEnabled

Whether the layout is laid out as if an error will be displayed

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This is a private symbol.

Related Methods

android.support.design:hintAnimationEnabled

Whether to animate hint state changes.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This is a private symbol.

android.support.design:hintTextAppearance

Related Methods

android:hint

The hint to display in the floating label

This corresponds to the global attribute resource symbol hint.

Related Methods

Public Constructors

public TextInputLayout (Context context)

public TextInputLayout (Context context, AttributeSet attrs)

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

Public Methods

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

Adds a child view with the specified layout parameters.

Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

Parameters
child the child view to add
index the position at which to add the child or -1 to add last
params the layout parameters to set on the child

public void draw (Canvas canvas)

Manually render this view (and all of its children) to the given Canvas. The view must have already done a full layout before this function is called. When implementing a view, implement onDraw(android.graphics.Canvas) instead of overriding this method. If you do need to override this method, call the superclass version.

Parameters
canvas The Canvas to which the View is rendered.

public EditText getEditText ()

Returns the EditText used for text input.

public 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.

public CharSequence getHint ()

Returns the hint which is displayed in the floating label.

Related XML Attributes

public boolean isErrorEnabled ()

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

Related XML Attributes

public boolean isHintAnimationEnabled ()

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

public void refreshDrawableState ()

Call this to force a view to update its drawable state. This will cause drawableStateChanged to be called on this view. Views that are interested in the new state should call getDrawableState.

public void setError (CharSequence error)

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
error Error message to display, or null to clear
See Also

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(CharSequence), will mean that this layout will not change size when an error is displayed.

Related XML Attributes

public void setHint (CharSequence hint)

Set the hint to be displayed in the floating label

Related XML Attributes

public void setHintAnimationEnabled (boolean enabled)

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

public void setHintTextAppearance (int resId)

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

public void setTypeface (Typeface typeface)

Set the typeface to use for the both the expanded and floating hint.

Parameters
typeface typeface to use, or null to use the default.

Protected Methods

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

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters
changed This is a new size or position for this view
left Left position, relative to parent
top Top position, relative to parent
right Right position, relative to parent
bottom Bottom position, relative to parent