Android EditText
之前讲了一个带动画的EditText
这一篇来讲一下
对于我个人也比较常用的一个EditText —— Material Design 的 TextInputEditText
网上也有很多文章关于这个TextInputEditText
很多属性也都归纳过
这里我就简单讲述一下 我使用的
仅为个人自己所学习和使用的
首先 TextInputEditText 要和TextInputLayout 搭配使用
TextInputLayout 就等同于一个线性布局,TextInputEditText的限制属性也可以在TextInputLayout 中描述声明
样例
简单放一下样例
样例中,字数超过限制后会相应的报错,如果用于密码还可以设置显示和隐藏密码
之前也写过文章关于这个隐藏密码的问题
Android TextInputEditText初始隐藏密码
图一xml
下面分别给出两张图的两段代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="@drawable/cloud"
tools:context=".ui.LoginActivity">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="320dp"
android:layout_height="320dp"
android:layout_centerInParent="true"
android:background="@drawable/shape_mine_top1"
android:elevation="5dp"
android:orientation="vertical"
android:paddingTop="10dp">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/identification"
android:drawableLeft="@drawable/identification"
android:hint="请输入账号"
android:imeOptions="actionNext"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
app:hintAnimationEnabled="true"
app:hintEnabled="true"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@color/toggle">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height=