ActionBar开启Overlay Mode(覆盖模式)

以下内容参考自Android官网http://developer.android.com/training/basics/actionbar/overlaying.html#EnableOverlay

 

直接调用ActionBar的hide()和show()方法,会造成Activity重新计算和重新绘制布局的新的大小。为了避免这种情况,需要使用Overlay Mode。

在3.0及以上,启用覆盖模式只需要在自定义的Theme中将android:windowActionBarOverlay性质设置为true。例如:

复制代码
<resources>
    <!-- the theme applied to the application or activity --> <style name="CustomActionBarTheme" parent="@android:style/Theme.Holo"> <item name="android:windowActionBarOverlay">true</item> </style> </resources>
复制代码

在3.0以下的话:

复制代码
<resources>
    <!-- the theme applied to the application or activity -->     <style name="CustomActionBarTheme"            parent="@android:style/Theme.AppCompat">         <!-- Support library compatibility -->         <item name="windowActionBarOverlay">true</item>     </style> </resources>
复制代码

别忘了去Manifest.xml文件去设置Theme。

如果想在覆盖模式下,依然让布局显示在ActionBar的下方,则在布局文件的父布局下设置paddingTop属性值:

3.0以上版本:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="?android:attr/actionBarSize"> ... </RelativeLayout>

3.0以下版本:

复制代码
<!-- Support library compatibility -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="?attr/actionBarSize"> ... </RelativeLayout>
复制代码

 

提示:如果想让ActionBar显示在布局的前面,也可以设置ActionBar的背景为透明即可。

效果如下。

 

转载于:https://www.cnblogs.com/lonng226/articles/4260645.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值