当输入超过 TextInputLayout 的 counterMaxLength 时出现 RuntimeException

RuntimeException when input exceeds counterMaxLength of TextInputLayout

我有一个带有 TextInputLayoutTextInputEditText 的表格。这是相关的 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 个字符输入该字段时,我的 activity 崩溃并显示以下堆栈跟踪:

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.access0(TextInputLayout.java:84)
at android.support.design.widget.TextInputLayout.afterTextChanged(TextInputLayout.java:248)
at android.widget.TextView.sendAfterTextChanged(TextView.java:8929)

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

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

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

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

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

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

这两种款式只不过是一件带有 android:textColor 名称的商品,例如,

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

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

查看完整说明 here

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