【发布时间】:2017-11-03 21:16:27
【问题描述】:
我有一个包含在 TextInputLayout 中的 TextInputEditText。但是在某些键盘上,当用户有拼写建议并点击单词以显示建议的弹出列表时,我的应用程序会严重崩溃,使键盘留在屏幕上,有时会超出对话框。
这发生在 Android 6、7 和 8 上。 我可以使用运行 6.0.1 的三星 Galaxy S5 和普通的三星键盘(但不能在同一设备上使用 Gboard 或 Swype)以及使用默认 Google 键盘运行 Android 8.0 的 Nexus 5x 来复制该问题。
应用程序以 26 为目标,并使用设计支持库版本 26.1.0。我们在多个版本的支持库中都显示了相同的堆栈跟踪,并且声称之前已修复此问题或类似问题。
很难找到原因并复制它。我没有设置任何特殊的主题或颜色 - 只是 appcompat。这是堆栈跟踪:
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:484)
at android.text.style.TextAppearanceSpan.<init>(TextAppearanceSpan.java:65)
at android.text.style.TextAppearanceSpan.<init>(TextAppearanceSpan.java:45)
at android.widget.Editor$SuggestionsPopupWindow$SuggestionInfo.<init>(Editor.java:3012)
at android.widget.Editor$SuggestionsPopupWindow$SuggestionInfo.<init>(Editor.java:3007)
at android.widget.Editor$SuggestionsPopupWindow.initContentView(Editor.java:2995)
at android.widget.Editor$PinnedPopupWindow.<init>(Editor.java:2844)
at android.widget.Editor$SuggestionsPopupWindow.<init>(Editor.java:2969)
at android.widget.Editor.showSuggestions(Editor.java:2229)
at android.widget.Editor$2.run(Editor.java:2109)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
以下是我能够找到的类似/相关问题:
- Android N crashes in TextAppearanceSpan
- Fatal Exception: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
- https://meta.stackexchange.com/questions/292199/android-app-crashes-when-tapping-on-red-underlined-by-the-spell-checker-text-w
不幸的是,似乎唯一的解决方法是在 TextInputEditText 字段上禁用所有用户的拼写建议,这很蹩脚。我愿意接受其他想法/建议。
【问题讨论】:
-
我的主题扩展了 Theme.AppCompat.Light.DarkActionBar。我尝试过 Theme.AppCompat.Light、Theme.AppCompat、Theme.Design 和 Theme.Design.Light,它们的崩溃都是一样的。
-
如需解决方案,请参阅stackoverflow.com/questions/41727729#47242474,您无需禁用文本建议。
-
@Mr-IDE 这对解决这个特定问题没有任何帮助(至少在我的情况下)。正如我在回答中指出的那样,这是由于将 TextApperance.AppCompat 应用为样式的父级,并将其用作主题,而不是 hintTextAppearance。
标签: android android-support-library android-appcompat android-support-design android-textinputedittext