Onelong

分享知识,与你一起进步......
RSS icon Home icon
  • android 选项菜单的实现

    post by onelong / 2010-5-29 18:02 Saturday [android]

     @Override
        public boolean onCreateOptionsMenu(Menu menu) {//重写onCreateOptionsMenu(Menu menu)方法实现创建选项菜单
            menu.add(0, MENU_SAVE, 0, "保存")
                .setIcon(android.R.drawable.ic_menu_save);
            menu.add(0, MENU_DELETE, 0, "删除")
                .setIcon(android.R.drawable.ic_menu_delete);
            SubMenu sub=menu.addSubMenu("搜索");//添加子菜单
            sub.setIcon(android.R.drawable.ic_menu_search);
            sub.add(0, MENU_LOCAL, 0, "本地");
            sub.add(0, MENU_INTERNET, 0, "网络");
            return true;
        }
       
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {//重写onOptionsItemSelected(MenuItem item)方法实现事件监听
            super.onOptionsItemSelected(item);
            switch (item.getItemId()) {
            case MENU_SAVE:
             //做保存的那些事。
                break;
            case MENU_DELETE:
             //做删除的那些事。
                break;
            }
               
        return false;
        }

    阅读全文>>