zoukankan      html  css  js  c++  java
  • 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的背景为透明即可。

    效果如下。

     

  • 相关阅读:
    Linux系统 虚拟化篇之KVM
    Linux系统 Top命令
    Linux系统 日常优化
    模拟浏览器多文件上传
    51nod 1315 合法整数集 (位操作理解、模拟、进制转换)
    51nod 1138 连续整数的和(等差数列)
    51nod 1042 数字0-9的数量 (数位dp、dfs、前导0)
    51nod 1136 欧拉函数(数论,用定义解题)
    51nod 1106 质数检测(数论)
    51nod 1006 最长公共子序列Lcs(dp+string,无标记数组实现)
  • 原文地址:https://www.cnblogs.com/rainmer/p/4255893.html
Copyright © 2011-2022 走看看