问题
I am using the support v7 library to implement ActionBar
in my app..I have this in my styles.xml
file
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/ActionBarTheme</item>
</style>
<style name="ActionBarTheme" parent="android:Widget.ActionBar">
<item name="android:background">#FFFF0000</item>
</style>
</resources>
However, Eclipse complains in the actionBarStyle
line. The error is this one:
android:actionBarStyle requires API level 11 (current min is 8)
What can I do to apply my theme to API levels 8-10?
回答1:
You need to provide two API specific styles.xml. In your values/styles.xml use
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">@style/ActionBarTheme</item>
</style>
and in your values-v14/styles.xml use
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/ActionBarTheme</item>
</style>
回答2:
If you use latest v7 support library (v21 at the time of this post), there is no need to add android:
prefix to any action bar attributes anymore.
In your case, adding the following to values/styles.xml
will be sufficient:
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">@style/ActionBarTheme</item>
</style>
Reference: https://chris.banes.me/2014/10/17/appcompat-v21/#migration-from-previous-setup
来源:https://stackoverflow.com/questions/18307622/applying-a-theme-to-v7-support-action-bar