Home > DeveloperSection > Blogs > Overlaying the Action Bar in Android App

Overlaying the Action Bar in Android App

Android Android  Android Styles  Android Layout 
0 Comment(s)
 1182  View(s)
Rate this:

Overlaying the Action Bar


Previously, we have learn how to :

Now we see how to  overlay the action bar.

By default, the action bar appears at the top of your activity window, slightly reducing the amount of space available for the rest of your activity's layout. If, during the course of 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.

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 is not there and the system draws the action bar in front of your layout. This obscures some of the layout at the top, but now when the action bar hides or appears, the system does not need to resize your layout and the transition is seamless.


Enable Overlay Mode

To enable overlay mode for the action bar, you need to create a custom theme that extends an existing action bar theme and set the android:windowActionBarOverlay property to true

If your minSdkVersion is set to 11 or higher, your custom theme should use Theme.Holo theme (or one of its descendants) as your parent theme. For example:

<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
<item name="android:windowActionBarOverlay">true</item>


Specify Layout Top-margin


When the action bar is in overlay mode, it might obscure some of your layout that should remain visible. To ensure that such items remain below the action bar at all 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"

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"


In this case, the ?attr/actionBarSize value without the prefix works on all versions, including Android 3.0 and higher.

This post is referred from Google docs Overlaying the Action Bar


Don't want to miss updates? Please click the below button!

Follow MindStick