Mar*_*nis 27 java eclipse android maven material-design
我在eclipse中有一个maven android项目,即使我已经配置我的项目使用兼容性库,它仍然在我的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)
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
的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>
Run Code Online (Sandbox Code Playgroud)
我希望我的应用程序材料设计功能具有向后兼容性支持.我怎样才能解决这个问题?
Dr.*_*hem 15
删除颜色名称前的android前缀.所以它将是:
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
Run Code Online (Sandbox Code Playgroud)
Kam*_*nek 14
这些属性适用于Android 21,Material Theme,因此您无法使用它们values/styles.xml.相反,你应该把它们放进去values-v21/styles.xml.
如果你想在以前版本的android中实现Material Design,你应该包括兼容性库:
dependencies {
compile "com.android.support:appcompat-v7:21.0.+"
}
Run Code Online (Sandbox Code Playgroud)
然后你可以使用:
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>
Run Code Online (Sandbox Code Playgroud)
更多信息:http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html