当前位置:网站首页>SumMenuDemo(子菜单)
SumMenuDemo(子菜单)
2022-07-27 17:02:00 【Ashurol】
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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);
getMenuInflater().inflate(R.menu.main, menu);
// SubMenu file = menu.addSubMenu("文件");
// SubMenu edit = menu.addSubMenu("编辑");
// file.add(1, 1, 1, "新建");
// file.add(1, 2, 1, "打开");
// file.add(1, 3, 1, "保存");
// file.setHeaderTitle("文件操作");//子菜单标题
// file.setHeaderIcon(R.drawable.ic_launcher);//子菜单图标
// edit.add(2, 1, 1, "复制");
// edit.add(2, 2, 1, "粘贴");
// edit.add(2, 3, 1, "剪切");
// edit.setHeaderTitle("编辑操作");
// edit.setHeaderIcon(R.drawable.ic_launcher);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
// if(item.getGroupId()==1)
// {
// switch(item.getItemId())
// {case 1:
// Toast.makeText(this, "点击了新建",Toast.LENGTH_SHORT).show();
// break;
// case 2:
// Toast.makeText(this, "点击了打开",Toast.LENGTH_SHORT).show();
// break;
// case 3:
// Toast.makeText(this, "点击了保存",Toast.LENGTH_SHORT).show();
// break;}
// }else if(item.getGroupId()==2)
// {
// switch(item.getItemId())
// {case 1:
// Toast.makeText(this, "点击了复制",Toast.LENGTH_SHORT).show();
// break;
// case 2:
// Toast.makeText(this, "点击了粘贴",Toast.LENGTH_SHORT).show();
// break;
// case 3:
// Toast.makeText(this, "点击了剪切",Toast.LENGTH_SHORT).show();
// break;}
// }
switch(item.getItemId())
{
case R.id.new_file:
Toast.makeText(this, "点击了新建",Toast.LENGTH_SHORT).show();
break;
case R.id.open_file:
Toast.makeText(this, "点击了打开",Toast.LENGTH_SHORT).show();
break;
case R.id.save_file:
Toast.makeText(this, "点击了保存",Toast.LENGTH_SHORT).show();
break;
case R.id.c_edit:
Toast.makeText(this, "点击了复制",Toast.LENGTH_SHORT).show();
break;
case R.id.v_edit:
Toast.makeText(this, "点击了粘贴",Toast.LENGTH_SHORT).show();
break;
case R.id.x_edit:
Toast.makeText(this, "点击了剪切",Toast.LENGTH_SHORT).show();
break;
}
return super.onOptionsItemSelected(item);
}
Menu文件夹中的main.xml文件<pre name="code" class="html"><menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.xin.zhicaidan.MainActivity"
>
<item
android:showAsAction="never"
android:title="文件">
<menu>
<item
android:id="@+id/new_file"
android:showAsAction="never"
android:title="新建"/>
<item
android:id="@+id/open_file"
android:showAsAction="never"
android:title="打开"/>
<item
android:id="@+id/save_file"
android:showAsAction="never"
android:title="保存"/>
</menu>
</item>
<item
android:showAsAction="never"
android:title="编辑">
<menu>
<item
android:id="@+id/c_edit"
android:showAsAction="never"
android:title="复制"/>
<item
android:id="@+id/v_edit"
android:showAsAction="never"
android:title="粘贴"/>
<item
android:id="@+id/x_edit"
android:showAsAction="never"
android:title="剪切"/>
</menu>
</item>
</menu>
边栏推荐
- 英特尔未来10年工艺路线图曝光:2029年推出1.4nm工艺!如何实现?
- C language: 6. Simple use and precautions of pointer
- 【深度学习目标检测系列 - 01】目标检测是什么
- [deep learning target detection series - 01] what is target detection
- HDU1323_Perfection【水题】
- 【深度学习基础知识 - 39】BN、LN、WN的比较
- PyTorch报CUDA error: no kernel image is available for execution on the device 错误
- High cost, difficult to implement, slow to take effect, what about open source security?
- Surpass Huawei? Ericsson has won more than 75 5g commercial contracts
- Intel launched the world's smallest high-resolution lidar, priced at only $349
猜你喜欢

Complex number proof of solvability of regular 17 sided ruler and gauge drawing

High cost, difficult to implement, slow to take effect, what about open source security?

电商商城小程序项目完整源码(微信小程序)

【深度学习基础知识 - 45】机器学习中常用的距离计算方法

C language: 14. Preprocessing

Complete source code of E-commerce mall applet project (wechat applet)

【深度学习基础知识 - 37】解决正负样本不均衡 Focal Loss

C language: 10. Input stream, output stream, error stream

二叉搜索树

c语言:8、makeFile编写
随机推荐
Intel releases horse ridge chip: 22nm process, which can control multiple qubits
嵌入式C语言结构体
[basic knowledge of deep learning - 47] Bayesian networks and naive Bayes
细数国产接口协作平台的六把武器!
HDU1323_ Perfection [water question]
Big guys, Oracle CDC, local operation, always encounter this an exception occurred in
Adhering to the integration of software and hardware, one Hengke makes efforts to the intelligent educational robot market
Flink 算子简介
IEC104 规约详细解读(二)交互流程以及协议解析
It is said that Apple plans to buy some JDI factories with us $200million
C language: 8. Makefile preparation
查看宝塔PHP扩展目录
C language: 7. How to use C language multi source files
Pytorch reports CUDA error: no kernel image is available for execution on the device error
台积电5nm即将量产:苹果A14独占7成产能,华为麒麟1020拿下3成
c语言:13、指针与内存
Intel launched the world's smallest high-resolution lidar, priced at only $349
[basic knowledge of deep learning - 43] concept of odds ratio
Optimization of embedded C language for indefinite cycles
嵌入式C语言对次数不定的循环的优化