为什么80%的码农都做不了架构师?>>>   

TextInputLayout

TextInputLayout 是一个布局,仅可以添加一个子View且必须为ExitText。

TextInputLayout 为用户提供了两个比较有意思的方法

1.hint是EditText的一个很好的属性,当用户输入数据后,hint内容将自动消失。使用TextInputLayout用户输入数据后内容将不会直接隐藏,而是上浮继续显示;

2.用户输入信息错误,错误提示将直接显示在输入EditText下发。

示例代码:

布局代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<EditText

android:id="@+id/original_edittext"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@id/section_label"

android:hint="请输入密码"

/>

<android.support.design.widget.TextInputLayout

android:id="@+id/text_input_layout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@id/original_edittext"

>

<EditText

android:id="@+id/Test_edittext"

android:layout_width="match_parent"

android:layout_height="wrap_content"

/>

</android.support.design.widget.TextInputLayout>

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@id/text_input_layout"

android:hint="请输入密码"

/>

</RelativeLayout>

Java代码:

final TextInputLayout textInputLayout = (TextInputLayout) rootView.findViewById(R.id.text_input_layout);

textInputLayout.setHint("请输入帐号"); //动态设置hint信息,尝试在布局中进行设置为成功

textInputLayout.getEditText().setOnFocusChangeListener(new View.OnFocusChangeListener() {

@Override

public void onFocusChange(View v, boolean hasFocus) {

if (!hasFocus) {

textInputLayout.setError("格式有误"); //自动设置setErrorEnabled为true

} else {

textInputLayout.setErrorEnabled(false); //设置错误信息提示。由于提示信息是需要占据一定位置,因此这里设置错误提示不可用

textInputLayout.setError(null); //设置错误提示信息为空

}

}

});

转载于:https://my.oschina.net/smuswc/blog/598957

TextInputLayout相关推荐

  1. 使用TextInputLayout分分钟构造一个酷炫登录框架

    Google在2015的IO大会上,给我们带来了更加详细的Material Design设计规范,同时,也给我们带来了全新的Android Design Support Library,Android ...

  2. 安卓Design包下的TextInputLayout和FloatingActionButton的简单使用

    终于介绍到Design包的最后的东西了. 也很简单,一个是TextInputLayout. TextInputLayout作为一个父容器,包含一个新的EditText,可以给EditText添加意想不 ...

  3. Android 带有字数统计的 TextInputLayout

    带有字数统计的 TextInputLayout 转载于:https://www.cnblogs.com/zhujiabin/p/5784378.html

  4. android design包控件,Android Design包之TextInputLayout和TextInputEditText的组合使用【原创】...

    在Android的日常开发中,EditText是个不可或缺的控件之一,作为输入框,用法也没什么太多值得可说的,拿一个简单的登录界面为例,平时差不多是这样的布局: 一般来说是这样,EditText里面的 ...

  5. Android开发2:事件处理及实现简单的对话框(Toast,AlertDialog,Snackbar,TextInputLayout的使用)...

    前言 啦啦啦~又要和大家一起学习Android开发啦,博主心里好激动哒~ 在上篇博文中,我们通过线性布局和基础组件的使用,完成了一个简单的学生课外体育积分电子认证系统的界面,本篇博文,将和大家一起熟悉 ...

  6. Android开发笔记(一百三十八)文本输入布局TextInputLayout

    文本输入布局TextInputLayout TextInputLayout是MaterialDesign库中对编辑框EditText进行增强的一个控件.众所周知,EditText未输入字符时,我们可以 ...

  7. android jni示例_Android TextInputLayout示例

    android jni示例 In this tutorial, we'll be looking in depth at the features that Android TextInputLayo ...

  8. TextInputLayout字数统计功能

    TextInputLayout字数统计功能实现 效果演示 图示可以看出,字数统计和浮动标签显示分为两种状态,一是字数未满的状态,图中显示的是红色,二是字数满了之后的状态,图中显示的是蓝色.这两种状态都 ...

  9. Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用

    在前不久的谷歌2015 I/O大会上,发布了Android新版本M,貌似从这个版本开始Android不在以数字命名版本了. 在这次的I/O大会上谷歌对Android并没有很大的改变,主要是修改完善之前 ...

最新文章

  1. 华为云交付项目服务器配置表,云端服务器配置表
  2. Xamarin.Android提示aapt退出,代码为255
  3. 如何用杠铃策略,构建你的“反脆弱性”
  4. 关于maven依赖中的scopeprovided/scope使用
  5. 如何接触到最新的前端动态、最前沿的前端技术
  6. Anaconda——conda换源可以直接通过conda命令来实现
  7. Linux MySQL主主复制(Replication)(MySQL数据双向同步)配置
  8. mysql 拼sql_在MySQL中拼SQL语句
  9. 图片不能有透明通道AppStore images can't contain alpha channels or transparencies windows iOS
  10. 现代城市生态与环境学
  11. tapd获取相应内容
  12. 第一篇博客-Sql排名函数DENSE_RANK
  13. v-if和v-show能和v-for同时出现吗?
  14. 逃不开的安迪-比尔定律,在智能机器人时代该如何破解?
  15. hidapi在linux下编译,HIDAPI
  16. 俞敏洪:《中国合伙人》
  17. 高级android开发工程师机会---纽交所上市互联网公司
  18. ninja 编译系统
  19. 破壁人AI百度:科技公司反内卷的典型样本
  20. Redis(2):持久化

热门文章

  1. 【 FPGA 】时钟偏斜及其影响
  2. JAVA性能优化思路探究
  3. 关于幂等性的解决方案
  4. 用7ch中断例程完成jmp near ptr s指令的功能,用bx向中断例程传送转移位移。
  5. tmux不自动加载配置文件.tmux.conf
  6. node.js浅入深出---fs模块的stat判断是否为文件夹
  7. weblogic反序列化漏洞CVE-2018-2628-批量检测脚本
  8. mxnet安装及NDArray初体验
  9. ubuntu14.04中安装opencv2.4.13
  10. Nginx+Keepalived实现Web服务器负载均衡