本文整理了Java中android.view.MenuItem.setOnMenuItemClickListener()
方法的一些代码示例,展示了MenuItem.setOnMenuItemClickListener()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MenuItem.setOnMenuItemClickListener()
方法的具体详情如下:
包路径:android.view.MenuItem
类名称:MenuItem
方法名:setOnMenuItemClickListener
暂无
代码示例来源:origin: aa112901/remusic
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
final MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.down, menu);
MenuItem down = menu.findItem(R.id.down);
down.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(SelectActivity.this, DownActivity.class);
startActivity(intent);
return false;
}
});
return true;
}
代码示例来源:origin: square/leakcanary
@Override public boolean onCreateOptionsMenu(Menu menu) {
AnalyzedHeap visibleLeak = getVisibleLeak();
if (visibleLeak != null) {
menu.add(R.string.leak_canary_share_leak)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override public boolean onMenuItemClick(MenuItem item) {
shareLeak();
return true;
}
});
if (visibleLeak.heapDumpFileExists) {
menu.add(R.string.leak_canary_share_heap_dump)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override public boolean onMenuItemClick(MenuItem item) {
shareHeapDump();
return true;
}
});
}
return true;
}
return false;
}
代码示例来源:origin: JZ-Darkal/AndroidHttpCapture
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.json_menu, menu);
MenuItem encodeButton = menu.findItem(R.id.encode);
encodeButton.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
DialogInterface.OnClickListener listener = new ButtonOnClick();
AlertDialog.Builder builder = new AlertDialog.Builder(JsonPreviewActivity.this);
builder.setNegativeButton("取消",null);
builder.setPositiveButton("确认", listener);
builder.setSingleChoiceItems(encodeItem,selectedEncode,listener);
builder.create().show();
return true;
}
});
return super.onCreateOptionsMenu(menu);
}
代码示例来源:origin: markzhai/AndroidPerformanceMonitor
@Override
public boolean onCreateOptionsMenu(Menu menu) {
final BlockInfoEx blockInfo = getBlock(mBlockStartTime);
if (blockInfo != null) {
menu.add(R.string.block_canary_share_leak)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
shareBlock(blockInfo);
return true;
}
});
menu.add(R.string.block_canary_share_stack_dump)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
shareHeapDump(blockInfo);
return true;
}
});
return true;
}
return false;
}
代码示例来源:origin: EverythingMe/overscroll-decor
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
final MenuItem detachMenuItem = menu.add("Detach over-scroll").setVisible(true);
final MenuItem attachMenuItem = menu.add("Attach over-scroll").setVisible(false);
detachMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
detachMenuItem.setVisible(false);
attachMenuItem.setVisible(true);
mHorizOverScrollEffect.detach();
mVertOverScrollEffect.detach();
return true;
}
});
attachMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
detachMenuItem.setVisible(true);
attachMenuItem.setVisible(false);
initHorizontalRecyclerView((RecyclerView) getView().findViewById(R.id.horizontal_recycler_view));
initVerticalRecyclerView((RecyclerView) getView().findViewById(R.id.vertical_recycler_view));
return true;
}
});
super.onCreateOptionsMenu(menu, inflater);
}
代码示例来源:origin: square/sqlbrite
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
MenuItem item = menu.add(R.string.new_list)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override public boolean onMenuItemClick(MenuItem item) {
listener.onNewListClicked();
return true;
}
});
MenuItemCompat.setShowAsAction(item, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
}
代码示例来源:origin: square/sqlbrite
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
MenuItem item = menu.add(R.string.new_item)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override public boolean onMenuItemClick(MenuItem item) {
listener.onNewItemClicked(getListId());
return true;
}
});
MenuItemCompat.setShowAsAction(item, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
}
代码示例来源:origin: ankidroid/Anki-Android
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
subMenu.clear();
getMenuInflater().inflate(R.menu.reviewer_bury, subMenu);
for (int i = 0; i < subMenu.size(); i++) {
subMenu.getItem(i).setOnMenuItemClickListener(this);
}
}
代码示例来源:origin: ankidroid/Anki-Android
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
subMenu.clear();
getMenuInflater().inflate(R.menu.reviewer_suspend, subMenu);
for (int i = 0; i < subMenu.size(); i++) {
subMenu.getItem(i).setOnMenuItemClickListener(this);
}
}
代码示例来源:origin: ankidroid/Anki-Android
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
subMenu.clear();
getMenuInflater().inflate(R.menu.reviewer_schedule, subMenu);
for (int i = 0; i < subMenu.size(); i++) {
subMenu.getItem(i).setOnMenuItemClickListener(this);
}
}
代码示例来源:origin: k9mail/k-9
.setOnMenuItemClickListener(listener);
.setOnMenuItemClickListener(listener);
.setOnMenuItemClickListener(listener);
.setOnMenuItemClickListener(listener);
context.getString(R.string.webview_contextmenu_image_save_action) :
context.getString(R.string.webview_contextmenu_image_download_action))
.setOnMenuItemClickListener(listener);
.setOnMenuItemClickListener(listener);
.setOnMenuItemClickListener(listener);
.setOnMenuItemClickListener(listener);
.setOnMenuItemClickListener(listener);
.setOnMenuItemClickListener(listener);
.setOnMenuItemClickListener(listener);
.setOnMenuItemClickListener(listener);
代码示例来源:origin: TeamNewPipe/NewPipe
private void buildItemPopupMenu(final PlayQueueItem item, final View view) {
final PopupMenu menu = new PopupMenu(this, view);
final MenuItem remove = menu.getMenu().add(RECYCLER_ITEM_POPUP_MENU_GROUP_ID, /*pos=*/0,
Menu.NONE, R.string.play_queue_remove);
remove.setOnMenuItemClickListener(menuItem -> {
if (player == null) return false;
final int index = player.getPlayQueue().indexOf(item);
if (index != -1) player.getPlayQueue().remove(index);
return true;
});
final MenuItem detail = menu.getMenu().add(RECYCLER_ITEM_POPUP_MENU_GROUP_ID, /*pos=*/1,
Menu.NONE, R.string.play_queue_stream_detail);
detail.setOnMenuItemClickListener(menuItem -> {
onOpenDetail(item.getServiceId(), item.getUrl(), item.getTitle());
return true;
});
final MenuItem append = menu.getMenu().add(RECYCLER_ITEM_POPUP_MENU_GROUP_ID, /*pos=*/2,
Menu.NONE, R.string.append_playlist);
append.setOnMenuItemClickListener(menuItem -> {
openPlaylistAppendDialog(Collections.singletonList(item));
return true;
});
final MenuItem share = menu.getMenu().add(RECYCLER_ITEM_POPUP_MENU_GROUP_ID, /*pos=*/3,
Menu.NONE, R.string.share);
share.setOnMenuItemClickListener(menuItem -> {
shareUrl(item.getTitle(), item.getUrl());
return true;
});
menu.show();
}
代码示例来源:origin: TeamNewPipe/NewPipe
captionOffItem.setOnMenuItemClickListener(menuItem -> {
final int textRendererIndex = getRendererIndex(C.TRACK_TYPE_TEXT);
if (textRendererIndex != RENDERER_UNAVAILABLE) {
MenuItem captionItem = captionPopupMenu.getMenu().add(captionPopupMenuGroupId,
i + 1, Menu.NONE, captionLanguage);
captionItem.setOnMenuItemClickListener(menuItem -> {
final int textRendererIndex = getRendererIndex(C.TRACK_TYPE_TEXT);
if (textRendererIndex != RENDERER_UNAVAILABLE) {
代码示例来源:origin: robolectric/robolectric
item = item.setEnabled(true);
assertThat(item).isNotNull();
item = item.setOnMenuItemClickListener(null);
assertThat(item).isNotNull();
item = item.setActionProvider(null);
代码示例来源:origin: ankidroid/Anki-Android
};
MenuItem mToolbarAddItem = mToolbar.getMenu().findItem(R.id.tags_dialog_action_add);
mToolbarAddItem.setOnMenuItemClickListener(menuItem -> {
String query = mToolbarSearchView.getQuery().toString();
if (mToolbarSearchItem.isActionViewExpanded() && !TextUtils.isEmpty(query)) {
checkAllItem.setOnMenuItemClickListener(menuItem -> {
boolean changed = false;
if (mCurrentTags.containsAll(mTagsArrayAdapter.mTagsList)) {
代码示例来源:origin: Cleveroad/WaveInApp
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.main, menu);
MenuItem preset = menu.findItem(R.id.action_preset);
Menu m = preset.getSubMenu();
String[] presets = getResources().getStringArray(R.array.presets);
for (int i = 0; i < presets.length; i++) {
final int index = i + 1;
m.add(Menu.NONE, i, Menu.NONE, presets[i]).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
setPreset(index);
return true;
}
});
}
}
代码示例来源:origin: willowtreeapps/Hyperion-Android
private void showMenu(View anchor) {
final Context context = anchor.getContext();
if (popupMenu != null) {
popupMenu.dismiss();
}
popupMenu = new PopupMenu(context, anchor);
popupMenu.inflate(R.menu.hgc_menu_options);
final Menu menu = popupMenu.getMenu();
final MenuItem areHapticsEnabledItem = menu.findItem(R.id.menu_item_use_haptics);
areHapticsEnabledItem.setChecked(detector.areHapticsEnabled());
areHapticsEnabledItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
boolean areHapticsEnabled = !item.isChecked();
item.setChecked(areHapticsEnabled);
detector.setHapticsEnabled(areHapticsEnabled);
return true;
}
});
popupMenu.show();
}
代码示例来源:origin: Ferfalk/SimpleSearchView
/**
* Handle click events for the MenuItem.
*
* @param menuItem MenuItem that opens the search
*/
public void setMenuItem(@NonNull MenuItem menuItem) {
menuItem.setOnMenuItemClickListener(item -> {
showSearch();
return true;
});
}
代码示例来源:origin: andstatus/andstatus
private void createCreateNoteButton(Menu menu) {
MenuItem item = menu.findItem(R.id.createNoteButton);
if (item != null) {
item.setOnMenuItemClickListener(item1 -> {
MyAccount accountForButton = accountForCreateNoteButton();
if (accountForButton != null) {
startEditingNote(NoteEditorData.newEmpty(accountForButton));
}
return false;
});
}
}
代码示例来源:origin: adolfAn/FBReader_AS
private void addMenuItem(Menu menu, String actionId, Integer iconId, String name) {
if (name == null) {
name = ZLResource.resource("menu").getResource(actionId).getValue();
}
final MenuItem menuItem = menu.add(name);
if (iconId != null) {
menuItem.setIcon(iconId);
}
menuItem.setOnMenuItemClickListener(myMenuListener);
myMenuItemMap.put(menuItem, actionId);
}
内容来源于网络,如有侵权,请联系作者删除!