SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Downloaden Sie, um offline zu lesen
AnDevCon SF 2013

The Action Bar,
Front to Back
Copyright © 2012 CommonsWare, LLC
Action Bar Options
●

Native Implementation
●

●

Works well if android:minSdkVersion is 11 or
higher

Backports
●

Official: AppCompat

●

Popular: ActionBarSherlock

Copyright © 2012 CommonsWare, LLC
Action Bar Options
●

AppCompat
●

Part of Android Support package

●

Pros
–
–

●

Google “seal of approval”
No additional libraries (since you probably are already
using the Android Support package)

Cons
–

Released in August 2013

–

Modest track record to date

Copyright © 2012 CommonsWare, LLC
Action Bar Options
●

ActionBarSherlock
●

Independent open source backport

●

Pros
–
–

●

Used by countless projects over 18+ months
Lots of material written about it

Cons
–

Requires an Android library project

–

No Google “seal of approval”

Copyright © 2012 CommonsWare, LLC
Manifest Changes
●

<uses-sdk android:targetSdkVersion=”14”>
●
●

●

Action bar added
Holographic theme for widgets

android:uiOptions=”splitActionBarWhenNarrow”
●

Two halves of action bar, top and bottom

●

Used for phones in portrait mode

Copyright © 2012 CommonsWare, LLC
Populating the Bar
●

res/menu/options.xml (or other name)
●

Root = <menu>

●

<menu> holds <item> elements

●

<item> defines a single menu item
–

android:id

–

android:title

–

android:icon

–

android:visible

–

android:enabled

Copyright © 2012 CommonsWare, LLC
Populating the Bar
●

Activity Callbacks for Action Bar
●

onCreateOptionsMenu()
–

●

onOptionsItemSelected()
–

●

Where you set up the basic options menu to use, via a
MenuInflater
Called when the user clicks on something in the action
bar

Default Behavior: Overflow
●

Devices with MENU button – use to display

●

Devices sans MENU button – … to display

Copyright © 2012 CommonsWare, LLC
Toolbar Buttons
●

●

Puts item right in action bar, vs. overflow
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

Copyright © 2012 CommonsWare, LLC
Fragments and the Action Bar
●

Step #1: Call setHasOptionsMenu(true)

●

Step #2: Implement onCreateOptionsMenu()
●

●

Slightly different method signature

Step #3: Implement onOptionsItemSelected()

Copyright © 2012 CommonsWare, LLC
Custom Action Bar Widgets
●

Option #1: Substitute Own Inflated Layout for
Standard Button
●

●

Add android:actionLayout to <item> in menu
resource
Call getActionView() on MenuItem to
configure at runtime

Copyright © 2012 CommonsWare, LLC
Custom Action Bar Widgets
●

Option #2: android:actionViewClass
●

Skip the layout, directly reference a View class

●

Often implements CollapsibleActionView interface
–

●

Allows automatic expansion to fill available space or
collapse to allow other action bar items to be seen

Built-In: SearchView

Copyright © 2012 CommonsWare, LLC
Custom Action Bar Widgets
●

Option #3: ActionProvider
●

●

Extend ActionProvider, implement
onCreateActionView()
Wire in via android:actionProviderClass in
menu resource

●

Supports overflow with simplified UI

●

Built-in
–

ShareActionProvider

–

MediaRouteActionProvider

Copyright © 2012 CommonsWare, LLC
ShareActionProvider
●

Stock Way to Share Content

●

Step #1: Add to <menu>

●

Step #2: Call setShareIntent()
●

●

●

Once or many times, as appropriate
Be sure to set MIME type!

Optional
●

Control share history

●

Register OnShareTargetSelectedListener, to update UI

Copyright © 2012 CommonsWare, LLC
SearchView
●

The Classic Magnifying Glass

●

Approaches
●

Iconified by default, expanding on click

●

Expanded by default
–

Good for tablets, particularly in landscape

Copyright © 2012 CommonsWare, LLC
Basic SearchView Usage
●

Step #1: Add to <menu>

●

Step #2: Configure in onCreateOptionsMenu()
●

Register listeners
–
–

●

●

OnQueryTextListener
OnCloseListener

Other settings

Step #3: Respond to Events
●

E.g., manage a ListView filter

Copyright © 2012 CommonsWare, LLC
App Icon
●

Default = activity icon
●

●

Virtual menu choice: android.R.id.home
●

●

Optional android:logo in <application> to
supply alternative image
Handle in onOptionsItemSelected()

setDisplayHomeAsUpEnabled()
●
●

Adds arrowhead
Handling “up navigation” well is beyond the
scope of this presentation

Copyright © 2012 CommonsWare, LLC
Action Bar Navigation
●

Option #1: Tabs
●

Use setNavigationMode() on ActionBar
–

NAVIGATION_MODE_TABS

●

Call addTab() to add a tab

●

Pros: easy to set up, automatic fragment support

●

Cons
–

May appear on separate row

–

May be converted into list navigation

Copyright © 2012 CommonsWare, LLC
Action Bar Navigation
●

Option #2: List
●

Use setNavigationMode() on ActionBar
–

●

NAVIGATION_MODE_LIST

Call setListNavigationCallbacks() to define
Spinner contents and listener

Copyright © 2012 CommonsWare, LLC
Action Bar Navigation
●

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 © 2012 CommonsWare, LLC
Action Modes
●

Alternate Action Bar for Contextual Actions
●

Operations on selections
–
–

●

Multiple selections in a list
Selected text in a TextView, EditText, WebView, etc.

Replacement for context menu

Copyright © 2012 CommonsWare, LLC
Action Modes
●

ActionMode.Callback
●

●

Configure ActionMode in
onCreateActionMode()
onActionItemClicked() if user clicks a toolbar
button

●

finish() the ActionMode when done

●

Clean up in onDestroyActionMode()

Copyright © 2012 CommonsWare, LLC
Action Modes
●

Automatic Multiple-Choice Action Mode
●

CHOICE_MODE_MULTIPLE_MODAL and an

appropriate row layout
●

Checking item toggles on action mode with your
supplied MultiChoiceModeListener callback
–

Serves as ActionBar.Callback, plus
onItemCheckedStateChanged() for check/uncheck
events

Copyright © 2012 CommonsWare, LLC
Action Modes
●

Long-Press-Initiated Automatic Action Mode
●

Start off in single-choice mode

●

On long-click of item, toggle into
CHOICE_MODE_MULTIPLE_MODAL

●

●

When action mode destroyed, switch back to
single-choice mode
Need to remember choice mode across
configuration changes!

Copyright © 2012 CommonsWare, LLC
Styles and Themes
●

Theme.Holo / Theme.Holo.Light
●

●

Standard themes, standard color scheme

Can Style the Action Bar
●

Easy: Action Bar Style Generator
–

●

http://jgilfelt.github.io/android-actionbarstylegenerator

More power: DIY
–

https://developer.android.com/training/basics/actionbar
/styling.html

Copyright © 2012 CommonsWare, LLC
What Else Is There?
●

Custom Action Providers

●

ActionBarDrawerToggle

●

Transparent/Translucent Action Bars

●

Checkable Action Items

●

Long-Press “Tooltip” Help

●

And more!

Copyright © 2012 CommonsWare, LLC

Weitere ähnliche Inhalte

Ähnlich wie The Action Bar: Front to Back

Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)
Oro Inc.
 
Google Integration in Android Apps - Mooscon 2013 Cebit
Google Integration in Android Apps - Mooscon 2013 CebitGoogle Integration in Android Apps - Mooscon 2013 Cebit
Google Integration in Android Apps - Mooscon 2013 Cebit
Friedger Müffke
 
android training_material ravy ramio
android training_material ravy ramioandroid training_material ravy ramio
android training_material ravy ramio
slesulvy
 
Writing Gadgets with the WSO2 Gadget Server
Writing Gadgets with the WSO2 Gadget ServerWriting Gadgets with the WSO2 Gadget Server
Writing Gadgets with the WSO2 Gadget Server
WSO2
 
User interface customization for aem6 circuit
User interface customization for aem6 circuitUser interface customization for aem6 circuit
User interface customization for aem6 circuit
Damien Antipa
 

Ähnlich wie The Action Bar: Front to Back (20)

Google I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and JetpackGoogle I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and Jetpack
 
Android design patterns
Android design patternsAndroid design patterns
Android design patterns
 
Android Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompatAndroid Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompat
 
Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)
 
Android Jump Start
Android Jump StartAndroid Jump Start
Android Jump Start
 
The Glass Class - Tutorial 3 - Android and GDK
The Glass Class - Tutorial 3 - Android and GDKThe Glass Class - Tutorial 3 - Android and GDK
The Glass Class - Tutorial 3 - Android and GDK
 
Google Integration in Android Apps - Mooscon 2013 Cebit
Google Integration in Android Apps - Mooscon 2013 CebitGoogle Integration in Android Apps - Mooscon 2013 Cebit
Google Integration in Android Apps - Mooscon 2013 Cebit
 
Android N Highligts
Android N HighligtsAndroid N Highligts
Android N Highligts
 
Lecture #3 activities and intents
Lecture #3  activities and intentsLecture #3  activities and intents
Lecture #3 activities and intents
 
android training_material ravy ramio
android training_material ravy ramioandroid training_material ravy ramio
android training_material ravy ramio
 
A journey through android development
A journey through android developmentA journey through android development
A journey through android development
 
Testing android apps with espresso
Testing android apps with espressoTesting android apps with espresso
Testing android apps with espresso
 
Compose In Practice
Compose In PracticeCompose In Practice
Compose In Practice
 
Writing Gadgets with the WSO2 Gadget Server
Writing Gadgets with the WSO2 Gadget ServerWriting Gadgets with the WSO2 Gadget Server
Writing Gadgets with the WSO2 Gadget Server
 
Eclipse Training - Standard Extension Points and APIs
Eclipse Training - Standard Extension Points and APIsEclipse Training - Standard Extension Points and APIs
Eclipse Training - Standard Extension Points and APIs
 
Native Android Development Practices
Native Android Development PracticesNative Android Development Practices
Native Android Development Practices
 
Parallelminds.web partdemo
Parallelminds.web partdemoParallelminds.web partdemo
Parallelminds.web partdemo
 
UI controls in Android
UI controls in Android UI controls in Android
UI controls in Android
 
UI Customization in AEM 6.0
UI Customization in AEM 6.0UI Customization in AEM 6.0
UI Customization in AEM 6.0
 
User interface customization for aem6 circuit
User interface customization for aem6 circuitUser interface customization for aem6 circuit
User interface customization for aem6 circuit
 

Mehr von CommonsWare

Gradle and Your Android Wearable Projects
Gradle and Your Android Wearable ProjectsGradle and Your Android Wearable Projects
Gradle and Your Android Wearable Projects
CommonsWare
 

Mehr von CommonsWare (20)

Gradle and Your Android Wearable Projects
Gradle and Your Android Wearable ProjectsGradle and Your Android Wearable Projects
Gradle and Your Android Wearable Projects
 
Getting Android Developers for Your Wearables
Getting Android Developers for Your WearablesGetting Android Developers for Your Wearables
Getting Android Developers for Your Wearables
 
When Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable AppsWhen Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable Apps
 
Android Security: Defending Your Users
Android Security: Defending Your UsersAndroid Security: Defending Your Users
Android Security: Defending Your Users
 
Secondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManagerSecondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManager
 
Not Quite As Painful Threading
Not Quite As Painful ThreadingNot Quite As Painful Threading
Not Quite As Painful Threading
 
Android Development: The 20,000-Foot View
Android Development: The 20,000-Foot ViewAndroid Development: The 20,000-Foot View
Android Development: The 20,000-Foot View
 
Maps V2... And You!
Maps V2... And You!Maps V2... And You!
Maps V2... And You!
 
A Deep Dive Into ViewPager
A Deep Dive Into ViewPagerA Deep Dive Into ViewPager
A Deep Dive Into ViewPager
 
Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2
 
Integrate Android Apps and Web Apps
Integrate Android Apps and Web AppsIntegrate Android Apps and Web Apps
Integrate Android Apps and Web Apps
 
X Means Y
X Means YX Means Y
X Means Y
 
The Wonderful World of Wearables
The Wonderful World of WearablesThe Wonderful World of Wearables
The Wonderful World of Wearables
 
Securing User Data with SQLCipher
Securing User Data with SQLCipherSecuring User Data with SQLCipher
Securing User Data with SQLCipher
 
Beaming Data to Devices with NFC
Beaming Data to Devices with NFCBeaming Data to Devices with NFC
Beaming Data to Devices with NFC
 
What's New in Jelly Bean
What's New in Jelly BeanWhat's New in Jelly Bean
What's New in Jelly Bean
 
Making Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business ModelsMaking Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business Models
 
AppsWorld Keynote
AppsWorld KeynoteAppsWorld Keynote
AppsWorld Keynote
 
App Integration (Revised and Updated)
App Integration (Revised and Updated)App Integration (Revised and Updated)
App Integration (Revised and Updated)
 
Rich Text Editing and Beyond
Rich Text Editing and BeyondRich Text Editing and Beyond
Rich Text Editing and Beyond
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

The Action Bar: Front to Back

  • 1. AnDevCon SF 2013 The Action Bar, Front to Back Copyright © 2012 CommonsWare, LLC
  • 2. Action Bar Options ● Native Implementation ● ● Works well if android:minSdkVersion is 11 or higher Backports ● Official: AppCompat ● Popular: ActionBarSherlock Copyright © 2012 CommonsWare, LLC
  • 3. Action Bar Options ● AppCompat ● Part of Android Support package ● Pros – – ● Google “seal of approval” No additional libraries (since you probably are already using the Android Support package) Cons – Released in August 2013 – Modest track record to date Copyright © 2012 CommonsWare, LLC
  • 4. Action Bar Options ● ActionBarSherlock ● Independent open source backport ● Pros – – ● Used by countless projects over 18+ months Lots of material written about it Cons – Requires an Android library project – No Google “seal of approval” Copyright © 2012 CommonsWare, LLC
  • 5. Manifest Changes ● <uses-sdk android:targetSdkVersion=”14”> ● ● ● Action bar added Holographic theme for widgets android:uiOptions=”splitActionBarWhenNarrow” ● Two halves of action bar, top and bottom ● Used for phones in portrait mode Copyright © 2012 CommonsWare, LLC
  • 6. Populating the Bar ● res/menu/options.xml (or other name) ● Root = <menu> ● <menu> holds <item> elements ● <item> defines a single menu item – android:id – android:title – android:icon – android:visible – android:enabled Copyright © 2012 CommonsWare, LLC
  • 7. Populating the Bar ● Activity Callbacks for Action Bar ● onCreateOptionsMenu() – ● onOptionsItemSelected() – ● Where you set up the basic options menu to use, via a MenuInflater Called when the user clicks on something in the action bar Default Behavior: Overflow ● Devices with MENU button – use to display ● Devices sans MENU button – … to display Copyright © 2012 CommonsWare, LLC
  • 8. Toolbar Buttons ● ● Puts item right in action bar, vs. overflow 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 Copyright © 2012 CommonsWare, LLC
  • 9. Fragments and the Action Bar ● Step #1: Call setHasOptionsMenu(true) ● Step #2: Implement onCreateOptionsMenu() ● ● Slightly different method signature Step #3: Implement onOptionsItemSelected() Copyright © 2012 CommonsWare, LLC
  • 10. Custom Action Bar Widgets ● Option #1: Substitute Own Inflated Layout for Standard Button ● ● Add android:actionLayout to <item> in menu resource Call getActionView() on MenuItem to configure at runtime Copyright © 2012 CommonsWare, LLC
  • 11. Custom Action Bar Widgets ● Option #2: android:actionViewClass ● Skip the layout, directly reference a View class ● Often implements CollapsibleActionView interface – ● Allows automatic expansion to fill available space or collapse to allow other action bar items to be seen Built-In: SearchView Copyright © 2012 CommonsWare, LLC
  • 12. Custom Action Bar Widgets ● Option #3: ActionProvider ● ● Extend ActionProvider, implement onCreateActionView() Wire in via android:actionProviderClass in menu resource ● Supports overflow with simplified UI ● Built-in – ShareActionProvider – MediaRouteActionProvider Copyright © 2012 CommonsWare, LLC
  • 13. ShareActionProvider ● Stock Way to Share Content ● Step #1: Add to <menu> ● Step #2: Call setShareIntent() ● ● ● Once or many times, as appropriate Be sure to set MIME type! Optional ● Control share history ● Register OnShareTargetSelectedListener, to update UI Copyright © 2012 CommonsWare, LLC
  • 14. SearchView ● The Classic Magnifying Glass ● Approaches ● Iconified by default, expanding on click ● Expanded by default – Good for tablets, particularly in landscape Copyright © 2012 CommonsWare, LLC
  • 15. Basic SearchView Usage ● Step #1: Add to <menu> ● Step #2: Configure in onCreateOptionsMenu() ● Register listeners – – ● ● OnQueryTextListener OnCloseListener Other settings Step #3: Respond to Events ● E.g., manage a ListView filter Copyright © 2012 CommonsWare, LLC
  • 16. App Icon ● Default = activity icon ● ● Virtual menu choice: android.R.id.home ● ● Optional android:logo in <application> to supply alternative image Handle in onOptionsItemSelected() setDisplayHomeAsUpEnabled() ● ● Adds arrowhead Handling “up navigation” well is beyond the scope of this presentation Copyright © 2012 CommonsWare, LLC
  • 17. Action Bar Navigation ● Option #1: Tabs ● Use setNavigationMode() on ActionBar – NAVIGATION_MODE_TABS ● Call addTab() to add a tab ● Pros: easy to set up, automatic fragment support ● Cons – May appear on separate row – May be converted into list navigation Copyright © 2012 CommonsWare, LLC
  • 18. Action Bar Navigation ● Option #2: List ● Use setNavigationMode() on ActionBar – ● NAVIGATION_MODE_LIST Call setListNavigationCallbacks() to define Spinner contents and listener Copyright © 2012 CommonsWare, LLC
  • 19. Action Bar Navigation ● 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 © 2012 CommonsWare, LLC
  • 20. Action Modes ● Alternate Action Bar for Contextual Actions ● Operations on selections – – ● Multiple selections in a list Selected text in a TextView, EditText, WebView, etc. Replacement for context menu Copyright © 2012 CommonsWare, LLC
  • 21. Action Modes ● ActionMode.Callback ● ● Configure ActionMode in onCreateActionMode() onActionItemClicked() if user clicks a toolbar button ● finish() the ActionMode when done ● Clean up in onDestroyActionMode() Copyright © 2012 CommonsWare, LLC
  • 22. Action Modes ● Automatic Multiple-Choice Action Mode ● CHOICE_MODE_MULTIPLE_MODAL and an appropriate row layout ● Checking item toggles on action mode with your supplied MultiChoiceModeListener callback – Serves as ActionBar.Callback, plus onItemCheckedStateChanged() for check/uncheck events Copyright © 2012 CommonsWare, LLC
  • 23. Action Modes ● Long-Press-Initiated Automatic Action Mode ● Start off in single-choice mode ● On long-click of item, toggle into CHOICE_MODE_MULTIPLE_MODAL ● ● When action mode destroyed, switch back to single-choice mode Need to remember choice mode across configuration changes! Copyright © 2012 CommonsWare, LLC
  • 24. Styles and Themes ● Theme.Holo / Theme.Holo.Light ● ● Standard themes, standard color scheme Can Style the Action Bar ● Easy: Action Bar Style Generator – ● http://jgilfelt.github.io/android-actionbarstylegenerator More power: DIY – https://developer.android.com/training/basics/actionbar /styling.html Copyright © 2012 CommonsWare, LLC
  • 25. What Else Is There? ● Custom Action Providers ● ActionBarDrawerToggle ● Transparent/Translucent Action Bars ● Checkable Action Items ● Long-Press “Tooltip” Help ● And more! Copyright © 2012 CommonsWare, LLC