Android ActionBar 返回为NULL

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>

 

主要注意红色部分

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。