Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android XML: RuntimeException: Failed to resolve attribute at index 6

Hello dear stackoverflower,

In my project, i am using the new "android design library". The problem is, that there is a runtime exception which says(Im trying to create a FloatingButton):

 java.lang.RuntimeException: Failed to resolve attribute at index 6         at android.content.res.TypedArray.getColorStateList(TypedArray.java:426)         at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:91)         at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:79)         at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:75) 

I was able to figure out, which the attribute cannot be resolved :

<style name="Widget.Design.FloatingActionButton" parent="android:Widget">     <item name="android:background">@drawable/fab_background</item>     <item name="backgroundTint">?attr/colorAccent</item>  **!! this one is missing !!**     <item name="fabSize">normal</item>     <item name="elevation">@dimen/fab_elevation</item>     <item name="pressedTranslationZ">@dimen/fab_translation_z_pressed</item>     <item name="rippleColor">?attr/colorControlHighlight</item>     <item name="borderWidth">@dimen/fab_border_width</item> </style> 

This is located in res/values/styles/styles.xml in the android-design-library

i have read in this post that the API lvl should bis 21+. But as the design library supports API 7+, this should not be a problem actually.

It is also worth to mention that i have not included the design library as a gradle-dependency like this:

 compile 'com.android.support:design:22.2.0' 

I am adding the library manually to the project because the Jenkins server has no Internet access. I have updated the support-v4 library to 21.2.0 also the appcompat support-v7 is included and updated.

Here is the android-design-library gradle file:

android { compileSdkVersion 21 buildToolsVersion "21.1.2"  defaultConfig {     minSdkVersion 17     targetSdkVersion 21 }  buildTypes {     release {         minifyEnabled false         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'     } } 

It would be great if someone can help me.

like image 402
Paul Reznik Avatar asked Jun 02 '15 11:06

Paul Reznik


2 Answers

Ran into this problem myself. It's because my app isn't using AppCompat yet, still just the regular support FragmentActivity. This means that FloatingActionButton was looking for two theme attributes and it couldn't find them.

Specifically adding in these missing attributes made it work for me without the need to start using AppCompat.

<LinearLayout     ...     xmlns:app="http://schemas.android.com/apk/res-auto"      .../>      <android.support.design.widget.FloatingActionButton         ...         app:backgroundTint="@color/{some color statelist}"         app:rippleColor="@color/{some color statelist}"         ... />  </LinearLayout> 
like image 119
Kevin Grant Avatar answered Oct 11 '22 19:10

Kevin Grant


Had the same issue because have used getApplicationContext() instead of Activity to retrieve LayoutInflater and inflate item view for list adapter.

like image 38
orium Avatar answered Oct 11 '22 18:10

orium