Action Bar in Android example and Tutorial

              ActionBar in android is a navigation panel that replaces the title bar at the top of every activity which maintains a consistent navigation across the application. The Action Bar provides a consistent framework for providing branding (Icon and Title), navigation and surfacing the key actions to be performed within a Activity.
 The Android Action bar is enabled by default in any activity that uses the default Theme.Holo theme as shown below :

It has an Icon and Title - AndroidActionBar. Action bar was introduced in Android 3.0 (API level 11). In this tutorial let see the basic functionalities that can be performed on the Android Action bar.

Toggle Action Bar visibility :
              Action bar can be toggled during run-time using show and hide methods as shown in the below code snippet :
ActionBar actionBar =getActionBar();

Icon and Title Text :
              If you wish to hide the Title and logo from the ActionBar do it as shown below:
Hide the title label
ActionBar actionBar =getActionBar();

Hide the logo
ActionBar actionBar =getActionBar();

Customizing Action Bar titles
             We can set a title and subtitle to the Action bar as shown in the code snippet.
ActionBar actionBar =getActionBar();

It will be resulted as shown below:

Customizing Action Bar background:
             The default background color of the Action bar depends on the underlying theme. The native Android Action bar background is transparent, with the Holo theme background set to black. We can also customize Action bar background with our own image using the SetBackgroundDrawable method. I have placed an image under res/drawable-mdpi/bg.png. This can be set as background to the Actionbar as shown below:


The Action bar will scale your image as required.

Hope this android actionbar example throws a better overview on it,  More tutorials on Action bar coming Soon !



Post a Comment