zoukankan      html  css  js  c++  java
  • Android开发菜单以及子菜单

    package com.example.androidtest;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.SubMenu;
    import android.widget.Toast;
    
    public class MainActivity extends Activity{
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
        }
        
        @Override
        public boolean onCreateOptionsMenu(Menu 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.img1);
            edit.add(2,1,1,"复制");
            edit.add(2,2,1,"粘贴");
            edit.add(2,3,1,"剪切");
            edit.setHeaderTitle("文件操作");
            edit.setHeaderIcon(R.drawable.img1);
            return true;
            
        }
        
        @Override
        public boolean onOptionsItemSelected(MenuItem item){
            if(item.getGroupId()==1){
                switch(item.getItemId()){
                case 1:
                    Toast.makeText(MainActivity.this, "点击了新建", Toast.LENGTH_SHORT).show();
                    break;
                case 2:
                    Toast.makeText(MainActivity.this, "点击了打开", Toast.LENGTH_SHORT).show();
                    break;
                case 3:
                    Toast.makeText(MainActivity.this, "点击了保存", Toast.LENGTH_SHORT).show();
                    break;
                }
            }else if(item.getGroupId()==2){
                switch(item.getItemId()){
                case 1:
                    Toast.makeText(MainActivity.this, "点击了复制", Toast.LENGTH_SHORT).show();
                    break;
                case 2:
                    Toast.makeText(MainActivity.this, "点击了粘贴", Toast.LENGTH_SHORT).show();
                    break;
                case 3:
                    Toast.makeText(MainActivity.this, "点击了剪切", Toast.LENGTH_SHORT).show();
                    break;
                }
            }
            return super.onOptionsItemSelected(item);
        }
    
    }
  • 相关阅读:
    listView控件演示程序
    猪悟能淘宝商品下载专家v3版开发手记
    c# WebClient类
    分隔控件splitter演示程序
    C#中SESSIONID的获取
    工具栏toolBar演示程序
    Cookie总结
    C#获取网页源码并且自动判断网页字符集编码
    如何在Google Code上建立私有代码版本库
    iOS应用程序生命周期(前后台切换,应用的各种状态)详解
  • 原文地址:https://www.cnblogs.com/guojinyu/p/6676458.html
Copyright © 2011-2022 走看看