Android 菜单 使用XML
发布时间:2020-12-15 07:17:10 所属栏目:Java 来源:网络整理
导读:@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main,menu); return true ; } @Override onOptionsItemSelected(MenuItem item)
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main,menu); return true; } @Override onOptionsItemSelected(MenuItem item) { TODO Auto-generated method stub switch (item.getItemId()) { case R.id.create: Toast.makeText(MainActivity.this,"选择了创建文件",1).show(); Intent intent = new Intent(MainActivity.class); item.setIntent(intent); /* 切换到第二个Activity */ break; R.id.open: Toast.makeText(MainActivity.).show(); R.id.load: Toast.makeText(MainActivity. R.id.save: Toast.makeText(MainActivity.default: ; } super.onOptionsItemSelected(item); } <menu xmlns:android="http://schemas.android.com/apk/res/android" >
item
android:id="@+id/action_settings"
android:icon="@drawable/a1"
android:orderInCategory="100"
android:showAsAction="never"
android:title="主菜单">
menu>
item
="@+id/create"
android:title="新建文件"/>
="@+id/open"="打开文件"/>
</>
item="@+id/action_user"="用户菜单"="@+id/load"="加载文件"="@+id/save"="保存文件">
>
菜单显示到导航栏android:showAsAction="ifRoom" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |