autojs之密码专用输入框

使用场景

密码输入框

效果展示

在这里插入图片描述

autojs版本

在这里插入图片描述

TextInputLayout

TextInputLayout 主要是作为 EditText 的容器,从而为 EditText 生成一个浮动的 Label,当用户点击 EditText 的时候,EditText 中的 hint 字符串会自动移到 EditText 的左上角。

代码讲解

1. 布局, 两个输入框
ui.layout(
  <vertical margin="10">
    <com.google.android.material.textfield.TextInputLayout
      android:id="@+id/userInputLayout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
    >
      <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="22sp" />
    </com.google.android.material.textfield.TextInputLayout>
    <input w="*"></input>
  </vertical>
);
2. 设置TextInputLayout属性
// 开启错误提示
ui.userInputLayout.setErrorEnabled(true);
// 开启计数
ui.userInputLayout.setCounterEnabled(true);
// 输入最大长度
ui.userInputLayout.setCounterMaxLength(10);
// 浮动标签文本
ui.userInputLayout.setHint("password");
// 启用或禁用密码可见性切换功能
ui.userInputLayout.setPasswordVisibilityToggleEnabled(true);
3. 设置输入框监听, 提醒用户错误原因
ui.userInputLayout.getEditText().addTextChangedListener(
  new android.text.TextWatcher({
    afterTextChanged: function (s) {
      if (ui.userInputLayout.getEditText().getText().toString().trim().length > 10) {
        ui.userInputLayout.setError("用户名长度超出限制");
      } else {
        ui.userInputLayout.setError(null);
      }
    },
  })
);

参考文章

1. Android Material Design 系列之 TextInputLayout 使用详解
2. 谷歌官网TextInputLayout

声明

部分内容来自网络

微信公众号 AutoJsPro教程

在这里插入图片描述

QQ群

747748653

在这里插入图片描述

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

牙叔教程

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

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

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

打赏作者

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

抵扣说明:

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

余额充值