action bar & actionbarsherlock
DESCRIPTION
Presentation @ Coeus-Solutions Lahore - Feb 2013TRANSCRIPT
Action Bar – AB&
ActionBarSherlock - ABS
ContentAction BarGeneral Organization Action BarSplit Action BarContextual Action BarActionBarSherlock
RequirementsCode SnippetsSummaryQuestions
Action barThe action bar is a window feature that
identify the application and user location, and provides user actions and navigation modes
Action bar offers users a consistent interface across application.
Introduced in API level 11 (Android 3.0 Honeycomb)
Backward CompatibilityActionBar class is not available in older
versions of Android (< 3.0).
Alternate: ActionBarSherlock (ABS) library helps creating Action bar, back up to android 2.x
Other option: Action Bar Compatibility (see sample app in API Demos)
General Organization
1. App Icon2. View Control3. Action Buttons4. Action Overflow
1. App Icon Establishes app's identity
Displays Up caret to the left of the app icon, to navigate up the hierarchy.
2. View controlIf your app displays data in different views,
this segment of the action bar allows users to switch views.i. Drop-down menusii. Tab controlsiii. Custom Navigation
App title or longer branding information can also use this space.
3. Action ButtonsAction buttons on the action bar surface
your app's most important activities.
Actions that don't fit in the action bar are moved automatically to the action overflow.
Action buttons used throughout the Gmail application
4. Action overflowAction overflow provides access to frequently
used actions. The overflow icon only appears on phones
that have no menu hardware keys. Phones with menu keys display the action
overflow when the user presses the key.
Action overflow is pinned to the right side.
Split Action Bars There are three possible locations to split
action bar content.
1. Main action bar2. Top bar3. Bottom bar
Note: Available on Android 4.0 (API level 14) and higher, for native AB, or use ABS for backward compatibility
AB on Different Screen Sizes
Gmail App
How many items will fit in the main action bar?
Action buttons in the main action bar may not occupy more than 50% of the bar's width.
Action buttons on bottom action bars can use the entire width.
How many actions will fit in the main action bar?
Density-independent pixels (dp) determine the number of items in action bar.
smaller than 360 dp = 2 icons360-499 dp = 3 icons500-599 dp = 4 icons600 dp and larger = 5 icons
Contextual Action Bar
A contextual action bar (CAB) is a temporary action bar.
It overlays the app's action bar for the duration of a particular sub-task.
CABs are most typically used for tasks that
involve acting on selected data or text.
Contextual Action Bar
Like normal Action Bar, CAB also support split action bar.
ActionMode represents a contextual mode (or CAB) of the user interface.
Dismiss the CAB via i. Navigation bar's Back buttonii. CAB's checkmark button
Contextual Action Bar
ActionBarSherlock (ABS)
ActionBarSherlock is a standalone library.
It allows developer to develop apps with action bar on Android API level 2.x and up.
Current version: 4.2.0 — 08-10-2012
Developed by : Jake Wharton
ActionBarSherlock (ABS)
The library will automatically use native Action Bar implementation on Android 4.0 or above.
On Android 3.x (Honeycomb), app will prefer ABS over native Action Bar.
ABS Requirements
It is required that both ABS library and your project are compiled with Android 4.0 or newer.
It is also required that you are compiling with JDK 1.6 in both, your editor and build systems.
ABS Theme RequirementsThe ABS library provides three core themes.
Theme.SherlockTheme.Sherlock.LightTheme.Sherlock.Light.DarkActionBar
One of above theme is must for all activities having action bar.
Custom Theme
Native AB VS ABS
Native AB classes ABS library classes
ActivityFragmentActivityFragmentListFragmentListActivityDialogFragment
SherlockActivitySherlockFragmentActi
vitySherlockFragmentSherlockListFragmentSherlockListActivitySherlockDialogFragme
nt
ABS Common ImportsEnsure that you are using these types
where appropriate
com.actionbarsherlock.app.ActionBarcom.actionbarsherlock.view.Menucom.actionbarsherlock.view.MenuItemcom.actionbarsherlock.view.MenuInflater
Note: ABS contain same classes that are named
same as their native counterparts
ABS and Proguard
Add the following lines in proguard.cfg, to ensure proper functionality of the library:
-keep class android.support.v4.app.** { *; }-keep interface android.support.v4.app.**
{ *; }-keep class com.actionbarsherlock.** { *; }-keep interface com.actionbarsherlock.** { *; }-keep attributes *Annotation*
Action Bar – Menu xmlCreate XML file in /res/menu/my_menu
Action Bar
Action Bar
Menu Item
Split Action Bar
Update AndroidManifest.xml
Tabs
ActionMode (CAB)
What else ?Action Providers i.e.
Settings Share Action
Provider
Navigation Mode
ProgressIndeterminate
ProgressHorizontal Progress
Bar
Search
Overlay
Static Attachment No need to extend
SherlockActivity etc Implement
OnCreateOptionsMenuListener
Summary
Native Action bar - Introduced in Android API 11 (Android 3.0 Honeycomb)
ActionBarSherlock support API 2.x and above.
ABS library will automatically use native Action Bar implementation on Android 4.0 or above.
Be careful while importing classes, ABS have same class names as native AB.
Split Action barContextual Action bar
Questions