ActionBar样式不会影响NewApi

时间:2015-04-15 11:09:32

标签: android android-actionbar android-styles

我正在使用自定义操作栏。我正在为各种API级别(API8-API21)创建一个应用程序

我的自定义操作栏正在API级别9中工作。但它不能在API级别工作> 11

我的AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
...
</application>

我的styles.xml

<style name="AppTheme" parent="AppBaseTheme">
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background" tools:ignore="NewApi">@color/green</item>
    <item name="background">@color/green</item>
    <item name="android:textColor">@color/white</item>
</style>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">

</style>

注意:我没有为我的活动定义任何样式

 <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >

但我的操作栏仍然是默认设置。有人能帮助我吗??

1 个答案:

答案 0 :(得分:0)

找到答案自己..

我需要在values-v11和values-v14中更改styles.xml,如下所示

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">

</style>
<style name="AppTheme" parent="AppBaseTheme">
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>
 <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@color/green</item>
    <item name="background">@color/green</item>
    <item name="android:textColor">@color/white</item>
</style>