Kotlin / anko

Pleasant Android application development
Apache License 2.0
15.89k stars 1.29k forks source link

"UnsupportedOperationException: Failed to resolve attribute" when using compat theme #315

Open mvysny opened 7 years ago

mvysny commented 7 years ago

When using the following code:

textView(theme = R.style.Base_TextAppearance_AppCompat_Button) {
}

(that is, trying to set theme to one of the Compat styles), I often receive the following exception:

java.lang.UnsupportedOperationException: Failed to resolve attribute at index 24: TypedValue{t=0x3/d=0x5cc "res/color/primary_text_material_light.xml" a=1 r=0x1060157}
at android.content.res.TypedArray.getColor(TypedArray.java:447)
at android.widget.TextView.<init>(TextView.java:745)
at android.widget.TextView.<init>(TextView.java:678)
at sk.baka.photoframe.frame.ExifListAdapter$ExifItemUI.<init>(ExifListAdapter.kt:148)

Am I correctly setting the theme parameter?

mvysny commented 7 years ago

I'm using the following theme for the activity: Theme.AppCompat.Light.DarkActionBar

mvysny commented 7 years ago

Just got another one, similar:

Caused by java.lang.RuntimeException: Failed to resolve attribute at index 96
       at android.content.res.TypedArray.getColor(TypedArray.java:401)
       at android.widget.TextView.<init>(TextView.java:717)
       at android.widget.TextView.<init>(TextView.java:648)
       at android.widget.TextView.<init>(TextView.java:644)
       at android.widget.TextView.<init>(TextView.java:640)
       at org.jetbrains.anko.$$Anko$Factories$Sdk15View$TEXT_VIEW$1.invoke(Views.kt:52)
       at org.jetbrains.anko.$$Anko$Factories$Sdk15View$TEXT_VIEW$1.invoke(Views.kt:13)

This happened on ASUS_Z00ED Android 5.0.2, when trying to use streamName = textView(R.style.TextAppearance_AppCompat_Title_Inverse) { ... }. The activity extends AppCompatActivity and should have the following theme Theme.AppCompat.Light.DarkActionBar. It seems that Android inflater contains some patches regarding this that Anko can't possibly contain, so I'll avoid using broken Android theming from now on.