当前位置: 首页 > news >正文

设计相关的网站百度知道官网

设计相关的网站,百度知道官网,网站建设 提案 框架,做会所在哪个网站推广一、概述 TextInputLayout通过对EditText进行包装,扩展了EditText的功能,今天,我们就来介绍一下和TextInputLayout相关的知识: 输入检查输入计数密码隐藏二、TextInputLayout 2.1 基本用法 首先,导入TextInputLayout的…

一、概述

TextInputLayout通过对EditText进行包装,扩展了EditText的功能,今天,我们就来介绍一下和TextInputLayout相关的知识:

  • 输入检查
  • 输入计数
  • 密码隐藏

二、TextInputLayout

2.1 基本用法

  • 首先,导入TextInputLayout的依赖包:
compile 'com.android.support:design:25.3.1'
复制代码
  • 之后,我们需要将TextInputLayout作为EditText的父容器以实现相关的功能,例如下面这样,我们的布局中有两个EditText,都使用TextInputLayout把它们包裹起来。
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_margin="20dp"><android.support.design.widget.TextInputLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><EditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:hint="Username"/></android.support.design.widget.TextInputLayout><android.support.design.widget.TextInputLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><EditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:hint="Password"/></android.support.design.widget.TextInputLayout>
</LinearLayout>
复制代码

EditText获得焦点的时候,android:hint所指定的字符串会以高亮的颜色显示在EditText的上方,而当EditText失去焦点时,hint会以灰显的方式显示在EditText中,这就是TextInputLayout最基本的使用,它让我们在输入的过程当中仍然可以获得当前EditText所关联的提示。

2.2 输入检查

除了在EditText上面的提示之外,TextInputLayout还支持在EditText下方显示提示,这种一般用于用户在输入过程中,输入了不符合要求的文本,用来给予用户错误提示。

private void checkError() {mPasswordEditText.addTextChangedListener(new TextWatcher() {@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {}@Override public void onTextChanged(CharSequence s, int start, int before, int count) {}@Override public void afterTextChanged(Editable s) {int len = s.length();if (len > MAX_PASSWORD_LEN) {mPasswordTextInput.setError("Max Password len is " + MAX_PASSWORD_LEN);} else {mPasswordTextInput.setErrorEnabled(false);}}});
}
复制代码

效果如下图所示:

在上面的例子中,我们通过监听EditText的输入,然后在某个条件被触发时,调用TextInputLayoutsetError方法,以提示用户,与setError相关的方法有:

  • public void setError(@Nullable final CharSequence error) 设置错误提示的文字,它会被显示在EditText的下方
  • public void setErrorTextAppearance(@StyleRes int resId) 设置错误提示的文字颜色和大小
  • public void setErrorEnabled(boolean enabled) 设置错误提示是否可用

2.3 输入计数

TextInputLayout还支持对于输入框内字符的实时统计,并在字符数超过阈值之后,改变输入框及提示文字的颜色。

private void checkCount() {mPasswordTextInput.setCounterEnabled(true);mPasswordTextInput.setCounterMaxLength(MAX_PASSWORD_LEN);
}
复制代码

与输入计数有关的方法有:

  • public void setCounterEnabled(boolean enabled) 设置计数功能是否可用
  • public void setCounterMaxLength(int maxLength) 设置计数功能的阈值

2.4 输入时隐藏密码

相信大家都有见到过这样的输入框,在输入框的右边有一个开关,可以让用户来决定输入过程中的字符是否隐藏(以*号显示),TextInputLayout也提供了这样的功能: EditTextinputTypetextPassword/textWebPassword/numberPassword时,通过下面的设置:

mPasswordTextInput.setPasswordVisibilityToggleEnabled(true);
复制代码

同时,我们也可以通过上面的方法来定义切换的图标以及它的着色。


更多文章,欢迎访问我的 Android 知识梳理系列:

  • Android 知识梳理目录:www.jianshu.com/p/fd82d1899…
  • 个人主页:lizejun.cn
  • 个人知识总结目录:lizejun.cn/categories/
http://www.lbrq.cn/news/2590075.html

相关文章:

  • 企业网站如何提高成都百度推广代理公司
  • wordpress企业站实操昆明seocn整站优化
  • php完整网站开发源码关键词优化排名首页
  • 卖酒的网站做线下怎么做超级软文网
  • 新疆建设厅网站官网搜索引擎营销sem包括
  • 深圳南山网站开发华为手机业务最新消息
  • 我想做直播网站该怎么做下载百度卫星导航
  • 房产信息网站系统链交换
  • 做项目网站要不要备案网络销售怎么学
  • 怎么在百度上做自己的网站网络营销的平台有哪些
  • 音乐影视类网站建设百度站长收录入口
  • 云服务器做网站上海广告推广
  • 十堰网站建设报价网店代运营十大排名
  • 网站被百度收录很重要广州百度seo代理
  • 香港产地证在哪个网站做域名注册查询官网
  • asp net网站开发语言的特点系统优化的例子
  • 上海微网站建设方案海南网站制作公司
  • 建设银行信用卡积分兑换商城网站北京网站seo费用
  • 聊城手机网站建设公司最近一周新闻大事摘抄
  • 佛山网站建设电话精准营销包括哪几个方面
  • wordpress 页面如何打开评论美国seo薪酬
  • 做站长建不好网站有效的网络推广
  • 建一个c2c网站要多少钱百度识图网站
  • xp怎么建设网站b站推广有用吗
  • 免费微信网站制作平台徐州百度推广
  • wordpress安装幻灯片网站seo推广方案
  • 国外服务器多少钱一个月windows优化大师好用吗
  • 中国十大做网站公司优化seo教程技术
  • 淄博网站建设公司哪家好南京百度推广
  • 广州 网站建设 制作雅虎日本新闻
  • 机器学习 入门——决策树分类
  • History 模式 vs Hash 模式:Vue Router 技术决策因素详解
  • 配置Mybatis环境
  • Android的UI View是如何最终绘制成一帧显示在手机屏幕上?
  • C++23 Concepts:用类型约束重构泛型编程的终极方案
  • 决策树的实际案例