SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
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

Mais conteúdo relacionado

Semelhante a The Action Bar: Front to Back

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 JetpackSunita Singh
 
Android design patterns
Android design patternsAndroid design patterns
Android design patternsPlatty Soft
 
Android Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompatAndroid Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompatcbeyls
 
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.
 
Android Jump Start
Android Jump StartAndroid Jump Start
Android Jump StartHaim Michael
 
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 GDKGun Lee
 
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 CebitFriedger Müffke
 
Android N Highligts
Android N HighligtsAndroid N Highligts
Android N HighligtsSercan Yusuf
 
Lecture #3 activities and intents
Lecture #3  activities and intentsLecture #3  activities and intents
Lecture #3 activities and intentsVitali Pekelis
 
android training_material ravy ramio
android training_material ravy ramioandroid training_material ravy ramio
android training_material ravy ramioslesulvy
 
A journey through android development
A journey through android developmentA journey through android development
A journey through android developmentraditya gumay
 
Testing android apps with espresso
Testing android apps with espressoTesting android apps with espresso
Testing android apps with espressoÉdipo Souza
 
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 ServerWSO2
 
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 APIsLuca D'Onofrio
 
Native Android Development Practices
Native Android Development PracticesNative Android Development Practices
Native Android Development PracticesRoy Clarkson
 
Parallelminds.web partdemo
Parallelminds.web partdemoParallelminds.web partdemo
Parallelminds.web partdemoManishaChothe
 
UI controls in Android
UI controls in Android UI controls in Android
UI controls in Android DivyaKS12
 
UI Customization in AEM 6.0
UI Customization in AEM 6.0UI Customization in AEM 6.0
UI Customization in AEM 6.0Gilles Knobloch
 
User interface customization for aem6 circuit
User interface customization for aem6 circuitUser interface customization for aem6 circuit
User interface customization for aem6 circuitDamien Antipa
 

Semelhante a 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
 

Mais de CommonsWare

Gradle and Your Android Wearable Projects
Gradle and Your Android Wearable ProjectsGradle and Your Android Wearable Projects
Gradle and Your Android Wearable ProjectsCommonsWare
 
Getting Android Developers for Your Wearables
Getting Android Developers for Your WearablesGetting Android Developers for Your Wearables
Getting Android Developers for Your WearablesCommonsWare
 
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 AppsCommonsWare
 
Android Security: Defending Your Users
Android Security: Defending Your UsersAndroid Security: Defending Your Users
Android Security: Defending Your UsersCommonsWare
 
Secondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManagerSecondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManagerCommonsWare
 
Not Quite As Painful Threading
Not Quite As Painful ThreadingNot Quite As Painful Threading
Not Quite As Painful ThreadingCommonsWare
 
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 ViewCommonsWare
 
Maps V2... And You!
Maps V2... And You!Maps V2... And You!
Maps V2... And You!CommonsWare
 
A Deep Dive Into ViewPager
A Deep Dive Into ViewPagerA Deep Dive Into ViewPager
A Deep Dive Into ViewPagerCommonsWare
 
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.2CommonsWare
 
Integrate Android Apps and Web Apps
Integrate Android Apps and Web AppsIntegrate Android Apps and Web Apps
Integrate Android Apps and Web AppsCommonsWare
 
The Wonderful World of Wearables
The Wonderful World of WearablesThe Wonderful World of Wearables
The Wonderful World of WearablesCommonsWare
 
Securing User Data with SQLCipher
Securing User Data with SQLCipherSecuring User Data with SQLCipher
Securing User Data with SQLCipherCommonsWare
 
Beaming Data to Devices with NFC
Beaming Data to Devices with NFCBeaming Data to Devices with NFC
Beaming Data to Devices with NFCCommonsWare
 
What's New in Jelly Bean
What's New in Jelly BeanWhat's New in Jelly Bean
What's New in Jelly BeanCommonsWare
 
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 ModelsCommonsWare
 
AppsWorld Keynote
AppsWorld KeynoteAppsWorld Keynote
AppsWorld KeynoteCommonsWare
 
App Integration (Revised and Updated)
App Integration (Revised and Updated)App Integration (Revised and Updated)
App Integration (Revised and Updated)CommonsWare
 
Rich Text Editing and Beyond
Rich Text Editing and BeyondRich Text Editing and Beyond
Rich Text Editing and BeyondCommonsWare
 

Mais de 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
 

Último

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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...Miguel Araújo
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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 RobisonAnna Loughnan Colquhoun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Último (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

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