本文整理匯總了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();
}