使用TextInputLayout所遇到的坑-java.lang.UnsupportedOperationException: Failed to resolve attribute at index
2016-08-10 01:06
609 查看
相信我们小伙伴们都用过这个TextInputLayout这个控件,By source Code ,发现它是继承于LinearLayout,关于LinearLayout的东东在这里就不啰嗦啦.我们只关心TextInputLayout自身的属性:
TextInputLayout自身的属性
然后当我们在使用TextInputLayout,而且添加了app:counterEnabled 和 app:counterMaxLength属性,里面嵌套着EditText,在代码中,我们给EditText在 addTextWatcher()里面的
onTextChanged()方法里,监听EditText的字符数。这时,当我们运行程序输入的字符串达到最大的counterMaxLength值时,程序就会crash,同时给出如下错误:
此时此刻,你的感觉应该是:“农村路也滑,人心更复杂”。
废话不多说了,直接上解决方案:
在 你的value包的styles声明主题Theme部分,加入如下代码:
或者
使你的theme 继承 Them.Design.*;
PS: 这个 textColorError 属性在这里定义是为了能在TextInputLayout的ErrorState下使用,你可以使用自己定义的color值,否则就会crash.
系统中有如下属性可供我们使用:
1.light themes下:
2.dark themes:
注:这些color值AS不会自动提示,需要自己动手..
最后给个stackOverFlow的链接:
http://stackoverflow.com/questions/35767158/android-edittext-with-textinputlayout-crashing-when-reaching-limit-of-countermax
我为这样做感到可耻:我不解决问题,我只是解决方案的搬运工。
努力提高自己才是硬道理。
TextInputLayout自身的属性
属性名 | 相关方法 | 描述 |
---|---|---|
app:counterEnabled | setCounterEnabled(boolean) | 设置是否显示一个计数器,布尔值 |
app:counterMaxLength | setCounterMaxLength(int) | 设置计数器的最大计数数值,整型 |
app:errorEnabled | setErrorEnabled(boolean) | 设置是否显示一个错误信息,布尔值 |
app:hintAnimationEnabled | setHintAnimationEnabled(boolean) | 设置是否要显示输入状态时候的动画效果,布尔值 |
app:hintEnabled | setHintEnabled(boolean) | 设置是否要用这个浮动标签的功能,布尔值 |
app:hintTextAppearance | setHintTextAppearance(int) | 设置提示文字的样式(注意这里是运行了动画效果之后的样式) |
onTextChanged()方法里,监听EditText的字符数。这时,当我们运行程序输入的字符串达到最大的counterMaxLength值时,程序就会crash,同时给出如下错误:
即:[code]
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 3: TypedValue{t=0x2/d=0x7f01010b a=2}[/code]
此时此刻,你的感觉应该是:“农村路也滑,人心更复杂”。
废话不多说了,直接上解决方案:
在 你的value包的styles声明主题Theme部分,加入如下代码:
[code]<item name="textColorError">@color/design_textinput_error_color_light</item>[/code]
或者
使你的theme 继承 Them.Design.*;
PS: 这个 textColorError 属性在这里定义是为了能在TextInputLayout的ErrorState下使用,你可以使用自己定义的color值,否则就会crash.
系统中有如下属性可供我们使用:
1.light themes下:
@color/design_textinput_error_color_light
2.dark themes:
@color/design_textinput_error_color_dark
注:这些color值AS不会自动提示,需要自己动手..
最后给个stackOverFlow的链接:
http://stackoverflow.com/questions/35767158/android-edittext-with-textinputlayout-crashing-when-reaching-limit-of-countermax
我为这样做感到可耻:我不解决问题,我只是解决方案的搬运工。
努力提高自己才是硬道理。
相关文章推荐
- java.lang.RuntimeException: Failed to resolve attribute at index 6
- Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 1 to dimension
- 安卓之使用DrawerLayout出现的java.lang.UnsupportedOperationException异常
- UnsupportedOperationException: Failed to resolve attribute xxx系列的问题
- linux中使用hbase出现 Failed to start master java.lang.RuntimeException: HMaster Aborted
- java.lang.UnsupportedOperationException at java.util.AbstractList
- tomcat启动不了报错: Publishing failed Could not publish to the server. java.lang.IndexOutOfBoundsException
- java.lang.UnsupportedOperationException at java.util.AbstractList
- Failed to resolve attribute at index 6
- java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
- java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
- Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x1
- java.lang.UnsupportedOperationException: Can't write to a readonly object
- Hbase delete遇到的常见异常: Exception in thread "main" java.lang.UnsupportedOperationException
- maven,Failed to create project.java.lang.NullPointerException,at com.genuitec.eclipse.maven.project.
- 使用MySQL和Hibernate时,出现java.lang.UnsupportedOperationException: Update queries only supported through HQL异常的解决方法
- layout使用继承TextView,Activity未使用,报java.lang.NullPointerException一例
- 在使用MaterialDesign中的CoordinatorLayout的时候出现了如下错误:java.lang.RuntimeException: Unable to start activity
- linux中使用hbase出现 Failed to start master java.lang.RuntimeException: HMaster Aborted
- Arrays.asList()使用---导致java.lang.UnsupportedOperationException分析