使用Theme.AppCompat的Android“Resources $NotFoundException:Resource不是ColorStateList”

我正在使用
Android Studio,我只在Android前Lollipop上抛出了“Resources $NotFoundException”.这里是:

Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x7f0100b7 a=2}

R文件中的’0x7f0100b7’表示’colorAccent’.
我相信这个问题与appcompat支持库有关.
我已将其添加到’build.gradle’文件中:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile "com.google.android.gms:play-services-maps:8.4.0"
}

这是主题:

<style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/bg_main</item>
    <item name="colorPrimaryDark">@color/bg_main_darker</item>
    <item name="colorAccent">@color/bg_dark</item>
</style>

那些颜色存在于’color.xml’中.

任何的想法?
非常感谢.

最佳答案 您正在使用特定于Material Design的属性,但在系统版本上运行,即先前的材质.

Note: If your app uses the material theme but does not provide an
alternative theme in this manner, your app will not run on versions of
Android earlier than 5.0.

您必须提供如here所述的替代主题,以运行早于5的版本.

例如.在res / values / colors.xml中提供:

<!-- extend one of the Theme.AppCompat themes -->
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
    <!-- customize the color palette -->
    <item name="colorPrimary">@color/material_blue_500</item>
    <item name="colorPrimaryDark">@color/material_blue_700</item>
    <item name="colorAccent">@color/material_green_A200</item>
</style>

在您的问题文本中,您正在编写color.xml而不是colors.xml,也许也是您问题的一部分:)

点赞