Overlaying the Action Bar --1.1.4
来源:互联网 发布:前端请求数据 编辑:程序博客网 时间:2024/05/24 15:41
默认情况下,Action bar 只占用一小部分的屏幕尺寸。如果在和用户的交互过程中,你想隐藏或者显示 Action bar ,可以通过调用hide()
或者show()
函数实现。但是这样做,将会导致 Activity 重新计算当前屏幕的尺寸,并且根据当前屏幕的尺寸重绘。
为了在隐藏和显示 Action bar 时,不让 Activity 重新计算当前屏幕的尺寸,你可以给 Action bar 设置 overlay mode
。这样做之后,你的 Activity 将占用整个屏幕,此时的 Action bar 和 Activity 不在一个维度,所以在调用 Action bar 的 hide()
或者show()
函数时,Activity 不会重新计算当前屏幕的尺寸,切换也会显得更加自然。
提示:如果你想创建一个半透明的 Action bar ,那你只需要为 Action bar 设置一个特定的背景可以了。
1. Enable Overlay Mode
为了给 Action bar 添加 overlay mode
,你需要自定义一个继承系统主题的主题,并且设置 android:windowActionBarOverlay
为true
。
1. For Android 3.0 and higher only
当你为 Android 版本为 11 及以上添加 Action bar 时,你可以像下面这样做:
<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>
2. For Android 2.1 and higher
如果你的 Android 版本不是 3.0,而是 2.1,而且想达到上面同样的效果,你可以这样:
<resources> <!-- the theme applied to the application or activity --> <style name="CustomActionBarTheme" parent="@android:style/Theme.AppCompat"> <item name="android:windowActionBarOverlay">true</item> <!-- Support library compatibility --> <item name="windowActionBarOverlay">true</item> </style></resources>
2. Specify Layout Top-margin
当你为 Action bar 设置 overlay mode
之后,它便会遮盖住你 Activity 的一部分,因此如果你不想让 Action bar 你的 Activity,你可以 Activity 的布局文件添加 Margin
或者Padding
,像下面这样:
<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>
如果你的 Android 版本不是 3.0,而是 2.1,而且想达到上面同样的效果,你可以这样:
<!-- 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>
好了,这篇文章到这里就结束了,希望能帮到小伙伴,have a good day~
- Overlaying the Action Bar --1.1.4
- Overlaying the Action Bar
- 【Android界面实现】Overlaying the Action Bar
- Adding the Action Bar - Overlaying the Action Bar
- Android官方文档翻译 十一 2.4Overlaying the Action Bar
- [Android学习笔记] Overlaying Action Bar
- Adding the Action Bar --1.1
- Setting Up the Action Bar --1.1.1
- Styling the Action Bar --1.1.3
- Add the Action Bar
- Styling the Action Bar
- Adding the Action Bar - Setting Up the Action Bar
- Adding the Action Bar - Styling the Action Bar
- Adding the Action Bar - Adding Action Buttons
- Using the Android action bar (ActionBar) - Tutorial
- 【Android界面实现】Styling the Action Bar
- 【Android界面实现】Styling the Action Bar
- 【Android文档】Training-------Adding the Action Bar
- MySQL SHOW INDEX语法的实际应用
- monit监控tomcat service
- 新老软件下载网站
- Linux设备驱动开发——1.tiny4412出厂系统的烧写
- 题目
- Overlaying the Action Bar --1.1.4
- linux cmake案例解释
- java 多线程sleep
- hdoj 5505 GT and numbers
- python脚本:计算某个目录下Code行数
- 母牛繁殖问题:一头母牛,每年年初生一头小母牛,每头小母牛从第四个年头起,每年年初也要生一头小母牛,问:第20个年头后共有多少只牛?
- 2.2 Cache的组成结构
- OpenCL函数-1
- 利用jQuery中hover()和cookie机制编写的小程序