public class
MainActivity
extends
Activity {
@Override
public void
onCreate
(Bundle savedInstanceState)
{
super
.onCreate(savedInstanceState)
;
}
@Override
public boolean
onCreateOptionsMenu
(Menu menu)
{
//-------------向menu中添加子菜单-----------------
SubMenu prog = menu.addSubMenu(
"启动程序"
)
;
//设置菜单头的图标
prog.setHeaderTitle(
"选择您要启动的程序"
)
;
//添加菜单项
MenuItem item = prog.add(
"查看Swift"
)
;
//为菜单项设置关联的Activity
item.setIntent(
new
Intent(
this,
OtherActivity.
class
))
;
return super
.onCreateOptionsMenu(menu)
;
}
}
<?
xml version=
"1.0"
encoding=
"utf-8"
?>
package=
"com.example.zxy.ex2"
>
<application
android
:allowBackup=
"true"
android
:icon=
"@mipmap/ic_launcher"
android
:label=
"@string/app_name"
android
:roundIcon=
"@mipmap/ic_launcher_round"
android
:supportsRtl=
"true"
android
:theme=
"@style/AppTheme"
>
<activity
android
:name=
".MainActivity"
android
:label=
"@string/app_name"
>
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action
android
:name=
"android.intent.action.MAIN"
/>
<category
android
:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
<activity
android
:name=
".OtherActivity"
android
:label=
"查看《疯狂Swift讲义》"
>
</activity>
</application>
</manifest>