AndroidUI學習:關於splitActionBarWhenNarrow設置下actionbar


Action Bar操做欄是一個窗口功能用於肯定應用程序和用戶的位置,並提供給用戶操做和導航模式。若是須要突出當前用戶的操做或導航,應該使用操做欄,由於操做欄爲用戶提供了一個一致的接口,這個接口跨應用程序和系統,而且不一樣尺寸的屏幕適配操做欄的外觀。html

Action Bar的基本使用我就不講了,能夠參考:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1114/554.htmlandroid


這裏講我在工做中遇到的一個問題。app

AndroidManifest.xml文件中我對一個activity設置了ui

android:uiOptions="splitActionBarWhenNarrow"google

這裏解釋一下spa

當 您的應用程序上運行Android 4.0系統(API 14級)或更高級別時,有一個額外的模式可稱action bar爲「split action bar」。當在一個狹窄的屏幕運行啓用split action bar時,會在屏幕的底部出現一個action bar顯示全部action item。分裂action bar用來分開action item,確保分配合理數量的空間來在一個狹窄的屏幕上顯示全部的action item,而空間留給頂端的導航和標題元素。 使用 split action bar,只需添加uiOptions=「splitActionBarWhenNarrow」,到你的<activity>或< application>清單元素。code


可是我這樣設置以後,發現底部action bar的背景並非我在代碼裏設置的那個,而是系統默認的。xml


網上找了不少資料都沒獲得解決。因而看了英文的google官方文檔,裏面在描述actionbar的高級樣式時有這樣的代碼:htm

1
<application android:theme= "@style/CustomActivityTheme" ... />
<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <!-- the theme applied to the application or activity --> 
    <style name="CustomActivityTheme" parent="@android:style/Theme.Holo"> 
        <item name="android:actionBarStyle">@style/MyActionBar</item> 
        <!-- other activity and action bar styles here --> 
    </style> 
      
    <!-- style for the action bar backgrounds --> 
    <style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar"> 
        <item name="android:background">@drawable/ab_background</item> 
        <item name="android:backgroundStacked">@drawable/ab_background</item> 
        <item name="android:backgroundSplit">@drawable/ab_split_background</item> 
    </style> 
</resources>

其中對actionbar的背景設置有三個接口

<item name= "android:background" >@drawable/ab_background</item>
<item name= "android:backgroundStacked" >@drawable/ab_background</item>
<item name= "android:backgroundSplit" >@drawable/ab_split_background</item>

我在代碼裏面用bar.setBackgroundDrawable(getResources().getDrawable(R.drawable.title_bar));只是設置了第一個。

所以被分裂的actionbar沒有從新設置,形成了上下actionbar的背景不同。

相關文章
相關標籤/搜索