标签: Android SDK
[1].[代码] menu.xml 跳至 [1] [2] [3]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
menu
xmlns:Android
=
"http://schemas.android.com/apk/res/android"
>
<
item
Android:id
=
"@+id/close"
android:title
=
"Close"
Android:orderInCategory
=
"3"
android:icon
=
"@drawable/eject"
/>
<
item
Android:id
=
"@+id/no_icon"
android:orderInCategory
=
"2"
Android:title
=
"Sans Icon"
/>
<
item
Android:id
=
"@+id/disabled"
android:orderInCategory
=
"4"
Android:enabled
=
"false"
android:title
=
"Disabled"
/>
<
group
Android:id
=
"@+id/other_stuff"
android:menuCategory
=
"secondary"
Android:visible
=
"false"
>
<
item
Android:id
=
"@+id/later"
android:orderInCategory
=
"0"
Android:title
=
"2nd-To-Last"
/>
<
item
Android:id
=
"@+id/last"
android:orderInCategory
=
"1"
Android:title
=
"Last"
/>
</
group
>
<
item
Android:id
=
"@+id/submenu"
android:orderInCategory
=
"3"
Android:title
=
"A Submenu"
>
<
menu
>
<
item
Android:id
=
"@+id/non_ghost"
android:title
=
"Non-Ghost"
Android:visible
=
"true"
android:alphabeticShortcut
=
"n"
/>
<
item
Android:id
=
"@+id/ghost"
android:title
=
"A Ghost"
Android:visible
=
"false"
android:alphabeticShortcut
=
"g"
/>
</
menu
>
</
item
>
</
menu
>
|
[2].[代码] main.xml 跳至 [1] [2] [3]
1
2
3
4
5
6
7
8
|
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
LinearLayout
xmlns:Android
=
"http://schemas.android.com/apk/res/android"
Android:orientation
=
"vertical"
Android:layout_width
=
"fill_parent"
Android:layout_height
=
"fill_parent"
>
</
LinearLayout
>
|
[3].[代码] XmlMenuAcitvity.java 跳至 [1] [2] [3]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package
yyl.xmlMenu;
import
Android.app.Activity;
import
Android.os.Bundle;
import
Android.view.ContextMenu;
import
Android.view.ContextMenu.ContextMenuInfo;
import
Android.view.Menu;
import
Android.view.MenuInflater;
import
Android.view.View;
public
class
XmlMenuAcitvity
extends
Activity {
/** Called when the activity is first created. */
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public
boolean
onCreateOptionsMenu(Menu menu) {
//将页面定义的menu配置到到activity中
new
MenuInflater(getApplication())
.inflate(R.layout.menu, menu);
return
super
.onCreateOptionsMenu(menu);
}
}
|