输入超出TextInputLayout的counterMaxLength时发生RuntimeException [英] RuntimeException when input exceeds counterMaxLength of TextInputLayout

查看:220
本文介绍了输入超出TextInputLayout的counterMaxLength时发生RuntimeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有TextInputLayoutTextInputEditText的表格.这是相关的XML:

I have a form with a TextInputLayout and TextInputEditText. This is the relevant XML:

<android.support.design.widget.TextInputLayout
        android:id="@+id/signup_til_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:hint="Name"
        app:counterEnabled="true"
        app:counterMaxLength="16"
        app:errorEnabled="true">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/signup_etext_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"/>
    </android.support.design.widget.TextInputLayout>

当我尝试在此字段中输入第17个字符时,我的活动因以下堆栈跟踪而崩溃:

When I try to input the 17th character into this field my activity crashes with the following stacktrace:

java.lang.RuntimeException: Failed to resolve attribute at index 3
at android.content.res.TypedArray.twGetColorStateList(TypedArray.java:438)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:420)
at android.widget.TextView.setTextAppearance(TextView.java:3029)
at android.support.design.widget.TextInputLayout.updateCounter(TextInputLayout.java:688)
at android.support.design.widget.TextInputLayout.access$300(TextInputLayout.java:84)
at android.support.design.widget.TextInputLayout$1.afterTextChanged(TextInputLayout.java:248)
at android.widget.TextView.sendAfterTextChanged(TextView.java:8929)

显然,这与不使用AppCompat主题有关,但是我已经在使用AppCompat主题:

Apparently it has to do with not using the AppCompat Theme, but I am using the AppCompat theme already:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"/>

不确定是否与此有关,但我也在使用Jake Wharton的RxBinding库RxTextView.textChanges(nameEditText);观察此TextInputEditText.

Not sure if this is relevant but I'm also observing this TextInputEditText using Jake Wharton's RxBinding library, RxTextView.textChanges(nameEditText);.

推荐答案

我建议添加其他两个属性并为其指定样式.一个是app:counterTextAppearance,另一个是app:counterOverflowTextAppearance像这里一样

I suggest adding additional two attributes and giving it a style. one is app:counterTextAppearance and another is app:counterOverflowTextAppearance like here,

<android.support.design.widget.TextInputLayout
  ....
  app:counterTextAppearance="@style/counterText"
  app:counterOverflowTextAppearance="@style/counterOverride">

</android.support.design.widget.TextInputLayout>

这两种样式不过是带有android:textColor名称的项目,例如

Those two styles are nothing but simply an item with android:textColor name like for example,

<style name="counterText">
  <item name="android:textColor">#aa5353cc</item>
</style>

<style name="counterOverride">
  <item name="android:textColor">#ff0000</item>
</style>

此处中查看完整说明.

如果这不起作用,那么我建议按照此答案中的建议从Theme.Design.*扩展Theme.

If that didn't work then I suggest extending the Theme from Theme.Design.* as suggested in this answer.

这篇关于输入超出TextInputLayout的counterMaxLength时发生RuntimeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆