Anko: "UnsupportedOperationException: Failed to resolve attribute" when using compat theme

Created on 11 Feb 2017  路  2Comments  路  Source: Kotlin/anko

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?

Anko Layouts bug

Most helpful comment

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.

All 2 comments

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

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.

Was this page helpful?
0 / 5 - 0 ratings