1 00:00:01,260 --> 00:00:01,770 Hello Dad. 2 00:00:02,100 --> 00:00:02,910 I'm Gaffigan. 3 00:00:02,910 --> 00:00:08,570 And welcome back to where tutorials in today's with you we'll be talking about menu items. 4 00:00:08,610 --> 00:00:12,650 So what is in many many ways is exactly what it sounds like. 5 00:00:12,750 --> 00:00:15,060 It is an option to perform some action. 6 00:00:15,660 --> 00:00:17,830 So let's create some menu items. 7 00:00:18,150 --> 00:00:19,400 Let's start a new project 8 00:00:23,150 --> 00:00:30,770 let's call our project a menu tutorials so menu tutorials that's on the next button. 9 00:00:32,470 --> 00:00:35,580 Again we're going to keep on minimum as the guest of theme. 10 00:00:35,640 --> 00:00:40,300 Why so that we can run our application although most hundred percent of the devices running Android 11 00:00:40,360 --> 00:00:41,070 in the world. 12 00:00:41,500 --> 00:00:44,050 Let's hit the next button. 13 00:00:44,240 --> 00:00:45,900 Let's start with an immediate duty. 14 00:00:46,940 --> 00:00:49,730 Let's call our first duty as main activity 15 00:00:54,770 --> 00:00:56,710 well understood as a building up project. 16 00:00:56,770 --> 00:00:58,420 So let's wait. 17 00:00:58,420 --> 00:01:00,820 Well the projects build and it's ready to go. 18 00:01:01,210 --> 00:01:05,240 So to define a menu item we need to define a menu for example file. 19 00:01:05,530 --> 00:01:06,460 So let's do that. 20 00:01:06,940 --> 00:01:09,570 So coming to up resources. 21 00:01:09,670 --> 00:01:11,380 Let's create a new directory here. 22 00:01:11,850 --> 00:01:16,160 So new directory let's call it menu. 23 00:01:16,630 --> 00:01:23,470 And that's a low key button again right click on the menu directory new menu resource file. 24 00:01:23,650 --> 00:01:27,670 Let's call it menu underscore brain activity so menu 25 00:01:30,220 --> 00:01:33,290 main activity Dot. 26 00:01:33,560 --> 00:01:35,060 Example building looks good. 27 00:01:35,100 --> 00:01:38,780 Let's have the okay button. 28 00:01:39,000 --> 00:01:40,370 Let's switch to tax mode. 29 00:01:40,860 --> 00:01:41,970 So everything's ready. 30 00:01:42,000 --> 00:01:43,650 So let's define a first menu item. 31 00:01:43,890 --> 00:01:45,510 So I do. 32 00:01:46,440 --> 00:01:48,290 Let's define the title do so. 33 00:01:48,310 --> 00:01:53,400 Dido defined either what we need a string or that let's define a string for example. 34 00:01:53,850 --> 00:01:56,230 So okay. 35 00:01:57,280 --> 00:02:05,810 So let's define a string let's call it say a string on SDR user profile. 36 00:02:05,920 --> 00:02:07,300 Let's call it to use profile. 37 00:02:09,460 --> 00:02:11,180 Let's define another string. 38 00:02:11,800 --> 00:02:14,380 Let's call it Share 39 00:02:18,530 --> 00:02:19,370 OK. 40 00:02:21,040 --> 00:02:27,800 So a star Cher Well the strings already so coming to our example file. 41 00:02:28,330 --> 00:02:28,780 OK. 42 00:02:28,790 --> 00:02:29,930 Let's use a string here. 43 00:02:29,930 --> 00:02:32,180 So which was a star user profile. 44 00:02:32,810 --> 00:02:34,970 Similarly let's define an I.D.. 45 00:02:35,270 --> 00:02:39,530 So let's call it menu user profile. 46 00:02:40,790 --> 00:02:41,600 We're good to go. 47 00:02:42,230 --> 00:02:43,120 Let's add another. 48 00:02:43,670 --> 00:02:44,610 So I do. 49 00:02:46,160 --> 00:02:50,020 Let's give it a title so as to your share. 50 00:02:50,120 --> 00:02:51,400 Let's give it an idea. 51 00:02:52,400 --> 00:02:54,640 So menu. 52 00:02:54,880 --> 00:02:56,430 Sure. 53 00:02:59,390 --> 00:03:00,090 OK. 54 00:03:00,220 --> 00:03:08,760 Are menu items that are already coming to our may not go to Angela so to render this menu items we need 55 00:03:08,770 --> 00:03:10,440 to implement the function. 56 00:03:11,140 --> 00:03:11,900 Let's do that. 57 00:03:12,340 --> 00:03:17,250 So on create options menu let's define a menu inflator here. 58 00:03:17,260 --> 00:03:25,150 So the menu inflator let's call it inflator as it will do get menu inflator so many flavors just like 59 00:03:25,150 --> 00:03:26,020 loud and fleeting. 60 00:03:26,680 --> 00:03:30,290 So what it does is it helps you to inflate the menu items. 61 00:03:30,920 --> 00:03:37,960 OK so let's use this later now so inflated or inflate that Menu menu may not do a deal. 62 00:03:38,530 --> 00:03:41,320 And let's suppose the menu instance here which is menu. 63 00:03:41,770 --> 00:03:48,360 So as you can see this line it's just like allowed inflator so loud inflated of inflate any of the lines 64 00:03:48,400 --> 00:03:50,090 allowed under view. 65 00:03:50,320 --> 00:03:57,870 So it's just like that and let's just return true because this function requires a balloon or don't 66 00:03:57,870 --> 00:03:58,200 type. 67 00:03:58,930 --> 00:03:59,750 OK. 68 00:03:59,890 --> 00:04:02,050 So let's run an obligation and see 69 00:04:06,830 --> 00:04:08,420 well our obligation is winning. 70 00:04:08,450 --> 00:04:09,620 So let's have a look. 71 00:04:10,030 --> 00:04:10,730 OK. 72 00:04:10,760 --> 00:04:17,400 As you can see these three lights let's click on it and we can see our do menu items the profile and 73 00:04:17,900 --> 00:04:19,190 share. 74 00:04:19,250 --> 00:04:21,610 So when I click on it nothing happens. 75 00:04:21,650 --> 00:04:23,300 So let's define the on the listener. 76 00:04:23,300 --> 00:04:27,210 So these are coming back to our may not do a devout Java. 77 00:04:27,770 --> 00:04:30,980 So for defining and link listeners we've got another function. 78 00:04:31,310 --> 00:04:32,860 So let's implement that. 79 00:04:33,130 --> 00:04:35,860 So on options item selected. 80 00:04:36,580 --> 00:04:37,090 OK. 81 00:04:37,550 --> 00:04:41,500 So let's define a switch case here because we've got multiple menu items. 82 00:04:42,080 --> 00:04:45,610 So switch item dot get item I.D.. 83 00:04:46,040 --> 00:04:49,790 So we're switching on the basis of menu item. 84 00:04:50,210 --> 00:04:50,820 OK. 85 00:04:51,320 --> 00:04:52,480 Let's define the case. 86 00:04:52,970 --> 00:04:58,360 So for the I.D. or ordered I.D. and there was menu user profile. 87 00:04:59,300 --> 00:04:59,570 OK. 88 00:04:59,600 --> 00:05:01,490 So that's generated those two. 89 00:05:01,670 --> 00:05:04,250 So those that make text. 90 00:05:04,250 --> 00:05:08,330 Let's parse the context so mean activity don't this. 91 00:05:08,480 --> 00:05:15,230 Let's suppose the string so let's say clicked user profile. 92 00:05:16,460 --> 00:05:25,820 Let's review the duration so let's short on this coalition function low on this function returns a boolean 93 00:05:25,820 --> 00:05:26,120 type. 94 00:05:26,120 --> 00:05:27,500 So let's return dot. 95 00:05:27,760 --> 00:05:29,320 So return true. 96 00:05:29,810 --> 00:05:32,640 Similarly let's define the case for our share. 97 00:05:32,870 --> 00:05:36,580 So case dot I.T. menu share. 98 00:05:37,340 --> 00:05:38,860 Let's define a dose for this as well. 99 00:05:38,870 --> 00:05:44,940 So dosed may text context which has been activated on this. 100 00:05:44,990 --> 00:05:50,600 Let's try the string so collect share. 101 00:05:51,560 --> 00:05:57,860 Let's lower the duration so low and short and let's call it show function just like a low let's return 102 00:05:58,190 --> 00:06:00,320 a boolean so let's say true. 103 00:06:00,350 --> 00:06:02,260 Now let's define a default case. 104 00:06:03,010 --> 00:06:04,550 And we're just going to use this one here 105 00:06:07,790 --> 00:06:11,580 role or cleverness listeners already so that's on our application and see 106 00:06:14,480 --> 00:06:17,080 what our obligation is running so let's have a look. 107 00:06:17,900 --> 00:06:19,170 OK. 108 00:06:19,330 --> 00:06:22,810 So when I click a little while it shows click usable file. 109 00:06:23,020 --> 00:06:23,530 That's right. 110 00:06:23,560 --> 00:06:24,220 I can share. 111 00:06:25,030 --> 00:06:26,400 Well it shows check. 112 00:06:27,250 --> 00:06:30,850 And now as you can see on menus are hidden with this dot dot dot. 113 00:06:31,420 --> 00:06:34,820 So what if I want my menu item too visible on the screen all the time. 114 00:06:34,840 --> 00:06:36,280 So let's try that. 115 00:06:36,370 --> 00:06:39,070 So coming to our menu example file. 116 00:06:39,490 --> 00:06:42,800 So we've got another attribute show as option. 117 00:06:42,820 --> 00:06:48,460 So we've got multiple option here always collapsed if room never What text. 118 00:06:48,460 --> 00:06:49,940 So let's say true. 119 00:06:50,170 --> 00:06:56,020 So if there is enough room to show our menu item then it would be visible or else it would be hidden. 120 00:06:56,590 --> 00:06:57,040 OK. 121 00:06:57,370 --> 00:07:03,160 Similarly let's define it for Chef shows action if true. 122 00:07:03,530 --> 00:07:05,540 Let's run an application and see the difference 123 00:07:08,800 --> 00:07:09,440 well. 124 00:07:09,660 --> 00:07:11,140 Our obligation is up and running. 125 00:07:11,200 --> 00:07:18,420 So let's have a look as you can see both of our menu visible here. 126 00:07:19,000 --> 00:07:21,100 They're working fine. 127 00:07:21,880 --> 00:07:22,340 OK. 128 00:07:22,380 --> 00:07:28,680 So no no one uses and takes menus anymore so let's replace the stakes with icons. 129 00:07:28,980 --> 00:07:29,390 OK. 130 00:07:30,450 --> 00:07:41,260 So when I need icons I go to Android so the studio and therefore I and multiple options. 131 00:07:41,260 --> 00:07:45,100 So we're going to generate an auction bar generator. 132 00:07:46,020 --> 00:07:47,510 OK. 133 00:07:47,890 --> 00:07:50,890 Let's use this one for user profile. 134 00:07:51,490 --> 00:07:52,610 Let's customizable it. 135 00:07:53,350 --> 00:07:57,010 OK so we need a custom team. 136 00:07:57,700 --> 00:08:00,390 Let's set it white or let's make it black. 137 00:08:01,210 --> 00:08:01,650 OK. 138 00:08:01,840 --> 00:08:03,310 So let's just download it. 139 00:08:03,430 --> 00:08:04,650 Let's open the file. 140 00:08:05,950 --> 00:08:08,310 OK. 141 00:08:09,010 --> 00:08:13,060 Here as you can see they've got multiple folders so global GDP by MPI. 142 00:08:13,540 --> 00:08:20,590 So this is GBI and the IDC to present the screen density so screen size somebody buys for medium sized 143 00:08:20,590 --> 00:08:27,640 screens as we buy as high resolution screens X as she buys extra high resolution screens. 144 00:08:27,640 --> 00:08:38,420 So basically devalues for small phones everyday API for families access GPI for tablets et cetera et 145 00:08:38,420 --> 00:08:38,950 cetera. 146 00:08:39,410 --> 00:08:41,180 So let's open the GPI. 147 00:08:42,470 --> 00:08:50,680 Well let's hope it does on base it in our droid boats so control c come to our droid boats here and 148 00:08:50,690 --> 00:08:54,570 that's pasted to OK. 149 00:08:55,820 --> 00:09:04,920 Similarly let's get another I can further share so clipboard Bartlett's search again. 150 00:09:04,980 --> 00:09:05,820 This one looks good. 151 00:09:07,350 --> 00:09:08,660 Okay let's down a little bit. 152 00:09:11,060 --> 00:09:20,400 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 153 00:09:23,310 --> 00:09:23,710 okay. 154 00:09:23,720 --> 00:09:29,850 So coming back to our project on many or eczema so let's just. 155 00:09:30,110 --> 00:09:43,290 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 156 00:09:43,800 --> 00:09:46,380 sorry I can I see. 157 00:09:46,400 --> 00:09:46,890 Sure. 158 00:09:48,170 --> 00:09:48,490 OK. 159 00:09:48,540 --> 00:09:50,730 So let's run our application and see the changes 160 00:09:53,380 --> 00:09:54,970 well thought applications running. 161 00:09:55,000 --> 00:09:56,020 So let's have a look. 162 00:09:57,920 --> 00:10:01,610 Allow as you can see the text is gone and we can see your icons here. 163 00:10:03,160 --> 00:10:08,300 So if I click on this it shows is a profile and if I click on Show I can chose picture. 164 00:10:09,080 --> 00:10:11,070 So that's all the menus. 165 00:10:11,360 --> 00:10:18,020 If you have any doubts any queries feel free to draw up a common unreadable Twitter how good they like.