SlideShare a Scribd company logo
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 1/16
You are here:  Home (/) /  Tutorials (/index.php/articles.html) /  Articles (/index.php/articles.html)
/  Using Android's Action Bar
Tweet 18 Check out our google+ page
(https://plus.google.com/+101appsCoZa/?prsrc=3)
Using Android's Action Bar
Written by  Clive
Where's the action?
The Action Bar
0Like Send 0Share Share

22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 2/16
The Action Bar
The Action Bar is at the top of every activity screen
The app icon displays in it by default.
You can replace the app icon with your company logo if you wish.
You can also include tabs, drop-down lists, pop-ups and menus in the Action Bar.
I’ll show you how to include menu items as Action items in the Action Bar.
Use the Action Bar on all devices, well almost…
The Action Bar has been available since Android 3.0 (Honeycomb, API level 11).
The Support Library
Using the support library makes the Action Bar available since Android 2.1 (API level 7).
We’ll be using the support library in our tutorial.
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 3/16
Adding an Action Bar
Import the ActionBar class
Make sure that you import the correct ActionBar class:
We’re using the support library class because we’re targeting earlier devices
Which class you import depends on the devices that you target:
API level 11 and above – import ActionBar
API level 10 and below – import support.v7.app.ActionBar. This is the one we’ll import
Create the activity
Create the activity by extending the ActionBarActivity class.
Include a theme
Edit the AndroidManifest.xml file to include the Theme.AppCompat.Light theme
Hiding the Action Bar
You can hide the Action Bar:
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 4/16
Use getSupportActionBar() to get an instance of the Action Bar then call hide() to hide it
Showing the Action Bar
You can show the Action Bar by getting an instance of the Action Bar and then call show():
Showing the Action Bar
Brand your app. Use your logo
The image on the left can either be the app icon or your company logo
Which image is displayed depends on these settings in the manifest:
The icon attribute image is the default
Include the logo attribute and this image will replace the icon image.
But there’s a catch…
The logo image will not show on any device running Android 10 and lower. Unless…
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 5/16
You include this code in your activity:
Get an instance of the action bar by calling getSupportActionBar(). Then call setLogo() to set the logo
If you use this workaround then you don’t have to include the logo attribute in the manifest.
Action items
Action items are menu options.
You can display the most important action items in the Action Bar.
Action items that are not important or cannot fit in the Action Bar end up in the action overflow.
You can access the action overflow by pressing the action overflow button
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 6/16
Pressing the overflow button reveals the Settings item. The Help and Phone items are displayed as Action Buttons in
the Action Bar
Creating the action items
Create the action items in a menu file and save it in the res>menu folder.
Here’s a code snippet:
Note the following:
icon – this image will show in the Action Bar. It will not show in the overflow
title – the title will show in the overflow. It will show in the Action Bar, if:
you include withText in the showAsOption attribute
there is room
app:showAsAction – because we are using the support library, we must use the custom namespace (app)
defined in the <menu> tag of the menu xml file:
The namespace is defined in the menu tag
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 7/16
showAsAction – use this to declare whether or not you want the action item to appear in the Action Bar. Some
common options are:
ifRoom – shows the action item in the Action Bar if there is room
withText – includes the action item’s title if there is room
never – never show this action item in the Action Bar
Always include an action title
You should always include an action title because:
only a title appears in the action overflow
blind users need it for their screen readers
long-pressing the Action Button displays a tooltip
Long-pressing the Action Button displays the tooltip, Phone
Getting action icons
You can download free action icons from the official Android site
(http://developer.android.com/design/downloads/index.html)
Displaying the Action Bar in an activity
The activity’s onCreateOptionsMenu() inflates the menu file and places the action items in the Action Bar.
Here’s the code:
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 8/16
This inflates the menu resource file and loads the action items into the Action Bar
Note the following:
getMenuInflater().inflate() – inflates the menu found in the resource file into the menu object
Handling clicks
Pressing an action item, calls onOptionsItemSelected(), passing the selected item as a parameter.
Here’s the code:
Note the following:
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 9/16
getItemId() – gets the ID of the selected action item
switch() – we use a switch statement to match the selected item ID with the id’s of our menu items as saved in
the menu resource file. The appropriate code is executed if it matches
message – we create a message for each of the action item id’s. The matching id’s message will display as a
Toast (/articles/making-toast.html)
Pressing an Action Button
Action item icons in the Action Bar are known as Action Buttons.
Pressing the Phone Action Button uses an intent to start another activity.
The second activity
This activity demonstrates the Split Action Bar and Up Navigation.
Splitting the Action Bar
You can split the Action Bar when running on narrow screens.
The action items will display at the bottom of the screen. This leaves room for navigation and title elements at the
top.
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 10/16
A narrow screen with a split Action Bar. The separate bar at the bottom of the screen displays the action items
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 11/16
The bar is not split on wide screens
Splitting the Bar: It depends on the device
Accommodating API 14 and higher
For devices using API level 14 or higher, add the uiOptions attribute to specific activities or the application as a
whole.
Accommodating API 13 and below
For devices using API level 13 or lower, add the <meta-data> element to the activities where you want to split the
action bar:
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 12/16
Include the first <meta-data> element to split the Action Bar on older devices
Navigating up with the app icon
Up navigation takes the user to the parent of the current activity.
The Back button takes the user to the previous activity.
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 13/16
If pressing an action button in activity A starts activity C then pressing the Up Navigation icon in activity C will return
the user to activity A. If the user reached activity C from A via B then, pressing the Back button will first return to
activity B and then to activity A
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 14/16
Enable the app icon as an Up button
The caret to the left of the logo icon indicates an Up Button
Here’s the code:
Use getSupportActionBar() to get an instance of an Action Bar then call setDisplayHomeAsUpEnabled(true) to enable
the Up Button
For it to work you need to specify the parent activity in the manifest file:
Add this code to the activity where you have enabled the Up Button
Run the app
The first activity
The first activity will display the Action Bar with the Strawberry logo on the left and the Action Buttons on the right.
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 15/16
Android apps and Google Drive: Picking files
(/index.php/articles/android-apps-and-google-drive-
picking-files.html)
Related items
Change the device orientation. The Phone action item’s title is displayed in landscape mode but not in portrait
mode.
Pressing the Phone action button starts the second activity.
The second activity
The Action Bar is split if the screen is narrow.
Change the device orientation. The Action Bar is not split when the device is in landscape mode.
The app logo is also an Up Button. Pressing the logo returns the user to the first activity.
I hope that you have found this tutorial useful.
You may also be interested in Android Fragments, Action Bar, Menus, Notifications and Tabs.
(http://www.amazon.com/Android-Fragments-Action-Menus-Notifications-ebook/dp/B00B7NQ2KQ/ref=sr_1_4?
ie=UTF8&qid=1393233618&sr=8-4&keywords=clive+sargeant)
This tutorial was created using Android Studio (http://www.amazon.com/Android-Studio-How-guide-tutorial-
ebook/dp/B00HZ1O78S/ref=sr_1_3?ie=UTF8&qid=1393233618&sr=8-3&keywords=clive+sargeant). You can
download the project files here   (/downloads.html)
Are you using Eclipse or another IDE? Here's how you can use this project's Android Studio files (/articles/importing-
android-studio-projects-into-eclipse.html).
22/05/2015 Using Android's Action Bar
http://www.101apps.co.za/articles/using­android­s­action­bar.html 16/16
Android apps and Google Drive: A tutorial
(/index.php/articles/android-apps-and-google-drive-a-
tutorial.html)
Converting Android Activities to Fragments
(/index.php/articles/converting-android-activities-to-
fragments.html)
Let your apps take a giant leap. A Tutorial
(/index.php/ebooks/let-your-apps-take-a-giant-leap-a-
tutorial.html)
Android: Launching activities
(/index.php/articles/android-launching-activities.html)

More Related Content

What's hot

IAT202 Tips and Tricks on Windows Phone 7 Development
IAT202 Tips and Tricks on Windows Phone 7 DevelopmentIAT202 Tips and Tricks on Windows Phone 7 Development
IAT202 Tips and Tricks on Windows Phone 7 Development
Zeddy Iskandar
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
Mindfire Solutions
 
Windows phone 8 session 11
Windows phone 8 session 11Windows phone 8 session 11
Windows phone 8 session 11
hitesh chothani
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
Wingston
 
I Phone101
I Phone101I Phone101
I Phone101
Febrian ‎
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
katayoon_bz
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
Ed Zel
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
Avinash Nandakumar
 
Londroid Android Home Screen Widgets
Londroid Android Home Screen WidgetsLondroid Android Home Screen Widgets
Londroid Android Home Screen WidgetsRichard Hyndman
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul Karim
 
Emergency androidstudiochapter
Emergency androidstudiochapterEmergency androidstudiochapter
Emergency androidstudiochapter
Aravindharamanan S
 
IOS Swift language 1st Tutorial
IOS Swift language 1st TutorialIOS Swift language 1st Tutorial
IOS Swift language 1st Tutorial
Hassan A-j
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivityAhsanul Karim
 
Android UI
Android UIAndroid UI
Android UI
nationalmobileapps
 
Facebook complete guide to power editor
Facebook complete guide to power editor Facebook complete guide to power editor
Facebook complete guide to power editor Rania Alahmad
 
Exploring Halifax Attractions using the Esri Runtime SDK for Android
Exploring Halifax Attractions using the Esri Runtime SDK for AndroidExploring Halifax Attractions using the Esri Runtime SDK for Android
Exploring Halifax Attractions using the Esri Runtime SDK for Android
COGS Presentations
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI WidgetsAhsanul Karim
 

What's hot (19)

IAT202 Tips and Tricks on Windows Phone 7 Development
IAT202 Tips and Tricks on Windows Phone 7 DevelopmentIAT202 Tips and Tricks on Windows Phone 7 Development
IAT202 Tips and Tricks on Windows Phone 7 Development
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
 
Windows phone 8 session 11
Windows phone 8 session 11Windows phone 8 session 11
Windows phone 8 session 11
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
 
I Phone101
I Phone101I Phone101
I Phone101
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Londroid Android Home Screen Widgets
Londroid Android Home Screen WidgetsLondroid Android Home Screen Widgets
Londroid Android Home Screen Widgets
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
 
Emergency androidstudiochapter
Emergency androidstudiochapterEmergency androidstudiochapter
Emergency androidstudiochapter
 
IOS Swift language 1st Tutorial
IOS Swift language 1st TutorialIOS Swift language 1st Tutorial
IOS Swift language 1st Tutorial
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivity
 
Android UI
Android UIAndroid UI
Android UI
 
Android development module
Android development moduleAndroid development module
Android development module
 
Facebook complete guide to power editor
Facebook complete guide to power editor Facebook complete guide to power editor
Facebook complete guide to power editor
 
Exploring Halifax Attractions using the Esri Runtime SDK for Android
Exploring Halifax Attractions using the Esri Runtime SDK for AndroidExploring Halifax Attractions using the Esri Runtime SDK for Android
Exploring Halifax Attractions using the Esri Runtime SDK for Android
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
 

Similar to Using android's action bar

Chapter 2 lesson-1 adding the action bar
Chapter 2 lesson-1 adding the action barChapter 2 lesson-1 adding the action bar
Chapter 2 lesson-1 adding the action bar
Kalluri Vinay Reddy
 
Android action bar and notifications-chapter16
Android action bar and notifications-chapter16Android action bar and notifications-chapter16
Android action bar and notifications-chapter16
Dr. Ramkumar Lakshminarayanan
 
Android app development guide for freshers by ace web academy
Android app development guide for freshers  by ace web academyAndroid app development guide for freshers  by ace web academy
Android app development guide for freshers by ace web academy
Ace Web Academy -Career Development Center
 
"Discover windows phone" 05. Application Bar
"Discover windows phone" 05. Application Bar"Discover windows phone" 05. Application Bar
"Discover windows phone" 05. Application BarYasmine Abdelhady
 
Tat learning applications en
Tat learning applications enTat learning applications en
Tat learning applications en
Toni Setyawan
 
Ios actions and outlets
Ios actions and outletsIos actions and outlets
Ios actions and outlets
veeracynixit
 
Create New Android Layout
Create New Android LayoutCreate New Android Layout
Create New Android Layout
Transpose Solutions Inc
 
How to Create Your First Android App Step by Step.pdf
How to Create Your First Android App Step by Step.pdfHow to Create Your First Android App Step by Step.pdf
How to Create Your First Android App Step by Step.pdf
BOSC Tech Labs
 
Android app development
Android app developmentAndroid app development
Android app development
Vara Prasad Kanakam
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and Layouts
Chandrakant Divate
 
Appy builder beginner tutorial
Appy builder beginner tutorialAppy builder beginner tutorial
Appy builder beginner tutorial
HabibulHakam
 
Android menus in android-chapter15
Android menus in android-chapter15Android menus in android-chapter15
Android menus in android-chapter15
Dr. Ramkumar Lakshminarayanan
 
Talk tomepart1 2perpage
Talk tomepart1 2perpageTalk tomepart1 2perpage
Talk tomepart1 2perpage
Silvio Cazella
 
Activity
ActivityActivity
Activity
NikithaNag
 
Activity
ActivityActivity
Activity
roopa_slide
 
Activity
ActivityActivity
Activity
NikithaNag
 
Activity
ActivityActivity
Activity
roopa_slide
 
I have adream
I have adreamI have adream
I have adream
ANASZ123
 
I have adream
I have adreamI have adream
I have adream
Kathryn Evans
 
App Inventor : Getting Started Guide
App Inventor : Getting Started GuideApp Inventor : Getting Started Guide
App Inventor : Getting Started GuideVasilis Drimtzias
 

Similar to Using android's action bar (20)

Chapter 2 lesson-1 adding the action bar
Chapter 2 lesson-1 adding the action barChapter 2 lesson-1 adding the action bar
Chapter 2 lesson-1 adding the action bar
 
Android action bar and notifications-chapter16
Android action bar and notifications-chapter16Android action bar and notifications-chapter16
Android action bar and notifications-chapter16
 
Android app development guide for freshers by ace web academy
Android app development guide for freshers  by ace web academyAndroid app development guide for freshers  by ace web academy
Android app development guide for freshers by ace web academy
 
"Discover windows phone" 05. Application Bar
"Discover windows phone" 05. Application Bar"Discover windows phone" 05. Application Bar
"Discover windows phone" 05. Application Bar
 
Tat learning applications en
Tat learning applications enTat learning applications en
Tat learning applications en
 
Ios actions and outlets
Ios actions and outletsIos actions and outlets
Ios actions and outlets
 
Create New Android Layout
Create New Android LayoutCreate New Android Layout
Create New Android Layout
 
How to Create Your First Android App Step by Step.pdf
How to Create Your First Android App Step by Step.pdfHow to Create Your First Android App Step by Step.pdf
How to Create Your First Android App Step by Step.pdf
 
Android app development
Android app developmentAndroid app development
Android app development
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and Layouts
 
Appy builder beginner tutorial
Appy builder beginner tutorialAppy builder beginner tutorial
Appy builder beginner tutorial
 
Android menus in android-chapter15
Android menus in android-chapter15Android menus in android-chapter15
Android menus in android-chapter15
 
Talk tomepart1 2perpage
Talk tomepart1 2perpageTalk tomepart1 2perpage
Talk tomepart1 2perpage
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
I have adream
I have adreamI have adream
I have adream
 
I have adream
I have adreamI have adream
I have adream
 
App Inventor : Getting Started Guide
App Inventor : Getting Started GuideApp Inventor : Getting Started Guide
App Inventor : Getting Started Guide
 

Recently uploaded

Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 

Recently uploaded (20)

Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 

Using android's action bar

  • 1. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 1/16 You are here:  Home (/) /  Tutorials (/index.php/articles.html) /  Articles (/index.php/articles.html) /  Using Android's Action Bar Tweet 18 Check out our google+ page (https://plus.google.com/+101appsCoZa/?prsrc=3) Using Android's Action Bar Written by  Clive Where's the action? The Action Bar 0Like Send 0Share Share 
  • 2. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 2/16 The Action Bar The Action Bar is at the top of every activity screen The app icon displays in it by default. You can replace the app icon with your company logo if you wish. You can also include tabs, drop-down lists, pop-ups and menus in the Action Bar. I’ll show you how to include menu items as Action items in the Action Bar. Use the Action Bar on all devices, well almost… The Action Bar has been available since Android 3.0 (Honeycomb, API level 11). The Support Library Using the support library makes the Action Bar available since Android 2.1 (API level 7). We’ll be using the support library in our tutorial.
  • 3. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 3/16 Adding an Action Bar Import the ActionBar class Make sure that you import the correct ActionBar class: We’re using the support library class because we’re targeting earlier devices Which class you import depends on the devices that you target: API level 11 and above – import ActionBar API level 10 and below – import support.v7.app.ActionBar. This is the one we’ll import Create the activity Create the activity by extending the ActionBarActivity class. Include a theme Edit the AndroidManifest.xml file to include the Theme.AppCompat.Light theme Hiding the Action Bar You can hide the Action Bar:
  • 4. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 4/16 Use getSupportActionBar() to get an instance of the Action Bar then call hide() to hide it Showing the Action Bar You can show the Action Bar by getting an instance of the Action Bar and then call show(): Showing the Action Bar Brand your app. Use your logo The image on the left can either be the app icon or your company logo Which image is displayed depends on these settings in the manifest: The icon attribute image is the default Include the logo attribute and this image will replace the icon image. But there’s a catch… The logo image will not show on any device running Android 10 and lower. Unless…
  • 5. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 5/16 You include this code in your activity: Get an instance of the action bar by calling getSupportActionBar(). Then call setLogo() to set the logo If you use this workaround then you don’t have to include the logo attribute in the manifest. Action items Action items are menu options. You can display the most important action items in the Action Bar. Action items that are not important or cannot fit in the Action Bar end up in the action overflow. You can access the action overflow by pressing the action overflow button
  • 6. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 6/16 Pressing the overflow button reveals the Settings item. The Help and Phone items are displayed as Action Buttons in the Action Bar Creating the action items Create the action items in a menu file and save it in the res>menu folder. Here’s a code snippet: Note the following: icon – this image will show in the Action Bar. It will not show in the overflow title – the title will show in the overflow. It will show in the Action Bar, if: you include withText in the showAsOption attribute there is room app:showAsAction – because we are using the support library, we must use the custom namespace (app) defined in the <menu> tag of the menu xml file: The namespace is defined in the menu tag
  • 7. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 7/16 showAsAction – use this to declare whether or not you want the action item to appear in the Action Bar. Some common options are: ifRoom – shows the action item in the Action Bar if there is room withText – includes the action item’s title if there is room never – never show this action item in the Action Bar Always include an action title You should always include an action title because: only a title appears in the action overflow blind users need it for their screen readers long-pressing the Action Button displays a tooltip Long-pressing the Action Button displays the tooltip, Phone Getting action icons You can download free action icons from the official Android site (http://developer.android.com/design/downloads/index.html) Displaying the Action Bar in an activity The activity’s onCreateOptionsMenu() inflates the menu file and places the action items in the Action Bar. Here’s the code:
  • 8. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 8/16 This inflates the menu resource file and loads the action items into the Action Bar Note the following: getMenuInflater().inflate() – inflates the menu found in the resource file into the menu object Handling clicks Pressing an action item, calls onOptionsItemSelected(), passing the selected item as a parameter. Here’s the code: Note the following:
  • 9. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 9/16 getItemId() – gets the ID of the selected action item switch() – we use a switch statement to match the selected item ID with the id’s of our menu items as saved in the menu resource file. The appropriate code is executed if it matches message – we create a message for each of the action item id’s. The matching id’s message will display as a Toast (/articles/making-toast.html) Pressing an Action Button Action item icons in the Action Bar are known as Action Buttons. Pressing the Phone Action Button uses an intent to start another activity. The second activity This activity demonstrates the Split Action Bar and Up Navigation. Splitting the Action Bar You can split the Action Bar when running on narrow screens. The action items will display at the bottom of the screen. This leaves room for navigation and title elements at the top.
  • 10. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 10/16 A narrow screen with a split Action Bar. The separate bar at the bottom of the screen displays the action items
  • 11. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 11/16 The bar is not split on wide screens Splitting the Bar: It depends on the device Accommodating API 14 and higher For devices using API level 14 or higher, add the uiOptions attribute to specific activities or the application as a whole. Accommodating API 13 and below For devices using API level 13 or lower, add the <meta-data> element to the activities where you want to split the action bar:
  • 12. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 12/16 Include the first <meta-data> element to split the Action Bar on older devices Navigating up with the app icon Up navigation takes the user to the parent of the current activity. The Back button takes the user to the previous activity.
  • 13. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 13/16 If pressing an action button in activity A starts activity C then pressing the Up Navigation icon in activity C will return the user to activity A. If the user reached activity C from A via B then, pressing the Back button will first return to activity B and then to activity A
  • 14. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 14/16 Enable the app icon as an Up button The caret to the left of the logo icon indicates an Up Button Here’s the code: Use getSupportActionBar() to get an instance of an Action Bar then call setDisplayHomeAsUpEnabled(true) to enable the Up Button For it to work you need to specify the parent activity in the manifest file: Add this code to the activity where you have enabled the Up Button Run the app The first activity The first activity will display the Action Bar with the Strawberry logo on the left and the Action Buttons on the right.
  • 15. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 15/16 Android apps and Google Drive: Picking files (/index.php/articles/android-apps-and-google-drive- picking-files.html) Related items Change the device orientation. The Phone action item’s title is displayed in landscape mode but not in portrait mode. Pressing the Phone action button starts the second activity. The second activity The Action Bar is split if the screen is narrow. Change the device orientation. The Action Bar is not split when the device is in landscape mode. The app logo is also an Up Button. Pressing the logo returns the user to the first activity. I hope that you have found this tutorial useful. You may also be interested in Android Fragments, Action Bar, Menus, Notifications and Tabs. (http://www.amazon.com/Android-Fragments-Action-Menus-Notifications-ebook/dp/B00B7NQ2KQ/ref=sr_1_4? ie=UTF8&qid=1393233618&sr=8-4&keywords=clive+sargeant) This tutorial was created using Android Studio (http://www.amazon.com/Android-Studio-How-guide-tutorial- ebook/dp/B00HZ1O78S/ref=sr_1_3?ie=UTF8&qid=1393233618&sr=8-3&keywords=clive+sargeant). You can download the project files here   (/downloads.html) Are you using Eclipse or another IDE? Here's how you can use this project's Android Studio files (/articles/importing- android-studio-projects-into-eclipse.html).
  • 16. 22/05/2015 Using Android's Action Bar http://www.101apps.co.za/articles/using­android­s­action­bar.html 16/16 Android apps and Google Drive: A tutorial (/index.php/articles/android-apps-and-google-drive-a- tutorial.html) Converting Android Activities to Fragments (/index.php/articles/converting-android-activities-to- fragments.html) Let your apps take a giant leap. A Tutorial (/index.php/ebooks/let-your-apps-take-a-giant-leap-a- tutorial.html) Android: Launching activities (/index.php/articles/android-launching-activities.html)