zoukankan      html  css  js  c++  java
  • Android 菜单 Menu

        @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);
    
            MenuItem menuSys = menu.add(1001, 100, 1, "系統菜单");
            menuSys.setTitle("菜单一"); /* 最多可以显示6个子菜单 */
    
            MenuItem menuUser = menu.add(1001, 101, 1, "用户菜单");
            menuUser.setTitle("菜单二");
            menuUser.setShortcut('c', 'c'); /* 给菜单设置快捷键 */
    
            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); /* 切换到第二个Activity */
                break;
            case 101:
                Toast.makeText(MainActivity.this, "选择了菜单二", 1).show();
                break;
            case 102:
                Toast.makeText(MainActivity.this, "选择了菜单三", 1).show();
                break;
            default:
                break;
            }
    
            return super.onOptionsItemSelected(item);
        }

    image

    image

  • 相关阅读:
    Redis(二)
    Redis
    Nginx
    Linux的环境配置
    深入mysql
    SpringBoot入门
    Thymeleaf入门
    Mybatis之resultMap
    Mybatis入门
    使用第三方实现微信登录
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/11787585.html
Copyright © 2011-2022 走看看