点击这里。原创更详细
TextInputLayout

  1. 当里面的EditText获取焦点后,EditText的hint文字,会移动到EditText的上面做Label
  2. 具有错误提示机制
  3. 字数统计功能 输入反馈、描述
//启用计数器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属性设置的颜色。

更多相关文章

  1. Android(安卓)TextView的设置
  2. Android开发笔记(一百零二)统计图表
  3. Android(安卓)开发常用颜色的编号代码
  4. Android开发资源文件用法小结
  5. ColorMatrixColorFilter颜色过滤(离线用户的灰色头像处理)
  6. Android环形统计控件
  7. 歌词效果制作
  8. Android(安卓)使用selector设置button字体颜色无效
  9. Android之加载图片时自定义进度条

随机推荐

  1. Build Android(安卓)Studio development
  2. Android(安卓)仿徽章圆形view
  3. 自定义通知栏布局
  4. Java 极光推送 ios,android 服务端
  5. Android之ExpandableListView控件
  6. android 圆形头像的Imageview
  7. Bring Up
  8. android in practice_Using internal sto
  9. Android(安卓)TV -1- Building TV Apps
  10. android与web交互-post请求