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(@StringRes int titleRes);

Source Link

Document

Add a new item to the menu.

Usage

From source file:gov.wa.wsdot.android.wsdot.ui.TravelTimesFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    //Create the search view
    SearchView searchView = new SearchView(
            ((ActionBarActivity) getActivity()).getSupportActionBar().getThemedContext());
    searchView.setQueryHint("Search Travel Times");
    searchView.setOnQueryTextListener(this);

    MenuItem menuItem_Search = menu.add(R.string.search_title).setIcon(R.drawable.ic_menu_search);
    MenuItemCompat.setActionView(menuItem_Search, searchView);
    MenuItemCompat.setShowAsAction(menuItem_Search,
            MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    MenuItemCompat.setOnActionExpandListener(menuItem_Search, new MenuItemCompat.OnActionExpandListener() {
        public boolean onMenuItemActionCollapse(MenuItem item) {
            mFilter = null;//from w w  w.  j a v a 2  s  . c  om
            getLoaderManager().restartLoader(0, null, TravelTimesFragment.this);

            return true;
        }

        public boolean onMenuItemActionExpand(MenuItem item) {

            return true;
        }
    });
}

From source file:com.google.plus.wigwamnow.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // If the user is signed in with any SocialProvider, display the Settings option in the
    // options menu, otherwise clear the menu.
    switch (currentProvider()) {
    case SocialProviderConstants.NONE:
        return false;
    default:/*from   ww w . j  a v a2 s.co m*/
        if (menu.size() == 0) {
            mSettingsId = menu.add(R.string.settings).getItemId();
        }
        return true;
    }
}

From source file:com.example.android.supportv7.widget.AnimatedRecyclerView.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    MenuItemCompat.setShowAsAction(menu.add("Layout"), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    return true;/*from ww w .j  a  v  a  2s .  co m*/
}

From source file:com.mozilla.SUTAgentAndroid.SUTAgentAndroid.java

public boolean onCreateOptionsMenu(Menu menu) {
    mExitMenuItem = menu.add("Exit");
    mExitMenuItem.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
    return super.onCreateOptionsMenu(menu);
}

From source file:com.ibuildapp.romanblack.NewsPlugin.NewsPlugin.java

/**
 * This menu contains reverse and refresh buttons
 *
 *///www .java 2s.  com
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.news_menu_main, menu);
    menu.clear();

    MenuItem menuItem = menu.add("");
    menuItem.setTitle(getString(R.string.news_reverse));
    menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            handler.sendEmptyMessage(REVERSE_LIST);
            return true;
        }
    });

    if (Statics.isRSS) {
        menuItem = menu.add("");
        menuItem.setTitle(R.string.news_refresh);
        menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (isOnline) {
                    handler.sendEmptyMessage(REFRESH_RSS);
                } else {
                    handler.sendEmptyMessage(CANT_REFRESH_RSS);
                }
                return true;
            }
        });
    }

    return false;
}

From source file:com.ibuildapp.romanblack.WebPlugin.WebPlugin.java

/**
 * This menu contains back, forward and refresh buttons.
 *
 * @param menu/*from w  ww .  jav  a  2  s.c  o m*/
 * @return true if there are no an exception while preparing, false otherwise
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    try {
        menu.clear();
        MenuItem itemBack = menu.add("");
        itemBack.setIcon(R.drawable.romanblack_html_menu_back);
        itemBack.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem mi) {
                webView.goBack();
                return true;
            }
        });
        if (!webView.canGoBack()) {
            itemBack.setEnabled(false);
        }

        MenuItem itemRefresh = menu.add("");
        itemRefresh.setIcon(R.drawable.romanblack_html_menu_refresh);
        itemRefresh.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem mi) {
                webView.reload();
                return true;
            }
        });
        if ("".equals(currentUrl) || "about:blank".equals(currentUrl)) {
            itemRefresh.setEnabled(false);
        }

        MenuItem itemForward = menu.add("");
        itemForward.setIcon(R.drawable.romanblack_html_menu_forward);
        itemForward.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem mi) {
                webView.goForward();
                return true;
            }
        });
        if (!webView.canGoForward()) {
            itemForward.setEnabled(false);
        }

        return true;

    } catch (Exception ex) {
        return false;
    }
}

From source file:at.jclehner.rxdroid.DrugListActivity2.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (mIsShowingDbErrorDialog) {
        menu.add(R.string._title_restore).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override//from   ww w . j ava  2 s .c  o m
            public boolean onMenuItemClick(MenuItem item) {
                final Intent intent = new Intent(DrugListActivity2.this, BackupActivity.class);
                intent.putExtra(BackupActivity.EXTRA_NO_BACKUP_CREATION, true);
                startActivity(intent);
                return true;
            }
        });
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.bitants.wally.fragments.SavedImagesFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.images_saved, menu);

    MenuItem menuItemFilter = menu.findItem(R.id.action_licenses);

    if (menuItemFilter != null) {
        menuItemFilter.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override//w  w w  .jav  a  2  s .c o  m
            public boolean onMenuItemClick(MenuItem item) {
                final LicensesDialogFragment fragment = LicensesDialogFragment.newInstance(R.raw.notices,
                        false);
                fragment.show(getFragmentManager(), null);
                return false;
            }
        });
    }

    if (!BuildConfig.BUILD_TYPE.equalsIgnoreCase("release")) {
        menu.add("Wally " + BuildConfig.VERSION_NAME);
    }

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.koushikdutta.superuser.FragmentLog.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    VectorDrawableCompat icon = VectorDrawableCompat.create(getContext().getResources(), R.drawable.ic_delete,
            getContext().getTheme());/* ww w .  ja va 2s .c  om*/

    if (!Theme.getThemeCurrent(PreferenceManager.getDefaultSharedPreferences(getContext()))
            .equals(MainActivity.PREF_BLACK_THEME)) {
        icon.setColorFilter(getActivity() instanceof ActivityLog ? ((ActivityLog) getActivity()).textToolbar
                : ((MainActivity) getActivity()).textToolbarDefault, PorterDuff.Mode.SRC_ATOP);

    } else {
        icon.setColorFilter(0xffeaeaea, PorterDuff.Mode.SRC_ATOP);
    }

    if (up == null) {
        MenuItem delete = menu.add(R.string.delete).setIcon(icon);
        delete.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        delete.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (up != null)
                    SuDatabaseHelper.delete(getActivity(), up);

                else
                    SuperuserDatabaseHelper.deleteLogs(getActivity());

                adapter.clear();
                callback.onLogCleared();
                //if (up != null) getActivity().finish();
                return true;
            }
        });
    }

}

From source file:com.nachiket.titan.LibraryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        MenuItem controls = menu.add(null);
        CompatHoneycomb.setActionView(controls, mActionControls);
        CompatHoneycomb.setShowAsAction(controls, MenuItem.SHOW_AS_ACTION_ALWAYS);
        MenuItem search = menu.add(0, MENU_SEARCH, 0, R.string.search).setIcon(R.drawable.ic_menu_search);
        CompatHoneycomb.setShowAsAction(search, MenuItem.SHOW_AS_ACTION_IF_ROOM);
    } else {//from w  w w  . jav  a  2s  .  c  o  m
        menu.add(0, MENU_SEARCH, 0, R.string.search).setIcon(R.drawable.ic_menu_search);
        menu.add(0, MENU_PLAYBACK, 0, R.string.playback_view).setIcon(R.drawable.ic_menu_gallery);
    }
    menu.add(0, MENU_SORT, 0, R.string.sort_by).setIcon(R.drawable.ic_menu_sort_alphabetically);
    return super.onCreateOptionsMenu(menu);
}