Example usage for android.view Menu add

List of usage examples for android.view Menu add

Introduction

In this page you can find the example usage for android.view Menu add.

Prototype

public MenuItem add(int groupId, int itemId, int order, @StringRes int titleRes);

Source Link

Document

Variation on #add(int,int,int,CharSequence) that takes a string resource identifier instead of the string itself.

Usage

From source file:com.example.android.notepad.NotesList.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    // This is our one standard application action -- inserting a
    // new note into the list.
    menu.add(0, MENU_ITEM_INSERT, 0, R.string.menu_insert).setShortcut('3', 'a')
            .setIcon(android.R.drawable.ic_menu_add);

    // ilya: add refresh
    menu.add(0, MENU_ITEM_REFRESH, 0, "Refresh").setShortcut('4', 'r').setIcon(android.R.drawable.ic_menu_view);

    // Generate any additional actions that can be performed on the
    // overall list.  In a normal install, there are no additional
    // actions found here, but this allows other applications to extend
    // our menu with their own actions.
    Intent intent = new Intent(null, getIntent().getData());
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, NotesList.class), null,
            intent, 0, null);//  ww  w . j  a v a2  s. c o  m

    return true;
}

From source file:fabiogentile.powertutor.ui.UMLogger.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, MENU_PREFERENCES, 0, "Options");
    menu.add(0, MENU_SAVE_LOG, 0, "Save log");
    return true;//from w  ww .  ja  v a2s . c  o  m
}

From source file:de.stadtrallye.rallyesoft.ConnectionAssistantActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem scan_qr = menu.add(Menu.NONE, R.id.scan_qr_login, 10, R.string.scan_barcode);
    scan_qr.setIcon(R.drawable.ic_scan_qr_light);
    scan_qr.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    return true;/* w w w  . j  a va 2  s. c o  m*/
}

From source file:com.mifos.mifosxdroid.online.documentlist.DocumentListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();// ww  w  . j a  v a2 s.c o m
    MenuItem menuItemAddNewDocument = menu.add(Menu.NONE, MENU_ITEM_ADD_NEW_DOCUMENT, Menu.NONE,
            getString(R.string.add_new));
    menuItemAddNewDocument.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_add_white_24dp));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        menuItemAddNewDocument.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    super.onPrepareOptionsMenu(menu);
}

From source file:com.piusvelte.wapdroid.MapData.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    boolean result = super.onCreateOptionsMenu(menu);
    menu.add(0, REFRESH_ID, 0,
            String.format(getString(R.string.refresh),
                    getString(mNetwork == 0 ? R.string.network : R.string.cell)))
            .setIcon(android.R.drawable.ic_menu_rotate);
    return result;
}

From source file:com.yeldi.yeldibazaar.FDroid.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    super.onCreateOptionsMenu(menu);
    menu.add(Menu.NONE, UPDATE_REPO, 1, R.string.menu_update_repo).setIcon(android.R.drawable.ic_menu_rotate);
    menu.add(Menu.NONE, MANAGE_REPO, 2, R.string.menu_manage).setIcon(android.R.drawable.ic_menu_agenda);
    MenuItem search = menu.add(Menu.NONE, SEARCH, 3, R.string.menu_search)
            .setIcon(android.R.drawable.ic_menu_search);
    menu.add(Menu.NONE, PREFERENCES, 4, R.string.menu_preferences)
            .setIcon(android.R.drawable.ic_menu_preferences);
    menu.add(Menu.NONE, ABOUT, 5, R.string.menu_about).setIcon(android.R.drawable.ic_menu_help);
    MenuItemCompat.setShowAsAction(search, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    return true;/*from   w w  w  .j  av  a2 s  .com*/
}

From source file:com.notifry.android.ChooseAccount.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    boolean result = super.onCreateOptionsMenu(menu);
    menu.add(0, REFRESH_IDS, 0, R.string.refresh_ids).setIcon(android.R.drawable.ic_menu_rotate)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    return result;
}

From source file:de.stadtrallye.rallyesoft.fragments.TaskDetailsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem submitItem = menu.add(Menu.NONE, R.id.submit_menu, Menu.NONE, R.string.submit_new_solution);
    submitItem.setIcon(R.drawable.ic_send_now_light);
    submitItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}

From source file:com.duy.pascal.ui.file.FileExplorerAction.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    menu.add(0, R.id.select_all, 0, R.string.select_all).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    menu.add(0, R.id.cut, 0, R.string.cut).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    menu.add(0, R.id.copy, 0, R.string.copy).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

    MenuItem pasteMenu = menu.add(0, R.id.paste, 0, R.string.paste);
    pasteMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    pasteMenu.setEnabled(mFileClipboard.canPaste());

    mRenameMenu = menu.add(0, R.id.rename, 0, R.string.rename);
    mRenameMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

    mShareMenu = menu.add(0, R.id.share, 0, R.string.share);
    mShareMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    mShareActionProvider = new ShareActionProvider(mContext);
    mShareActionProvider.setOnShareTargetSelectedListener(this);
    MenuItemCompat.setActionProvider(mShareMenu, mShareActionProvider);

    menu.add(0, R.id.delete, 0, R.string.delete).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    return true;//  w w w.  ja  v  a 2  s  .c  o m
}

From source file:finalproject.ece558.edu.pdx.ece.brailleblackjack.LearnBrailleActivity.java

/**
 * Create the action menu to provide buttons to navigate the Pager
 * @param menu Menu object//from ww  w . java2s.c o m
 * @return Boolean true
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu_main, menu);

    // Add/enable previous button depending on which page is active
    // is currently selected.
    MenuItem prev_item = menu.add(Menu.NONE, R.id.action_previous, Menu.NONE, R.string.action_previous);

    prev_item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    menu.findItem(R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0);

    // Add either a "next" or "finished" button to the action bar, depending on which page
    // is currently active.
    MenuItem next_item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE,
            (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1) ? R.string.action_finish
                    : R.string.action_next);
    next_item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    menu.findItem(R.id.action_next).setEnabled(!(mPager.getCurrentItem() == 3));

    menu.findItem(R.id.action_next).setEnabled(mPager.getCurrentItem() < 3);
    return true;
}