Android Learning Route (10) How to stack the action bar on your layout

Source: Internet
Author: User

For the completeness of the sixth article, here first put out the original text, next time to translate;:p

Original address: http://developer.android.com/training/basics/actionbar/overlaying.html

by default, the action bar appears at the top of your Activity window, slightly reducin G 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  show ()  on the actionbar . However, this causes your activity to recompute and redraw the layout based on its new size.

Figure 1. Gallery ' s action bar in overlay 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.

Tip: If you want your layout to being partially visible behind the action bar, create a custom style for the action bar with a par tially transparent background, such as the one shown in Figure 1. For information the Define the action bar background, read styling the action Bar.

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 property to android:windowActionBarOverlay true .

For Android 3.0 and higher only

If your minSdkVersion 11 is set to or higher, your custom theme should use Theme.Holo theme (or one of its descendants) as your pare NT 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

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:

<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 style:one with the prefix and one windowActionBarOverlay android: without. The one with the prefix are for versions of Android which include the style in the platform and the one android: without the PR Efix is for older versions this read the style from the support Library.

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:

<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:

<!--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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.