在我们的应用中,我们使用
EditText
和TextInputLayout
来显示验证错误。一切都很正常,直到我们更新到最新的支持库com.android.support:design:23.2.0
后,当应用程序尝试在布局上显示错误时,它开始崩溃。<android.support.design.widget.TextInputLayout
android:id="@+id/name_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:counterMaxLength="100"
>
<EditText
android:id="@+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/group_name"
android:inputType="textMultiLine|textCapWords"
android:textSize="16sp"/>
</android.support.design.widget.TextInputLayout>
代码:
nameLayout.setError("Error);
nameEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
nameLayout.setError(null);
}
}
});
错误:
FATAL EXCEPTION: main
Process: im.grouvi.app.debug, PID: 10704
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 3: TypedValue{t=0x2/d=0x7f01010b a=2}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:482)
at android.widget.TextView.setTextAppearance(TextView.java:2757)
at android.support.design.widget.TextInputLayout.updateCounter(TextInputLayout.java:681)
at android.support.design.widget.TextInputLayout.access$300(TextInputLayout.java:82)
at android.support.design.widget.TextInputLayout$1.afterTextChanged(TextInputLayout.java:242)
at android.widget.TextView.sendAfterTextChanged(TextView.java:8004)
at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:10165)
at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1043)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:560)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:492)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:491)
at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:685)
at android.view.inputmethod.BaseInputConnection.setComposingText(BaseInputConnection.java:445)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:340)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
编辑
经过更多测试,只有在达到counterMaxLength
设置的输入字符最大值时才会崩溃。