Android XML:RuntimeException:无法在索引6处解析属性 [英] Android XML: RuntimeException: Failed to resolve attribute at index 6

查看:273
本文介绍了Android XML:RuntimeException:无法在索引6处解析属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好亲爱的stackoverflower,



在我的项目中,我正在使用新的android设计库。
问题是,有一个运行时异常说(我试图创建一个FloatingButton):

  java .lang.RuntimeException:无法在索引6处解析属性
at android.content.res.TypedArray.getColorStateList(TypedArray.java:426)
at android.support.design.widget.FloatingActionButton。< init>(FloatingActionButton.java:91)
在android.support.design.widget.FloatingActionButton。< init>(FloatingActionButton.java:79)
在android.support.design.widget.FloatingActionButton。 < init>(FloatingActionButton.java:75)

我能够弄清楚哪个属性无法解决:

 < style name =Widget.Design.FloatingActionButtonparent =android:Widget> 
< item name =android:background> @ drawable / fab_background< / item>
< item name =backgroundTint>?attr / colorAccent< / item> **!这个没有!**
< 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>

这个位于android-design-library中的res / values / styles / styles.xml中/ p>

我已阅读这个的帖子说,API lvl应该是21+以上。但是,由于设计库支持API 7+,这实际上不应该是一个问题。



还有一点值得一提的是,我没有将设计库作为一个毕业生-dependency like this:

  compile'c​​om.android.support:design:22.2.0'

我将该库手动添加到项目中,因为Jenkins服务器没有Internet访问。
我已将support-v4库更新为21.2.0
还包括并更新了appcompat support-v7。



这是android -design-library毕业文件:

  android {
compileSdkVersion 21
buildToolsVersion21.1.2

defaultConfig {
minSdkVersion 17
targetSdkVersion 21
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.txt'
}
}

如果有人可以帮助我,这将是很棒的。

解决方案

。这是因为我的应用程序尚未使用AppCompat,仍然只是常规支持 FragmentActivity 。这意味着 FloatingActionButton 正在寻找两个主题属性,它找不到它们。



具体添加在这些缺少属性使其适用于我,而无需开始使用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>


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.

解决方案

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>

这篇关于Android XML:RuntimeException:无法在索引6处解析属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆