SlideShare a Scribd company logo
1 of 25
By
Kalluri Vinay Reddy
Android Club
www.facebook.com/vitccandroidclub
Chapter-2
Adding the Action Bar
lesson-1
The action bar is one of the most important design elements you can
implement for your app's activities. It provides several user interface
features that make your app immediately familiar to users by offering
consistency between other Android apps. Key functions include:
A dedicated space for giving your app an identity and indicating the user's
location in the app.
Access to important actions in a predictable way (such as Search).
Adding the Action Bar
• Support for navigation and view switching (with tabs or drop-down
lists).
• This training class offers a quick guide to the action bar's basics.
Lessons
Setting Up the Action Bar
Learn how to add a basic action bar to your activity, whether your app
supports only Android 3.0 and higher or also supports versions as low as
Android 2.1 (by using the Android Support Library).
Adding Action Buttons
Learn how to add and respond to user actions in the action bar.
Styling the Action Bar
Learn how to customize the appearance of your action bar.
Overlaying the Action Bar
Learn how to overlay the action bar in front of your layout, allowing for
seamless transitions when hiding the action bar.
• In its most basic form, the action bar displays the title for the activity
and the app icon on the left.
• Even in this simple form, the action bar is useful for all activities to
inform users about where they are and to maintain a consistent identity
for your app.
Setting Up the Action Bar
Support Android 3.0 and Above Only
Beginning with Android 3.0 (API level 11), the action bar is
included in all activities that use the Theme.Holotheme
(or one of its descendants), which is the default theme when
either the targetSdkVersion orminSdkVersion attribute is set
to "11" or greater.
So to add the action bar to your activities, simply set either
attribute to 11 or higher.
For example:
<manifest ... >
<uses-sdk android:minSdkVersion="11" ... />
...
</manifest>
Support Android 2.1 and Above
Adding the action bar when running on versions older than Android 3.0 (down to
Android 2.1)
requires that you include the Android Support Library in your application.
To get started, read the Support Library Setup document and set up the v7 appcompat
library (once you've downloaded the library package, follow the instructions
for Adding libraries with resources).
Once you have the Support Library integrated with your app project:
1.Update your activity so that it extends ActionBarActivity.
2. For example:public class MainActivity extends ActionBarActivity { ... }
2.In your manifest file, update either the <application> element or
individual <activity>
3.elements to use one of the Theme.AppCompat themes. For example:<activity
android:theme="@style/Theme.AppCompat.Light" ... >
Note:
If you've created a custom theme, be sure it uses one of the Theme.AppCompat
themes as its parent.
Styling the Action Bar.
Now your activity includes the action bar when running on Android 2.1
(API level 7) or higher.
Remember to properly set your app's API level support in the manifest:
<manifest ... >
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="18" />
...
</manifest>
The action bar allows you to add buttons for the most
important action items relating to the app's current context.
Those that appear directly in the action bar with an icon
and/or text are known as action buttons.
Actions that can't fit in the action bar or aren't important
enough are hidden in the action overflow.
Adding Action Buttons
Action bar with an action button for Search
and the action overflow, which reveals
additional actions.
Specify the Actions in XML
All action buttons and other items available in the action
overflow are defined in an XML
menu resource. To add actions to the action bar, create
a new XML file in your project's
res/menu/ directory.
Add an <item> element for each item you want to include
in the action bar.
res/menu/main_activity_actions.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:showAsAction="never" />
</menu>
This declares that the Search action should appear as an action
button when room is
available in the action bar, but the Settings action should always
appear in the overflow.
(By default, all actions appear in the overflow, but it's good
practice to explicitly declare
your design intentions for each action.)
The icon attribute requires a resource ID for an image. The name that
follows @drawable/
must be the name of a bitmap image you've saved in your
project's res/drawable/ directory.
For example,
"@drawable/ic_action_search“
refers to ic_action_search.png.
Likewise, the title attribute uses a string resource
that's
defined by an XML file in your project's res/values/
directory, as discussed in Building a Simple User
Interface.
• Note: When creating icons and other bitmap images for your app, it's
important that you provide multiple versions that are each optimized
for a different screen density. This is discussed more in the lesson about
Supporting Different Screens.
If your app is using the Support Library
for compatibility on versions as low as Android 2.1, the showAsActionattribute
is not available from the android: namespace.
Instead this attribute is provided
by the Support Library and you must define your own XML namespace and use that
namespace as the attribute prefix.
(A custom XML namespace should be based on your
app name, but it can be any name you want and is only accessible within the scope
of the file in which you declare it.)
res/menu/main_activity_actions.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
yourapp:showAsAction="ifRoom" />
...
</menu>
Add the Actions to the Action Bar
To place the menu items into the action bar, implement
the onCreateOptionsMenu() callback method in your activity to
inflate the menu resource into the given Menu object.
For example:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
Respond to Action Buttons
When the user presses one of the action buttons or another
item in the action overflow, the system calls your
activity's onOptionsItemSelected() callback method.
In your implementation of this method, call getItemId() on
the given MenuItem to determine which item was pressed—the
returned ID matches the value you declared in the
corresponding <item> element's android:id attribute.
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
openSearch();
return true;
case R.id.action_settings:
openSettings();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
All screens in your app that are not the main entrance to your app
(activities that are not the "home" screen) should offer the user a way to
navigate to the logical parent screen in the app's hierarchy by pressing
the Up button in the action bar.
Add Up Button for Low-level Activities
When running on Android 4.1 (API level 16) or higher, or when using
ActionBarActivity from the Support Library, performing Upnavigation simply
requires that you declare the parent activity in the manifest file and enable
the Up button for the action bar.
For example, here's how you can declare an activity's parent in the
manifest:
<application ... >
...
<!-- The main/home activity (it has no parent activity) -->
<activity
android:name="com.example.myfirstapp.MainActivity" ...>
...
</activity>
<!-- A child of the main activity -->
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
Then enable the app icon as the Up button by
calling setDisplayHomeAsUpEnabled():
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_displaymessage);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// If your minSdkVersion is 11 or higher, instead use:
// getActionBar().setDisplayHomeAsUpEnabled(true);
}
Because the system now knows MainActivity is the parent activity for
DisplayMessageActivity, when the user presses the Up button,
the system navigates to the parent activity as appropriate—you do not
need to handle the Up button's event.
Chapter 2 lesson-1 adding the action bar

More Related Content

What's hot

android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
View groups containers
View groups containersView groups containers
View groups containersMani Selvaraj
 
Android Screen Containers & Layouts
Android Screen Containers & LayoutsAndroid Screen Containers & Layouts
Android Screen Containers & LayoutsVijay Rastogi
 
Lab: Developing with the extension library
Lab: Developing with the extension libraryLab: Developing with the extension library
Lab: Developing with the extension libraryWorkFlowStudios
 
CCI 2019 - PowerApps for Enterprise Developers
CCI 2019 - PowerApps for Enterprise DevelopersCCI 2019 - PowerApps for Enterprise Developers
CCI 2019 - PowerApps for Enterprise Developerswalk2talk srl
 
Android appwidget
Android appwidgetAndroid appwidget
Android appwidgetKrazy Koder
 
Android Training (Android UI)
Android Training (Android UI)Android Training (Android UI)
Android Training (Android UI)Khaled Anaqwa
 
Android Tutorials : Basic widgets
Android Tutorials : Basic widgetsAndroid Tutorials : Basic widgets
Android Tutorials : Basic widgetsPrajyot Mainkar
 
Lab: Mobile App Development with XPages and Extension Library
Lab:  Mobile App Development with XPages and Extension LibraryLab:  Mobile App Development with XPages and Extension Library
Lab: Mobile App Development with XPages and Extension LibraryWorkFlowStudios
 
11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16Niit Care
 
Android Material Design APIs/Tips
Android Material Design APIs/TipsAndroid Material Design APIs/Tips
Android Material Design APIs/TipsKen Yee
 
Android Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection WidgetAndroid Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection WidgetPrajyot Mainkar
 
1) workbench basics
1) workbench basics1) workbench basics
1) workbench basicstechbed
 
Web application development process
Web application development processWeb application development process
Web application development processJohn Smith
 
11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16Vivek chan
 

What's hot (20)

Android UI Patterns
Android UI PatternsAndroid UI Patterns
Android UI Patterns
 
Android development session 3 - layout
Android development   session 3 - layoutAndroid development   session 3 - layout
Android development session 3 - layout
 
android layouts
android layoutsandroid layouts
android layouts
 
View groups containers
View groups containersView groups containers
View groups containers
 
Android Screen Containers & Layouts
Android Screen Containers & LayoutsAndroid Screen Containers & Layouts
Android Screen Containers & Layouts
 
Lab: Developing with the extension library
Lab: Developing with the extension libraryLab: Developing with the extension library
Lab: Developing with the extension library
 
CCI 2019 - PowerApps for Enterprise Developers
CCI 2019 - PowerApps for Enterprise DevelopersCCI 2019 - PowerApps for Enterprise Developers
CCI 2019 - PowerApps for Enterprise Developers
 
Android appwidget
Android appwidgetAndroid appwidget
Android appwidget
 
Android Training (Android UI)
Android Training (Android UI)Android Training (Android UI)
Android Training (Android UI)
 
Android Tutorials : Basic widgets
Android Tutorials : Basic widgetsAndroid Tutorials : Basic widgets
Android Tutorials : Basic widgets
 
Lab: Mobile App Development with XPages and Extension Library
Lab:  Mobile App Development with XPages and Extension LibraryLab:  Mobile App Development with XPages and Extension Library
Lab: Mobile App Development with XPages and Extension Library
 
11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16
 
iOS Development (Part 2)
iOS Development (Part 2)iOS Development (Part 2)
iOS Development (Part 2)
 
Android Material Design APIs/Tips
Android Material Design APIs/TipsAndroid Material Design APIs/Tips
Android Material Design APIs/Tips
 
Android Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection WidgetAndroid Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection Widget
 
Material Design Android
Material Design AndroidMaterial Design Android
Material Design Android
 
1) workbench basics
1) workbench basics1) workbench basics
1) workbench basics
 
Android layouts
Android layoutsAndroid layouts
Android layouts
 
Web application development process
Web application development processWeb application development process
Web application development process
 
11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16
 

Viewers also liked

Performance Tuning en Azure SQL Database
Performance Tuning en Azure SQL DatabasePerformance Tuning en Azure SQL Database
Performance Tuning en Azure SQL DatabaseJoseph Lopez
 
Level Up Your Biml: Best Practices and Coding Techniques (TUGA IT 2016)
Level Up Your Biml: Best Practices and Coding Techniques (TUGA IT 2016)Level Up Your Biml: Best Practices and Coding Techniques (TUGA IT 2016)
Level Up Your Biml: Best Practices and Coding Techniques (TUGA IT 2016)Cathrine Wilhelmsen
 
Cinzia Battistella; Modeling a business ecosystem: a network analysis approach
Cinzia Battistella; Modeling a business ecosystem: a network analysis approachCinzia Battistella; Modeling a business ecosystem: a network analysis approach
Cinzia Battistella; Modeling a business ecosystem: a network analysis approachCBOD ANR project U-PSUD
 
Level Up Your Biml: Best Practices and Coding Techniques (NTK 2016)
Level Up Your Biml: Best Practices and Coding Techniques (NTK 2016)Level Up Your Biml: Best Practices and Coding Techniques (NTK 2016)
Level Up Your Biml: Best Practices and Coding Techniques (NTK 2016)Cathrine Wilhelmsen
 
Biml Academy 2 - Lesson 5: Importing source metadata into Biml
Biml Academy 2 - Lesson 5: Importing source metadata into BimlBiml Academy 2 - Lesson 5: Importing source metadata into Biml
Biml Academy 2 - Lesson 5: Importing source metadata into BimlCathrine Wilhelmsen
 
WiFi direct
WiFi directWiFi direct
WiFi directRoy Chen
 
Continuous Integration & Continuous Delivery on Android - Nur Rendra Toro Sin...
Continuous Integration & Continuous Delivery on Android - Nur Rendra Toro Sin...Continuous Integration & Continuous Delivery on Android - Nur Rendra Toro Sin...
Continuous Integration & Continuous Delivery on Android - Nur Rendra Toro Sin...Dicoding
 
COP21 and the Philippines - Updates from the DENR
COP21 and the Philippines - Updates from the DENRCOP21 and the Philippines - Updates from the DENR
COP21 and the Philippines - Updates from the DENREnP Ragene Andrea Palma
 
Firebase Auth Tutorial
Firebase Auth TutorialFirebase Auth Tutorial
Firebase Auth TutorialBukhori Aqid
 
DepEd Order no. 36 s. 2016
DepEd Order no. 36 s. 2016DepEd Order no. 36 s. 2016
DepEd Order no. 36 s. 2016Vera Salamat
 

Viewers also liked (15)

IoT Business Reality & Patent Development
IoT Business Reality & Patent DevelopmentIoT Business Reality & Patent Development
IoT Business Reality & Patent Development
 
IoT Disruptive Innovation & Patent Exploitation
IoT Disruptive Innovation & Patent ExploitationIoT Disruptive Innovation & Patent Exploitation
IoT Disruptive Innovation & Patent Exploitation
 
Startup Idea Pitching
Startup Idea PitchingStartup Idea Pitching
Startup Idea Pitching
 
Performance Tuning en Azure SQL Database
Performance Tuning en Azure SQL DatabasePerformance Tuning en Azure SQL Database
Performance Tuning en Azure SQL Database
 
Level Up Your Biml: Best Practices and Coding Techniques (TUGA IT 2016)
Level Up Your Biml: Best Practices and Coding Techniques (TUGA IT 2016)Level Up Your Biml: Best Practices and Coding Techniques (TUGA IT 2016)
Level Up Your Biml: Best Practices and Coding Techniques (TUGA IT 2016)
 
Cinzia Battistella; Modeling a business ecosystem: a network analysis approach
Cinzia Battistella; Modeling a business ecosystem: a network analysis approachCinzia Battistella; Modeling a business ecosystem: a network analysis approach
Cinzia Battistella; Modeling a business ecosystem: a network analysis approach
 
Level Up Your Biml: Best Practices and Coding Techniques (NTK 2016)
Level Up Your Biml: Best Practices and Coding Techniques (NTK 2016)Level Up Your Biml: Best Practices and Coding Techniques (NTK 2016)
Level Up Your Biml: Best Practices and Coding Techniques (NTK 2016)
 
Biml Academy 2 - Lesson 5: Importing source metadata into Biml
Biml Academy 2 - Lesson 5: Importing source metadata into BimlBiml Academy 2 - Lesson 5: Importing source metadata into Biml
Biml Academy 2 - Lesson 5: Importing source metadata into Biml
 
WiFi direct
WiFi directWiFi direct
WiFi direct
 
Continuous Integration & Continuous Delivery on Android - Nur Rendra Toro Sin...
Continuous Integration & Continuous Delivery on Android - Nur Rendra Toro Sin...Continuous Integration & Continuous Delivery on Android - Nur Rendra Toro Sin...
Continuous Integration & Continuous Delivery on Android - Nur Rendra Toro Sin...
 
COP21 and the Philippines - Updates from the DENR
COP21 and the Philippines - Updates from the DENRCOP21 and the Philippines - Updates from the DENR
COP21 and the Philippines - Updates from the DENR
 
Firebase Auth Tutorial
Firebase Auth TutorialFirebase Auth Tutorial
Firebase Auth Tutorial
 
17 Karakter yang Harus Dimiliki Seorang Entrepreneur
17 Karakter yang Harus Dimiliki Seorang Entrepreneur17 Karakter yang Harus Dimiliki Seorang Entrepreneur
17 Karakter yang Harus Dimiliki Seorang Entrepreneur
 
Patrick geddes theory
Patrick geddes theoryPatrick geddes theory
Patrick geddes theory
 
DepEd Order no. 36 s. 2016
DepEd Order no. 36 s. 2016DepEd Order no. 36 s. 2016
DepEd Order no. 36 s. 2016
 

Similar to Chapter 2 lesson-1 adding the action bar

Building a simple user interface lesson2
Building a simple user interface lesson2Building a simple user interface lesson2
Building a simple user interface lesson2Kalluri Vinay Reddy
 
Android apps development
Android apps developmentAndroid apps development
Android apps developmentMonir Zzaman
 
Learn Xamarin Absolute Beginners - Permissions, Building the App GUI & Menus
Learn Xamarin Absolute Beginners - Permissions, Building the App GUI & MenusLearn Xamarin Absolute Beginners - Permissions, Building the App GUI & Menus
Learn Xamarin Absolute Beginners - Permissions, Building the App GUI & MenusEng Teong Cheah
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Dr. Ramkumar Lakshminarayanan
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivitiesmaamir farooq
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activitiesmaamir farooq
 
Android Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidAndroid Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidDenis Minja
 
Android session 2-behestee
Android session 2-behesteeAndroid session 2-behestee
Android session 2-behesteeHussain Behestee
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android AppsGil Irizarry
 
android activity
android activityandroid activity
android activityDeepa Rani
 
Kotlin for Android App Development Presentation
Kotlin for Android App Development PresentationKotlin for Android App Development Presentation
Kotlin for Android App Development PresentationKnoldus Inc.
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul Karim
 

Similar to Chapter 2 lesson-1 adding the action bar (20)

Building a simple user interface lesson2
Building a simple user interface lesson2Building a simple user interface lesson2
Building a simple user interface lesson2
 
Twitter trends
Twitter trendsTwitter trends
Twitter trends
 
Android action bar and notifications-chapter16
Android action bar and notifications-chapter16Android action bar and notifications-chapter16
Android action bar and notifications-chapter16
 
Android Development Basics
Android Development BasicsAndroid Development Basics
Android Development Basics
 
Using android's action bar
Using android's action barUsing android's action bar
Using android's action bar
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Learn Xamarin Absolute Beginners - Permissions, Building the App GUI & Menus
Learn Xamarin Absolute Beginners - Permissions, Building the App GUI & MenusLearn Xamarin Absolute Beginners - Permissions, Building the App GUI & Menus
Learn Xamarin Absolute Beginners - Permissions, Building the App GUI & Menus
 
Ap quiz app
Ap quiz appAp quiz app
Ap quiz app
 
Android Programming.pptx
Android Programming.pptxAndroid Programming.pptx
Android Programming.pptx
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivities
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activities
 
Android menus in android-chapter15
Android menus in android-chapter15Android menus in android-chapter15
Android menus in android-chapter15
 
Android Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidAndroid Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_android
 
Android session 2-behestee
Android session 2-behesteeAndroid session 2-behestee
Android session 2-behestee
 
Android resources in android-chapter9
Android resources in android-chapter9Android resources in android-chapter9
Android resources in android-chapter9
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
 
android activity
android activityandroid activity
android activity
 
Kotlin for Android App Development Presentation
Kotlin for Android App Development PresentationKotlin for Android App Development Presentation
Kotlin for Android App Development Presentation
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
 

More from Kalluri Vinay Reddy (10)

Create an other activity lesson 3
Create an other activity lesson 3Create an other activity lesson 3
Create an other activity lesson 3
 
Social media marketing
Social media marketingSocial media marketing
Social media marketing
 
Data Centers and Internet
Data Centers and InternetData Centers and Internet
Data Centers and Internet
 
Frame relay
Frame relayFrame relay
Frame relay
 
web development basics tables part2
web development basics tables part2web development basics tables part2
web development basics tables part2
 
Web development basics 3
Web development basics 3Web development basics 3
Web development basics 3
 
Web development basics2
Web development basics2Web development basics2
Web development basics2
 
Android basic
Android basicAndroid basic
Android basic
 
Web development basics
Web development basicsWeb development basics
Web development basics
 
Inside Google
Inside Google Inside Google
Inside Google
 

Recently uploaded

Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 

Recently uploaded (20)

Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 

Chapter 2 lesson-1 adding the action bar

  • 1. By Kalluri Vinay Reddy Android Club www.facebook.com/vitccandroidclub Chapter-2 Adding the Action Bar lesson-1
  • 2. The action bar is one of the most important design elements you can implement for your app's activities. It provides several user interface features that make your app immediately familiar to users by offering consistency between other Android apps. Key functions include: A dedicated space for giving your app an identity and indicating the user's location in the app. Access to important actions in a predictable way (such as Search). Adding the Action Bar
  • 3. • Support for navigation and view switching (with tabs or drop-down lists). • This training class offers a quick guide to the action bar's basics.
  • 4. Lessons Setting Up the Action Bar Learn how to add a basic action bar to your activity, whether your app supports only Android 3.0 and higher or also supports versions as low as Android 2.1 (by using the Android Support Library). Adding Action Buttons Learn how to add and respond to user actions in the action bar. Styling the Action Bar Learn how to customize the appearance of your action bar. Overlaying the Action Bar Learn how to overlay the action bar in front of your layout, allowing for seamless transitions when hiding the action bar.
  • 5. • In its most basic form, the action bar displays the title for the activity and the app icon on the left. • Even in this simple form, the action bar is useful for all activities to inform users about where they are and to maintain a consistent identity for your app. Setting Up the Action Bar
  • 6. Support Android 3.0 and Above Only Beginning with Android 3.0 (API level 11), the action bar is included in all activities that use the Theme.Holotheme (or one of its descendants), which is the default theme when either the targetSdkVersion orminSdkVersion attribute is set to "11" or greater. So to add the action bar to your activities, simply set either attribute to 11 or higher. For example: <manifest ... > <uses-sdk android:minSdkVersion="11" ... /> ... </manifest>
  • 7. Support Android 2.1 and Above Adding the action bar when running on versions older than Android 3.0 (down to Android 2.1) requires that you include the Android Support Library in your application. To get started, read the Support Library Setup document and set up the v7 appcompat library (once you've downloaded the library package, follow the instructions for Adding libraries with resources). Once you have the Support Library integrated with your app project: 1.Update your activity so that it extends ActionBarActivity. 2. For example:public class MainActivity extends ActionBarActivity { ... } 2.In your manifest file, update either the <application> element or individual <activity> 3.elements to use one of the Theme.AppCompat themes. For example:<activity android:theme="@style/Theme.AppCompat.Light" ... >
  • 8. Note: If you've created a custom theme, be sure it uses one of the Theme.AppCompat themes as its parent. Styling the Action Bar. Now your activity includes the action bar when running on Android 2.1 (API level 7) or higher. Remember to properly set your app's API level support in the manifest: <manifest ... > <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="18" /> ... </manifest>
  • 9. The action bar allows you to add buttons for the most important action items relating to the app's current context. Those that appear directly in the action bar with an icon and/or text are known as action buttons. Actions that can't fit in the action bar or aren't important enough are hidden in the action overflow. Adding Action Buttons
  • 10. Action bar with an action button for Search and the action overflow, which reveals additional actions.
  • 11. Specify the Actions in XML All action buttons and other items available in the action overflow are defined in an XML menu resource. To add actions to the action bar, create a new XML file in your project's res/menu/ directory. Add an <item> element for each item you want to include in the action bar.
  • 12. res/menu/main_activity_actions.xml <menu xmlns:android="http://schemas.android.com/apk/res/android" > <!-- Search, should appear as action button --> <item android:id="@+id/action_search" android:icon="@drawable/ic_action_search" android:title="@string/action_search" android:showAsAction="ifRoom" /> <!-- Settings, should always be in the overflow --> <item android:id="@+id/action_settings" android:title="@string/action_settings" android:showAsAction="never" /> </menu>
  • 13. This declares that the Search action should appear as an action button when room is available in the action bar, but the Settings action should always appear in the overflow. (By default, all actions appear in the overflow, but it's good practice to explicitly declare your design intentions for each action.) The icon attribute requires a resource ID for an image. The name that follows @drawable/ must be the name of a bitmap image you've saved in your project's res/drawable/ directory.
  • 14. For example, "@drawable/ic_action_search“ refers to ic_action_search.png. Likewise, the title attribute uses a string resource that's defined by an XML file in your project's res/values/ directory, as discussed in Building a Simple User Interface.
  • 15. • Note: When creating icons and other bitmap images for your app, it's important that you provide multiple versions that are each optimized for a different screen density. This is discussed more in the lesson about Supporting Different Screens.
  • 16. If your app is using the Support Library for compatibility on versions as low as Android 2.1, the showAsActionattribute is not available from the android: namespace. Instead this attribute is provided by the Support Library and you must define your own XML namespace and use that namespace as the attribute prefix. (A custom XML namespace should be based on your app name, but it can be any name you want and is only accessible within the scope of the file in which you declare it.)
  • 17. res/menu/main_activity_actions.xml <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:yourapp="http://schemas.android.com/apk/res-auto" > <!-- Search, should appear as action button --> <item android:id="@+id/action_search" android:icon="@drawable/ic_action_search" android:title="@string/action_search" yourapp:showAsAction="ifRoom" /> ... </menu>
  • 18. Add the Actions to the Action Bar To place the menu items into the action bar, implement the onCreateOptionsMenu() callback method in your activity to inflate the menu resource into the given Menu object. For example: @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_activity_actions, menu); return super.onCreateOptionsMenu(menu); }
  • 19. Respond to Action Buttons When the user presses one of the action buttons or another item in the action overflow, the system calls your activity's onOptionsItemSelected() callback method. In your implementation of this method, call getItemId() on the given MenuItem to determine which item was pressed—the returned ID matches the value you declared in the corresponding <item> element's android:id attribute.
  • 20. @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_search: openSearch(); return true; case R.id.action_settings: openSettings(); return true; default: return super.onOptionsItemSelected(item); } }
  • 21. All screens in your app that are not the main entrance to your app (activities that are not the "home" screen) should offer the user a way to navigate to the logical parent screen in the app's hierarchy by pressing the Up button in the action bar. Add Up Button for Low-level Activities When running on Android 4.1 (API level 16) or higher, or when using ActionBarActivity from the Support Library, performing Upnavigation simply requires that you declare the parent activity in the manifest file and enable the Up button for the action bar.
  • 22. For example, here's how you can declare an activity's parent in the manifest: <application ... > ... <!-- The main/home activity (it has no parent activity) --> <activity android:name="com.example.myfirstapp.MainActivity" ...> ... </activity> <!-- A child of the main activity --> <activity android:name="com.example.myfirstapp.DisplayMessageActivity" android:label="@string/title_activity_display_message" android:parentActivityName="com.example.myfirstapp.MainActivity" > <!-- Parent activity meta-data to support 4.0 and lower --> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.example.myfirstapp.MainActivity" /> </activity> </application>
  • 23. Then enable the app icon as the Up button by calling setDisplayHomeAsUpEnabled(): @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_displaymessage); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // If your minSdkVersion is 11 or higher, instead use: // getActionBar().setDisplayHomeAsUpEnabled(true); }
  • 24. Because the system now knows MainActivity is the parent activity for DisplayMessageActivity, when the user presses the Up button, the system navigates to the parent activity as appropriate—you do not need to handle the Up button's event.