Hire everyone in this tutorial I run a touch about menus in Android.
So just click on this start in your Android studio project and for the application name just type in
an app 48 and then click on next and here choose API 16 Android 4.1 Jelly Bean and then click on next
and here choose empty activity next.
And here click on finish.
So now as you can see our project is actually created.
So now it's actually double click on this and this folder here.
And now I want to actually create a directory for my menu.
OK.
So just right click on this race for that new and then click on directory.
And for the name of our directory just type in here menu and then click on OK.
So here I have this menu directory.
So now I want to actually put our I took the XML file inside this menu for the menu that I want to use
in my application.
So just right click on the menu here new and then click on menu resource find.
OK.
And as you can see here now you need to specify our name for our menu.
So here I am just typing menu underlined made ok because I want this menu to be inside the inside the
main activity for my activity underline main that I examine.
So this is going to be the name menu underline main the source said should be made as you can see here
and the directory name must be menu.
OK.
And then click on it.
OK.
So here inside this menu directory I have this menu underline made that examen.
OK.
And here is my menu underlined minute example.
So here I can actually create create some items.
So here I can just open tag.
And as you can see here we have this group and we have this item.
So just select this item here and then our present space key on your keyboard.
And now I can actually for example specify an ID for my item.
For example the ID is going to be at sign Plus Id slash.
And here the is for example settings and here are just a present interview on your keyboard now I want
to specify a title for this idea.
For example I can just type in title and the title is going to be settings OK for this menu.
This is the title.
And now I need to actually close this item.
This item tag so i can just put this closing tag here and now as you can see I closed this item back.
So now I have this item here and now inside this main activity class we need to actually overwrite some
of the methods that are related to the menu.
So the first one is on create options menu as you can see here.
So just select it and press Enter key on your keyboard.
So as you can see here this is our Meffert the first of it and the second one is when the user clicks
on one of those items inside the menu.
So the second one is on item as you can see here on options item selected as you can see here.
So just select the second one on options item selected and then press on Enter key on your keyboard.
So here I have these two methods that are related to the menu.
So now let's actually run our project and see what happens.
So now as you can see our application is running on this emulator and we cannot see the menu inside
this action bar here.
So remember that this is the action board.
OK.
And here is the name of our application at 48 and here at the right side I want to see the menu actually
the menu button.
So in order to do that let's actually delete this line of code here on here as you can see inside this
uncreate options menu.
It is a line of code and inside this method to actually put my own logic here.
So here inside this uncreate options menu I can just type in the GET menu inflator.
OK.
So when this object here in order to actually put our menu are inside our action bar.
OK.
So as you can see here this is an action bar and I want to actually put the menu here.
So here I need to put this method here.
Get menu inflator dot inflate.
And here we need to actually specify two arguments.
The first one is the menu XML file that we created in our project.
So as you can see here in our project an insight is this fall that I have this race and have this a
menu directory and insight is menu.
I have this exemplified menu underline main that exemption.
So I need to refer to that XML file.
I just need to type in here are dots menu that may menu underline main.
OK comma and for the second argument I need to refer to this menu object that we receive as an argument
from the Smurfette uncreate options menu.
So here I can just type in menu.
So now let's actually as you can see here this Smurfette returns a boolean value.
So we need to return a boolean value so I can just type in here return to semicolon.
So let's run our project now and see what happens.
So now as you can see our application is running on this emulator here and here as you can see inside
this inside this action bar I have this menu button here.
So if I click on it and now we can see this item settings for this menu.
OK.
So inside this menu underline the example I created an item and I assigned an ID to this item.
And here is the title of this item settings for menu.
And here we can see these settings for this menu here.
So let's go back to our main activity the double file here and now I want to actually do something when
the user clicks on these settings for this menu but in here on this item.
OK.
So in order to do that let me actually delete this line of code here.
And as you can see we have this method and this if it returns a value of a boolean and this and the
name of this if it is an optional item selected.
And we have an argument of type menu item and the name of this argument is item.
So here we can specify that up which one of the items is actually selected by actually using this argument.
So in order to do that here I can just get the ID of the items that are inside this menu underline that
exemption.
So as you can see here I have this item here and the I.D. of this item is sitting as you can see here.
So inside this main activity that I here and inside is an options item selected in order to get that
ID again it just create an int variable.
Int ID the name of this variable is the assignment operator and that here and refer to the name of this
item that is of type menu item.
Right.
So I can't just type in an item that gets item ID.
So now I have that by the.