Android ActionBar 返回为NULL

Posted on 2015-05-05 09:58  阿祥当码农  阅读(1746)  评论(0编辑  收藏  举报

AndroidBar返回为NULL。是因为values-v11和values-v14下面的style的主题的设置的原因。

在SDK 11的设备上,会使用第二处,SDK 14会使用第三处。

只需要将三个地方的主题分别设置就可以,结构如下:

values--------

<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

</resources>

 

values-v11--------

 

<resources>

    <!--
        Base application theme for API 11+. This theme completely replaces
        AppBaseTheme from BOTH res/values/styles.xml and
        res/values-v11/styles.xml on API 14+ devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
        <!-- API 14 theme customizations can go here. -->
        <item name="android:actionBarStyle">@style/my_actionbar_style</item>
    </style>

    <style name="my_actionbar_style" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">#ff8c00</item>
        <item name="android:titleTextStyle">@style/AcBar_titleStyle</item>
        <item name="android:displayOptions">showTitle</item>
    </style>

    <style name="AcBar_titleStyle">
        <item name="android:textColor">#FFFFFF</item>
        <item name="android:textSize">20sp</item>
    </style>

    <style name="AppTheme" parent="AppBaseTheme"></style>
</resources>

 

values-v14--------

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!--
        Base application theme for API 14+. This theme completely replaces
        AppBaseTheme from BOTH res/values/styles.xml and
        res/values-v11/styles.xml on API 14+ devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <!-- API 14 theme customizations can go here. -->
        <item name="android:actionBarStyle">@style/my_actionbar_style</item> 
    </style>

    <style name="my_actionbar_style" parent="@android:style/Widget.Holo.Light.ActionBar">  
        <item name="android:background">#ff8c00</item>  
        <item name="android:titleTextStyle">@style/AcBar_titleStyle</item>
         <item name="android:displayOptions">showTitle</item>
    </style>
    <style name="AcBar_titleStyle">    
        <item name="android:textColor">#FFFFFF</item>
        <item name="android:textSize">20sp</item>  
    </style>
    <style name="AppTheme" parent="AppBaseTheme"></style>
</resources>

 

主要注意红色部分