没有资源的发现,匹配给定的名字:ATTR“colorPrimary”

没有资源的发现,匹配给定的名字:ATTR“colorPrimary”

问题描述:

我想改变我的操作栏的颜色机器人工作室。我已经改变了的minSdkVersion为21,所以我知道这是没有问题的。然而,我不断收到错误,我不知道是怎么回事。这里是我的xml:

I am trying to change the color of my action bar in android studio. I have already changed the minSDKVersion to 21 so I know that is not the problem. Yet I keep getting the error, I don't know what is going on. Here is my xml:

<!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Material">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/my_action_bar_color</item>
    <item name="android:navigationBarColor">@color/my_action_bar_color</item>
</style>

没有资源的发现,匹配给定的名字:ATTRcolorPrimary

No resource found that matches the given name: attr 'colorPrimary'.

使用安卓colorPrimary colorPrimary 自己才会如果你是从 Theme.AppCompat 继承工作。

Use android:colorPrimary. colorPrimary on its own will only work if you are inheriting from Theme.AppCompat.

因此​​,例如,在此示例项目,我有:

So, for example, in this sample project, I have:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Apptheme" parent="android:Theme.Material">
    <item name="android:colorPrimary">@color/primary</item>
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <item name="android:colorAccent">@color/accent</item>
  </style>
</resources>