Android 如何使用TextInputLayout
示例
确保将以下依赖项添加到build.gradle依赖项下的应用程序文件中:
compile 'com.android.support:design:25.3.1'
输入值时,将EditText的提示显示为浮动标签。
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_username"/>
</android.support.design.widget.TextInputLayout>为了使用TextInputLayout显示密码显示眼睛图标,我们可以使用以下代码:
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_current_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
android:id="@+id/current_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/current_password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>其中app:passwordToggleEnabled="true"&android:inputType="textPassword"是必需的参数。
app应该使用命名空间xmlns:app="http://schemas.android.com/apk/res-auto"
您可以在专用主题中找到更多详细信息和示例。