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的背景不同。