本文整理汇总了Java中android.view.Menu.add方法的典型用法代码示例。如果您正苦于以下问题:Java Menu.add方法的具体用法?Java Menu.add怎么用?Java Menu.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.Menu
的用法示例。
在下文中一共展示了Menu.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateOptionsMenu
import android.view.Menu; //导入方法依赖的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;
}
示例2: smoothScrollToUserSelectedPosition
import android.view.Menu; //导入方法依赖的package包/类
public static void smoothScrollToUserSelectedPosition(final DiscreteScrollView scrollView, View anchor) {
PopupMenu popupMenu = new PopupMenu(scrollView.getContext(), anchor);
Menu menu = popupMenu.getMenu();
final RecyclerView.Adapter adapter = scrollView.getAdapter();
int itemCount = (adapter instanceof InfiniteScrollAdapter) ?
((InfiniteScrollAdapter) adapter).getRealItemCount() :
adapter.getItemCount();
for (int i = 0; i < itemCount; i++) {
menu.add(String.valueOf(i + 1));
}
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int destination = Integer.parseInt(String.valueOf(item.getTitle())) - 1;
if (adapter instanceof InfiniteScrollAdapter) {
destination = ((InfiniteScrollAdapter) adapter).getClosestPosition(destination);
}
scrollView.smoothScrollToPosition(destination);
return true;
}
});
popupMenu.show();
}
示例3: onPrepareOptionsMenu
import android.view.Menu; //导入方法依赖的package包/类
@Override
public boolean onPrepareOptionsMenu(Menu menu)
{
Log.v(L.TAG, "SimplyDoActivity.onPrepareOptionsMenu() called");
menu.clear();
ViewSwitcher viewSwitch = (ViewSwitcher)findViewById(R.id.ListsItemsSwitcher);
boolean isItemDisplay = viewSwitch.getDisplayedChild() != 0;
if(isItemDisplay)
{
MenuItem deleteInactiveMI = menu.add(Menu.NONE, DELETE_INACTIVE, Menu.NONE, "Delete Inactive");
deleteInactiveMI.setIcon(android.R.drawable.ic_menu_delete);
}
MenuItem settingsMI = menu.add(Menu.NONE, SETTINGS, Menu.NONE, "Settings");
settingsMI.setIcon(android.R.drawable.ic_menu_preferences);
if(isItemDisplay)
{
MenuItem sortNowMI = menu.add(Menu.NONE, SORT_NOW, Menu.NONE, "Sort Now");
sortNowMI.setIcon(android.R.drawable.ic_menu_sort_by_size);
}
return true;
}
示例4: onPrepareOptionsMenu
import android.view.Menu; //导入方法依赖的package包/类
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear(); //Clear view of previous menu
menu.add(0, ITEM0, 0, getString(R.string.menu_calcassist));
menu.add(0, ITEM1, 0, getString(R.string.menu_chartmgr));
menu.add(0, ITEM2, 0, getString(R.string.menu_plotcomplicatedgraph));
menu.add(0, ITEM3, 0, getString(R.string.menu_integrate));
menu.add(0, ITEM4, 0, getString(R.string.menu_history));
if (mnSoftKeyState == ENABLE_SHOW_SOFTKEY) {
menu.add(0, ITEM5, 0, getString(R.string.menu_alwayshidesoftkeyboard));
} else {
menu.add(0, ITEM6, 0, getString(R.string.menu_enablesoftkeyboard));
}
menu.add(0, ITEM7, 0, getString(R.string.menu_settings));
menu.add(0, ITEM8, 0, getString(R.string.menu_help));
return super.onPrepareOptionsMenu(menu);
}
示例5: resolveActionMode
import android.view.Menu; //导入方法依赖的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;
}
示例6: onCreateOptionsMenu
import android.view.Menu; //导入方法依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_main, menu);
if (isPlaylistPage()) {
menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title);
}
Fragment currentFragment = getCurrentFragment();
if (currentFragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment && currentFragment.isAdded()) {
AbsLibraryPagerRecyclerViewCustomGridSizeFragment absLibraryRecyclerViewCustomGridSizeFragment = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment;
MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size);
if (Util.isLandscape(getResources())) {
gridSizeItem.setTitle(R.string.action_grid_size_land);
}
setUpGridSizeMenu(absLibraryRecyclerViewCustomGridSizeFragment, gridSizeItem.getSubMenu());
menu.findItem(R.id.action_colored_footers).setChecked(absLibraryRecyclerViewCustomGridSizeFragment.usePalette());
menu.findItem(R.id.action_colored_footers).setEnabled(absLibraryRecyclerViewCustomGridSizeFragment.canUsePalette());
} else {
menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title);
menu.removeItem(R.id.action_grid_size);
menu.removeItem(R.id.action_colored_footers);
}
colorToolbar();
}
示例7: onCreateOptionsMenu
import android.view.Menu; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater2 = getMenuInflater();
inflater2.inflate(R.menu.play, menu);
MenuInflater inflater7 = getMenuInflater();
inflater7.inflate(R.menu.save, menu);
MenuInflater inflater4 = getMenuInflater();
inflater4.inflate(R.menu.discard, menu);
MenuInflater inflater6 = getMenuInflater();
inflater6.inflate(R.menu.settings, menu);
menu.add(1, ABOUT, 0, R.string.about_menu_short);
return true;
}
示例8: onCreateOptionsMenu
import android.view.Menu; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.clear();
preventMenu = menu.add(Menu.NONE, R.string.prevent, Menu.NONE, R.string.prevent);
preventMenu.setIcon(R.drawable.ic_menu_prevent);
preventMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
preventMenu.setVisible(false);
removeMenu = menu.add(Menu.NONE, R.string.remove, Menu.NONE, R.string.remove);
removeMenu.setIcon(R.drawable.ic_menu_recover);
removeMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
removeMenu.setVisible(false);
menu.add(Menu.NONE, R.string.switch_theme, Menu.NONE, R.string.switch_theme);
menu.add(Menu.NONE, R.string.report_bug, Menu.NONE, R.string.report_bug);
menu.add(Menu.NONE, R.string.user_guide, Menu.NONE, R.string.user_guide);
return super.onCreateOptionsMenu(menu);
}
示例9: onPrepareOptionsMenu
import android.view.Menu; //导入方法依赖的package包/类
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear(); //Clear view of previous menu
menu.add(0, Menu.FIRST, 0, getString(R.string.menu_fill_example));
if (mnSoftKeyState == ENABLE_SHOW_SOFTKEY) {
menu.add(0, Menu.FIRST + 1, 0, getString(R.string.hide_system_soft_key));
} else {
menu.add(0, Menu.FIRST + 1, 0, getString(R.string.pop_up_system_soft_key));
}
menu.add(0, Menu.FIRST + 2, 0, getString(R.string.menu_help));
return super.onPrepareOptionsMenu(menu);
}
示例10: onCreateOptionsMenu
import android.view.Menu; //导入方法依赖的package包/类
@Override
/*
* Create menus
*/
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, ITEM0, 0, getString(R.string.menu_add));
menu.add(0, ITEM1, 0, getString(R.string.menu_addleft));
menu.add(0, ITEM2, 0, getString(R.string.menu_addright));
menu.add(0, ITEM3, 0, getString(R.string.menu_delete));
menu.add(0, ITEM4, 0, getString(R.string.menu_save));
menu.add(0, ITEM5, 0, getString(R.string.menu_help));
return true;
}
示例11: onCreateOptionsMenu
import android.view.Menu; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuItem menuItem = menu.add(0, MENU_PREFERENCES, 0, R.string.preferences);
menuItem.setIcon(android.R.drawable.ic_menu_preferences);
return true;
}
示例12: onCreateOptionsMenu
import android.view.Menu; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!inflateMenuItems)
return super.onCreateOptionsMenu(menu);
// Adding the add user option only if group chat is enabled.
if (BDefines.Options.GroupEnabled)
{
MenuItem item =
menu.add(Menu.NONE, R.id.action_chat_sdk_add, 10, getString(R.string.chat_activity_show_users_item_text));
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
item.setIcon(R.drawable.ic_plus);
}
if (BDefines.Options.ThreadDetailsEnabled)
{
MenuItem itemThreadUsers =
menu.add(Menu.NONE, R.id.action_chat_sdk_thread_details, 10, getString(R.string.chat_activity_show_thread_details));
itemThreadUsers.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
itemThreadUsers.setIcon(android.R.drawable.ic_menu_info_details);
}
return super.onCreateOptionsMenu(menu);
}
示例13: onCreateOptionsMenu
import android.view.Menu; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (App.fejlsøgning) {
menu.add(0, 644, 0, "Hent nyeste udvikler-version");
menu.add(0, 642, 0, "Fejlsøgning");
menu.add(0, 643, 0, "Vis log");
menu.add(0, 646, 0, "Send fejlrapport");
menu.add(0, 647, 0, "Fremtving crash (og send rapport)");
// menu.add(0, 2645, 0, "Status på hentninger");
menu.add(0, 13643, 0, "Vis servertid");
}
return super.onCreateOptionsMenu(menu);
}
示例14: onCreateOptionsMenu
import android.view.Menu; //导入方法依赖的package包/类
/**
* Called when your activity's options menu needs to be created.
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(Menu.NONE, MENU_SPEEDDOWN, Menu.NONE, "Slower");
menu.add(Menu.NONE, MENU_SPEEDUP, Menu.NONE, "Faster");
menu.add(Menu.NONE, MENU_FRAMES, Menu.NONE, "Show Frames");
menu.add(Menu.NONE, MENU_RESTART, Menu.NONE, "Restart");
menu.add(Menu.NONE, MENU_EXIT, Menu.NONE, "Exit");
return true;
}
示例15: onCreateOptionsMenu
import android.view.Menu; //导入方法依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
//super.onCreateOptionsMenu(menu, inflater);
menu.add(0, R.string.add_ssh_server, 0, R.string.add_ssh_server);
if(mCurrentDirectory!=null){
MenuItem mi;
if(ShortcutDb.STATIC.isShortcut(getActivity(), mCurrentDirectory.toString())<=0)
mi= menu.add(0,R.string.add_ssh_shortcut, 0,R.string.add_ssh_shortcut);
else
mi= menu.add(0,R.string.remove_from_shortcuts, 0,R.string.remove_from_shortcuts);
mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
if(getActivity() instanceof MainActivity) {
mSearchView = ((MainActivity) getActivity()).getSearchView();
mSearchView.setSearchableInfo(null);
mSearchView.setQuery("", true);//resetting query
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
boolean isFirstEntryTextChange = true;
@Override
public boolean onQueryTextChange(String newText) {
if (!isFirstEntryTextChange)
filter(newText);
isFirstEntryTextChange = false;
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
return true;
}
});
}
}