TextInputLayout基本使用

来源:互联网 发布:帝国cms好还是织梦好 编辑:程序博客网 时间:2024/06/09 15:34

     TextInputLayout的主要作用是作为EditText的容器,从而为EditText默认生成一个浮动的Label,当用户点击EditText之后,EditText中设置的hint字符串会自动移动到EditText的左上角。但是我发现当完之后那个hint不消失。。哎,可能是我没有用好style,等我再使用一下会贴出来。


   使用代码和效果如下:

    

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="shen.da.ye.textinputlayout.MainActivity">    <android.support.design.widget.TextInputLayout        android:layout_width="368dp"        android:layout_height="wrap_content"        app:errorEnabled="true"        app:errorTextAppearance="@style/TextAppearance.Design.Error"        tools:layout_editor_absoluteX="8dp"        tools:layout_editor_absoluteY="0dp">        <EditText            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:hint="请输入数字号码"            android:imeOptions="actionGo"            android:inputType="number" />    </android.support.design.widget.TextInputLayout>    <android.support.design.widget.TextInputLayout        android:layout_width="368dp"        android:layout_height="wrap_content"        app:errorEnabled="true"        app:errorTextAppearance="@style/TextAppearance.Design.Error"        tools:layout_editor_absoluteX="8dp"        tools:layout_editor_absoluteY="0dp">        <EditText            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:hint="请输入数字号码2"            android:imeOptions="actionGo"            android:inputType="number" />    </android.support.design.widget.TextInputLayout></LinearLayout>