Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No resource found that matches the given name attr "colorPrimary"

I'm having a hard time compiling my Android App in Xamarin Studio. The error that comes up is as follows:

No resource found that matches the given name attr "colorPrimary"

Which refers to my styles.xml:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <!--item name="colorPrimaryDark">@color/colorPrimaryDark</item-->
        <!--item name="colorAccent">@color/colorAccent</item-->
    </style>
</resources>

The usual advice found online is to set the SDK version to 21 or higher. But I already tried that:

  • Set minSdkVersion to 21 in manifest
  • Set targetSdkVersion to 21 in manifest
  • Set taget framework to Android 5.0 in project settings
  • Cleaned and rebuilt project

The error is still there :-( Are there other settings required to make this work?

like image 518
Boris Avatar asked Aug 17 '16 12:08

Boris


3 Answers

This is what worked for my project.

In res/values-v21/styles.xml,

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <style name="AppTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
    <item name="android:colorPrimary">@color/primaryColor</item>
    </style>
</resources>

In res/values/styles.xml,

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/primaryColor</item>
    </style>
</resources>
like image 146
K Neeraj Lal Avatar answered Oct 30 '22 23:10

K Neeraj Lal


You should follow the convention directly from the Material Design documentation(https://developer.android.com/training/material/theme.html#ColorPalette):

<resources>
  <!-- inherit from the material theme -->
  <style name="AppTheme" parent="android:Theme.Material">
    <!-- Main theme colors -->
    <!--   your app branding color for the app bar -->
    <item name="android:colorPrimary">@color/primary</item>
    <!--   darker variant for the status bar and contextual app bars -->
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <!--   theme UI controls like checkboxes and text fields -->
    <item name="android:colorAccent">@color/accent</item>
  </style>
</resources>

What you are missing here is the android: namespace prefix to the colorPrimary item. Because of this, it cannot find the respective attribute as it's not defined in the scope.

Otherwise you would need to remove the android: prefix from the theme

parent="@android:style/Theme.Material.Light.DarkActionBar"
like image 31
Jon Douglas Avatar answered Oct 30 '22 23:10

Jon Douglas


In my case, the colors used in styles.xml where not defined. So,make sure u have defined all the colors as well as names properly.

like image 2
Kaveri Avatar answered Oct 30 '22 23:10

Kaveri