List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:com.afg.MngProductContentProvider.Home_Activity.java
public void setupDrawerContent() { mNav.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/*from w w w .ja va 2 s.co m*/ public boolean onNavigationItemSelected(@NonNull MenuItem item) { item.setChecked(true); switch (item.getItemId()) { case R.id.action_home: showHome(); break; case R.id.action_list: showList(); break; case R.id.pharmacy: showPharmacy(); break; case R.id.action_sales: showSales(); break; case R.id.category: showListCategories(); default: item.setChecked(false); break; } mDrawer.closeDrawer(GravityCompat.START); setTitle(item.getTitle()); return true; } }); }
From source file:com.antonioleiva.materializeyourapp.MainActivity.java
private void setupDrawerLayout() { drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); navigationView = (NavigationView) findViewById(R.id.navigation_view); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/*from w w w . j a va 2s . c o m*/ public boolean onNavigationItemSelected(MenuItem menuItem) { Snackbar.make(content, menuItem.getTitle() + " pressed", Snackbar.LENGTH_LONG).show(); menuItem.setChecked(true); drawerLayout.closeDrawers(); return true; } }); }
From source file:it.gmariotti.changelog.demo.MainActivity.java
private void setupDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override// w ww . ja v a 2 s .c o m public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); selectNavigationItem(menuItem.getItemId()); mDrawerLayout.closeDrawers(); return true; } }); // When the user runs the app for the first time, we want to land them with the // navigation drawer open. But just the first time. if (!PrefUtils.isWelcomeDone(this)) { // first run of the app starts with the nav drawer open PrefUtils.markWelcomeDone(this); mDrawerLayout.openDrawer(GravityCompat.START); } }
From source file:com.hacktx.android.activities.MainActivity.java
protected void setupDrawerContent(final DrawerLayout drawerLayout, NavigationView navigationView) { this.drawerLayout = drawerLayout; ((TextView) navigationView.getHeaderView(0).findViewById(R.id.navHeaderEmail)) .setText(UserStateStore.getUserEmail(this)); if (!mConfigManager.getValue(ConfigParam.CHECK_IN)) { navigationView.getMenu().getItem(5).setEnabled(false); navigationView.getMenu().getItem(5).setVisible(false); }//www. j a va2s. c om navigationView.getMenu().getItem(0).setChecked(true); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(final MenuItem menuItem) { menuItem.setChecked(true); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); switch (menuItem.getItemId()) { case R.id.nav_schedule: mMetricsManager.logEvent(R.string.analytics_event_nav_schedule, null); transaction.replace(R.id.content_fragment, new ScheduleMainFragment()); transaction.commit(); break; case R.id.nav_announcement: mMetricsManager.logEvent(R.string.analytics_event_nav_announcement, null); transaction.replace(R.id.content_fragment, new AnnouncementFragment()); transaction.commit(); break; case R.id.nav_twitter: mMetricsManager.logEvent(R.string.analytics_event_nav_twitter, null); transaction.replace(R.id.content_fragment, new TwitterFragment()); transaction.commit(); break; case R.id.nav_map: mMetricsManager.logEvent(R.string.analytics_event_nav_map, null); transaction.replace(R.id.content_fragment, new GoogleMapFragment()); transaction.commit(); break; case R.id.nav_sponsors: mMetricsManager.logEvent(R.string.analytics_event_nav_sponsors, null); transaction.replace(R.id.content_fragment, new SponsorFragment()); transaction.commit(); break; case R.id.nav_check_in: mMetricsManager.logEvent(R.string.analytics_event_nav_check_in, null); startActivity(new Intent(MainActivity.this, CheckInActivity.class)); break; case R.id.nav_settings: mMetricsManager.logEvent(R.string.analytics_event_nav_settings, null); startActivity(new Intent(MainActivity.this, PreferencesActivity.class)); break; } drawerLayout.closeDrawers(); return true; } }); }
From source file:com.microsoft.azure.engagement.MainActivity.java
/** * Method that updates the current menu item selected * * @param item The menu item to select//from w ww .java 2 s.com */ private final void updateSelection(MenuItem item) { if (item.isCheckable() == true) { item.setChecked(true); if (previousItem != null) { previousItem.setChecked(false); } previousItem = item; } }
From source file:com.guodong.sun.guodong.activity.MainActivity.java
private void selectDrawerItem(MenuItem item) { // Toast.makeText(this, item.getTitle(), Toast.LENGTH_SHORT).show(); item.setChecked(true); // ---------------------------------- switch (item.getItemId()) { case R.id.nav_clean: cleanCache();//from w w w . j a v a 2 s . co m break; case R.id.nav_setting: AboutMeActivity.startActivity(this); mDrawerLayout.closeDrawers(); break; } // ---------------------------------- // mDrawerLayout.closeDrawers(); }
From source file:am.project.x.business.main.MainActivity.java
@Override protected void initializeActivity(@Nullable Bundle savedInstanceState) { ViewUtils.setLayoutFullscreen(getWindow().getDecorView(), false); final Toolbar toolbar = findViewById(R.id.main_toolbar); mVDrawer = findViewById(R.id.main_drawer); mVContent = findViewById(R.id.main_lyt_content); final NavigationView navigation = findViewById(R.id.main_navigation); setSupportActionBar(toolbar);//from w w w . j ava 2 s.c om final ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mVDrawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); toggle.setToolbarNavigationClickListener(this); mVDrawer.addDrawerListener(toggle); toggle.syncState(); navigation.setNavigationItemSelectedListener(this); final String tag; final boolean debug = BuildConfig.DEBUG; if (savedInstanceState == null) { tag = TAG_WIDGETS; final MenuItem item = navigation.getMenu().findItem(R.id.main_nav_widgets); item.setChecked(true); setTitle(item.getTitle()); if (debug) DevelopingActivity.start(this); } else { tag = savedInstanceState.getString(EXTRA_FRAGMENT, TAG_WIDGETS); MenuItem item; switch (tag) { default: case TAG_WIDGETS: item = navigation.getMenu().findItem(R.id.main_nav_widgets); break; case TAG_DRAWABLES: item = navigation.getMenu().findItem(R.id.main_nav_drawables); break; case TAG_OTHERS: item = navigation.getMenu().findItem(R.id.main_nav_others); break; case TAG_DEVELOP: item = navigation.getMenu().findItem(R.id.main_nav_develop); break; } item.setChecked(true); setTitle(item.getTitle()); } final MenuItem develop = navigation.getMenu().findItem(R.id.main_nav_develop); develop.setVisible(debug); setFragment(tag); }
From source file:nz.ac.auckland.lablet.ExperimentAnalysisFragment.java
private void showDataMenu(ExperimentAnalysis experimentAnalysis) { final View menuView = getActivity().findViewById(R.id.action_data); PopupMenu popup = new PopupMenu(getActivity(), menuView); final ViewPager pager = ((ExperimentAnalysisActivity) getActivity()).getViewPager(); final List<ExperimentAnalysis.AnalysisEntry> analysisList = experimentAnalysis .getAnalysisRunAt(analysisRef.runId).analysisList; int i = 0;/*from w w w. j av a 2 s . co m*/ for (ExperimentAnalysis.AnalysisEntry analysisEntry : analysisList) { MenuItem item = popup.getMenu().add(1, i, Menu.NONE, analysisEntry.analysis.getDisplayName()); item.setCheckable(true); if (pager.getCurrentItem() == i) item.setChecked(true); i++; } popup.getMenu().setGroupCheckable(1, true, true); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { int item = menuItem.getItemId(); pager.requestLayout(); pager.setCurrentItem(item, true); return false; } }); popup.show(); }
From source file:org.dmfs.webcal.fragments.CalendarTitleFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.menu_starred) { boolean checked = !item.isChecked(); item.setChecked(checked); // Selectors don't seem to work with menu options, so we have to hard code the icons. item.setIcon(checked ? R.drawable.ic_fa_star : R.drawable.ic_fa_star_o); ContentItem.setStarred(getActivity(), mId, checked); Analytics.event("starred", "calendar-action", checked ? "starred" : "un-starred", null, String.valueOf(mId), null); return true; }/*from w w w.j a v a 2 s . c o m*/ return super.onOptionsItemSelected(item); }
From source file:com.krossovochkin.adsl.MainActivity.java
private void setupNavigationView(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/*from w w w. ja v a 2s.c o m*/ public boolean onNavigationItemSelected(MenuItem item) { if (item.getGroupId() == R.id.checkableGroup) { item.setChecked(true); } // TODO: provide some action depending on item selected - by item.getItemId() mDrawerLayout.closeDrawers(); return true; } }); Menu menu = navigationView.getMenu(); SwitchCompat switchCompat = (SwitchCompat) MenuItemCompat.getActionView(menu.findItem(R.id.switchItem)) .findViewById(R.id.switchCompat); switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Toast.makeText(MainActivity.this, "switch is " + (isChecked ? "checked" : "unchecked"), Toast.LENGTH_SHORT).show(); } }); TextView textView = (TextView) MenuItemCompat.getActionView(menu.findItem(R.id.counterItem)) .findViewById(R.id.textView); textView.setText("5"); }