Java Code Examples for android.view.Menu#add()
The following examples show how to use
android.view.Menu#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActionbarActivity.java From ui with Apache License 2.0 | 6 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.activity_screen_slide, menu); menu.findItem(R.id.action_previous).setEnabled(viewPager.getCurrentItem() > 0); //help since this attribute is ignored in the xml by api <11. ie 2.3.3 //but the change is should xml, use app: instead of android is the ActionBarActivity can read it. //see xml //MenuItemCompat.setShowAsAction(menu.findItem(R.id.action_previous),MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE, (viewPager.getCurrentItem() == mPagerAdapter.getCount() - 1) ? R.string.action_finish : R.string.action_next); //item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); MenuItemCompat.setShowAsAction(item,MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); return true; }
Example 2
Source File: CustomSelectionCallback.java From QuickLyric with GNU General Public License v3.0 | 6 votes |
@Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { changeThemeColors(true); if (menu.size() > 0) { menu.add(0, 9876, Menu.NONE, R.string.share); menu.findItem(9876).setIcon(R.drawable.ic_menu_share); menu.findItem(9876).setOnMenuItemClickListener(item -> { View focus = mActivity.getCurrentFocus(); if (focus instanceof TextView) { CharSequence selection = ((TextView) focus).getText().subSequence(((TextView) focus) .getSelectionStart(), ((TextView) focus).getSelectionEnd()); final Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, selection.toString()); mActivity.startActivity(Intent.createChooser(sendIntent, mActivity.getString(R.string.share))); return true; } return false; }); } return true; }
Example 3
Source File: PlayerActivity.java From Exoplayer_VLC with Apache License 2.0 | 6 votes |
public void showAudioPopup(View v) { PopupMenu popup = new PopupMenu(this, v); Menu menu = popup.getMenu(); menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio); final MenuItem backgroundAudioItem = menu.findItem(0); backgroundAudioItem.setCheckable(true); backgroundAudioItem.setChecked(enableBackgroundAudio); OnMenuItemClickListener clickListener = new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item == backgroundAudioItem) { enableBackgroundAudio = !item.isChecked(); return true; } return false; } }; configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO); popup.show(); }
Example 4
Source File: ScreenSlideActivity.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.activity_screen_slide, menu); menu.findItem(R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0); // Add either a "next" or "finish" button to the action bar, depending on which page // is currently selected. MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE, (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1) ? R.string.action_finish : R.string.action_next); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); return true; }
Example 5
Source File: FriendsEventFRAGMENT.java From ALLGO with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // TODO 添加actionbar菜单 MenuItem actionItem2 = menu.add("组织活动") ; actionItem2.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); actionItem2.setIcon(R.drawable.ic_action_new_label); }
Example 6
Source File: NavigationActivity.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * {@inheritDoc} */ @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.add(0, OPTION_RELOAD_DATABASE, 0, getString(R.string.menu_reload_db)); menu.add(0, OPTION_SETTINGS, 1, getString(R.string.menu_settings)); menu.add(0, OPTION_SYNC, 2, getString(R.string.menu_sync)); return true; }
Example 7
Source File: CollectionCoverSearchFragment.java From Mizuu with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { for (int i = 0; i < mItems.length; i++) menu.add(0, i, i, mItems[i]); menu.setGroupCheckable(0, true, true); super.onCreateOptionsMenu(menu, inflater); }
Example 8
Source File: EncounterTaskList.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); Locales.updateLocale(this, getString(R.string.force_locale)); menu.add(0, OPTION_SYNC_PATIENT, 0, getString(R.string.title_synch_subjects)); menu.add(0, OPTION_SYNC_TASKS, 1, getString(R.string.title_synch_tasks)); //menu.add(0, OPTION_CLEAR, 2, "CLEAR"); return true; }
Example 9
Source File: CursorFragment.java From V.FlyoutTest with MIT License | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // Place an action bar item for searching. MenuItem item = menu.add("Search"); item.setIcon(android.R.drawable.ic_menu_search); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); SearchView sv = new SearchView(getActivity()); sv.setOnQueryTextListener(this); item.setActionView(sv); }
Example 10
Source File: NavigationActivity.java From SmartPack-Kernel-Manager with GNU General Public License v3.0 | 5 votes |
private void appendFragments(boolean setShortcuts) { mActualFragments.clear(); Menu menu = mNavigationView.getMenu(); menu.clear(); SubMenu lastSubMenu = null; for (NavigationFragment navigationFragment : mFragments) { Class<? extends Fragment> fragmentClass = navigationFragment.mFragmentClass; int id = navigationFragment.mId; if (fragmentClass == null) { lastSubMenu = menu.addSubMenu(id); mActualFragments.put(id, null); } else if (Prefs.getBoolean(fragmentClass.getSimpleName() + "_enabled", true, this)) { MenuItem menuItem = lastSubMenu == null ? menu.add(0, id, 0, id) : lastSubMenu.add(0, id, 0, id); menuItem.setIcon(ViewUtils.getColoredIcon(Prefs.getBoolean("section_icons", true, this) && navigationFragment.mDrawable != 0 ? navigationFragment.mDrawable : R.drawable.ic_blank, this)); menuItem.setCheckable(true); if (mSelection != 0) { mNavigationView.setCheckedItem(mSelection); } mActualFragments.put(id, fragmentClass); } } if (setShortcuts) { setShortcuts(); } }
Example 11
Source File: InstallFromListActivity.java From commcare-android with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.add(0, RETRIEVE_APPS_FOR_DIFF_USER, 0, Localization.get("menu.app.list.install.other.user")); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.install_from_list_menu, menu); } return true; }
Example 12
Source File: General.java From redalert-android with Apache License 2.0 | 5 votes |
void initializeShareButton(Menu OptionsMenu) { // Add share button MenuItem shareItem = OptionsMenu.add(Menu.NONE, Menu.NONE, Menu.NONE, getString(R.string.share)); // Set up the view shareItem.setIcon(R.drawable.ic_share); // Specify the show flags MenuItemCompat.setShowAsAction(shareItem, MenuItem.SHOW_AS_ACTION_ALWAYS); // On click, open share shareItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { // Prepare share intent Intent shareIntent = new Intent(Intent.ACTION_SEND); // Set as text/plain shareIntent.setType("text/plain"); // Add text shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.shareMessage)); // Show chooser startActivity(Intent.createChooser(shareIntent, getString(R.string.shareDesc))); // Consume event return true; } }); }
Example 13
Source File: PrivacyPreferences.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); MenuItem help = menu.add( Menu.NONE, R.id.menu_id_targeted_help, Menu.NONE, R.string.menu_help); help.setIcon(R.drawable.ic_help_and_feedback); }
Example 14
Source File: SampleMilitaryIconsMarker.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // Put overlay items first mMapView.getOverlayManager().onCreateOptionsMenu(menu, MENU_LAST_ID, mMapView); menu.add(0, MENU_ZOOMIN_ID, Menu.NONE, "ZoomIn"); menu.add(0, MENU_ZOOMOUT_ID, Menu.NONE, "ZoomOut"); menu.add(0, MENU_ZOOMOUT_ID, Menu.NONE, "ZoomOut"); menu.add(0, MENU_ADDICONS_ID, Menu.NONE, "AddIcons"); super.onCreateOptionsMenu(menu, inflater); }
Example 15
Source File: SettingsFragment.java From openboard with GNU General Public License v3.0 | 5 votes |
@Override public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { if (FeedbackUtils.isHelpAndFeedbackFormSupported()) { menu.add(NO_MENU_GROUP, MENU_HELP_AND_FEEDBACK /* itemId */, MENU_HELP_AND_FEEDBACK /* order */, R.string.help_and_feedback); } final int aboutResId = FeedbackUtils.getAboutKeyboardTitleResId(); if (aboutResId != 0) { menu.add(NO_MENU_GROUP, MENU_ABOUT /* itemId */, MENU_ABOUT /* order */, aboutResId); } }
Example 16
Source File: ToDoManagerActivity.java From coursera-android-labs with MIT License | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.add(Menu.NONE, MENU_DELETE, Menu.NONE, "Delete all"); menu.add(Menu.NONE, MENU_DUMP, Menu.NONE, "Dump to log"); return true; }
Example 17
Source File: CodenameOneActivity.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); menu.clear(); try { Form currentForm = Display.getInstance().getCurrent(); if (currentForm == null || Toolbar.isGlobalToolbar()) { return false; } int numCommands = currentForm.getCommandCount(); // If there are no commands, there's nothing to put in the menu if (numCommands == 0) { return false; } // Build menu items from commands for (int n = 0; n < numCommands; n++) { Command command = currentForm.getCommand(n); if (command != null) { String txt = currentForm.getUIManager().localize(command.getCommandName(), command.getCommandName()); MenuItem item = menu.add(Menu.NONE, n, Menu.NONE, txt); Image icon = command.getIcon(); if (icon != null) { Bitmap b = (Bitmap) icon.getImage(); // Using BitmapDrawable with resources, to use device density (from 1.6 and above). BitmapDrawable d = new BitmapDrawable(getResources(), b); item.setIcon(d); } if (!command.isEnabled()) { item.setEnabled(false); } if (android.os.Build.VERSION.SDK_INT >= 11 && command.getClientProperty("android:showAsAction") != null) { String androidShowAsAction = command.getClientProperty("android:showAsAction").toString(); // From https://developer.android.com/guide/topics/resources/menu-resource.html // "ifRoom" | "never" | "withText" | "always" | "collapseActionView" if (androidShowAsAction.equalsIgnoreCase("ifRoom")) { item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); } else if (androidShowAsAction.equalsIgnoreCase("never")) { item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } else if (androidShowAsAction.equalsIgnoreCase("withText")) { item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); } else if (androidShowAsAction.equalsIgnoreCase("always")) { item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); } else if (android.os.Build.VERSION.SDK_INT >= 14 && androidShowAsAction.equalsIgnoreCase("collapseActionView")) { item.setShowAsAction(8); //MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW } } } } } catch (Throwable t) { } return nativeMenu; }
Example 18
Source File: RecentActivity.java From document-viewer with GNU General Public License v3.0 | 4 votes |
protected void addStorageMenuItem(final Menu menu, final int resId, final String name, final String path) { final MenuItem bmi = menu.add(R.id.actions_storageGroup, R.id.actions_storage, Menu.NONE, name); bmi.setIcon(resId); ActionMenuHelper.setMenuItemExtra(bmi, "path", path); }
Example 19
Source File: LoaderThrottleSupport.java From V.FlyoutTest with MIT License | 4 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuItem populateItem = menu.add(Menu.NONE, POPULATE_ID, 0, "Populate"); MenuItemCompat.setShowAsAction(populateItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); MenuItem clearItem = menu.add(Menu.NONE, CLEAR_ID, 0, "Clear"); MenuItemCompat.setShowAsAction(clearItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); }
Example 20
Source File: MainActivity.java From PedestrianDetectionSystem with Apache License 2.0 | 4 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { menu.add("关于"); return super.onCreateOptionsMenu(menu); }