Mais conteúdo relacionado
Semelhante a The Action Bar: Front to Back (20)
The Action Bar: Front to Back
- 2. Action Bar and System Bar
Action Bar
System Bar
Copyright © 2011 CommonsWare, LLC
- 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. 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
- 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
- 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. 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
- 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
- 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. Action Modes
● Alternate Action Bar for Contextual Actions
– Operations on multiple selections
– Replacement for context menu
Copyright © 2011 CommonsWare, LLC
- 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. 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
- 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. What About the Phone?
● ActionBarSherlock
– Modified Android Compatibility Library with
backwards-compatible action bar
● Ice Cream Sandwich
Copyright © 2011 CommonsWare, LLC
- 26. Source Code
● http://github.com/commonsguy/cw-android
– Menus/InflationBC project
● http://github.com/commonsguy/cw-advandroid
– Honeycomb/* projects
Copyright © 2011 CommonsWare, LLC