TextInputLayout详解
TextInputLayout是什么
TextInputLayout主要是作为EditText的容器,从而为EditText生成一个浮动的Label,当用户点击EditText的时候,EditText中的hint字符串会自动移到EditText的左上角。
TextInputLayout如何使用
●基本用法
xml布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_marginTop="20dp" android:layout_height="wrap_content"> <EditText android:layout_width="match_parent" android:hint="请输入用户名" android:layout_height="wrap_content" /> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_marginTop="20dp" android:layout_height="wrap_content"> <EditText android:layout_width="match_parent" android:hint="请输入邮箱" android:layout_height="wrap_content" /> </android.support.design.widget.TextInputLayout> </LinearLayout>
●设置最大字符数及错误提示
xml
<android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_marginTop="20dp" app:counterEnabled="true" //设置为true才能显字符数 app:counterMaxLength="5" //设置最大字符数为5 app:counterOverflowTextAppearance="@style/HintError" //设置超出字符数后提示文字的颜色,如果不设置默认为@color/colorAccent的颜色 android:layout_height="wrap_content"> <EditText android:layout_width="match_parent" android:hint="请输入用户名" android:layout_height="wrap_content" /> </android.support.design.widget.TextInputLayout>
style文件(设置超出字符数的文字提示颜色为红色)
<style name="HintError" parent="TextAppearance.AppCompat"> <item name="android:textColor">@color/colorRed</item> </style>
●设置错误提示文字
xml
<android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_marginTop="20dp" app:errorEnabled="true" //设置为true android:id="@+id/textinputlayout_email" android:layout_height="wrap_content"> <EditText android:layout_width="match_parent" android:hint="请输入邮箱" android:id="@+id/et_email" android:layout_height="wrap_content" /> </android.support.design.widget.TextInputLayout>
java代码
editText_email=findViewById(R.id.et_email); textInputLayout =findViewById(R.id.textinputlayout_email); editText_email.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { if(!RegexUtils.isEmail(charSequence)){ textInputLayout.setError("邮箱格式错误"); textInputLayout.setErrorEnabled(true); }else { textInputLayout.setErrorEnabled(false); } } @Override public void afterTextChanged(Editable editable) { } });
●设置密码是否可见
xml
<android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_marginTop="20dp" app:errorEnabled="true" app:passwordToggleEnabled="true" //设置为true android:id="@+id/textinputlayout_password" android:layout_height="wrap_content"> <EditText android:layout_width="match_parent" android:hint="请输入密码" android:id="@+id/et_password" android:inputType="textPassword" android:layout_height="wrap_content" /> </android.support.design.widget.TextInputLayout>
个人博客:https://myml666.github.io
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Android进阶之自定义View(2)高仿钉钉运动步数实现可动的进度圆环(下)
接着上篇Android进阶之自定义控件(2)高仿钉钉运动步数实现可动的进度圆环(上)的基础,我们来实现钉钉运动的效果: 《一》View效果分析: 对钉钉运动的效果进行分析: 1、圆弧应该是从135°起,绘制了270°。 2、步数小于10000步时,背景圆弧为灰色,进度圆弧为蓝色渐变色;步数大于10000步时,进度圆弧为渐变的黄色 3、需要绘制中间的步数及步数上面的名次 4、实现步数及进度的动态变化 dingding.gif 有了上篇的基础,实现钉钉运动步数的效果,就很简单了。还是先看一下我最终实现的高仿版效果,给大家点信心。变化的速度可以配置: 高仿钉钉运动效果.gif 《二》实现步骤分解: (1)绘制灰色背景圆弧,135°起,绘制了270° canvas.drawArc(oval, 135, 270, false, mPaint); (2)绘制进度圆弧 canvas.drawArc(oval, 0 + 135, mCurrentStep/ mMaxStep * 270, false, mProgressPaint); (3)绘制文字很简单,只需要以正中间的文字为标准,往上移动一个te...
- 下一篇
Cisco ISO 计划命令 kron实现配置定时自动备份
如果您想要在Cisco设备上执行计划命令,如果您使用 的 IOS 是12.3(1)以后的新版本那么”kron”无疑是您理想的选择。 举个简单的例子,如果想要在每个星期日天晚上11点钟保存一份running config 到您的tftp(10.1.1.1)服务器那么就可以这么做: Router(config)# kron policy-list Backup Router(config-kron-policy)# show run | redirect tftp://10.1.1.1/test.cfg Router(config-kron-policy)# exit Router(config)# kron occurrence Backup at 23:00 Sun recurring Router(config-kron-occurrence)# policy-list Backup要注意的是,交互式命令不可以用在kron中,比方说 copy running-config start-config就不可以使用。原因是你在使用这条命令的时候,系统会要求你输入确认信息。
相关文章
文章评论
共有0条评论来说两句吧...