本文整理汇总了Java中android.view.MenuItem.setOnMenuItemClickListener方法的典型用法代码示例。如果您正苦于以下问题:Java MenuItem.setOnMenuItemClickListener方法的具体用法?Java MenuItem.setOnMenuItemClickListener怎么用?Java MenuItem.setOnMenuItemClickListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.MenuItem
的用法示例。
在下文中一共展示了MenuItem.setOnMenuItemClickListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateOptionsMenu
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.main, menu);
MenuItem menuItem = menu.findItem(R.id.write_message);
Utils.setMenuIconTint(getContext(), menuItem, R.attr.colorAccent);
menuItem.setVisible(true);
menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// open SMS sending activity
CustomFragmentActivity.show(getContext(),
getString(R.string.New_message),
SMSSendFragment.class, null);
return true;
}
});
super.onCreateOptionsMenu(menu, inflater);
}
示例2: buildMenu
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.swap_next_search, menu);
MenuItem nextMenuItem = menu.findItem(R.id.action_next);
int flags = MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT;
MenuItemCompat.setShowAsAction(nextMenuItem, flags);
nextMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
getActivity().onAppsSelected();
return true;
}
});
SearchView searchView = new SearchView(getActivity());
MenuItem searchMenuItem = menu.findItem(R.id.action_search);
MenuItemCompat.setActionView(searchMenuItem, searchView);
MenuItemCompat.setShowAsAction(searchMenuItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
searchView.setOnQueryTextListener(this);
return true;
}
示例3: onCreateOptionsMenu
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (showReloadPlacesButton) {
getMenuInflater().inflate(R.menu.main_menu, menu);
final MenuItem myActionMenuItem = menu.findItem(R.id.action_refresh);
myActionMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
PlaceFragment placeFragment = (PlaceFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_container);
if (placeFragment.isAdded()) {
placeFragment.currentPlace();
}
return false;
}
});
}
return super.onCreateOptionsMenu(menu);
}
示例4: onCreateOptionsMenu
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.main, menu);
MenuItem menuItem = menu.findItem(R.id.write_message);
Utils.setMenuIconTint(getContext(), menuItem, R.attr.colorAccent);
menuItem.setVisible(true);
menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// open activity with fragment of sending SMS
openSMSSendActivity(contactName, contactNumber, messageEdit.getText().toString());
messageEdit.setText("");
return true;
}
});
super.onCreateOptionsMenu(menu, inflater);
}
示例5: onCreateOptionsMenu
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.example_menu_drawer, menu);
final MenuItem menuItem = menu.findItem(R.id.toggle_example_toolbar);
menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
drawerLayout.onMenuItemClick();
return true;
}
});
drawerLayout.setViewsClickableAction(new Action1<Boolean>() {
@Override
public void execute(Boolean isEnabled) {
menuItem.setEnabled(isEnabled);
}
});
return true;
}
示例6: showToc
import android.view.MenuItem; //导入方法依赖的package包/类
protected void showToc() {
Map<String,String> tocmap = book.getToc();
PopupMenu tocmenu = new PopupMenu(this, findViewById(R.id.contents_button));
for (final String point: tocmap.keySet()) {
String text = tocmap.get(point);
MenuItem m = tocmenu.getMenu().add(text);
//Log.d("EPUB", "TOC2: " + text + ". File: " + point);
m.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
handleLink(point);
return true;
}
});
}
if (tocmap.size()==0) {
tocmenu.getMenu().add(R.string.no_toc_found);
}
tocmenu.show();
}
示例7: onLongClick
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public boolean onLongClick(final View v) {
PopupMenu p = new PopupMenu(this, v);
MenuItem m = p.getMenu().add("Delete");
m.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
list.removeView(v);
db.deleteWebSite((String)v.getTag());
return true;
}
});
p.show();
return true;
}
示例8: onCreateOptionsMenu
import android.view.MenuItem; //导入方法依赖的package包/类
/**
* Create menu items such as "delete" button
* @param menu The menu
* @return
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
final MenuItem deleteItem = menu.add(
Menu.NONE, DELETE_BUTTON_ID, Menu.NONE, "Delete");
MenuItemCompat.setShowAsAction(
deleteItem, MenuItem.SHOW_AS_ACTION_IF_ROOM);
deleteItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
confirmDelete();
return true;
}
});
return true;
}
示例9: resolveActionMode
import android.view.MenuItem; //导入方法依赖的package包/类
/**
* 处理item,处理点击
* @param actionMode
*/
private ActionMode resolveActionMode(ActionMode actionMode) {
if (actionMode != null) {
final Menu menu = actionMode.getMenu();
mActionMode = actionMode;
menu.clear();
for (int i = 0; i < mActionList.size(); i++) {
menu.add(mActionList.get(i));
}
for (int i = 0; i < menu.size(); i++) {
MenuItem menuItem = menu.getItem(i);
menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
getSelectedData((String) item.getTitle());
releaseAction();
return true;
}
});
}
}
mActionMode = actionMode;
return actionMode;
}
示例10: onCreateOptionsMenu
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuItem reset = menu.add(R.string.menu_colors_reset);
reset.setAlphabeticShortcut('r');
reset.setNumericShortcut('1');
reset.setIcon(android.R.drawable.ic_menu_revert);
reset.setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem arg0) {
// Reset each individual color to defaults.
for (int i = 0; i < Colors.defaults.length; i++) {
if (mColorList[i] != Colors.defaults[i]) {
mHostDb.setGlobalColor(i, Colors.defaults[i]);
mColorList[i] = Colors.defaults[i];
}
}
mColorGrid.invalidateViews();
// Reset the default FG/BG colors as well.
mFgSpinner.setSelection(HostDatabase.DEFAULT_FG_COLOR);
mBgSpinner.setSelection(HostDatabase.DEFAULT_BG_COLOR);
mHostDb.setDefaultColorsForScheme(HostDatabase.DEFAULT_COLOR_SCHEME,
HostDatabase.DEFAULT_FG_COLOR, HostDatabase.DEFAULT_BG_COLOR);
return true;
}
});
return true;
}
示例11: buildMenu
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.swap_skip, menu);
MenuItem next = menu.findItem(R.id.action_next);
MenuItemCompat.setShowAsAction(next,
MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
next.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
getActivity().showWifiQr();
return true;
}
});
return true;
}
示例12: buildMenu
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.swap_next, menu);
MenuItem next = menu.findItem(R.id.action_next);
MenuItemCompat.setShowAsAction(next,
MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
next.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
getActivity().showSelectApps();
return true;
}
});
return true;
}
示例13: setupDialog
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public void setupDialog(Dialog dialog, int style) {
super.setupDialog(dialog, style);
View root = View.inflate(getActivity(), R.layout.sheet_filter_edirt, null);
Toolbar toolbar = root.findViewById(R.id.toolbar);
toolbar.setTitle(R.string.search_options);
MenuItem saveItem = toolbar.getMenu().add(R.string.save);
saveItem.setIcon(CurrentTheme.getDrawableFromAttribute(getActivity(), R.attr.toolbarOKIcon));
saveItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
saveItem.setOnMenuItemClickListener(menuItem -> {
onSaveClick();
return true;
});
mEmptyText = root.findViewById(R.id.empty_text);
RecyclerView mRecyclerView = root.findViewById(R.id.recycler_view);
RecyclerView.LayoutManager manager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
mRecyclerView.setLayoutManager(manager);
mAdapter = new SearchOptionsAdapter(mData);
mAdapter.setOptionClickListener(this);
mRecyclerView.setAdapter(mAdapter);
resolveEmptyTextVisibility();
dialog.setContentView(root);
}
示例14: onPrepareOptionsMenu
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem actionViewItem = menu.findItem(R.id.btn_removeVehicle_bar);
actionViewItem.setTitle(getString(R.string.update));
actionViewItem.setOnMenuItemClickListener(this);
return super.onPrepareOptionsMenu(menu);
}
示例15: selectFontSize
import android.view.MenuItem; //导入方法依赖的package包/类
private void selectFontSize() {
final int defsize = webView.getSettings().getDefaultFontSize();
int minsize = webView.getSettings().getMinimumFontSize();
final float scale = getResources().getDisplayMetrics().density;
// Log.d("READER", "def " + defsize + " " + scale);
final PopupMenu sizemenu = new PopupMenu(this, findViewById(R.id.zoom_button));
for (int size=minsize; size<=36; size+=2) {
final int s = size;
MenuItem mi = sizemenu.getMenu().add(" "+size);
mi.setCheckable(true);
mi.setChecked(size==defsize);
mi.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
Log.d("READER", "def " + (defsize-s));
int scrolloffset = (int)(-webView.getScrollY()*(defsize - s)/scale/2.7);
Log.d("READER", "scrollby " + scrolloffset);
setFontSize(s);
//attempt to adjust the scroll to keep the same text position.
// needs much work
webView.scrollBy(0, scrolloffset);
sizemenu.dismiss();
return true;
}
});
}
sizemenu.show();
}