使用Android Design Support库时出现错误:找不到属性backgroundTint。

15

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

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

这是在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>

我将我的项目定向使用SDK 21,最低SDK设置为17。

编辑:我已经更新了所有的SDK工具。


你是否拥有以下更新的 Android 支持库、Android 支持存储库、Google Play 服务和 Google 存储库? - Jorgesys
@Elenasys 是的,我已经安装并更新了所有这些软件。 - igece
5个回答

32
将 appcompat-v7 库作为依赖项添加到设计库项目中。
这解决了我遇到的相同错误。

你在任何Eclipse项目中集成了设计库吗?你需要勾选“是库”复选框吗?对我来说,在导入设计支持库时,这个选项是未勾选的。 - HarshalK
是的,我在我的 Eclipse 中集成了设计库。对我来说也是未选中的。我们需要勾选复选框将其更改为库项目。 - Kamalanathan
@HarshalK,我已经添加了appcompat-v7引用并将导入的项目标记为库。问题在于其他方面。 - igece
这个应该放得更高,解决了我的问题,没有任何问题 - 谢谢。 - ElliotM
这正是问题所在。谢谢! - TerryTate

16

我能够通过@igece的解决方案来解决问题,但后来发现真正的问题是过时的appcompat-v7库

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


3
似乎已经解决了,在 /res/values/attrs.xml 中将 backgroundTint backgroundTintMode 项目的 format 属性添加即可:

之前:

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

之后:

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

现在的问题是,我无法引用设计支持库类。一遍又一遍地检查了我的项目的Java Build Paths配置,确保有对支持库的引用。 - igece

0

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

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

0

如果您已经安装了最新的Android支持库和Google Play服务,则将appcompat-v7库添加到设计库项目的依赖项中是解决此问题的方法。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接