Android official Getting Started document [8] overlapping action bar overlaying the action Bar
Overlapping action bars
This lesson teaches
1.Enable Overlay Mode
1.For Android 3.0 and higher only
2.For Android 2.1 and higher
2.Specify Layout Top-margin
You should also read
? Styles and Themes
This lesson teaches you
1. Enable Overlay mode
1.3.0 and later versions of Android
2. For Android 2.1 and above
2. Specify the top margin of the layout
You should also read
? styles and Themes
by default, the action bar appears at the top of your Activity window, slightly reduc ing the amount of space available for the rest of the your activity ' s layout. If, during the course of the user interaction, you want to hide and show the action Bar, you can do so by calling hide () and S How () on the ActionBar. However, this causes your activity to recompute and redraw the layout based on its new size.
By default, the action bar appears at the top of your active window, slightly reducing the amount of free space available for the remainder of your active layout. If, during user interaction, you want to hide and show the action Bar, you can do so by calling Hide () and show () in the action Bar. However, this will cause your activity to recalculate and redraw based on the new size layout.
Figure 1. Gallery ' s action bar in overlay mode.
Figure 1. The Action Bar of the Gallery Gallery in overlapping mode.
to avoid resizing your layout when the action bar hides and shows, you can enable overlay Mode for the action bar. When in overlay mode, your activity layout uses all the space available as if the action bar was not there and the system D Raws the action Bar in front of your layout. This obscures some of the "the" in the top, but if the action bar hides or appears, the system does not need to res Ize your layout and the transition is seamless.
to avoid resizing your layout, the action bar is hidden and displayed, and you can enable the Action bar for overlay mode. When overlay mode, your active layout uses all available space, if the action bar is not present, the system draws the action bar before the layout. This obscures the top of some layouts, but now when the action Bar is hidden or displayed, the system does not need to adjust your layout and transitions are seamless.
Tip:if you want your layout to being partially visible behind the action bar, create a custom style for the action bar with A partially transparent background, such as the one shown in Figure 1. For information the Define the action bar background, read styling the action Bar.
Tip: If you want your layout to be visible later in the action Bar, create an action bar custom style with a partially transparent background, such as 1. For one of the background information on how to define the action bar, read the styled action Bar.
Enable Overlay Mode
Enable overlay mode
--------------------------------------------------------------------------------
To enable overlay mode for the action bar, your need to create a custom theme that extends an existing action bar theme and Set the Android:windowactionbaroverlay property to True.
To enable the overlay mode action bar, you need to create a custom theme, extend the existing action bar theme, and set the android: to true Windowactionbaroverlay property.
For Android 3.0 and higher only
For Android3.0 and later versions
If your minsdkversion is set to one or higher, your custom theme should use Theme.holo theme (or one of its descendants) as Your parent theme. For example:
If your minsdkversion is set to 11 or higher, your custom theme should use the Theme.holo theme (or its subclasses) as your parent's theme. For example:
<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>
For Android 2.1 and higher
For Android2.1 and higher
If your app is using the support Library for compatibility on devices running versions lower than Android 3.0, your custom Theme should use Theme.appcompat theme (or one of its descendants) as your parent theme. For example:
If your application is using a version that runs on the compatibility of the support library, your custom theme should use the Theme.appcompat theme (or its subclasses) as your parent topic than the device under Android3.0. For example:
<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>
Also Notice that this theme includes a definitions for the Windowactionbaroverlay Style:one with the Android:prefix an D one without. The one with the Android:prefix are for versions of Android which include the style in the platform and the one without the Prefix is for older versions this read the style from the support Library.
Also note that this theme contains two definitions for Windowactionbaroverlay styling: One is Android: prefix, one does not. One with Android: The prefix is the platform containing the style and one without the prefix is the old version, which reads from the Support library style Android version.
Specify Layout Top-margin
Specify layout top margin
--------------------------------------------------------------------------------
When the action bar was in overlay mode, it might obscure some of your layout that should remain visible. To ensure this such items remain below the action bar at any times, add either margin or padding to the top of the view (s) Using the height specified by actionbarsize. For example:
When the action Bar is in overlay mode, it may obscure some of your layout should remain visible. To ensure that these items are still below the action bar at any time, either increase the margin or fill the top of the view to take advantage of the actionbarsize specified height. For example:
<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>
If you're using the support Library for the action bar, you need to remove the android:prefix. For example:
If you are using the support library in the action bar, you need to remove the android: prefix. For example:
<!--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>
The the Attr/actionbarsize value without the prefix works on all versions, including Android 3.0 and higher.
In this case, if there is no prefix, the? Attr/actionbarsize value applies to all versions, including Android3.0 and higher.
Next class:supporting Different Devices
Next lesson: Supporting different devices
This article is translated from: https://developer.android.com/training/basics/actionbar/overlaying.html
Android official Getting Started document [8] overlapping action Bar