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:
The error is still there :-( Are there other settings required to make this work?
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>
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With