前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ActionBar开启Overlay Mode(覆盖模式)

ActionBar开启Overlay Mode(覆盖模式)

作者头像
用户1737026
发布2018-05-17 17:43:16
1.6K0
发布2018-05-17 17:43:16
举报
文章被收录于专栏:五毛程序员五毛程序员

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

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

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

代码语言:javascript
复制
<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以下的话:

代码语言:javascript
复制
<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以上版本:

代码语言:javascript
复制
<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以下版本:

代码语言:javascript
复制
<!-- 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的背景为透明即可。

效果如下。

本文参与?腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015-01-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体同步曝光计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com