找不到与给定名称匹配的资源:attr" tabIndicatorColor'

时间:2016-03-11 16:57:04

标签: android tabs

我知道有几个类似的问题,但我找不到正确的答案。我尝试在我的应用中使用标签。我创建了样式-21文件,如下所示:

    <!-- Base application theme. -->
    <style name="AppTheme" parent="AppTheme.Base"/>
    <!-- inherit from the material theme -->
    <style name="AppTheme.Base" parent="AppTheme.Base">
        <!-- colorPrimary is used for the default action bar background -->
        <item name="android:colorPrimary">#3F51B5</item>

        <!-- colorPrimaryDark is used for the status bar -->
        <item name="android:colorPrimaryDark">#303F9F</item>

        <!-- colorAccent is used as the default value for colorControlActivated
             which is used to tint widgets -->
        <item name="android:colorAccent">#FF4081</item>
    </style>

    <style name="MyCustomTabLayout" parent="AppTheme.Base">
        <item name="tabIndicatorColor">@color/dark_blue</item>
    </style>

</resources> 

然而,当我尝试构建项目时,我收到错误:

Error:(20, 25) No resource found that matches the given name: attr 'tabIndicatorColor'.
Error:Execution failed for task ':Baseline:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\Programowanie\sdk1\build-tools\23.0.2\aapt.exe'' finished with non-zero exit value 1

我尝试使用不同的sdk,在appcompat属性文件中更改目标版本但仍然遇到相同的错误。我的gradle看起来像这样:

dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
    compile project(':zxing-2.3.0:android')
    compile project(':google-play-services_lib')
    compile 'com.android.support:recyclerview-v7:21.0.3'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:support-v4:23.1.1'

}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    }*/

知道我做错了什么吗?

1 个答案:

答案 0 :(得分:1)

您可以通过更改选项卡标题的颜色或使用指示条来实现相同的效果。基本上你需要添加一个会改变颜色的选择器。看一下这个例子:http://www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html

这是带有指示条的非常好的材料设计标签布局的另一个示例:http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/