No resource found that matches the given name attr "colorPrimary"
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.