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

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

问题描述

你好,亲爱的 stackoverflower,

Hello dear stackoverflower,

在我的项目中,我使用了新的android 设计库".问题是,有一个运行时异常说(我正在尝试创建一个浮动按钮):

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>

它位于android-design-library中的res/values/styles/styles.xml

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

我已阅读这个发布 API lvl 应该是 21+.但由于设计库支持 API 7+,这实际上应该不是问题.

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.

还值得一提的是,我没有像这样将设计库作为 gradle 依赖项包括在内:

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'

我正在手动将库添加到项目中,因为 Jenkins 服务器无法访问 Internet.我已将 support-v4 库更新为 21.2.0还包含并更新了 appcompat support-v7.

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.

这是 android-design-library gradle 文件:

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.

推荐答案

自己遇到了这个问题.这是因为我的应用程序还没有使用 AppCompat,仍然只是常规支持 FragmentActivity.这意味着 FloatingActionButton 正在寻找两个主题属性,但找不到它们.

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.

特别添加这些缺失的属性使我无需开始使用 AppCompat.

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天全站免登陆