Onelong

分享知识,与你一起进步......
RSS icon Home icon
  • android 创建子菜单的方法

    post by onelong / 2010-5-29 19:44 Saturday [android]

     @Override
        public boolean onCreateOptionsMenu(Menu menu) {
                            //重写onCreateOptionsMenu(Menu menu)方法实现创建选项菜单
            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;
        }
     public boolean onOptionsItemSelected(MenuItem item) {
        //重写onOptionsItemSelected(MenuItem item)方法实现事件监听
            super.onOptionsItemSelected(item);
            switch (item.getItemId()) {
             case MENU_LOCAL:
                //处理点击事件
              break;
            }
    实现子菜单的功能的步骤:
    1。重新实现public boolean onCreateOptionsMenu(Menu menu)
    2。重新实现public boolean onOptionsItemSelected(MenuItem item)


    引用地址:
     

    我要评论