The Action Bar: Front to Back

4,755 views

Published on

Presentation from the 2011 Android Open conference

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,755
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
71
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

The Action Bar: Front to Back

  1. 1. The Action Bar: Front to Back Copyright © 2011 CommonsWare, LLC
  2. 2. Action Bar and System Bar Action Bar System Bar Copyright © 2011 CommonsWare, LLC
  3. 3. Targeting Honeycomb● <uses-sdk android:targetSdkVersion=“11”>● Effects – Action bar added – Options menu hoisted from status bar soft button to normal action bar “overflow” position – Holographic theme for widgets Copyright © 2011 CommonsWare, LLC
  4. 4. Toolbar Buttons● Toolbar Buttons = Options Menu Items● Add android:showAsAction to <item> in menu resource – ifRoom to indicate it can remain an options menu item if there is no room – withText if you want icon & title● Backwards-compatible automatically – Attribute ignored on older Android versions Copyright © 2011 CommonsWare, LLC
  5. 5. Copyright © 2011 CommonsWare, LLC
  6. 6. Copyright © 2011 CommonsWare, LLC
  7. 7. Toolbar Widgets● Substitute Own Inflated Layout for Standard Toolbar Button – Add android:actionLayout to <item> in menu resource – Call getActionView() on MenuItem to configure at runtime ● New method in API Level 11 ● Requires special care to remain backwards- compatible Copyright © 2011 CommonsWare, LLC
  8. 8. Copyright © 2011 CommonsWare, LLC
  9. 9. Copyright © 2011 CommonsWare, LLC
  10. 10. Home Affordance● Fancy Term for “Icon On The Left” – Default = activity icon – Optional android:logo in <application> to supply alternative image● Virtual menu choice: android.R.id.home – Handle in onOptionsItemSelected()● setDisplayHomeAsUpEnabled() – Adds arrowhead Copyright © 2011 CommonsWare, LLC
  11. 11. Navigation Modes● Tabs – Replacement for TabHost – Use setNavigationMode() to enable tabs – Call addTab() on ActionBar for each tab ● Supply a TabListener – Process tab events ● Selected ● Unselected ● Reselected Copyright © 2011 CommonsWare, LLC
  12. 12. Copyright © 2011 CommonsWare, LLC
  13. 13. Copyright © 2011 CommonsWare, LLC
  14. 14. Copyright © 2011 CommonsWare, LLC
  15. 15. Navigation Modes● “List” – Puts Spinner in navigation area of action bar – Call setNavigationMode() to enable this mode – Call setListNavigationCallbacks() to supply SpinnerAdapter and an OnNavigationListener – Respond to selection events Copyright © 2011 CommonsWare, LLC
  16. 16. Copyright © 2011 CommonsWare, LLC
  17. 17. Copyright © 2011 CommonsWare, LLC
  18. 18. Copyright © 2011 CommonsWare, LLC
  19. 19. Navigation Modes● setCustomView() – You supply your own View or layout resource ID – Used in the navigation space on the action bar, instead of tabs or Spinner – Example: AutoCompleteTextView for browser – getCustomView() to retrieve inflated layout for runtime configuration Copyright © 2011 CommonsWare, LLC
  20. 20. Action Modes● Alternate Action Bar for Contextual Actions – Operations on multiple selections – Replacement for context menu Copyright © 2011 CommonsWare, LLC
  21. 21. Action Modes● DIY Action Mode – Call startActionMode() with ActionMode.Callback – Configure ActionMode in onCreateActionMode() – onActionItemClicked() if user clicks a toolbar button – finish() the ActionMode when done Copyright © 2011 CommonsWare, LLC
  22. 22. Action Modes● Automatic Multiple-Choice Action Mode – CHOICE_MODE_MULTIPLE_MODAL and an appropriate row layout – Long-press checks item, enables remaining checkboxes, toggles on action mode with your supplied MultiChoiceModeListener callback ● Serves as ActionBar.Callback, plus onItemCheckedStateChanged() for check/uncheck events Copyright © 2011 CommonsWare, LLC
  23. 23. Copyright © 2011 CommonsWare, LLC
  24. 24. Styles and Themes● Theme.Holo / Theme.Holo.Light – Standard themes, standard color scheme● Can Style the Action Bar – Lightly-documented – Nick Butcher blog post: http://goo.gl/wUSxN ● Does not work – cannot inherit from private theme ● Carlos Sessa workaround: http://goo.gl/TNN0S Copyright © 2011 CommonsWare, LLC
  25. 25. What About the Phone?● ActionBarSherlock – Modified Android Compatibility Library with backwards-compatible action bar● Ice Cream Sandwich Copyright © 2011 CommonsWare, LLC
  26. 26. Source Code● http://github.com/commonsguy/cw-android – Menus/InflationBC project● http://github.com/commonsguy/cw-advandroid – Honeycomb/* projects Copyright © 2011 CommonsWare, LLC

×