dcousens dcousens - 25 days ago 35
Java Question

No resource found that matches the given name: attr 'colorPrimaryDark'


~/myApp/app/build/intermediates/res/merged/debug/values/values.xml:102:
error: Error: No resource found that matches the given name: attr
'colorAccent'.


And for
colorPrimary
, and
colorPrimaryDark
.
This is a bare-bones project, targeting version 21+.

For posterity, see my
values/
:

values/styles.xml

<resources>
<style name="AppTheme" parent="android:Theme.Material">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>
</resources>


values/colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#3F51B5</color>
<color name="primary_dark">#303F9F</color>
<color name="accent">#FF4081</color>
</resources>


build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.dcousens.myapplication"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
}

.. snip
}


There are many questions under this name, but the resolutions for them are bumping
compileSdkVersion
to at least 21.
This has already been done, and the error persists.

Answer Source

If you are using android:Theme.Material, rather than the suggested Theme.AppCompat, you must use the android: prefix on each item.

<style name="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>

Using AppCompatActivity and Theme.AppCompat is recommended for all API levels as things have continued to change since API 21 and AppCompat continues to add fixes up through even API 24.