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

Error using Android Design Support Library: attr backgroundTint not found

尝试在我的项目中使用新的设计支持库,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 工具都是最新的。

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

似乎可以通过向 /res/values/attrs.xml 中的 backgroundTintbackgroundTintMode 项添加 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"/>

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

将其升级到最新版本后,无需对Google的库进行任何编辑。

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

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

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