private void onCreateMenu(Menu menu) { SubMenu note = menu.addSubMenu(0, 2002, 2, "Notes"); note.setIcon(R.drawable.menu_note); SubMenu parametre = menu.addSubMenu(0, 2001, 3, "Parametres"); parametre.setIcon(R.drawable.menu_param); // icone systeme SubMenu help = menu.addSubMenu(0, 2003, 4, "Aide"); help.setIcon(R.drawable.ad_question); // m.add(0, 1000, 0, "menu 1").setChecked(true).setCheckable(true); // m.add(0, 1001, 0, "menu 2").setEnabled(false); // pourquoi sous-classer une méthode ? = pour limiter les ressources // privilégier la création "à la demande" le menu est créé uniquement // lorsque la touche physique <menu> est appuyée par l'utilisateur // r.add(0, 1002, 0, "menu 3"); // r.add(0, 1003, 0, "menu 4"); }
/** On options menu creation. */ @Override public boolean onCreateOptionsMenu(Menu menu) { // === SubMenu sortMenu = menu.addSubMenu(group2Id, MENU_ITEM_SORT, sortBtnId, R.string.logsmenu_sort); sortMenu.add(MENU_ITEM_SORT, MENU_ITEM_SORT_ALL, 0, R.string.logsmenu_sort_all); sortMenu.add(MENU_ITEM_SORT, MENU_ITEM_SORT_BY_XODIL, 1, R.string.logsmenu_sort_xodil); sortMenu.add( MENU_ITEM_SORT, MENU_ITEM_SORT_BY_PODTVERDIL, 2, R.string.logsmenu_sort_podtverdil); sortMenu.setIcon(android.R.drawable.ic_menu_sort_alphabetically); // // === // MenuItem item_2 = menu.add(group2Id, MENU_ITEM_LOGSTEXT, // logstextBtnId, R.string.logsmenu_sort_all); // item_2.setIcon(android.R.drawable.ic_menu_edit); // // === // MenuItem item_2 = menu.add(group2Id, MENU_ITEM_SORT_ALL, // sortAllBtnId, R.string.logsmenu_sort_all); // item_2.setIcon(android.R.drawable.ic_menu_edit); // // // === // MenuItem item_3 = menu.add(group2Id, MENU_ITEM_SORT_BY_PODTVERDIL, // sortPodtverdilBtnId, R.string.logsmenu_sort_podtverdil); // item_3.setIcon(android.R.drawable.ic_menu_sort_by_size); return super.onCreateOptionsMenu(menu); }
/** * Sets up the options menu when the menu button is push, dynamic population of the station select * menu */ public boolean onPrepareOptionsMenu(Menu menu) { menu.clear(); boolean result = super.onCreateOptionsMenu(menu); SubMenu subMenu = menu.addSubMenu(BASE_OPTION_MENU, FM_BAND, Menu.NONE, R.string.band_select); subMenu.setIcon(android.R.drawable.ic_menu_mapmode); // Populate the band selection menu subMenu.add(BAND_SELECTION_MENU, BAND_US, Menu.NONE, R.string.band_us); subMenu.add(BAND_SELECTION_MENU, BAND_EU, Menu.NONE, R.string.band_eu); subMenu.add(BAND_SELECTION_MENU, BAND_CHINA, Menu.NONE, R.string.band_ch); subMenu.add(BAND_SELECTION_MENU, BAND_JAPAN, Menu.NONE, R.string.band_ja); subMenu.setGroupCheckable(BAND_SELECTION_MENU, true, true); subMenu.getItem(mSelectedBand).setChecked(true); return result; }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. // getMenuInflater().inflate(R.menu.activity_menu_principal, menu); // return true; // MENÚ 1 Y SUBMENÚ 1 // SubMenu sub1 = menu.addSubMenu(id del grupo, id del item, orden, título del menu) SubMenu sub1 = menu.addSubMenu(1, 1, 1, "Salir"); // Icono del menú 1 sub1.setIcon(R.drawable.salir); // Icono de las opciones del submenú del menú 1 sub1.setHeaderIcon(R.drawable.salir); // sub1.add(id del grupo, id del item, orden, título de la opción) // sub1.add(1, 10, 1, "Menu salir opción 0"); // sub1.add(1, 11, 1, "Menu salir opción 1"); // MENÚ 2 Y SUBMENÚ 2 PARECIDO AL ANTERIOR SubMenu sub2 = menu.addSubMenu(2, 2, 2, "Información"); sub2.setHeaderIcon(R.drawable.info); sub2.setIcon(R.drawable.info); // sub2.add(1, 20, 0, "Menú información opción 0"); // sub2.add(1, 21, 1, "Menú información opción 1"); /*Como podéis comprobar en las opciones del menú 1 de id del item le pongo * a la 1ª opción 10 y a la 2ª 11 debido a que pertenece al menú 1 la opción 0 y la opción 1 * lo mismo hago con las id de las opciones del 2º menú 20 a la primera y 21 a la segunda. * Esto cada persona lo puede poner como quiera, pero hay que tener cuidado, ya que * no se puede repetir el id de ningun item (opción) */ return super.onCreateOptionsMenu(menu); }
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem item; item = menu.add(Menu.NONE, MENU_UNDO, Menu.NONE, R.string.undo); item.setIcon(R.drawable.ic_menu_revert); item = menu.add(Menu.NONE, MENU_REDO, Menu.NONE, R.string.redo); item.setIcon(R.drawable.ic_menu_redo); item = menu.add(Menu.NONE, MENU_ADD_FACT, Menu.NONE, R.string.add); item.setIcon(R.drawable.ic_menu_add); item = menu.add( Menu.NONE, MENU_CHANGE_ORDER, Menu.NONE, R.string.card_browser_change_display_order); item.setIcon(R.drawable.ic_menu_sort_by_size); item = menu.add(Menu.NONE, MENU_SHOW_MARKED, Menu.NONE, R.string.card_browser_show_marked); item.setIcon(R.drawable.ic_menu_star_on); SubMenu selectSubMenu = menu.addSubMenu(Menu.NONE, MENU_SELECT, Menu.NONE, R.string.card_browser_search); selectSubMenu.setIcon(R.drawable.ic_menu_search); selectSubMenu.add( Menu.NONE, MENU_SELECT_SUSPENDED, Menu.NONE, R.string.card_browser_search_suspended); selectSubMenu.add(Menu.NONE, MENU_SELECT_TAG, Menu.NONE, R.string.card_browser_search_by_tag); item.setIcon(R.drawable.ic_menu_close_clear_cancel); return true; }
public static void getMenu( AlfrescoSession session, Menu menu, Folder parentFolder, boolean extended) { MenuItem mi; if (parentFolder == null) { return; } Permissions permission = session.getServiceRegistry().getDocumentFolderService().getPermissions(parentFolder); if (!extended && parentFolder != null && permission.canAddChildren()) { mi = menu.add( Menu.NONE, MenuActionItem.MENU_CREATE_FOLDER, Menu.FIRST + MenuActionItem.MENU_CREATE_FOLDER, R.string.folder_create); mi.setIcon(R.drawable.ic_add_folder); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); } if (!extended && parentFolder != null && permission.canAddChildren()) { SubMenu devCaptureMenu = menu.addSubMenu( Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE, Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE, R.string.upload); devCaptureMenu.setIcon(android.R.drawable.ic_menu_add); devCaptureMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); devCaptureMenu.add( Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_PHOTO, Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_PHOTO, R.string.take_photo); if (AndroidVersion.isICSOrAbove()) { devCaptureMenu.add( Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_VIDEO, Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_VIDEO, R.string.make_video); } devCaptureMenu.add( Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE_MIC_AUDIO, Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_MIC_AUDIO, R.string.record_audio); devCaptureMenu.add( Menu.NONE, MenuActionItem.MENU_UPLOAD, Menu.FIRST + MenuActionItem.MENU_UPLOAD, R.string.content_upload); } if (extended && parentFolder != null && permission.canEdit()) { mi = menu.add( Menu.NONE, MenuActionItem.MENU_EDIT, Menu.FIRST + MenuActionItem.MENU_EDIT, R.string.edit); mi.setIcon(R.drawable.ic_edit); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); } if (extended && parentFolder != null && permission.canDelete()) { mi = menu.add( Menu.NONE, MenuActionItem.MENU_DELETE_FOLDER, Menu.FIRST + MenuActionItem.MENU_DELETE_FOLDER, R.string.delete); mi.setIcon(R.drawable.ic_delete); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); } if (!extended && parentFolder != null) { mi = menu.add( Menu.NONE, MenuActionItem.MENU_REFRESH, Menu.FIRST + MenuActionItem.MENU_REFRESH, R.string.refresh); mi.setIcon(R.drawable.ic_refresh); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); } }
public static void getMenu( AlfrescoSession session, Menu menu, Folder parentFolder, boolean actionMode) { MenuItem mi; if (parentFolder == null) { return; } Permissions permission = null; try { permission = session.getServiceRegistry().getDocumentFolderService().getPermissions(parentFolder); } catch (Exception e) { return; } if (!actionMode) { mi = menu.add( Menu.NONE, MenuActionItem.MENU_SEARCH_FOLDER, Menu.FIRST + MenuActionItem.MENU_SEARCH_FOLDER, R.string.search); mi.setIcon(R.drawable.ic_search); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); } if (!actionMode && permission.canAddChildren()) { mi = menu.add( Menu.NONE, MenuActionItem.MENU_CREATE_FOLDER, Menu.FIRST + MenuActionItem.MENU_CREATE_FOLDER, R.string.folder_create); mi.setIcon(R.drawable.ic_add_folder); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); SubMenu createMenu = menu.addSubMenu( Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE, Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE, R.string.add_menu); createMenu.setIcon(android.R.drawable.ic_menu_add); createMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); createMenu.add( Menu.NONE, MenuActionItem.MENU_UPLOAD, Menu.FIRST + MenuActionItem.MENU_UPLOAD, R.string.upload_title); createMenu.add( Menu.NONE, MenuActionItem.MENU_CREATE_DOCUMENT, Menu.FIRST + MenuActionItem.MENU_CREATE_DOCUMENT, R.string.create_document); createMenu.add( Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_PHOTO, Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_PHOTO, R.string.take_photo); if (AndroidVersion.isICSOrAbove()) { createMenu.add( Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_VIDEO, Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_VIDEO, R.string.make_video); } createMenu.add( Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE_MIC_AUDIO, Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_MIC_AUDIO, R.string.record_audio); } if (actionMode) { mi = menu.add( Menu.NONE, MenuActionItem.MENU_DETAILS, Menu.FIRST + MenuActionItem.MENU_DETAILS, R.string.action_view_properties); mi.setIcon(R.drawable.ic_details); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); } if (actionMode && permission.canEdit()) { mi = menu.add( Menu.NONE, MenuActionItem.MENU_EDIT, Menu.FIRST + MenuActionItem.MENU_EDIT, R.string.edit); mi.setIcon(R.drawable.ic_edit); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); } if (actionMode && permission.canDelete()) { mi = menu.add( Menu.NONE, MenuActionItem.MENU_DELETE, Menu.FIRST + MenuActionItem.MENU_DELETE, R.string.delete); mi.setIcon(R.drawable.ic_delete); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); } if (!actionMode) { mi = menu.add( Menu.NONE, MenuActionItem.MENU_REFRESH, Menu.FIRST + MenuActionItem.MENU_REFRESH, R.string.refresh); mi.setIcon(R.drawable.ic_refresh); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); } }
private void addAddonMenuItem(final MenuItemInfo info) { if (mMenu == null) { if (mAddonMenuItemsCache == null) mAddonMenuItemsCache = new Vector<MenuItemInfo>(); mAddonMenuItemsCache.add(info); return; } Menu menu; if (info.parent == 0) { menu = mMenu; } else { MenuItem parent = mMenu.findItem(info.parent); if (parent == null) return; if (!parent.hasSubMenu()) { mMenu.removeItem(parent.getItemId()); menu = mMenu.addSubMenu(Menu.NONE, parent.getItemId(), Menu.NONE, parent.getTitle()); if (parent.getIcon() != null) ((SubMenu) menu).getItem().setIcon(parent.getIcon()); } else { menu = parent.getSubMenu(); } } final MenuItem item = menu.add(Menu.NONE, info.id, Menu.NONE, info.label); item.setOnMenuItemClickListener( new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { Log.i(LOGTAG, "menu item clicked"); GeckoAppShell.sendEventToGecko( GeckoEvent.createBroadcastEvent( "Menu:Clicked", Integer.toString(info.id - ADDON_MENU_OFFSET))); return true; } }); if (info.icon != null) { if (info.icon.startsWith("data")) { BitmapDrawable drawable = new BitmapDrawable(BitmapUtils.getBitmapFromDataURI(info.icon)); item.setIcon(drawable); } else if (info.icon.startsWith("jar:") || info.icon.startsWith("file://")) { GeckoAppShell.getHandler() .post( new Runnable() { public void run() { try { URL url = new URL(info.icon); InputStream is = (InputStream) url.getContent(); try { Drawable drawable = Drawable.createFromStream(is, "src"); item.setIcon(drawable); } finally { is.close(); } } catch (Exception e) { Log.w(LOGTAG, "Unable to set icon", e); } } }); } } item.setCheckable(info.checkable); item.setChecked(info.checked); item.setEnabled(info.enabled); item.setVisible(info.visible); }