槲寄生txt,最新刑侦电视剧,光荣大地下载
本文实例为大家分享了textinputlayout输入框悬浮标签的具体代码,供大家参考,具体内容如下
textinputlayout也是5.0以后的效果,想要使用同样需要在build中配置:
dependencies { compile 'com.android.support:design:23.3.0' }
textinputlayout可以用来显示一个提示错误信息,把hint放到edittext左上方等效果的一个布局;
如果项目中有这类的需求,使用textinputlayout实现起来非常方便;
使用方法也比较简单,直接用textinputlayout包裹edittext即可:
<android.support.design.widget.textinputlayout android:id="@+id/til_user" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="20dp" android:layout_marginleft="20dp" android:layout_marginright="20dp"> <edittext android:id="@+id/et_user" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入用户名"/> </android.support.design.widget.textinputlayout>
但是默认情况下,当你输入文本的时候textinputlayout只会将hint移动到左上方,不会有错误提示,错误提示需要我们手动设置:
etuser= (edittext) findviewbyid(r.id.et_user); tiluser= (textinputlayout) findviewbyid(r.id.til_user); //添加文本变化监听 etuser.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) { if(s.length()>6){ //打开textinputlayout异常提示 tiluser.seterrorenabled(true); //设置textinputlayout异常提示信息 tiluser.seterror("账号最大长度为6"); }else { //关闭textinputlayout异常提示 tiluser.seterrorenabled(false); } } @override //输入以后调用 public void aftertextchanged(editable s) { } });
点击打开链接免费
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android apk 项目一键打包并上传到蒲公英的实现方法
Android 自定义LineLayout实现满屏任意拖动功能的示例代码
android 限制某个操作每天只能操作指定的次数(示例代码详解)
Android 集成 google 登录并获取性别等隐私信息的实现代码
网友评论