File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 3
3
4
4
<string name =" app_name" >MenuOptionsExample</string >
5
5
<string name =" hello_world" >Example app to show case the Menu Options an Items in Android!</string >
6
+ <string name =" colors" >Background Color Preference</string >
7
+ <string name =" options" >Random Options</string >
8
+ <string name =" quit" >Quit App</string >
6
9
<string name =" action_settings" >Settings</string >
7
10
8
11
</resources >
Original file line number Diff line number Diff line change 7
7
8
8
public class MainActivity extends Activity {
9
9
10
+ private static final int ITEM_COLORS_ID = Menu .FIRST ;
11
+ private static final int ITEM_OPTIONS_ID = Menu .FIRST + 1 ;
12
+ private static final int ITEM_QUIT_ID = Menu .FIRST + 2 ;
13
+
10
14
@ Override
11
15
protected void onCreate (Bundle savedInstanceState ) {
12
16
super .onCreate (savedInstanceState );
@@ -16,7 +20,13 @@ protected void onCreate(Bundle savedInstanceState) {
16
20
@ Override
17
21
public boolean onCreateOptionsMenu (Menu menu ) {
18
22
// Inflate the menu; this adds items to the action bar if it is present.
19
- getMenuInflater ().inflate (R .menu .main , menu );
23
+ //getMenuInflater().inflate(R.menu.main, menu);
24
+
25
+ //Adding Menu Items Programatically
26
+ menu .add (Menu .NONE , ITEM_COLORS_ID , Menu .NONE , R .string .colors );
27
+ menu .add (Menu .NONE , ITEM_OPTIONS_ID , Menu .NONE , R .string .options );
28
+ menu .add (Menu .NONE , ITEM_QUIT_ID , Menu .NONE , R .string .quit );
29
+
20
30
return true ;
21
31
}
22
32
You can’t perform that action at this time.
0 commit comments