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的背景为透明即可。

效果如下。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM