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:net.idlesoft.android.apps.github.activities.NewsFeed.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    if (!menu.hasVisibleItems()) {
        if (!mUsername.equals(null) && !mPassword.equals(null)) {
            menu.add(0, 1, 0, "Sign out");
        }// w  w  w .j a va2s. c o m
        menu.add(0, 2, 0, "Clear Cache");
    }
    return true;
}

From source file:com.android.systemui.tuner.QsTuner.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.add(0, MENU_RESET, 0, com.android.internal.R.string.reset);
    menu.add(0, MENU_EDIT, 0, "toggle edit");
}

From source file:edu.cmu.cylab.starslinger.demo.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuItem iUse = menu.add(0, MENU_MSG, 0, "Usage").setIcon(android.R.drawable.ic_menu_info_details);
    MenuCompat.setShowAsAction(iUse, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);

    if (getNfcState(this) != null) {
        menu.add(Menu.NONE, MENU_NFC, Menu.NONE, R.string.dev_menu_nfc_settings);
    }//from  ww  w .  j  a v a2 s  .  co m

    return true;
}

From source file:org.quantumbadger.redreader.activities.InboxListingActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    menu.add(0, OPTIONS_MENU_MARK_ALL_AS_READ, 0, R.string.mark_all_as_read);
    return super.onCreateOptionsMenu(menu);
}

From source file:gov.wa.wsdot.android.wsdot.ui.mountainpasses.passitem.MountainPassItemActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuItem menuItem_Star = menu.add(0, MENU_ITEM_STAR, menu.size(), R.string.description_star);
    MenuItemCompat.setShowAsAction(menuItem_Star, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    if (mIsStarred) {
        menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star_on);
        menu.getItem(MENU_ITEM_STAR).setTitle("Favorite checkbox, checked");
    } else {/*from  w w w  . j  av a 2 s.c o m*/
        menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star);
        menu.getItem(MENU_ITEM_STAR).setTitle("Favorite checkbox, not checked");
    }

    MenuItem menuItem_Refresh = menu.add(1, MENU_ITEM_REFRESH, menu.size(), R.string.description_refresh);
    MenuItemCompat.setShowAsAction(menuItem_Refresh, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    menu.getItem(MENU_ITEM_REFRESH).setIcon(R.drawable.ic_menu_refresh);

    if (mRefreshState) {
        startRefreshAnimation();
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.wenhui.syncedListView.demo.demo.SyncListViewContainerFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    String title = (mLayout.isAnimating()) ? "Stop anim" : "Start anim";
    mAnimMenu = menu.add(Menu.NONE, R.id.animation, 0, title);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mAnimMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }/*  ww w. j av a  2s  .c  o  m*/
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.example.cardflipanimation.CardFlipActivity.java

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

    // Add either a "photo" or "finish" button to the action bar, depending
    // on which page
    // is currently selected.
    MenuItem item = menu.add(Menu.NONE, R.id.action_flip, Menu.NONE,
            mShowingBack ? R.string.action_photo : R.string.action_info);
    item.setIcon(mShowingBack ? R.drawable.ic_action_photo : R.drawable.ic_action_info);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    return true;//from w  w  w  .jav  a2s.  co m
}

From source file:com.thesis.asa.mainui.MainSlideActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.activity_screen_slide, menu);

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

    MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE,
            (pager.getCurrentItem() == pagerAdapter.getCount() - 1) ? R.string.action_finish
                    : R.string.action_next);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    return true;/*from ww w . j a  v a2 s.co  m*/
}

From source file:com.cyanogenmod.eleven.utils.PopupMenuHelper.java

/**
 * Simple helper function for adding an item to the menu
 *//*w ww .  ja  v a2  s. c o m*/
public void addToMenu(final Menu menu, final int id, final int resourceId) {
    menu.add(getGroupId(), id, id /*as order*/, mActivity.getString(resourceId));
}

From source file:com.example.android.actionbarcompat.basic.MainActivity.java

/**
 * Use this method to instantiate your menu, and add your items to it. You
 * should return true if you have added items to it and want the menu to be displayed.
 *//*from w  ww . j  a v  a 2s  .co  m*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate our menu from the resources by using the menu inflater.
    getMenuInflater().inflate(R.menu.main, menu);

    // It is also possible add items here. Use a generated id from
    // resources (ids.xml) to ensure that all menu ids are distinct.
    MenuItem locationItem = menu.add(0, R.id.menu_location, 0, R.string.menu_location);
    locationItem.setIcon(R.drawable.ic_action_location);

    // Need to use MenuItemCompat methods to call any action item related methods
    MenuItemCompat.setShowAsAction(locationItem, MenuItem.SHOW_AS_ACTION_IF_ROOM);

    return true;
}