I have a TextInputEditText wrapped in a TextInputLayout. However on some keyboards, when the user has a spelling suggestion, and taps on the word to display the popup list of suggestions, my app crashes hard, leaving the keyboard on screen, sometimes overtop of the dialog.
This happens on Android 6, 7, and 8. I can replicate the issue with an Samsung Galaxy S5 running 6.0.1 and the stock Samsung keyboard, but not Gboard or Swype on the same device, and on a Nexus 5x running Android 8.0 using the default Google keyboard.
The application targets 26, and is using the design support library version 26.1.0. This same stack trace has shown up for us across several versions of the support library, and this, or a similar issue is claimed to have been fixed before.
It was pretty difficult to track down the cause and replicate it. I'm not setting any special themes or colors - just appcompat. Here's the stack trace:
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)
Here's similar/related issues I was able to find:
- 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
Unfortunately it seems like the only workaround is to disable spelling suggestions for all users on TextInputEditText fields, which is pretty lame. I'm open to other ideas/suggestions.