I have a maven android project in eclipse and even though I have configured my project to use the compatibility library its still give the following error in my styles.xml:
android:colorAccent requires API level 21 (current min is 15)
android:colorPrimary requires API level 21 (current min is 15)
android:colorPrimaryDark requires API level 21 (current min is 15)
style.xml
<style name="AppBaseTheme" parent="Theme.AppCompat"></style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:colorPrimary">@color/primary</item>
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<item name="android:colorAccent">@color/accent</item>
</style>
AndroidManifest.xml
package="com.app"
android:versionCode="1"
android:versionName="0.0.1-SNAPSHOT" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name="com.app.activity.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
pom.xml
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android.plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>21</platform>
</sdk>
</configuration>
</plugin>
</plugins>
</build>
I want my applications material design features to have backward compatibility support. How can I fix this?
Just deletes android:
.
Check: http://developer.android.com/guide/topics/ui/actionbar.html#StyleExample
Remove the android prefix before the color name. So it will be:
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
These properties are intended to work with Android 21, Material Theme thus you cannot use them in values/styles.xml
. Instead, you should put them in values-v21/styles.xml
.
If you want to implement Material Design in previous versions of android you should include compatibility library:
dependencies {
compile "com.android.support:appcompat-v7:21.0.+"
}
and then you can use:
values/themes.xml:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- colorPrimary is used for the default action bar background -->
<item name=”colorPrimary”>@color/my_awesome_color</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name=”colorPrimaryDark”>@color/my_awesome_darker_color</item>
<!-- colorAccent is used as the default value for colorControlActivated,
which is used to tint widgets -->
<item name=”colorAccent”>@color/accent</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight, and colorSwitchThumbNormal. -->
</style>
More info here: http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html
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