1
00:00:00,270 --> 00:00:06,570
So here as you can see our application is running on the simulator but now I want to actually create

2
00:00:06,630 --> 00:00:09,890
a menu for my application here inside this action.

3
00:00:09,910 --> 00:00:11,660
But I want to create a menu.

4
00:00:12,030 --> 00:00:19,080
So now in my project structure here I need to actually click on these raids folder here.

5
00:00:19,320 --> 00:00:20,390
Right click on it.

6
00:00:21,390 --> 00:00:27,700
And then click on Android early source directory as you can see here.

7
00:00:27,710 --> 00:00:34,710
Android resource directory and for the name just type in here just for the resource type just select

8
00:00:34,920 --> 00:00:40,280
menu OK and then click on OK as you can see the directory name is menu.

9
00:00:40,410 --> 00:00:44,660
There is sort of the resource type menu and the source said is me OK.

10
00:00:44,760 --> 00:00:47,030
And then click on OK here.

11
00:00:47,100 --> 00:00:53,850
So as you can see here I have this menu of folder this our menu directory inside my race for that right.

12
00:00:53,910 --> 00:00:57,360
So just right click on these menu here.

13
00:00:57,570 --> 00:00:58,320
And a new.

14
00:00:58,360 --> 00:01:01,160
And then click on menu resource file.

15
00:01:01,500 --> 00:01:10,530
So just for the name of our menu file which is going to be an XML file just type in here menu underly

16
00:01:10,610 --> 00:01:11,220
made.

17
00:01:11,580 --> 00:01:13,230
And then click on OK.

18
00:01:13,650 --> 00:01:19,170
So inside this menu directory I have this menu underline the XML file here.

19
00:01:19,230 --> 00:01:21,250
So as you can see here this is that file.

20
00:01:21,480 --> 00:01:24,220
So now I want to actually create an item.

21
00:01:24,360 --> 00:01:33,780
So just open a type here item and for the title just type in here settings and then I want to actually

22
00:01:33,780 --> 00:01:35,430
give an ID to this item.

23
00:01:35,430 --> 00:01:41,850
So just type in here ID as you can see here and then press enter key to select this idea here.

24
00:01:42,090 --> 00:01:48,720
And in order to create an ID unit to actually used this here at sign Plus Id This is very important

25
00:01:48,990 --> 00:01:49,470
at sign.

26
00:01:49,470 --> 00:01:53,840
Plus Id just use this piece of code here and then press that into the general keyboard.

27
00:01:54,060 --> 00:01:58,710
So now I can actually specify an ID for my item here.

28
00:01:58,800 --> 00:02:08,080
So for the ID just type in here settings OK and then now let's actually close this item here by just

29
00:02:08,140 --> 00:02:10,790
using a closing tag here.

30
00:02:10,840 --> 00:02:14,440
Now let's run our project and see what happens.

31
00:02:14,470 --> 00:02:20,790
So as you can see here now our application is running on the simulator and still we can't see this the

32
00:02:20,830 --> 00:02:22,420
item menu here.

33
00:02:22,570 --> 00:02:23,050
OK.

34
00:02:23,170 --> 00:02:27,700
So we need to go back inside our main activity the java file here and we need to actually overwrite

35
00:02:27,700 --> 00:02:28,850
some methods.

36
00:02:28,900 --> 00:02:34,990
The first one is on create options menu.

37
00:02:35,440 --> 00:02:37,230
And as you can see here we have this method.

38
00:02:37,240 --> 00:02:42,270
So the autocomplete feature of the Android studio is helping me to find Mefford.

39
00:02:42,420 --> 00:02:45,700
So just a selected and then person enter key on your keyboard.

40
00:02:46,060 --> 00:02:51,790
So as you can see here this is that Meffert and the second half of any two over right here is actually

41
00:02:51,880 --> 00:02:58,740
an options item selected as you can see here just select it and press on entelechy on your keyboard.

42
00:02:58,840 --> 00:03:04,810
So now inside this uncreate options menu Meffert as you can see we have this line of code here.

43
00:03:04,810 --> 00:03:08,140
Just select this line of code and then press until it key on your keyboard.

44
00:03:08,290 --> 00:03:11,480
So now I want to actually put in my own logic here.

45
00:03:11,710 --> 00:03:19,000
So now I want to actually inflate the menu on my action but so as you can see here in our emulator we

46
00:03:19,000 --> 00:03:19,650
have this action.

47
00:03:19,660 --> 00:03:23,830
But here and I want to actually inflate the menu on this action but here.

48
00:03:24,000 --> 00:03:32,230
So in order to do that I can just type in here get menu inflator does inflate and here you need to actually

49
00:03:32,230 --> 00:03:33,740
pass two arguments.

50
00:03:33,880 --> 00:03:36,450
The first one is of type menu resource file.

51
00:03:36,610 --> 00:03:41,980
So as you can see here we have this our menu resource file here in our project structure inside this

52
00:03:42,150 --> 00:03:45,180
race folder menu that underline minute example.

53
00:03:45,280 --> 00:03:52,960
So here I can just type in our start menu that menu underline main here and then press on Enter key

54
00:03:52,960 --> 00:03:53,760
on your keyboard.

55
00:03:53,890 --> 00:03:55,560
So this is the first argument.

56
00:03:55,690 --> 00:04:01,510
The second one is the menu object that you actually receive as an argument from this on create options

57
00:04:01,510 --> 00:04:02,400
menu method.

58
00:04:02,560 --> 00:04:04,890
So here I can just type in menu.

59
00:04:05,620 --> 00:04:12,700
So now because this if it actually returns a boolean value we need to return true in order to inflate

60
00:04:12,700 --> 00:04:15,230
this menu here on our action bar.

61
00:04:15,280 --> 00:04:21,070
So here I can just type in return true and then put a semicolon at the end of your statement.

62
00:04:21,070 --> 00:04:24,700
So now let's actually run our project and see what happens.

63
00:04:24,700 --> 00:04:30,920
So as you can see here now our application is running on this emulator here and here at the top.

64
00:04:30,950 --> 00:04:33,700
Inside this action but here we can see this menu.

65
00:04:33,790 --> 00:04:36,810
And if I selected I can see the settings here.

66
00:04:36,960 --> 00:04:37,610
OK.

67
00:04:37,720 --> 00:04:43,430
So this is the item that they actually created inside this menu and the line made that examine the title

68
00:04:43,430 --> 00:04:46,420
the settings and the ID's settings right.

69
00:04:46,420 --> 00:04:49,820
So let's go back into our main activity Dodgeville file here.

70
00:04:50,050 --> 00:04:52,480
And I want to actually do something.

71
00:04:52,660 --> 00:04:55,340
When the user clicks on these settings here.

72
00:04:55,450 --> 00:04:56,260
OK.

73
00:04:56,260 --> 00:05:02,990
So again let's actually go inside this on options item selected here and here as you can see this before

74
00:05:02,990 --> 00:05:05,080
it again returns a boolean value.

75
00:05:05,200 --> 00:05:11,080
So it is actually enough to really turn the supervision of the Smurfette superdad on options item selected

76
00:05:11,140 --> 00:05:11,490
item.

77
00:05:11,530 --> 00:05:12,080
OK.

78
00:05:12,220 --> 00:05:16,300
So now before this line of code here we can put our own logic here.

79
00:05:16,330 --> 00:05:21,370
First of all I want to actually get the ID of the item that you've selected.

80
00:05:21,370 --> 00:05:26,590
So inside this menu under the nine minute segment as you can see I have this item and I actually provided

81
00:05:26,620 --> 00:05:29,080
an ID for this item sitting right.

82
00:05:29,080 --> 00:05:31,690
So here inside is an options item selected.

83
00:05:31,690 --> 00:05:33,260
I can get that ID.

84
00:05:33,280 --> 00:05:39,460
So in order to get the ID I can create an entire idea about it and the name of my value is going to

85
00:05:39,460 --> 00:05:40,190
be ID.

86
00:05:40,330 --> 00:05:41,660
Assignment operator.

87
00:05:41,770 --> 00:05:44,530
So as you can see here we actually received this item.

88
00:05:44,590 --> 00:05:48,670
This menu item as an argument from an optional item selected Nefert.

89
00:05:48,670 --> 00:05:55,700
So I can just refer to the name of this argument item that gets item ID.

90
00:05:55,720 --> 00:05:59,460
So now I can actually access the ID of my item.

91
00:05:59,530 --> 00:06:00,160
OK.

92
00:06:00,160 --> 00:06:05,360
So here I can actually create an if statement or actually a switch statement.

93
00:06:05,560 --> 00:06:12,220
And here I can switch between the IDs of the items that are inside of this menu that menu that main

94
00:06:12,730 --> 00:06:17,760
menu and the alignment that means that example as you can see here we have only one item here.

95
00:06:18,280 --> 00:06:22,830
And the 80s settings so I can just type in switch ID.

96
00:06:23,370 --> 00:06:24,110
OK.

97
00:06:24,130 --> 00:06:29,650
And then I need to open and close this switch block here and then I can create an ok statement.

98
00:06:29,760 --> 00:06:37,720
Case r that I'd already thought settings as you can see here just select it and then person enter key

99
00:06:37,780 --> 00:06:44,070
on your keyboard and then put a colon here and then create a break statement here.

100
00:06:44,320 --> 00:06:51,800
So now for this break case statement I can't say that I can actually create an intent object here.

101
00:06:51,850 --> 00:07:00,010
So what I want to do I want to actually move from this activity to the preferences example that I am

102
00:07:00,130 --> 00:07:01,150
going to create.

103
00:07:01,160 --> 00:07:07,410
Now first of all let's actually create that example of file and then we're going to actually continue

104
00:07:07,720 --> 00:07:10,150
coding inside this case statement.

105
00:07:10,160 --> 00:07:17,940
So now in our project structure let's actually select this arrays folder here as you can see right click

106
00:07:17,940 --> 00:07:22,890
on it and then click on new and then click on Android resource wide.

107
00:07:23,070 --> 00:07:23,880
OK.

108
00:07:24,300 --> 00:07:33,470
And for the name of our file just type in here pretty for preferences underline file that exit mail.

109
00:07:33,810 --> 00:07:34,420
OK.

110
00:07:34,710 --> 00:07:43,080
And the resource type just type in Excel like this XML here for the resource type and the root element

111
00:07:43,080 --> 00:07:49,160
is going to be pretty friends screen and the source said is main and the directory name is XML.

112
00:07:49,590 --> 00:07:50,220
OK.

113
00:07:50,610 --> 00:07:56,490
So it's going to actually create a directory for us and then it's going to actually also create this

114
00:07:56,670 --> 00:07:57,300
XML file.

115
00:07:57,300 --> 00:07:59,470
Preferences underline find that example.

116
00:07:59,660 --> 00:08:01,960
OK so let's click on OK here.

117
00:08:02,870 --> 00:08:06,740
An insight Isarel falter I have this XML directory.

118
00:08:06,800 --> 00:08:10,050
As you can see an insight is ASML directory.

119
00:08:10,070 --> 00:08:14,470
I have these preferences underlined file that ASML here.

120
00:08:14,600 --> 00:08:19,780
OK so now let's to go inside these preferences underline find that example here.

121
00:08:20,030 --> 00:08:23,200
And now let's actually put some lines of code here.

122
00:08:23,510 --> 00:08:28,670
So this is going to be the settings activity the settings a layout of our application.

123
00:08:28,670 --> 00:08:33,830
So when the user clicks on these settings here as you can see when the user clicks on the settings here

124
00:08:34,080 --> 00:08:40,850
is they're going to actually go to this XML file and then they can actually interact with that XML file

125
00:08:41,090 --> 00:08:46,480
and specify some actually preferences for their application for the application.

126
00:08:46,490 --> 00:08:47,320
Right.

127
00:08:47,450 --> 00:08:53,630
So now I went actually pasting some lines of code here and then I'm going to explain to you what's going

128
00:08:53,630 --> 00:08:54,490
on here.

129
00:08:54,770 --> 00:09:03,350
So now as you can see here these are the lines of code that I actually pasted here inside these preferences

130
00:09:03,630 --> 00:09:10,280
underline file that example he had as you can see inside these preferences preferences are preference.

131
00:09:10,280 --> 00:09:16,040
Screen tag here as you can see I have this preference category here as you can see.

132
00:09:16,220 --> 00:09:17,770
So I have these lines of code.

133
00:09:17,840 --> 00:09:21,550
So now I'm gonna actually explain to you what's going on here.

134
00:09:22,100 --> 00:09:28,930
As you can see here in line 6 as you can see I created this tag here preference category.

135
00:09:29,390 --> 00:09:31,890
And I gave a title to this category.

136
00:09:32,120 --> 00:09:36,120
And as you can see here the title is text number 1 settings.

137
00:09:36,140 --> 00:09:36,650
OK.

138
00:09:36,830 --> 00:09:40,700
So here I want to specify the settings for the text number of on.

139
00:09:40,880 --> 00:09:45,160
So as you can see here in our emulator I have this takes number one here.

140
00:09:45,200 --> 00:09:45,890
OK.

141
00:09:45,890 --> 00:09:52,170
So as you can see I have these settings and I want to provide some settings for this text number one.

142
00:09:52,400 --> 00:09:54,860
So let's see what that is going to be the settings.

143
00:09:54,890 --> 00:09:59,530
The first item as you can see here inside this preference category here.

144
00:09:59,660 --> 00:10:06,100
I have this checkbox preference so I'm going to actually create a checkbox for this.

145
00:10:06,370 --> 00:10:08,790
Takes one here checkbox preference.

146
00:10:08,960 --> 00:10:14,940
And as you can see here these are the attributes that they actually assigned for this checkbox preference.

147
00:10:14,960 --> 00:10:20,270
So first of all I actually gave a key to this checkbox preference.

148
00:10:20,310 --> 00:10:22,930
The keys checkbox underline font.

149
00:10:22,960 --> 00:10:25,240
The line number of underlined text 1.

150
00:10:25,490 --> 00:10:32,360
So now you can actually understand that you want to actually specify the font for my text one here.

151
00:10:32,640 --> 00:10:33,440
OK.

152
00:10:33,650 --> 00:10:40,390
When I go into the settings XML file I want to specify the font of this text one here for example.

153
00:10:40,580 --> 00:10:42,180
So this is going to be the key.

154
00:10:42,200 --> 00:10:51,840
So help us to actually this helps us to use this key in our Java file and interact with this checkbox

155
00:10:51,870 --> 00:10:52,630
preference.

156
00:10:52,760 --> 00:10:57,660
So this is very important that you actually give a key to your checkbox preference.

157
00:10:58,040 --> 00:11:05,160
And here I gave a title to my a checkbox free France and the title is traunch 5.

158
00:11:05,420 --> 00:11:10,000
OK so this is going to be the name of the format that the user can select for.

159
00:11:10,010 --> 00:11:11,200
This takes one here.

160
00:11:11,210 --> 00:11:13,220
This is takes number one.

161
00:11:13,430 --> 00:11:16,340
And as you can see here I have this summary.

162
00:11:16,940 --> 00:11:21,680
So the Samadi is going to be a string value that I will be showing you in a minute.

163
00:11:21,740 --> 00:11:27,450
So it's going to give you a description about this specific tick box preference the summary.

164
00:11:27,800 --> 00:11:29,970
And we have this default value.

165
00:11:30,230 --> 00:11:34,070
So default the default value is going to be the default itself.

166
00:11:34,190 --> 00:11:36,140
Chunk 5 that or T.F..

167
00:11:36,170 --> 00:11:42,650
So as you can see here in our project structure here in our assets folder I have this Faunce directory.

168
00:11:42,670 --> 00:11:46,780
And as you can see here I have this and chaunced 5 that Auty ATF.

169
00:11:46,910 --> 00:11:52,670
So it is very important that the name that you actually put here for this default value must be the

170
00:11:52,670 --> 00:11:53,690
same as this name.

171
00:11:53,690 --> 00:11:55,470
Here inside this Faunce directory.

172
00:11:55,520 --> 00:12:01,230
So here as you can see I am actually closing this tag here this checkbox preference.

173
00:12:01,640 --> 00:12:05,850
And again here I actually created another checkbox preference.

