Honeycomb's introduction of the action bar widget went a long way to improving user experience on Android devices. However, the fact remains users want to do a lot on a screen that in most cases is less than five inches tall. Google validated the periodic need for an application to utilize the entire screen efficiently with the introduction of immersive mode in KitKat.

On occasion I have found that deciding whether an app should present the user with a fully immersive experience or a more traditional persistent navigation layout is not always a matter of either or. There are times when the best choice is smartly presenting the action bar based on user gestures. A good example is when scrolling through a list where the action bar has no contextual significance. The video below demonstrates what I mean.

2. For the purpose of this demonstration I've included three large images in my /res/drawable-xhdpi folder titled appropriately.

3. In the /res/layout folder I have modified activity_main.xml to include a scroll view that wraps a linear layout. The linear layout includes our three images. Note the padding applied to the top of the linear layout. This is how we can access the height of our action bar at design time.

4. With our resources in place now we are ready to write some code. While the actual hiding and showing of the action bar happens in the on scroll changed handler, the magic happens in our on create override. First is the addition of the flag FEATURE_ACTION_BAR_OVERLAY to the main window. This prevents the parent from laying out the children each time we hide and show the action bar. The second noteworthy call is attaining the size of the action bar via the applied theme. This is the java equivalent of: ?android:attr/actionBarSize.

I am repeating myself, but keep in mind this convention completely breaks the user experience if your action bar contains a contextual option. For example, if you have a delete option in your action bar, you can't very well hide it, as the user may need to delete an option at the bottom of the list. When carefully considered and used sparingly, though, I find smartly managing the persistence of the action bar a handy tool in my bag of UI tricks.

Automatically sign up for TechRepublic's The Android Expert newsletter.

About William J. Francis

William J Francis began programming computers at age eleven. Specializing in embedded and mobile platforms, he has more than 20 years of professional software engineering under his belt, including a four year stint in the US Army's Military Intellige...

Full Bio

William J Francis began programming computers at age eleven. Specializing in embedded and mobile platforms, he has more than 20 years of professional software engineering under his belt, including a four year stint in the US Army's Military Intelligence Corps. Throughout his career William has published numerous technical articles, as well as the occasional short story.