@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
public boolean 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.this, NextActivity.class);
item.setIntent(intent); /* 切换到第二个Activity */
break;
case R.id.open:
Toast.makeText(MainActivity.this, "选择了打开文件", 1).show();
break;
case R.id.load:
Toast.makeText(MainActivity.this, "选择了加载文件", 1).show();
break;
case R.id.save:
Toast.makeText(MainActivity.this, "选择了保存文件", 1).show();
break;
default:
break;
} return 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
android:id="@+id/create"
android:title="新建文件"/>
<item
android:id="@+id/open"
android:title="打开文件"/>
</menu>
</item>
<item
android:id="@+id/action_user"
android:icon="@drawable/a1"
android:orderInCategory="100"
android:showAsAction="never"
android:title="用户菜单">
<menu>
<item
android:id="@+id/load"
android:title="加载文件"/>
<item
android:id="@+id/save"
android:title="保存文件"/>
</menu>
</item> </menu>

菜单显示到导航栏

android:showAsAction="ifRoom"

Android 菜单 使用XML的更多相关文章

  1. [转载]关于android SDK安装Failed to fetch URL http://dl-ssl.google.com/android/repository/addons_list-1.xml出错

    原文地址为:http://blog.csdn.net/springsky_/article/details/7442388 因为入行移动测试,所以很多测试环境的搭建.从中遇到了和这个GG同样的问题.怕 ...

  2. Android菜单详解(四)——使用上下文菜单ContextMenu

    之前在<Android菜单详解(二)——创建并响应选项菜单>和<Android菜单详解(三)——SubMenu和IconMenu>中详细讲解了选项菜单,子菜单和图标菜单.今天接 ...

  3. 【转】Android菜单详解——理解android中的Menu--不错

    原文网址:http://www.cnblogs.com/qingblog/archive/2012/06/08/2541709.html 前言 今天看了pro android 3中menu这一章,对A ...

  4. Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Connect

    Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Connect ...

  5. Android菜单

    Android菜单概述 菜单是Activity的一个重要组成部分,它为用户操作提供了快捷的途径.Android提供了一个简单的框架来向程序中添加标准菜单 . 一.创建一个菜单资源 你需要在一个XML ...

  6. Android菜单(menu)

    Android  菜单 我们继续来进行学习,今天写一下在软件中用的还算较多的菜单. 1.Menu 菜单,很显然,作用就是点击不同的选项触发不同的方法.现在在安卓使用中推荐使用ActionBar,但这里 ...

  7. Android在layout xml中使用include

    Android include与merge标签使用详解 - shuqiaoniu的博客 - 博客频道 - CSDN.NEThttp://blog.csdn.net/shuqiaoniu/article ...

  8. android获取string.xml的值(转)

    为什么需要把应用中出现的文字单独存放在string.xml文件中呢? 一:是为了国际化,当需要国际化时,只需要再提供一个string.xml文件,把里面的汉子信息都修改为对应的语言(如,English ...

  9. [android警告] AndroidManifest.xml警告 Should explicitly set android:allowBackup to true or false

    http://www.cnblogs.com/javadu/p/3812528.html Android中AndroidManifest.xml警告 Should explicitly set and ...

随机推荐

  1. 洛谷P1402——乒乓球

    原题链接: https://www.luogu.com.cn/problem/P1042 题面简述 国际乒联现在主席沙拉拉自从上任以来就立志于推行一系列改革,以推动乒乓球运动在全球的普及.其中11分制 ...

  2. centos7.6安装python3.7

    1.安装python3.7后,需要: yum install libffi-devel -y 然后再到python源码目录再make install 重新编译一下. 否则pip安装一些包时会安装不上, ...

  3. xcode8 运行项目时自己打印些东西

    使用 Xcode 8 运行工程的时候,在打印台会发现如下这些奇怪的日志输出: 2016-09-19 10:43:44.001757 Demo[7100:171568] subsystem: com.a ...

  4. WebGL简易教程——目录

    目录 1. 绪论 2. 目录 3. 资源 1. 绪论 最近研究WebGL,看了<WebGL编程指南>这本书,结合自己的专业知识写的一系列教程.之前在看OpenGL/WebGL的时候总是感觉 ...

  5. 《Windows内核安全与驱动开发》 4.4 线程与事件

    <Windows内核安全与驱动开发>阅读笔记 -- 索引目录 <Windows内核安全与驱动开发> 4.4 线程与事件 一.开辟一个线程,参数为(打印内容+打印次数),利用线程 ...

  6. TypeError: 'list' object cannot be interpreted as an integer

    TypeError: 'list' object cannot be interpreted as an integer 类型错误,不能将list对象转换为一个整数. 错误代码,例如如下例子: arg ...

  7. SQL语句中将形式(12/10/19 4:13:21 PM)转化为(2019-12-10)

    convert(char(10),convert(datetime, H.TOEX_FIN_REJECT_TIMR)+1,20),

  8. luogu P1417 烹调方案 |dp

    题目背景 由于你的帮助,火星只遭受了最小的损失.但gw懒得重建家园了,就造了一艘飞船飞向遥远的earth星.不过飞船飞到一半,gw发现了一个很严重的问题:肚子饿了~ gw还是会做饭的,于是拿出了储藏的 ...

  9. play-with-docker搭配ffsend完成文件上传及下载(解决从docker hub拉取镜像慢问题)

    由于众所周知的原因,大家有的时候pull docker hub上的镜像是很困难的,下载到99%就这么不动了也是很正常的事情 这个时候以下步骤是100%可以解决问题的: 1.找一台国外的服务器安装doc ...

  10. dotnet core gbk 编码错误解决方案

    .Net Core GBK解码 1.添加引用 System.Text.Encoding.CodePages 2.注册   Encoding.RegisterProvider(CodePagesEnco ...