Android 常用且比较好看的EditText(二)—— TextInputEditText

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=
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

iㅤ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值