3

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:

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.

Mark
  • 2,362
  • 18
  • 34
  • My theme extends Theme.AppCompat.Light.DarkActionBar. I've tried Theme.AppCompat.Light, Theme.AppCompat, Theme.Design, and Theme.Design.Light, and the crash is the same in all of them. – Mark Nov 06 '17 at 15:22
  • For a solution, see https://stackoverflow.com/questions/41727729#47242474 and you don't need to disable text suggestions. – Mr-IDE Nov 11 '17 at 22:52
  • @Mr-IDE That doesn't have anything that helps with this particular issue (at least in my case). As I noted in my answer, it was due to applying TextApperance.AppCompat as the parent of a style, and using that as the theme, instead of the hintTextAppearance. – Mark Nov 16 '17 at 21:25

3 Answers3

1

In my case here, I had applied a custom textAppearance to the parent TextInputLayout:

    <android.support.design.widget.TextInputLayout
      android:textColorHint="@color/textColorPrimary"
      android:textColor="@color/textColorPrimary"
      android:theme="@style/smallHint"
      android:hint="@string/add_a_comment"
      android:layout_marginEnd="16dp">

      <android.support.design.widget.TextInputEditText
        android:id="@+id/comment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        android:inputType="textImeMultiLine|textCapSentences"
        android:importantForAutofill="noExcludeDescendants"
        tools:ignore="UnusedAttribute"/>

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

The theme definition looked like this:

<style name="smallHint" parent="TextAppearance.AppCompat">
  ...
</style>

This was not correct. TextInputLayout's theme should not be set to something with a parent of TextAppearance.AppCompat.

Instead of android:theme, I should have used app:hintTextAppearance.

Mark
  • 2,362
  • 18
  • 34
  • Have the same issue.. How can I use colorControlActivated and colorColorControlNormal without using `android:theme` ?? Any suggestions? – sanjeev Dec 31 '18 at 05:13
0

For me the problem was

android:textAppearance="@style/TextAppearanceMedium"

set to AppCompatEditText

SpyZip
  • 5,511
  • 4
  • 32
  • 53
0

I ran into the same problem. I was able to leave the android:theme to my custom style but switch the style's parent to Widget.Design.TextInputLayout from TextAppearance.AppCompat. The overflow suggestions menu works just fine, and I was able to keep my styling the way I wanted it.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
rpezzuti
  • 1
  • 1