gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:49:01 25 4
gpt4 key购买 nike

我有一个带有 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.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 主题了:

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

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

最佳答案

我建议添加额外的两个属性并为其指定样式。一个是 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 .

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

关于android - 当输入超过 TextInputLayout 的 counterMaxLength 时出现 RuntimeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37416530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com