Hello Dad.
I'm Gaffigan.
And welcome back to where tutorials in today's with you we'll be talking about menu items.
So what is in many many ways is exactly what it sounds like.
It is an option to perform some action.
So let's create some menu items.
Let's start a new project
let's call our project a menu tutorials so menu tutorials that's on the next button.
Again we're going to keep on minimum as the guest of theme.
Why so that we can run our application although most hundred percent of the devices running Android
in the world.
Let's hit the next button.
Let's start with an immediate duty.
Let's call our first duty as main activity
well understood as a building up project.
So let's wait.
Well the projects build and it's ready to go.
So to define a menu item we need to define a menu for example file.
So let's do that.
So coming to up resources.
Let's create a new directory here.
So new directory let's call it menu.
And that's a low key button again right click on the menu directory new menu resource file.
Let's call it menu underscore brain activity so menu
main activity Dot.
Example building looks good.
Let's have the okay button.
Let's switch to tax mode.
So everything's ready.
So let's define a first menu item.
So I do.
Let's define the title do so.
Dido defined either what we need a string or that let's define a string for example.
So okay.
So let's define a string let's call it say a string on SDR user profile.
Let's call it to use profile.
Let's define another string.
Let's call it Share
OK.
So a star Cher Well the strings already so coming to our example file.
OK.
Let's use a string here.
So which was a star user profile.
Similarly let's define an I.D..
So let's call it menu user profile.
We're good to go.
Let's add another.
So I do.
Let's give it a title so as to your share.
Let's give it an idea.
So menu.
Sure.
OK.
Are menu items that are already coming to our may not go to Angela so to render this menu items we need
to implement the function.
Let's do that.
So on create options menu let's define a menu inflator here.
So the menu inflator let's call it inflator as it will do get menu inflator so many flavors just like
loud and fleeting.
So what it does is it helps you to inflate the menu items.
OK so let's use this later now so inflated or inflate that Menu menu may not do a deal.
And let's suppose the menu instance here which is menu.
So as you can see this line it's just like allowed inflator so loud inflated of inflate any of the lines
allowed under view.
So it's just like that and let's just return true because this function requires a balloon or don't
type.
OK.
So let's run an obligation and see
well our obligation is winning.
So let's have a look.
OK.
As you can see these three lights let's click on it and we can see our do menu items the profile and
share.
So when I click on it nothing happens.
So let's define the on the listener.
So these are coming back to our may not do a devout Java.
So for defining and link listeners we've got another function.
So let's implement that.
So on options item selected.
OK.
So let's define a switch case here because we've got multiple menu items.
So switch item dot get item I.D..
So we're switching on the basis of menu item.
OK.
Let's define the case.
So for the I.D. or ordered I.D. and there was menu user profile.
OK.
So that's generated those two.
So those that make text.
Let's parse the context so mean activity don't this.
Let's suppose the string so let's say clicked user profile.
Let's review the duration so let's short on this coalition function low on this function returns a boolean
type.
So let's return dot.
So return true.
Similarly let's define the case for our share.
So case dot I.T. menu share.
Let's define a dose for this as well.
So dosed may text context which has been activated on this.
Let's try the string so collect share.
Let's lower the duration so low and short and let's call it show function just like a low let's return
a boolean so let's say true.
Now let's define a default case.
And we're just going to use this one here
role or cleverness listeners already so that's on our application and see
what our obligation is running so let's have a look.
OK.
So when I click a little while it shows click usable file.
That's right.
I can share.
Well it shows check.
And now as you can see on menus are hidden with this dot dot dot.
So what if I want my menu item too visible on the screen all the time.
So let's try that.
So coming to our menu example file.
So we've got another attribute show as option.
So we've got multiple option here always collapsed if room never What text.
So let's say true.
So if there is enough room to show our menu item then it would be visible or else it would be hidden.
OK.
Similarly let's define it for Chef shows action if true.
Let's run an application and see the difference
well.
Our obligation is up and running.
So let's have a look as you can see both of our menu visible here.
They're working fine.
OK.
So no no one uses and takes menus anymore so let's replace the stakes with icons.
OK.
So when I need icons I go to Android so the studio and therefore I and multiple options.
So we're going to generate an auction bar generator.
OK.
Let's use this one for user profile.
Let's customizable it.
OK so we need a custom team.
Let's set it white or let's make it black.
OK.
So let's just download it.
Let's open the file.
OK.
Here as you can see they've got multiple folders so global GDP by MPI.
So this is GBI and the IDC to present the screen density so screen size somebody buys for medium sized
screens as we buy as high resolution screens X as she buys extra high resolution screens.
So basically devalues for small phones everyday API for families access GPI for tablets et cetera et
cetera.
So let's open the GPI.
Well let's hope it does on base it in our droid boats so control c come to our droid boats here and
that's pasted to OK.
Similarly let's get another I can further share so clipboard Bartlett's search again.
This one looks good.
Okay let's down a little bit.
We've got another or so let's open a gate so our associates as DPR and let's copy pasted or not Doyle's
okay.
So coming back to our project on many or eczema so let's just.
I consume so I can in the name of all I can was I see action around what's on for the shirt was I see
sorry I can I see.
Sure.
OK.
So let's run our application and see the changes
well thought applications running.
So let's have a look.
Allow as you can see the text is gone and we can see your icons here.
So if I click on this it shows is a profile and if I click on Show I can chose picture.
So that's all the menus.
If you have any doubts any queries feel free to draw up a common unreadable Twitter how good they like.