Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android N crashes in TextAppearanceSpan

Since upgrading my Nexus 5X to Android N, I have the following crash when using EditText:

   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:528)
       at android.text.style.TextAppearanceSpan.<init>(TextAppearanceSpan.java:65)
       at android.text.style.TextAppearanceSpan.<init>(TextAppearanceSpan.java:45)
       at android.widget.Editor$SuggestionsPopupWindow.setUp(Editor.java:3316)
       at android.widget.Editor$PinnedPopupWindow.<init>(Editor.java:3016)
       at android.widget.Editor$SuggestionsPopupWindow.<init>(Editor.java:3309)
       at android.widget.Editor.replace(Editor.java:356)
       at android.widget.Editor$3.run(Editor.java:2129)
       at android.os.Handler.handleCallback(Handler.java:751)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6077)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

It happens when clicking on an EditText that has some text already. I am assuming it is the auto-correct popup or something similar.

My app uses support libs 24.2.0 and Theme.AppCompat.Light.NoActionBar

Edit: It works fine if I add android:colorAccent in addition to just colorAccent in my theme:

<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/mainBrandColor</item>
    <item name="colorPrimaryDark">@color/mainBrandDarkerColor</item>
    <item name="colorAccent">@color/mainBrandColor</item>
    <item name="android:colorAccent">@color/mainBrandColor</item>
</style>

But this shouldn't be needed as I inherit from Theme.AppCompat.

I made a small app that showcases the problem:

https://github.com/martinbonnin/TextAppearanceSpanCrash/blob/master/app/src/main/java/mbonnin/com/textappearancescancrash/MainActivity.java

like image 656
mbonnin Avatar asked Aug 30 '16 18:08

mbonnin


1 Answers

Add this to your Edit text view android:textAppearance="@color/" like this:

<EditText 
      android:textAppearance="@color/abc_primary_text_disable_only_material_dark"
      ...
/>

"@color/abc_primary_text_disable_only_material_dark" (built in) :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="@color/bright_foreground_disabled_material_dark"/>
    <item android:color="@color/bright_foreground_material_dark"/>
</selector>

it works for me

like image 132
Tygro Avatar answered Oct 24 '22 15:10

Tygro