android.view.MenuItem.setOnMenuItemClickListener()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(309)

本文整理了Java中android.view.MenuItem.setOnMenuItemClickListener()方法的一些代码示例,展示了MenuItem.setOnMenuItemClickListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MenuItem.setOnMenuItemClickListener()方法的具体详情如下:
包路径:android.view.MenuItem
类名称:MenuItem
方法名:setOnMenuItemClickListener

暂无

代码示例

代码示例来源:origin: aa112901/remusic

  1. @Override
  2. public boolean onCreateOptionsMenu(Menu menu) {
  3. // Inflate the menu; this adds items to the action bar if it is present.
  4. final MenuInflater inflater = getMenuInflater();
  5. inflater.inflate(R.menu.down, menu);
  6. MenuItem down = menu.findItem(R.id.down);
  7. down.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  8. @Override
  9. public boolean onMenuItemClick(MenuItem item) {
  10. Intent intent = new Intent(SelectActivity.this, DownActivity.class);
  11. startActivity(intent);
  12. return false;
  13. }
  14. });
  15. return true;
  16. }

代码示例来源:origin: square/leakcanary

  1. @Override public boolean onCreateOptionsMenu(Menu menu) {
  2. AnalyzedHeap visibleLeak = getVisibleLeak();
  3. if (visibleLeak != null) {
  4. menu.add(R.string.leak_canary_share_leak)
  5. .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  6. @Override public boolean onMenuItemClick(MenuItem item) {
  7. shareLeak();
  8. return true;
  9. }
  10. });
  11. if (visibleLeak.heapDumpFileExists) {
  12. menu.add(R.string.leak_canary_share_heap_dump)
  13. .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  14. @Override public boolean onMenuItemClick(MenuItem item) {
  15. shareHeapDump();
  16. return true;
  17. }
  18. });
  19. }
  20. return true;
  21. }
  22. return false;
  23. }

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

  1. @Override
  2. public boolean onCreateOptionsMenu(Menu menu) {
  3. getMenuInflater().inflate(R.menu.json_menu, menu);
  4. MenuItem encodeButton = menu.findItem(R.id.encode);
  5. encodeButton.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  6. @Override
  7. public boolean onMenuItemClick(MenuItem item) {
  8. DialogInterface.OnClickListener listener = new ButtonOnClick();
  9. AlertDialog.Builder builder = new AlertDialog.Builder(JsonPreviewActivity.this);
  10. builder.setNegativeButton("取消",null);
  11. builder.setPositiveButton("确认", listener);
  12. builder.setSingleChoiceItems(encodeItem,selectedEncode,listener);
  13. builder.create().show();
  14. return true;
  15. }
  16. });
  17. return super.onCreateOptionsMenu(menu);
  18. }

代码示例来源:origin: markzhai/AndroidPerformanceMonitor

  1. @Override
  2. public boolean onCreateOptionsMenu(Menu menu) {
  3. final BlockInfoEx blockInfo = getBlock(mBlockStartTime);
  4. if (blockInfo != null) {
  5. menu.add(R.string.block_canary_share_leak)
  6. .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  7. @Override
  8. public boolean onMenuItemClick(MenuItem item) {
  9. shareBlock(blockInfo);
  10. return true;
  11. }
  12. });
  13. menu.add(R.string.block_canary_share_stack_dump)
  14. .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  15. @Override
  16. public boolean onMenuItemClick(MenuItem item) {
  17. shareHeapDump(blockInfo);
  18. return true;
  19. }
  20. });
  21. return true;
  22. }
  23. return false;
  24. }

代码示例来源:origin: EverythingMe/overscroll-decor

  1. @Override
  2. public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  3. final MenuItem detachMenuItem = menu.add("Detach over-scroll").setVisible(true);
  4. final MenuItem attachMenuItem = menu.add("Attach over-scroll").setVisible(false);
  5. detachMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  6. @Override
  7. public boolean onMenuItemClick(MenuItem item) {
  8. detachMenuItem.setVisible(false);
  9. attachMenuItem.setVisible(true);
  10. mHorizOverScrollEffect.detach();
  11. mVertOverScrollEffect.detach();
  12. return true;
  13. }
  14. });
  15. attachMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  16. @Override
  17. public boolean onMenuItemClick(MenuItem item) {
  18. detachMenuItem.setVisible(true);
  19. attachMenuItem.setVisible(false);
  20. initHorizontalRecyclerView((RecyclerView) getView().findViewById(R.id.horizontal_recycler_view));
  21. initVerticalRecyclerView((RecyclerView) getView().findViewById(R.id.vertical_recycler_view));
  22. return true;
  23. }
  24. });
  25. super.onCreateOptionsMenu(menu, inflater);
  26. }

代码示例来源:origin: square/sqlbrite

  1. @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  2. super.onCreateOptionsMenu(menu, inflater);
  3. MenuItem item = menu.add(R.string.new_list)
  4. .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  5. @Override public boolean onMenuItemClick(MenuItem item) {
  6. listener.onNewListClicked();
  7. return true;
  8. }
  9. });
  10. MenuItemCompat.setShowAsAction(item, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
  11. }

代码示例来源:origin: square/sqlbrite

  1. @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  2. super.onCreateOptionsMenu(menu, inflater);
  3. MenuItem item = menu.add(R.string.new_item)
  4. .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  5. @Override public boolean onMenuItemClick(MenuItem item) {
  6. listener.onNewItemClicked(getListId());
  7. return true;
  8. }
  9. });
  10. MenuItemCompat.setShowAsAction(item, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
  11. }

代码示例来源:origin: ankidroid/Anki-Android

  1. @Override
  2. public void onPrepareSubMenu(SubMenu subMenu) {
  3. subMenu.clear();
  4. getMenuInflater().inflate(R.menu.reviewer_bury, subMenu);
  5. for (int i = 0; i < subMenu.size(); i++) {
  6. subMenu.getItem(i).setOnMenuItemClickListener(this);
  7. }
  8. }

代码示例来源:origin: ankidroid/Anki-Android

  1. @Override
  2. public void onPrepareSubMenu(SubMenu subMenu) {
  3. subMenu.clear();
  4. getMenuInflater().inflate(R.menu.reviewer_suspend, subMenu);
  5. for (int i = 0; i < subMenu.size(); i++) {
  6. subMenu.getItem(i).setOnMenuItemClickListener(this);
  7. }
  8. }

代码示例来源:origin: ankidroid/Anki-Android

  1. @Override
  2. public void onPrepareSubMenu(SubMenu subMenu) {
  3. subMenu.clear();
  4. getMenuInflater().inflate(R.menu.reviewer_schedule, subMenu);
  5. for (int i = 0; i < subMenu.size(); i++) {
  6. subMenu.getItem(i).setOnMenuItemClickListener(this);
  7. }
  8. }

代码示例来源:origin: k9mail/k-9

  1. .setOnMenuItemClickListener(listener);
  2. .setOnMenuItemClickListener(listener);
  3. .setOnMenuItemClickListener(listener);
  4. .setOnMenuItemClickListener(listener);
  5. context.getString(R.string.webview_contextmenu_image_save_action) :
  6. context.getString(R.string.webview_contextmenu_image_download_action))
  7. .setOnMenuItemClickListener(listener);
  8. .setOnMenuItemClickListener(listener);
  9. .setOnMenuItemClickListener(listener);
  10. .setOnMenuItemClickListener(listener);
  11. .setOnMenuItemClickListener(listener);
  12. .setOnMenuItemClickListener(listener);
  13. .setOnMenuItemClickListener(listener);
  14. .setOnMenuItemClickListener(listener);

代码示例来源:origin: TeamNewPipe/NewPipe

  1. private void buildItemPopupMenu(final PlayQueueItem item, final View view) {
  2. final PopupMenu menu = new PopupMenu(this, view);
  3. final MenuItem remove = menu.getMenu().add(RECYCLER_ITEM_POPUP_MENU_GROUP_ID, /*pos=*/0,
  4. Menu.NONE, R.string.play_queue_remove);
  5. remove.setOnMenuItemClickListener(menuItem -> {
  6. if (player == null) return false;
  7. final int index = player.getPlayQueue().indexOf(item);
  8. if (index != -1) player.getPlayQueue().remove(index);
  9. return true;
  10. });
  11. final MenuItem detail = menu.getMenu().add(RECYCLER_ITEM_POPUP_MENU_GROUP_ID, /*pos=*/1,
  12. Menu.NONE, R.string.play_queue_stream_detail);
  13. detail.setOnMenuItemClickListener(menuItem -> {
  14. onOpenDetail(item.getServiceId(), item.getUrl(), item.getTitle());
  15. return true;
  16. });
  17. final MenuItem append = menu.getMenu().add(RECYCLER_ITEM_POPUP_MENU_GROUP_ID, /*pos=*/2,
  18. Menu.NONE, R.string.append_playlist);
  19. append.setOnMenuItemClickListener(menuItem -> {
  20. openPlaylistAppendDialog(Collections.singletonList(item));
  21. return true;
  22. });
  23. final MenuItem share = menu.getMenu().add(RECYCLER_ITEM_POPUP_MENU_GROUP_ID, /*pos=*/3,
  24. Menu.NONE, R.string.share);
  25. share.setOnMenuItemClickListener(menuItem -> {
  26. shareUrl(item.getTitle(), item.getUrl());
  27. return true;
  28. });
  29. menu.show();
  30. }

代码示例来源:origin: TeamNewPipe/NewPipe

  1. captionOffItem.setOnMenuItemClickListener(menuItem -> {
  2. final int textRendererIndex = getRendererIndex(C.TRACK_TYPE_TEXT);
  3. if (textRendererIndex != RENDERER_UNAVAILABLE) {
  4. MenuItem captionItem = captionPopupMenu.getMenu().add(captionPopupMenuGroupId,
  5. i + 1, Menu.NONE, captionLanguage);
  6. captionItem.setOnMenuItemClickListener(menuItem -> {
  7. final int textRendererIndex = getRendererIndex(C.TRACK_TYPE_TEXT);
  8. if (textRendererIndex != RENDERER_UNAVAILABLE) {

代码示例来源:origin: robolectric/robolectric

  1. item = item.setEnabled(true);
  2. assertThat(item).isNotNull();
  3. item = item.setOnMenuItemClickListener(null);
  4. assertThat(item).isNotNull();
  5. item = item.setActionProvider(null);

代码示例来源:origin: ankidroid/Anki-Android

  1. };
  2. MenuItem mToolbarAddItem = mToolbar.getMenu().findItem(R.id.tags_dialog_action_add);
  3. mToolbarAddItem.setOnMenuItemClickListener(menuItem -> {
  4. String query = mToolbarSearchView.getQuery().toString();
  5. if (mToolbarSearchItem.isActionViewExpanded() && !TextUtils.isEmpty(query)) {
  6. checkAllItem.setOnMenuItemClickListener(menuItem -> {
  7. boolean changed = false;
  8. if (mCurrentTags.containsAll(mTagsArrayAdapter.mTagsList)) {

代码示例来源:origin: Cleveroad/WaveInApp

  1. @Override
  2. public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  3. super.onCreateOptionsMenu(menu, inflater);
  4. inflater.inflate(R.menu.main, menu);
  5. MenuItem preset = menu.findItem(R.id.action_preset);
  6. Menu m = preset.getSubMenu();
  7. String[] presets = getResources().getStringArray(R.array.presets);
  8. for (int i = 0; i < presets.length; i++) {
  9. final int index = i + 1;
  10. m.add(Menu.NONE, i, Menu.NONE, presets[i]).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  11. @Override
  12. public boolean onMenuItemClick(MenuItem item) {
  13. setPreset(index);
  14. return true;
  15. }
  16. });
  17. }
  18. }

代码示例来源:origin: willowtreeapps/Hyperion-Android

  1. private void showMenu(View anchor) {
  2. final Context context = anchor.getContext();
  3. if (popupMenu != null) {
  4. popupMenu.dismiss();
  5. }
  6. popupMenu = new PopupMenu(context, anchor);
  7. popupMenu.inflate(R.menu.hgc_menu_options);
  8. final Menu menu = popupMenu.getMenu();
  9. final MenuItem areHapticsEnabledItem = menu.findItem(R.id.menu_item_use_haptics);
  10. areHapticsEnabledItem.setChecked(detector.areHapticsEnabled());
  11. areHapticsEnabledItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
  12. @Override
  13. public boolean onMenuItemClick(MenuItem item) {
  14. boolean areHapticsEnabled = !item.isChecked();
  15. item.setChecked(areHapticsEnabled);
  16. detector.setHapticsEnabled(areHapticsEnabled);
  17. return true;
  18. }
  19. });
  20. popupMenu.show();
  21. }

代码示例来源:origin: Ferfalk/SimpleSearchView

  1. /**
  2. * Handle click events for the MenuItem.
  3. *
  4. * @param menuItem MenuItem that opens the search
  5. */
  6. public void setMenuItem(@NonNull MenuItem menuItem) {
  7. menuItem.setOnMenuItemClickListener(item -> {
  8. showSearch();
  9. return true;
  10. });
  11. }

代码示例来源:origin: andstatus/andstatus

  1. private void createCreateNoteButton(Menu menu) {
  2. MenuItem item = menu.findItem(R.id.createNoteButton);
  3. if (item != null) {
  4. item.setOnMenuItemClickListener(item1 -> {
  5. MyAccount accountForButton = accountForCreateNoteButton();
  6. if (accountForButton != null) {
  7. startEditingNote(NoteEditorData.newEmpty(accountForButton));
  8. }
  9. return false;
  10. });
  11. }
  12. }

代码示例来源:origin: adolfAn/FBReader_AS

  1. private void addMenuItem(Menu menu, String actionId, Integer iconId, String name) {
  2. if (name == null) {
  3. name = ZLResource.resource("menu").getResource(actionId).getValue();
  4. }
  5. final MenuItem menuItem = menu.add(name);
  6. if (iconId != null) {
  7. menuItem.setIcon(iconId);
  8. }
  9. menuItem.setOnMenuItemClickListener(myMenuListener);
  10. myMenuItemMap.put(menuItem, actionId);
  11. }

相关文章