Material Design学习-----TextInputLayout
TextInputLayout是为EditText提供了一种新的实现和交互方式。在传统的EditText中存在一个hint属性,是说在editext中没有内容时,默认的提示信息。当想edittext中输入信息的时候会自动消失。而在TextInputLayout中当想edittext中输入信息的时候,这些提示信息会通过动画的方式,移动到控件顶部继续存在,同时还会提示错误的信息,实现了一个更好的交互效果。实现的效果如下图:
1、实现方式
TextInputLayout和一般的layout一样,是一个容器,只要把想实现效果的edittext放在容器中就可以了,但是同时TextInputLayout和scrollview一样,其中只能放一个控件作为其子控件。实现代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/username_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="用户名"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/pwd_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/pwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="密码"/>
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/btn_b"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
从上面可以看出,要想让多个edittext实现效果,就要使用多个TextInputLayout进行嵌套。
要想让结果实现,光是在xml布局文件中实现还是不够的,同时还需要在Activity中实现相应的设置:
text1= (TextInputLayout) findViewById(R.id.username_layout);
text2= (TextInputLayout) findViewById(R.id.pwd_layout);
btn= (Button) findViewById(R.id.btn_b);
text1.setHint("用户名");
text2.setHint("密码");
同时要是想要实现错误提示信息的话,就要设置相应的setErrorEnabled方法和setErrror方法:
text1.setErrorEnabled(true);
text1.setError("密码错误");
2、自定义样式
你可能还想做最后一件事,改变TextInputLayout控件的颜色。默认AppCompact会把它设置成绿色的,但是很有可能这个颜色会和你的颜色主题(color palette)冲突。
谷歌把Design Support Library写的很好。每一个控件的颜色都是直接通过主题颜色绘制的,在 style.xml 中指定。打开它添加colorAccent 到主题以改变表单的颜色。
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">#3498db</item>
</style>
Material Design学习-----TextInputLayout的更多相关文章
- Material Design之TextInputLayout使用示例
Google在2015的IO大会上,给我们带来了更加详细的Material Design设计规范,同时,也给我们带来了全新的Android Design Support Library,在这个supp ...
- Material Design学习之 Button(具体分析,传说中的水滴动画)
转载请注明出处:王亟亟的大牛之路 上一篇大致介绍了Material Design的一些基本概念传送门:http://blog.csdn.net/ddwhan0123/article/details/5 ...
- Material Design学习笔记
Wiki->移动开发->Android->Material Design-原质化设计 (友情链接:http://wiki.jikexueyuan.com/project/materi ...
- Material Design学习
前言: 最为一个用习惯了bootstrap的前端小菜,今天偶然听闻material design 这个从未听闻的前端框架,带着好奇开始了新的尝试,并将bootstrap跟material design ...
- Android Material Design 学习笔记 - Matrial Theme
google在2014年 I/O大会上推出了一种新的设计设计语言—Material design,这种设计语言语言旨在为手机.平板电脑.台式机和“其他平台”提供更一致.更广泛的“外观和感觉”(附上官方 ...
- Material Design之TextInputLayout、Snackbar的使用
这两个控件也是Google在2015 I/O大会上公布的Design Library包下的控件,使用比較简单,就放在一起讲了,但有的地方也是须要特别注意一下. TextInputLayout Text ...
- Material Design学习之 ProgreesBar
转载奇怪注明出处:王亟亟的大牛之路 继续我们Material Design的内容,这一篇讲的是进度条,上一篇是Switch地址例如以下:http://blog.csdn.net/ddwhan0123/ ...
- Material Design学习之 Camera
转载请注明出处:王亟亟的大牛之路 年后第一篇,自从来了某司产量骤减,这里批评下自己,这一篇的素材来源于老牌Material Design控件写手afollestad的 https://github.c ...
- Material Design学习之 Bottom navigation
转载请注明出处:王亟亟的大牛之路 礼拜4一天由于事假没有去单位然后礼拜3由于生日也没写文章,今天一早上班就补一篇MD的内容.这一篇是关于颇有争议的Bottom navigation相关内容(主要是翻译 ...
随机推荐
- NSBundle介绍
原文:http://blog.sina.com.cn/s/blog_8c87ba3b0100t89v.html bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像,声音,编译 ...
- centos 6.5下安装文件上传下载服务
centos 6.5下安装文件上传下载服务 由于每次在CentOS中要下载一些配置文件到物理机,和上传一些文件到服务器,导致来回的开启ftp软件有点麻烦,这里我们可以使用文件上传下载服务,来解决上传和 ...
- Delphi拷贝目录(含子目录)的方法
要实现目录级的拷贝,可以利用Windows API函数ShFileOperation( ),其函数声明如下: WINSHELLAPI int WINAPI SHFileOperation( LPSHF ...
- delphi 获得memo,Richedit焦点所在行
procedure TForm1.Button1Click(Sender: TObject); var i:Integer; begin i:=SendMessage(Richedit1.handle ...
- JavaScript的4种this调用模式
方法调用模式:函数调用模式:构造器调用模式:apply调用模式: 方法调用模式: 当一个函数被保存为对象的一个属性时,我们称它为一个方法.当一个方法被调用时,this被绑定到该对象. 函数调用模式: ...
- NSNotificationCenter机制
作用:NSNotificationCenter是专门供程序中不同类间的消息通信而设置的. 注册通知:即要在什么地方接受消息 [[NSNotificationCenter defaultCenter] ...
- Java泛型的类型擦除
package com.srie.testjava; import java.util.ArrayList; import java.util.List; public class TestGener ...
- js冒泡排序及计算其运行时间
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- CodeForces758D
D. Ability To Convert time limit per test:1 second memory limit per test:256 megabytes input:standar ...
- 照片提取GPS 转成百度地图坐标
感谢: 小慧only http://www.cnblogs.com/zhaohuionly/p/3142623.html GPS转化坐标方法 大胡子青松 http://www.cnblogs.com ...