eclipse 使用 Android 设计支持库时出错:找不到 attr backgroundTint

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30602710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:40:44  来源:igfitidea点击:

Error using Android Design Support Library: attr backgroundTint not found

androideclipseadt

提问by igece

Trying to use the new Design Support Library in my project, AAPT throws the following error:

尝试在我的项目中使用新的设计支持库时,AAPT 抛出以下错误:

Description: Error: No resource found that matches the given name: attr 'backgroundTint'.
Resource:    /design/res/values/styles.xml
Location:    line 21 

This is the affected entry in styles.xml:

这是 中受影响的条目styles.xml

<style name="Widget.Design.FloatingActionButton" parent="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>

I'm targeting my project to use SDK 21, with min SDK set to 17.

我的目标是我的项目使用 SDK 21,最小 SDK 设置为 17。

Edit:I have all SDK tools up to date.

编辑:我拥有最新的所有 SDK 工具。

回答by Kamalanathan

Add appcompat-v7 library as dependency to the design library project. It resolve the same error for me. I think it helps you.

添加 appcompat-v7 库作为设计库项目的依赖项。它为我解决了同样的错误。我认为这对你有帮助。

回答by thiagolr

I was able to fix the issue with @igece solution, but later I found out that the real issue is an outdated appcompat-v7 library.

我能够用@igece 解决方案解决这个问题,但后来我发现真正的问题是一个过时的appcompat-v7 library.

After upgrading it to the latest versionnothing had to be edited on Google's libraries.

将其升级到最新版本后,无需在 Google 的库中编辑任何内容。

回答by igece

Seems to be solved adding the formatattribute to both backgroundTintand backgroundTintModeitems in /res/values/attrs.xml:

似乎可以解决将format属性添加到backgroundTint和 中的backgroundTintMode项目/res/values/attrs.xml

Before:

前:

<declare-styleable name="FloatingActionButton">
    <!-- Background for the FloatingActionButton -->
    <attr name="android:background"/>
    <attr name="backgroundTint"/>
    <attr name="backgroundTintMode"/>

After:

后:

<declare-styleable name="FloatingActionButton">
    <!-- Background for the FloatingActionButton -->
    <attr name="android:background"/>
    <attr name="backgroundTint" format="color"/>
    <attr name="backgroundTintMode" format="integer"/>

回答by Sarojini2064130

Adding appcompat-v7 library in dependancy of design library project is the solution for this issue if you have already installed updated Android Support Repository and Google Play Services.

如果您已经安装了更新的 Android Support Repository 和 Google Play Services,则在设计库项目的依赖项中添加 appcompat-v7 库是解决此问题的方法。

回答by ChinLoong

I wanted to add this as comment under third answer, but code was not formatted properly. I have to add both dependencies below to resolve the issue:

我想将此添加为第三个答案下的评论,但代码格式不正确。我必须在下面添加两个依赖项才能解决问题:

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'