List of usage examples for android.view Menu getItem
public MenuItem getItem(int index);
From source file:fr.cph.stock.android.activity.OverallActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.overall, menu); refreshItem = menu.getItem(2); return true;//from w w w.j a v a 2 s.co m }
From source file:com.example.ali.topcoderandroid.Activities.MainActivity.java
private void setNavigation(NavigationView navigationView, ChallengeType challengeType) { int preferredCheckItemId = 0; switch (challengeType) { case Design://from w ww. ja v a2s.c om preferredCheckItemId = 0; break; case Develop: preferredCheckItemId = 1; break; case Data: preferredCheckItemId = 2; break; } Menu menu = navigationView.getMenu(); if (menu != null) menu.getItem(preferredCheckItemId).setChecked(true); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { //Checking if the item is in checked state or not, if not make it in checked state if (!menuItem.isChecked()) { menuItem.setChecked(true); } //Closing drawer on item click drawerLayout.closeDrawers(); //Check to see which item was being clicked and perform appropriate action switch (menuItem.getItemId()) { case R.id.navDesign: //Toast.makeText(getApplicationContext(), "Design Challenges", Toast.LENGTH_SHORT).show(); preferredChallengeType = ChallengeType.Design; break; case R.id.navDevelop: //Toast.makeText(getApplicationContext(), "Develop Challenges", Toast.LENGTH_SHORT).show(); preferredChallengeType = ChallengeType.Develop; break; case R.id.navData: //Toast.makeText(getApplicationContext(), "Data Challenges", Toast.LENGTH_SHORT).show(); preferredChallengeType = ChallengeType.Data; break; default: Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show(); return true; } recyclerViewFragment.fetchChallenges(preferredChallengeType); return true; } }); }
From source file:org.mariotaku.twidere.util.ThemeUtils.java
public static void wrapToolbarMenuIcon(@Nullable ActionMenuView view, int itemColor, int popupItemColor, int... excludeGroups) { if (view == null) return;/*w w w . j a v a 2s .c om*/ final Menu menu = view.getMenu(); final int childCount = view.getChildCount(); for (int i = 0, j = menu.size(), k = 0; i < j; i++) { final MenuItem item = menu.getItem(i); wrapMenuItemIcon(item, itemColor, excludeGroups); if (item.hasSubMenu()) { wrapMenuIcon(item.getSubMenu(), popupItemColor, popupItemColor, excludeGroups); } if (item.isVisible()) { k++; } } }
From source file:org.mariotaku.twidere.util.ThemeUtils.java
public static void wrapMenuIcon(ActionMenuView view, int colorDark, int colorLight, int... excludeGroups) { final int itemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext()); final int popupItemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext(), view.getPopupTheme());//from w ww .j a v a 2s . c o m final int itemColor = TwidereColorUtils.getContrastYIQ(itemBackgroundColor, colorDark, colorLight); final int popupItemColor = TwidereColorUtils.getContrastYIQ(popupItemBackgroundColor, colorDark, colorLight); final Menu menu = view.getMenu(); final int childCount = view.getChildCount(); for (int i = 0, j = menu.size(), k = 0; i < j; i++) { final MenuItem item = menu.getItem(i); wrapMenuItemIcon(item, itemColor, excludeGroups); if (item.hasSubMenu()) { wrapMenuIcon(item.getSubMenu(), popupItemColor, popupItemColor, excludeGroups); } if (item.isVisible()) { k++; } } }
From source file:rus.cpuinfo.Ui.Fragments.Base.CpuInfoBaseTabFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.options, menu); MenuItem menuItem = menu.getItem(0); menuItem.setActionView(R.layout.include_app_comat_spinner); mSpinner = (AppCompatSpinner) menuItem.getActionView(); mSpinner.setOnItemSelectedListener(this); mTabLayout.setOnTabSelectedListener(this); mSpinner.setSelection(mCurrentItem); if (getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT) { menuItem.setVisible(false);/*from ww w. java2 s.com*/ } }
From source file:com.klinker.android.twitter.activities.drawer_activities.discover.DiscoverPager.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); final int DISMISS = 0; final int SEARCH = 1; final int COMPOSE = 2; final int NOTIFICATIONS = 3; final int DM = 4; final int SETTINGS = 5; final int TOFIRST = 6; menu.getItem(NOTIFICATIONS).setVisible(false); return true;//w w w . j a va 2 s. c o m }
From source file:com.jefftharris.passwdsafe.PasswdSafeNavDrawerFragment.java
/** * Update drawer for the fragments displayed in the activity * @param fileNameUpdate If non-null, the file name to set in the view *//*from www . jav a2s .c o m*/ public void updateView(Mode mode, String fileNameUpdate, boolean fileOpen) { boolean drawerEnabled = false; boolean openDrawer = false; int upIndicator = 0; NavMenuItem selNavItem = null; switch (mode) { case INIT: { drawerEnabled = true; break; } case RECORDS_LIST: { drawerEnabled = true; // If the user hasn't 'learned' about the drawer, open it openDrawer = shouldOpenDrawer(); selNavItem = NavMenuItem.RECORDS; break; } case RECORDS_SINGLE: { selNavItem = NavMenuItem.RECORDS; break; } case RECORDS_ACTION: { upIndicator = R.drawable.ic_action_close_cancel; selNavItem = NavMenuItem.RECORDS; break; } case POLICIES: { drawerEnabled = true; selNavItem = NavMenuItem.PASSWORD_POLICIES; break; } case EXPIRATIONS: { drawerEnabled = true; selNavItem = NavMenuItem.EXPIRED_PASSWORDS; break; } case PREFERENCES: { drawerEnabled = true; selNavItem = NavMenuItem.PREFERENCES; break; } case ABOUT: { drawerEnabled = true; selNavItem = NavMenuItem.ABOUT; break; } } updateDrawerToggle(drawerEnabled, upIndicator); Menu menu = getNavView().getMenu(); for (int i = 0; i < menu.size(); ++i) { MenuItem item = menu.getItem(i); int itemId = item.getItemId(); if (selNavItem == null) { item.setChecked(false); } else if (selNavItem.itsMenuId == itemId) { item.setChecked(true); } if ((itemId == NavMenuItem.RECORDS.itsMenuId) || (itemId == NavMenuItem.PASSWORD_POLICIES.itsMenuId) || (itemId == NavMenuItem.EXPIRED_PASSWORDS.itsMenuId)) { item.setEnabled(fileOpen); } } itsSelNavItem = selNavItem; if (fileNameUpdate != null) { GuiUtils.setVisible(itsFileName, !TextUtils.isEmpty(fileNameUpdate)); itsFileName.setText(fileNameUpdate); } openDrawer(openDrawer); }
From source file:com.android.screenspeak.contextmenu.ListMenuManager.java
private CharSequence[] getItemsFromMenu(Menu menu) { int size = menu.size(); List<CharSequence> items = new ArrayList<>(); for (int i = 0; i < size; i++) { MenuItem item = menu.getItem(i); if (item != null && item.isEnabled() && item.isVisible()) { items.add(item.getTitle());/*from w w w .ja v a 2 s.c om*/ } } return items.toArray(new CharSequence[items.size()]); }
From source file:com.pepperonas.truthordare.fragments.FragmentTwoPlayer.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); menu.add(0, 0, 0, "Start").setIcon(R.drawable.ic_marked_circle_white_24dp) .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); menu.getItem(0).setOnMenuItemClickListener(this); }
From source file:com.shafiq.mytwittle.view.TweetSpotlightActivity.java
void storeMenuItems(Menu menu) { for (int i = 0; i < menu.size(); i++) { MenuItem menuItem = menu.getItem(i); if (menuItem.getItemId() == R.id.action_favorite) { mFavoriteMenuItem = menuItem; boolean isDarkTheme = AppSettings.get().getCurrentTheme() == AppSettings.Theme.Holo_Dark; if (mStatus.mIsFavorited == true) { mFavoriteMenuItem.setIcon( isDarkTheme ? R.drawable.ic_action_star_on_dark : R.drawable.ic_action_star_on_light); mFavoriteMenuItem.setTitle(R.string.action_unfavorite); } else { mFavoriteMenuItem.setIcon( isDarkTheme ? R.drawable.ic_action_star_off_dark : R.drawable.ic_action_star_off_light); mFavoriteMenuItem.setTitle(R.string.action_favorite); }// ww w. j a v a 2 s . c o m break; } } }