Example usage for android.view Menu getItem

List of usage examples for android.view Menu getItem

Introduction

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

Prototype

public MenuItem getItem(int index);

Source Link

Document

Gets the menu item at the given index.

Usage

From source file:org.spinsuite.login.Login.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.cancel_ok, menu);
    MenuItem item = menu.getItem(0);
    item.setVisible(true);/*from   w ww. ja  v  a  2  s. c  o  m*/
    // Add either a "next" or "finish" button to the action bar, depending on which page
    // is currently selected.
    /*MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE,
        (mPager.getCurrentItem() == mPagerAdapter.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 source file:net.carlh.toast.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    menuTimer = menu.getItem(1);
    return true;//from   www  . j a v  a  2s  .co  m
}

From source file:me.abhrajit.hackernewsreader.MainActivity.java

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    Menu menu = navigationView.getMenu();
    int selected = -1;
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.isChecked()) {
            selected = i;/* ww  w  .ja  v a2 s . co  m*/
            break;
        }
    }
    savedInstanceState.putInt(getString(R.string.nav_Selected), selected);
    super.onSaveInstanceState(savedInstanceState);
}

From source file:com.adkdevelopment.e_contact.ui.MainActivity.java

/**
 * Updated buttons in the Navigation Drawer according to a state
 *///from w  ww .  j  a v  a2 s .  c  o  m
private void updateDrawer() {
    // select first item in navigation drawer on startup
    Menu drawerMenu = mNavigationView.getMenu();
    drawerMenu.getItem(0).setChecked(true);

    // set correct visibility of we are logged in or logged out
    MenuItem facebookProfile = drawerMenu.findItem(R.id.profile_button);
    MenuItem login = drawerMenu.findItem(R.id.login_button);
    if (facebookProfile != null) {
        if (AccessToken.getCurrentAccessToken() != null) {
            login.setVisible(false);
            facebookProfile.setVisible(true);
        } else {
            login.setVisible(true);
            facebookProfile.setVisible(false);
        }
    }
}

From source file:com.imgtec.hobbyist.fragments.loginsignup.LogInFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    MenuItem appLogsItem = menu.getItem(0);
    appLogsItem.setVisible(loginError);
}

From source file:com.douncoding.noe.ui.car_action.register.CarRegisterFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_register, menu);
    // DONE  ? /*from  w ww . java2s.  c  om*/
    Drawable icon = menu.getItem(0).getIcon();
    icon.setColorFilter(ContextCompat.getColor(getContext(), R.color.carPrimaryColor), PorterDuff.Mode.SRC_IN);
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.doplgangr.secrecy.views.MainActivity.java

private void hideMenuItems(Menu menu, boolean visible) {
    for (int i = 0; i < menu.size(); i++)
        menu.getItem(i).setVisible(visible);
}

From source file:gov.wa.wsdot.android.wsdot.ui.FerriesRouteSchedulesDaySailingsActivity.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_IF_ROOM);

    if (mIsStarred) {
        menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star_on);
    } else {/*  w  w w.j av a  2s.c o m*/
        menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star);
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.alibaba.weex.extend.module.WXTitleBar.java

@JSMethod
public void setStyle(JSONObject object) {
    String bgColor = object.getString("backgroundColor");
    String color = object.getString("foregroundColor");
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        if (bgColor != null) {
            int c = WXResourceUtils.getColor(bgColor);
            actionBar.setBackgroundDrawable(new ColorDrawable(c));
        }// w ww  . j a  v a  2  s  .c om

        if (color != null) {
            int c = WXResourceUtils.getColor(color);

            Toolbar toolbar = (Toolbar) ((Activity) mWXSDKInstance.getContext()).findViewById(R.id.toolbar);
            if (toolbar != null) {
                toolbar.setTitleTextColor(c);
                toolbar.setSubtitleTextColor(c);

                Drawable upNavigation = toolbar.getNavigationIcon();
                if (null != upNavigation) {
                    upNavigation = DrawableCompat.wrap(upNavigation);
                    upNavigation = upNavigation.mutate();
                    DrawableCompat.setTint(upNavigation, c);
                    toolbar.setNavigationIcon(upNavigation);
                }

                Drawable overflowIcon = toolbar.getOverflowIcon();
                if (null != overflowIcon) {
                    overflowIcon = DrawableCompat.wrap(overflowIcon);
                    overflowIcon = overflowIcon.mutate();
                    DrawableCompat.setTint(overflowIcon, c);
                    toolbar.setOverflowIcon(overflowIcon);
                }

                Menu menu = toolbar.getMenu();
                if (menu != null && menu.size() > 0) {
                    for (int i = 0; i < menu.size(); i++) {
                        MenuItem item = menu.getItem(i);
                        if (item != null && item.getIcon() != null) {
                            Drawable drawable = item.getIcon();
                            if (null != drawable) {
                                drawable = DrawableCompat.wrap(drawable);
                                drawable = drawable.mutate();
                                DrawableCompat.setTint(drawable, c);
                                item.setIcon(drawable);
                            }
                        }
                    }
                    ((Activity) mWXSDKInstance.getContext()).invalidateOptionsMenu();
                }
            }
        }
    }
}

From source file:com.liuwuping.sm.ui.repodetail.RepoDetailActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_add, menu);
    menuItem = menu.getItem(0);
    return super.onCreateOptionsMenu(menu);
}