Android(安卓)Material Design 之 TextInputLayout
16lz
2021-01-26
点击这里。原创更详细
TextInputLayout
- 当里面的EditText获取焦点后,EditText的hint文字,会移动到EditText的上面做Label
- 具有错误提示机制
- 字数统计功能 输入反馈、描述
//启用计数器app:counterEnabled="true"//最大长度app:counterMaxLength="50"//错误提示app:errorEnabled="true"
修改编辑框上label的颜色大小
app:hintTextAppearance="@style/HintAppearance"
修改错误提示的颜色
app:errorTextAppearance="@style/ErrorAppearance"
修改统计字数的样式
//没有超过最大字数app:counterTextAppearance="@style/CounterAppearance"//超过最大字数app:counterOverflowTextAppearance="@style/CounterOverflowAppearance"
使用TextInputLayout遇到的一些坑:
① 如果加上字数统计需要在style里加上textErrorColor,否则超过字数会后会闪退。
② 如果不需要字数统计,且启用错误机制(setErrorEnabled(true)), 不需要加上textErrorColor(不会闪退)系统会提供一个默认的error color。 当然可以通过textErrorColor来自定义错误颜色(error color). 可以使用更为强大的errorTextAppearance来定义错误颜色,字体大小等属性。如果TextInputLayout 同时 设置了textErrorColor和errorTextAppearance ,只有errorTextAppearance生效.
③ 如果加上字数统计,且同时设置了textErrorColor和errorTextAppearance。
这个时候回出现奇怪的效果,Label和统计的颜色为textErrorColor的颜色。
EditText的横线 和 错误文字提示为errorTextAppearance设置的效果。所以为什么不加上textErrorColor会闪退,因为超过字数后TextInputLayout需要textErrorColor属性设置的颜色。
更多相关文章
- Android(安卓)TextView的设置
- Android开发笔记(一百零二)统计图表
- Android(安卓)开发常用颜色的编号代码
- Android开发资源文件用法小结
- ColorMatrixColorFilter颜色过滤(离线用户的灰色头像处理)
- Android环形统计控件
- 歌词效果制作
- Android(安卓)使用selector设置button字体颜色无效
- Android之加载图片时自定义进度条