TextInputLayout

# **[UI](doc:yajxjIPq)** > ### `<TextInputLayout>` 当用户在输入框输入文本时附带提示文字浮动动画,使用时只能包含一个EditText或其子类的控件,该布局可以通过设置hint和Error显示浮动标签的布局。![{登录输入}](https://user-gold-cdn.xitu.io/2017/1/16/5961d4b0a721a1fbaaf0c8ab205e9519?imageView2/0/w/1280/h/960/format/webp/ignore-error/1) 该布局引自Android的新特性布局控件,可参见‘[Android开发者官网](https://developer.android.google.cn/about)’官方android API说明:[com.google.android.material.textfield.TextInputLayout](https://developer.android.google.cn/reference/com/google/android/material/textfield/TextInputLayout?hl=en)类。使用时要注意需引入类名全称:`<com.google.android.material.textfield.TextInputLayout>`。一般多用在如登录等输入提示界面。 `TextInputLayout`布局控件的常用属性摘取: |属性|可设值|说明| |-|-|-| |hint|Str文字|框内提示文字| |hintTextColor|color色值|提示文字颜色| |counterEnabled|Num数值|输入框字数计数| |counterMaxLength|Num数值|输入框字数计数最大数| |counterTextColor|color色值|计数文字颜色| |passwordToggleEnabled|bool布尔值|密码是否可见| 更多属性参见android API。 在xml标签中使用可能无效果,可以通过代码实现,在属性前面加set,再接属性首字大写,如:`setHint("请输入");` 该布局使用时只能包含==一个==EditText或其子类的控件 > 范码 ```xml <linear id="login_form" layout_width="match_parent" layout_height="wrap_content" orientation="vertical"> <com.google.android.material.textfield.TextInputLayout id="accountName" layout_width="match_parent" layout_height="wrap_content" hint="userName"> <EditText id="account" layout_width="match_parent" layout_height="wrap_content" singleLine="true"/> </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout id="passwordinput" layout_width="match_parent" layout_height="wrap_content" hint="password"> <EditText id="password" layout_width="match_parent" layout_height="wrap_content" singleLine="true"/> </android.support.design.widget.TextInputLayout> <Button id="sign_in_button" style="?android:textAppearanceSmall" layout_width="match_parent" layout_height="wrap_content" layout_marginTop="16dp" textColor="#fa5555" text="action_sign_in" textStyle="bold"/> </linear> ```