AndroidUI学习:关于splitActionBarWhenNarrow设置下actionbar


Action Bar操作栏是一个窗口功能用于确定应用程序和用户的位置,并提供给用户操作和导航模式。如果需要突出当前用户的操作或导航,应该使用操作栏,因为操作栏为用户提供了一个一致的接口,这个接口跨应用程序和系统,并且不同尺寸的屏幕适配操作栏的外观。

Action Bar的基本使用我就不讲了,可以参考:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1114/554.html


这里讲我在工作中遇到的一个问题。

AndroidManifest.xml文件中我对一个activity设置了

android:uiOptions="splitActionBarWhenNarrow"

这里解释一下

当 您的应用程序上运行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>清单元素。


但是我这样设置之后,发现底部action bar的背景并不是我在代码里设置的那个,而是系统默认的。


网上找了很多资料都没得到解决。于是看了英文的google官方文档,里面在描述actionbar的高级样式时有这样的代码:

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


转载于:https://my.oschina.net/u/2359500/blog/504818

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值