Android menu Menu

    @Override
     public  Boolean the onCreateOptionsMenu (Menu MENU) {
         // the Inflate The MENU; ADDS items to the this IF IT IS The Present Action bar.
 //         getMenuInflater () the inflate (R.menu.main, MENU);. 

        The MenuItem menuSys = MENU. add (1001, 100, 1, " system menu" ); 
        menuSys.setTitle ( "a menu"); / * up to 6 sub-menus * / 

        the MenuItem menuUser = Menu.add (1001, 101,. 1, "user menu " ); 
        menuUser.setTitle ( " menu two " ); 
        menuUser.setShortcut ( 'C', 'C');/ * To set up shortcuts menu * / 

        MenuItem menuCust= menu.add(1001, 102, 1, "客户菜单");
        menuCust.setTitle("菜单三");

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        switch (item.getItemId()) {
        case 100:
            Toast.makeText(MainActivity.this, "选择了菜单一", 1).show();
            Intent intent = new Intent(MainActivity.this, NextActivity.class);
            item.setIntent(intent); / * Switch to the second the Activity * / 
            BREAK ;
         Case 101 : 
            Toast.makeText (. The MainActivity the this , "two selected menu",. 1 ) the .Show ();
             BREAK ;
         Case 102 : 
            . Toast.makeText (the MainActivity the this , "select menu three",. 1 ) the .Show ();
             BREAK ;
         default :
             BREAK ; 
        } 

        return  Super .onOptionsItemSelected (Item); 
    }

image

image

Guess you like

Origin www.cnblogs.com/zhangxuechao/p/11787585.html