Action Bar• The action bar is a window feature that identifies the application and user location, and provides user actions and navigation modes.• You should use the action bar in most activities that need to prominently present user actions or global navigation.• You can control the behaviors and visibility of the action bar with the ActionBar APIs, which were added in Android 3.0 (API level 11).• To use ActionBar in previous Android versions there is a Library ‘ActionBarSherlock’ which can be downloaded from http://actionbarsherlock.com/• ActionBarSherlock supports from Android 2.0 and over.
Using ActionBarSherlock(ABS) • To use ABS it has to be imported in eclipse and has to be an opened project. • Create a new Android project in Eclipse. • In create project window select ‘Create project from existing source’ • In the location browse to the ‘library folder’ in ABS library which was downloaded.
Using ActionBarSherlock(ABS) • Go to the build path window of action bar project. • Under Libraries tab add jar ‘android-support- v4.jar’ which is already included in the libs folder. • Also set the build target to API 14 or higher. • Though ABS will be used with 2.0 or above it requires to be built with 4.0 or higher
Using ActionBarSherlock(ABS) • Now create a new project in Eclipse with minimum SDK 7 and set Build target to 15.
Using ActionBarSherlock(ABS)• Go to the project properties again and in the library section add the Previous created ‘ActionBarSherlock’ library• Since the action bar widget is very complex it requires a set of default themes. The library provides three core themes—one of which must be applied to each activity on which you want the action bar present.• In the Manifest set theme in the appication tag for all activities or or under specific Activities• ‘android:theme="@style/Theme.S herlock">’
• Now we are ready to integrate Action Bar.• To Enable Action Bar for any activity, the Activity must extend ‘SherlockActivity’ instead of ‘Activity’• To access ActionBar use getSupportActionBar() instead of getActionBar().
Adding Menu in ActionBar• To add menu in ActionBar use menu like optionsMenu.• Define in the XML but Add the tag ‘showAsAction’ and set it to ‘ifRoom’
• Now in the Activity’s onCreateOptionsMenu() use getSupportMenuInflater() to get the menu inflater and inflate the XML menu file• In the onOptionsItemSelect ed() do the necessary jobs identified menu items by ‘id‘ set in the XML file