SlideShare une entreprise Scribd logo
1  sur  21
ActionBar
ActionBar
The Action Bar is the graphical component of each application
that identifies the navigated section, provide the user with the
possible actions for that section and defines the type of
navigation.
Action Bar
1. Icon that identifies the application
2. Available Shares
3. Menu overflow to other actions
ActionBar
The ActionBar has been added with Android 3.0. To make its
functionality available for all versions of Android, you must:
● Integrate the support library v7 and use:
import android.support.v7.app.ActionBar;
instead of:
import android.app.ActionBar;
● Extend ActionBarActivity class
● Declare a compatible theme for the Activity:
<activity android:theme="@style/Theme.AppCompat.Light" >
You can show or hide the ActionBar using:
getSupportActionBar().show();
getSupportActionBar().hide();
Support Action Bar
ActionBar
In order to add actions on the Action Bar actions must be defined
in /res/menu folder with an .xml file:
<menu
xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"/>
<item android:id="@+id/action_compose"
android:icon="@drawable/ic_action_compose"
android:title="@string/action_compose" />
</menu>
In Activity class you must override the onCreateOptionMenu()
method:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.actions, menu);
return true;
}
Action Items
ActionBar
The management of the actions and their visibility are entrusted
to the system which calculates the available space and adds
them according to the definition of the xml file. Adding the
showAsAction attribute in the menu you can manage the actions:
●
never:it is never shown
●
ifRoom: it's shown if there is enaough space available,
otherwise it is added to the overflow
●
always: it's always shown
<item
android:id="@+id/action_compose"
android:icon="@drawable/ic_action_compose"
android:showAsAction="ifRoom"/>
Action Items
ActionBar
When the user interacts with the Action Items the
Activity.onOptionsItemSelected() method is invoked :
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_search:
openSearch();
return true;
case R.id.action_compose:
composeMessage();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Action Items Selection
ActionBar
If the space for action is not enough, you can bring up an
extension on the bottom of the display in which Action Items are
shown.
To do so, you must add the following attribute to the Activity in the
Manifest:
android:uiOptions="splitActionBarWhenNarrow"
Split Action Bar
ActionBar
You can enable the up navigation by enabling the user to return to
a higher level of navigation. To do this, in onCreate() method it
must be entered:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
This enables clicking on the home icon and show the arrow.
Pattern: up the navigation and click on the back of the system do
not always get the same result:
●Back navigation: it shows the order in reverse chronological
navigation
●Up navigation: it shows hierarchically the higher level navigation
Up Navigation
ActionBar
In order to define the result of the up navigation through Activity,
there are 2 alternatives:
● You can defines the ParentActivity in Manifest for each
Activity:
android:parentActivityName="com.example.myfirstapp.MainActivity"
● You can override:
@Override
public Intent getSupportParentActivityIntent() {
return super.getSupportParentActivityIntent();
}
Up Navigation
ActionBar
The Action View is a widget that replaces the icon when the user
interacts with it. In order to declare an Action View you must add
the following in the menu file:
● android:actionLayout="@layout/search_view"
● android:actionViewClass="android.support.v7.widget.Sea
rchView"
Action View
ActionBar
An Action Provider as a ActionView replaces the button, but it has
complete control of the behavior of the Action.
To insert a Action Provider on the Action Bar You must add the
following attribute inside the menu xml file (there are predefined
by the ActionProvider platform, as ShareActionProvider):
android:actionProviderClass="android.support.v7.widget.ShareActionProvider"
To define a custom Action Provider you must extend
ActionProvider. In these cases it is not necessary to enter the
event management in Activity.onOptionsItemSelected(), but you
can use the ActionProvider.onPerformDefaultAction().
Action Provider
ActionBar
In a Custom Action Provider you must:
● Pass the Context to the costructor:
public CustomActionProvider(Context context) {
super(context);
}
● Define the Action View:
@Override
public View onCreateActionView() {
LayoutInflater inflater = LayoutInflater.from(getContext());
View view = inflater.inflate(R.layout.activity_main, null);
return view;
}
● Define the action:
@Override
public boolean onPerformDefaultAction() {
Intent intent = new Intent(Intent.ACTION_SEND);
getContext().startActivity(intent);
return true;
}
Action Provider
ActionBar
The Action Bar allows you to define a 3-tier Application
Navigation:
● Navigation Tabs: the user navigates between sections with
horizontal swype
● Drop-Down Menu: the user selects the title of the Action Bar
and a drop down menu appears with a list of available
sections
● Navigation Drawer: the user selects the application icon on
the Action Bar and an additional menu appears to the left
where the developer can put any type of View.
Navigation
ActionBar
The graphical management of the placement of the Tab is given
to the system that decides whether to include them as part of the
Action Bar or in a separate space.
Navigation - Tabs
To integrate the Activity with this type of navigation:
● Declare the Tab Navigation in Activity.onCreate():
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar
Navigation - Tabs
● Implement ActionBar.TabListener interface:
@Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
}
@Override
public void onTabSelected(Tab arg0, FragmentTransaction arg1) {
}
@Override
public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
}
● Add Tabs to the Action Bar in Activity.onCreate():
Tab tab = getSupportActionBar().newTab().setText(R.string.example)
.setTabListener(this);
getSupportActionBar().addTab(tab);
ActionBar
Navigation – DropDown Menu
The DropDown menu (or Spinner) is used when it is not
frequently change the contents of the Activity.
ActionBar
Navigation – DropDown Menu
In order to integrate it:
● Declare List Navigation in Activity.onCreate():
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
● Create a SpinnerAdapter:
SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this,
R.array.action_list,
android.R.layout.simple_spinner_dropdown_item);
● Implements ActionBar.OnNavigationListener:
@Override
public boolean onNavigationItemSelected(int position, long itemId) {
return true;
}
● Set the callbacks to handle Action Bar click:
getSupportActionBar().setListNavigationCallbacks(spinnerAdapter,
navigationCallback);
ActionBar
Navigation – Drawer
The Navigation Drawer is a panel that appears to the left as the
user selects the icon for the Action Bar and shows you the
navigation options.
ActionBar
Navigation – Drawer
In order to integrate it:
● Insert a DrawerLayout as Activity layout root:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start" />
</android.support.v4.widget.DrawerLayout>
ActionBar
Navigation – Drawer
● Retrieve Activity DrawerLayout and ListView:
DrawerLayout mDrawerLayout = (DrawerLayout)
findViewById(R.id.drawer_layout);
ListView mDrawerList = (ListView) findViewById(R.id.left_drawer);
● Set an Adapter to the list:
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, mPlanetTitles));
● Handle the on item clicks of the list:
mDrawerList.setOnItemClickListener(this);
It is possible to handle the Navigation Drawer opening/closing
events:
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,
mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open,
R.string.drawer_close) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
ActionBar
Action Bar Style
In order to customize the Action Bar you can use styles in
/res/values file.
<resources>
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">@style/TabTextStyle</item>
<item name="android:actionMenuTextColor">@color/actionbar_text</item>
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="actionBarTabTextStyle">@style/TabTextStyle</item>
<item name="actionMenuTextColor">@color/actionbar_text</item>
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">@style/TitleTextStyle</item>
<item name="android:background">@drawable/actionbar_background</item>
<item name="android:backgroundStacked">@drawable/actionbar_background</item>
<item name="android:backgroundSplit">@drawable/actionbar_background</item>
<item name="titleTextStyle">@style/TitleTextStyle</item>
<item name="background">@drawable/actionbar_background</item>
<item name="backgroundStacked">@drawable/actionbar_background</item>
<item name="backgroundSplit">@drawable/actionbar_background</item>
</style>
<style name="TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/actionbar_text</item>
</style>
<style name="TabTextStyle" parent="@style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">@color/actionbar_text</item>
</style>
</resources>

Contenu connexe

Tendances (20)

Fragment
Fragment Fragment
Fragment
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Android styles and themes
Android styles and themesAndroid styles and themes
Android styles and themes
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
 
Xhtml
XhtmlXhtml
Xhtml
 
Layouts in android
Layouts in androidLayouts in android
Layouts in android
 
Android resources
Android resourcesAndroid resources
Android resources
 
DTD
DTDDTD
DTD
 
Introduction to Android Fragments
Introduction to Android FragmentsIntroduction to Android Fragments
Introduction to Android Fragments
 
Android ui dialog
Android ui dialogAndroid ui dialog
Android ui dialog
 
Distributed database
Distributed databaseDistributed database
Distributed database
 
Android resource
Android resourceAndroid resource
Android resource
 
Android User Interface
Android User InterfaceAndroid User Interface
Android User Interface
 
java swing
java swingjava swing
java swing
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
 
Data dictionary
Data dictionaryData dictionary
Data dictionary
 
4.C#
4.C#4.C#
4.C#
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptx
 
Bootstrap PPT Part - 2
Bootstrap PPT Part - 2Bootstrap PPT Part - 2
Bootstrap PPT Part - 2
 
HTML: Tables and Forms
HTML: Tables and FormsHTML: Tables and Forms
HTML: Tables and Forms
 

Similaire à Android App Development - 05 Action bar

Android Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompatAndroid Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompatcbeyls
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in AndroidRobert Cooper
 
Advancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and GesturesAdvancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and GesturesSamsung Developers
 
Android Sliding Menu dengan Navigation Drawer
Android Sliding Menu dengan Navigation DrawerAndroid Sliding Menu dengan Navigation Drawer
Android Sliding Menu dengan Navigation DrawerAgus Haryanto
 
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 barKalluri Vinay Reddy
 
Android App Development - 04 Views and layouts
Android App Development - 04 Views and layoutsAndroid App Development - 04 Views and layouts
Android App Development - 04 Views and layoutsDiego Grancini
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developersPavel Lahoda
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon Berlin
 
Adopting 3D Touch in your apps
Adopting 3D Touch in your appsAdopting 3D Touch in your apps
Adopting 3D Touch in your appsJuan C Catalan
 
Design Patterns for Tablets and Smartphones
Design Patterns for Tablets and SmartphonesDesign Patterns for Tablets and Smartphones
Design Patterns for Tablets and SmartphonesMichael Galpin
 
Android animations
Android animationsAndroid animations
Android animationsKumar
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
Navigation Architecture Component(京都Devかふぇ バージョン)
Navigation Architecture Component(京都Devかふぇ バージョン)Navigation Architecture Component(京都Devかふぇ バージョン)
Navigation Architecture Component(京都Devかふぇ バージョン)Yasutaka Kawamoto
 
A Single activity app with Jetpack's Navigation Component
A Single activity app with Jetpack's Navigation ComponentA Single activity app with Jetpack's Navigation Component
A Single activity app with Jetpack's Navigation ComponentBoonya Kitpitak
 
Android apps development
Android apps developmentAndroid apps development
Android apps developmentMonir Zzaman
 
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, PepperThe Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, PepperDroidConTLV
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJSRajthilakMCA
 

Similaire à Android App Development - 05 Action bar (20)

Android 3
Android 3Android 3
Android 3
 
Android Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompatAndroid Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompat
 
Action bar
Action barAction bar
Action bar
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in Android
 
Android action bar and notifications-chapter16
Android action bar and notifications-chapter16Android action bar and notifications-chapter16
Android action bar and notifications-chapter16
 
Advancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and GesturesAdvancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and Gestures
 
Android Sliding Menu dengan Navigation Drawer
Android Sliding Menu dengan Navigation DrawerAndroid Sliding Menu dengan Navigation Drawer
Android Sliding Menu dengan Navigation Drawer
 
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 App Development - 04 Views and layouts
Android App Development - 04 Views and layoutsAndroid App Development - 04 Views and layouts
Android App Development - 04 Views and layouts
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developers
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
 
Adopting 3D Touch in your apps
Adopting 3D Touch in your appsAdopting 3D Touch in your apps
Adopting 3D Touch in your apps
 
Design Patterns for Tablets and Smartphones
Design Patterns for Tablets and SmartphonesDesign Patterns for Tablets and Smartphones
Design Patterns for Tablets and Smartphones
 
Android animations
Android animationsAndroid animations
Android animations
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Navigation Architecture Component(京都Devかふぇ バージョン)
Navigation Architecture Component(京都Devかふぇ バージョン)Navigation Architecture Component(京都Devかふぇ バージョン)
Navigation Architecture Component(京都Devかふぇ バージョン)
 
A Single activity app with Jetpack's Navigation Component
A Single activity app with Jetpack's Navigation ComponentA Single activity app with Jetpack's Navigation Component
A Single activity app with Jetpack's Navigation Component
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, PepperThe Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
 

Plus de Diego Grancini

Android App Development - 14 location, media and notifications
Android App Development - 14 location, media and notificationsAndroid App Development - 14 location, media and notifications
Android App Development - 14 location, media and notificationsDiego Grancini
 
Android App Development - 13 Broadcast receivers and app widgets
Android App Development - 13 Broadcast receivers and app widgetsAndroid App Development - 13 Broadcast receivers and app widgets
Android App Development - 13 Broadcast receivers and app widgetsDiego Grancini
 
Android App Development - 12 animations
Android App Development - 12 animationsAndroid App Development - 12 animations
Android App Development - 12 animationsDiego Grancini
 
Android App Development - 11 Lists, grids, adapters, dialogs and toasts
Android App Development - 11 Lists, grids, adapters, dialogs and toastsAndroid App Development - 11 Lists, grids, adapters, dialogs and toasts
Android App Development - 11 Lists, grids, adapters, dialogs and toastsDiego Grancini
 
Android App Development - 10 Content providers
Android App Development - 10 Content providersAndroid App Development - 10 Content providers
Android App Development - 10 Content providersDiego Grancini
 
Android App Development - 09 Storage
Android App Development - 09 StorageAndroid App Development - 09 Storage
Android App Development - 09 StorageDiego Grancini
 
Android App Development - 08 Services
Android App Development - 08 ServicesAndroid App Development - 08 Services
Android App Development - 08 ServicesDiego Grancini
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 ThreadingDiego Grancini
 
Android App Development - 06 Fragments
Android App Development - 06 FragmentsAndroid App Development - 06 Fragments
Android App Development - 06 FragmentsDiego Grancini
 
Android App Development - 03 Resources
Android App Development - 03 ResourcesAndroid App Development - 03 Resources
Android App Development - 03 ResourcesDiego Grancini
 
Android App Development - 02 Activity and intent
Android App Development - 02 Activity and intentAndroid App Development - 02 Activity and intent
Android App Development - 02 Activity and intentDiego Grancini
 
Android App Development - 01 Introduction
Android App Development - 01 IntroductionAndroid App Development - 01 Introduction
Android App Development - 01 IntroductionDiego Grancini
 

Plus de Diego Grancini (12)

Android App Development - 14 location, media and notifications
Android App Development - 14 location, media and notificationsAndroid App Development - 14 location, media and notifications
Android App Development - 14 location, media and notifications
 
Android App Development - 13 Broadcast receivers and app widgets
Android App Development - 13 Broadcast receivers and app widgetsAndroid App Development - 13 Broadcast receivers and app widgets
Android App Development - 13 Broadcast receivers and app widgets
 
Android App Development - 12 animations
Android App Development - 12 animationsAndroid App Development - 12 animations
Android App Development - 12 animations
 
Android App Development - 11 Lists, grids, adapters, dialogs and toasts
Android App Development - 11 Lists, grids, adapters, dialogs and toastsAndroid App Development - 11 Lists, grids, adapters, dialogs and toasts
Android App Development - 11 Lists, grids, adapters, dialogs and toasts
 
Android App Development - 10 Content providers
Android App Development - 10 Content providersAndroid App Development - 10 Content providers
Android App Development - 10 Content providers
 
Android App Development - 09 Storage
Android App Development - 09 StorageAndroid App Development - 09 Storage
Android App Development - 09 Storage
 
Android App Development - 08 Services
Android App Development - 08 ServicesAndroid App Development - 08 Services
Android App Development - 08 Services
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 Threading
 
Android App Development - 06 Fragments
Android App Development - 06 FragmentsAndroid App Development - 06 Fragments
Android App Development - 06 Fragments
 
Android App Development - 03 Resources
Android App Development - 03 ResourcesAndroid App Development - 03 Resources
Android App Development - 03 Resources
 
Android App Development - 02 Activity and intent
Android App Development - 02 Activity and intentAndroid App Development - 02 Activity and intent
Android App Development - 02 Activity and intent
 
Android App Development - 01 Introduction
Android App Development - 01 IntroductionAndroid App Development - 01 Introduction
Android App Development - 01 Introduction
 

Dernier

哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...wyqazy
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Niamh verma
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPsychicRuben LoveSpells
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRnishacall1
 

Dernier (9)

哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
 
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 

Android App Development - 05 Action bar

  • 2. ActionBar The Action Bar is the graphical component of each application that identifies the navigated section, provide the user with the possible actions for that section and defines the type of navigation. Action Bar 1. Icon that identifies the application 2. Available Shares 3. Menu overflow to other actions
  • 3. ActionBar The ActionBar has been added with Android 3.0. To make its functionality available for all versions of Android, you must: ● Integrate the support library v7 and use: import android.support.v7.app.ActionBar; instead of: import android.app.ActionBar; ● Extend ActionBarActivity class ● Declare a compatible theme for the Activity: <activity android:theme="@style/Theme.AppCompat.Light" > You can show or hide the ActionBar using: getSupportActionBar().show(); getSupportActionBar().hide(); Support Action Bar
  • 4. ActionBar In order to add actions on the Action Bar actions must be defined in /res/menu folder with an .xml file: <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/action_search" android:icon="@drawable/ic_action_search" android:title="@string/action_search"/> <item android:id="@+id/action_compose" android:icon="@drawable/ic_action_compose" android:title="@string/action_compose" /> </menu> In Activity class you must override the onCreateOptionMenu() method: @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.actions, menu); return true; } Action Items
  • 5. ActionBar The management of the actions and their visibility are entrusted to the system which calculates the available space and adds them according to the definition of the xml file. Adding the showAsAction attribute in the menu you can manage the actions: ● never:it is never shown ● ifRoom: it's shown if there is enaough space available, otherwise it is added to the overflow ● always: it's always shown <item android:id="@+id/action_compose" android:icon="@drawable/ic_action_compose" android:showAsAction="ifRoom"/> Action Items
  • 6. ActionBar When the user interacts with the Action Items the Activity.onOptionsItemSelected() method is invoked : @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_search: openSearch(); return true; case R.id.action_compose: composeMessage(); return true; default: return super.onOptionsItemSelected(item); } } Action Items Selection
  • 7. ActionBar If the space for action is not enough, you can bring up an extension on the bottom of the display in which Action Items are shown. To do so, you must add the following attribute to the Activity in the Manifest: android:uiOptions="splitActionBarWhenNarrow" Split Action Bar
  • 8. ActionBar You can enable the up navigation by enabling the user to return to a higher level of navigation. To do this, in onCreate() method it must be entered: getSupportActionBar().setDisplayHomeAsUpEnabled(true); This enables clicking on the home icon and show the arrow. Pattern: up the navigation and click on the back of the system do not always get the same result: ●Back navigation: it shows the order in reverse chronological navigation ●Up navigation: it shows hierarchically the higher level navigation Up Navigation
  • 9. ActionBar In order to define the result of the up navigation through Activity, there are 2 alternatives: ● You can defines the ParentActivity in Manifest for each Activity: android:parentActivityName="com.example.myfirstapp.MainActivity" ● You can override: @Override public Intent getSupportParentActivityIntent() { return super.getSupportParentActivityIntent(); } Up Navigation
  • 10. ActionBar The Action View is a widget that replaces the icon when the user interacts with it. In order to declare an Action View you must add the following in the menu file: ● android:actionLayout="@layout/search_view" ● android:actionViewClass="android.support.v7.widget.Sea rchView" Action View
  • 11. ActionBar An Action Provider as a ActionView replaces the button, but it has complete control of the behavior of the Action. To insert a Action Provider on the Action Bar You must add the following attribute inside the menu xml file (there are predefined by the ActionProvider platform, as ShareActionProvider): android:actionProviderClass="android.support.v7.widget.ShareActionProvider" To define a custom Action Provider you must extend ActionProvider. In these cases it is not necessary to enter the event management in Activity.onOptionsItemSelected(), but you can use the ActionProvider.onPerformDefaultAction(). Action Provider
  • 12. ActionBar In a Custom Action Provider you must: ● Pass the Context to the costructor: public CustomActionProvider(Context context) { super(context); } ● Define the Action View: @Override public View onCreateActionView() { LayoutInflater inflater = LayoutInflater.from(getContext()); View view = inflater.inflate(R.layout.activity_main, null); return view; } ● Define the action: @Override public boolean onPerformDefaultAction() { Intent intent = new Intent(Intent.ACTION_SEND); getContext().startActivity(intent); return true; } Action Provider
  • 13. ActionBar The Action Bar allows you to define a 3-tier Application Navigation: ● Navigation Tabs: the user navigates between sections with horizontal swype ● Drop-Down Menu: the user selects the title of the Action Bar and a drop down menu appears with a list of available sections ● Navigation Drawer: the user selects the application icon on the Action Bar and an additional menu appears to the left where the developer can put any type of View. Navigation
  • 14. ActionBar The graphical management of the placement of the Tab is given to the system that decides whether to include them as part of the Action Bar or in a separate space. Navigation - Tabs To integrate the Activity with this type of navigation: ● Declare the Tab Navigation in Activity.onCreate(): getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  • 15. ActionBar Navigation - Tabs ● Implement ActionBar.TabListener interface: @Override public void onTabReselected(Tab arg0, FragmentTransaction arg1) { } @Override public void onTabSelected(Tab arg0, FragmentTransaction arg1) { } @Override public void onTabUnselected(Tab arg0, FragmentTransaction arg1) { } ● Add Tabs to the Action Bar in Activity.onCreate(): Tab tab = getSupportActionBar().newTab().setText(R.string.example) .setTabListener(this); getSupportActionBar().addTab(tab);
  • 16. ActionBar Navigation – DropDown Menu The DropDown menu (or Spinner) is used when it is not frequently change the contents of the Activity.
  • 17. ActionBar Navigation – DropDown Menu In order to integrate it: ● Declare List Navigation in Activity.onCreate(): getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); ● Create a SpinnerAdapter: SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.action_list, android.R.layout.simple_spinner_dropdown_item); ● Implements ActionBar.OnNavigationListener: @Override public boolean onNavigationItemSelected(int position, long itemId) { return true; } ● Set the callbacks to handle Action Bar click: getSupportActionBar().setListNavigationCallbacks(spinnerAdapter, navigationCallback);
  • 18. ActionBar Navigation – Drawer The Navigation Drawer is a panel that appears to the left as the user selects the icon for the Action Bar and shows you the navigation options.
  • 19. ActionBar Navigation – Drawer In order to integrate it: ● Insert a DrawerLayout as Activity layout root: <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" /> </android.support.v4.widget.DrawerLayout>
  • 20. ActionBar Navigation – Drawer ● Retrieve Activity DrawerLayout and ListView: DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); ListView mDrawerList = (ListView) findViewById(R.id.left_drawer); ● Set an Adapter to the list: mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles)); ● Handle the on item clicks of the list: mDrawerList.setOnItemClickListener(this); It is possible to handle the Navigation Drawer opening/closing events: ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { public void onDrawerClosed(View view) { super.onDrawerClosed(view); } public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); } }; mDrawerLayout.setDrawerListener(mDrawerToggle);
  • 21. ActionBar Action Bar Style In order to customize the Action Bar you can use styles in /res/values file. <resources> <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light"> <item name="android:actionBarStyle">@style/MyActionBar</item> <item name="android:actionBarTabTextStyle">@style/TabTextStyle</item> <item name="android:actionMenuTextColor">@color/actionbar_text</item> <item name="actionBarStyle">@style/MyActionBar</item> <item name="actionBarTabTextStyle">@style/TabTextStyle</item> <item name="actionMenuTextColor">@color/actionbar_text</item> </style> <style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar"> <item name="android:titleTextStyle">@style/TitleTextStyle</item> <item name="android:background">@drawable/actionbar_background</item> <item name="android:backgroundStacked">@drawable/actionbar_background</item> <item name="android:backgroundSplit">@drawable/actionbar_background</item> <item name="titleTextStyle">@style/TitleTextStyle</item> <item name="background">@drawable/actionbar_background</item> <item name="backgroundStacked">@drawable/actionbar_background</item> <item name="backgroundSplit">@drawable/actionbar_background</item> </style> <style name="TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"> <item name="android:textColor">@color/actionbar_text</item> </style> <style name="TabTextStyle" parent="@style/Widget.AppCompat.ActionBar.TabText"> <item name="android:textColor">@color/actionbar_text</item> </style> </resources>