List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:com.robertcm.romcontrol.project.MainActivity.java
private void setUpPrefsMenu(Menu navigationMenu) { String[] titles = getResources().getStringArray(R.array.nav_menu_prefs_titles); TypedArray iconIds = getResources().obtainTypedArray(R.array.nav_menu_prefs_drawables); mNavMenuItemsIds = new ArrayList<>(); for (int i = 0; i < titles.length; i++) { Integer id = View.generateViewId(); mNavMenuItemsIds.add(id);/* w ww .ja v a2s . com*/ MenuItem item = navigationMenu.add(Menu.NONE, id, 0, titles[i]).setIcon(iconIds.getResourceId(i, -1)); if (titles[i] != null && titles[i].equals(getTitle().toString())) { item.setChecked(true); } } iconIds.recycle(); navigationMenu.setGroupCheckable(Menu.NONE, true, true); }
From source file:com.saloon.android.bluecactus.app.UI.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); enableMyLocation();// w w w.ja v a 2s .c om // Location check Locator locator = new Locator(this); locator.getLocation(Locator.Method.NETWORK, listener); // Network request test with volley NetworkRequests networkRequest = new NetworkRequests(this); divisionList = networkRequest.getDivisions(); Log.i("Array List size: ", divisionList.size() + ""); GlobalVariables.getInstance().setArrayList(divisionList); // Adding Toolbar to Main screen Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Setting ViewPager for each Tabs ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); // Set Tabs inside Toolbar TabLayout tabs = (TabLayout) findViewById(R.id.tabs); tabs.setupWithViewPager(viewPager); // Create Navigation drawer and inlfate layout NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer); // Adding menu icon to Toolbar ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { VectorDrawableCompat indicator = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu, getTheme()); indicator.setTint(ResourcesCompat.getColor(getResources(), R.color.white, getTheme())); supportActionBar.setHomeAsUpIndicator(indicator); supportActionBar.setDisplayHomeAsUpEnabled(true); } // Set behavior of Navigation drawer navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { // This method will trigger on item Click of navigation menu @Override public boolean onNavigationItemSelected(MenuItem menuItem) { // Set item in checked state menuItem.setChecked(true); Log.d("Menu Item id: ", menuItem.getTitle() + ""); handleMenuClick(menuItem.getTitle().toString()); // TODO: handle navigation // Toast.makeText(MainActivity.this, "Clicked: " + menuItem.getTitle(), Toast.LENGTH_SHORT).show(); // // Intent intent = new Intent(MainActivity.this, Appointment.class); // // MainActivity.this.startActivity(intent); // // Closing drawer on item click mDrawerLayout.closeDrawers(); return true; } }); // Adding Floating Action Button to bottom right of main view FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Snackbar.make(v, "Hello Snackbar!", Snackbar.LENGTH_LONG).show(); } }); }
From source file:com.oddsoft.buddhavoice2.view.MainActivity.java
private void initDrawer() { navigation.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override/*from w ww . ja va 2s .com*/ 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(false); else menuItem.setChecked(true); //Closing drawer on item click drawerLayout.closeDrawers(); switch (menuItem.getItemId()) { case R.id.navSetting: startActivity(new Intent(MainActivity.this, Prefs.class)); break; case R.id.navAbout: new LibsBuilder() //provide a style (optional) (LIGHT, DARK, LIGHT_DARK_TOOLBAR) .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR).withAboutIconShown(true) .withAboutVersionShown(true).withAboutAppName(getString(R.string.app_name)) .withActivityTitle(getString(R.string.about_title)) .withAboutDescription(getString(R.string.license)) //start the activity .start(MainActivity.this); break; } return false; } }); //change navigation drawer item icons navigation.getMenu().findItem(R.id.navSetting).setIcon( new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_settings).color(Color.GRAY).sizeDp(24)); navigation.getMenu().findItem(R.id.navAbout) .setIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_info).color(Color.GRAY).sizeDp(24)); actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.app_name, R.string.app_name) { @Override public void onDrawerClosed(View drawerView) { // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank super.onDrawerClosed(drawerView); } @Override public void onDrawerOpened(View drawerView) { // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank super.onDrawerOpened(drawerView); } }; //Setting the actionbarToggle to drawer layout drawerLayout.setDrawerListener(actionBarDrawerToggle); //calling sync state is necessay or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); }
From source file:com.android.adam.navigation.BottomNavigationMenuView.java
public BottomNavigationMenuView(Context context, AttributeSet attrs) { super(context, attrs); final Resources res = getResources(); mInactiveItemMaxWidth = res/*from w w w. j ava2 s . c o m*/ .getDimensionPixelSize(android.support.design.R.dimen.design_bottom_navigation_item_max_width); mInactiveItemMinWidth = res .getDimensionPixelSize(android.support.design.R.dimen.design_bottom_navigation_item_min_width); mActiveItemMaxWidth = res.getDimensionPixelSize( android.support.design.R.dimen.design_bottom_navigation_active_item_max_width); mItemHeight = res.getDimensionPixelSize(android.support.design.R.dimen.design_bottom_navigation_height); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { mAnimationHelper = new BottomNavigationAnimationHelperIcs(); } else { mAnimationHelper = new BottomNavigationAnimationHelperBase(); } mOnClickListener = new OnClickListener() { @Override public void onClick(View v) { final BottomNavigationItemView itemView = (BottomNavigationItemView) v; MenuItem item = itemView.getItemData(); if (!mMenu.performItemAction(item, mPresenter, 0)) { item.setChecked(true); } } }; mTempChildWidths = new int[BottomNavigationMenu.MAX_ITEM_COUNT]; }
From source file:id.zelory.tanipedia.activity.TanyaActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tanya); toolbar = (Toolbar) findViewById(R.id.anim_toolbar); setSupportActionBar(toolbar);/*from w w w. j a v a 2 s .com*/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbar.setTitle("Tanya Tani"); animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow); fabMargin = getResources().getDimensionPixelSize(R.dimen.fab_margin); drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer); setUpNavDrawer(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.getMenu().getItem(2).setChecked(true); TextView nama = (TextView) navigationView.findViewById(R.id.nama); nama.setText(PrefUtils.ambilString(this, "nama")); TextView email = (TextView) navigationView.findViewById(R.id.email); email.setText(PrefUtils.ambilString(this, "email")); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); drawerLayout.closeDrawers(); Intent intent; switch (menuItem.getItemId()) { case R.id.cuaca: intent = new Intent(TanyaActivity.this, CuacaActivity.class); break; case R.id.berita: intent = new Intent(TanyaActivity.this, BeritaActivity.class); break; case R.id.tanya: return true; case R.id.harga: intent = new Intent(TanyaActivity.this, KomoditasActivity.class); break; case R.id.logout: PrefUtils.simpanString(TanyaActivity.this, "nama", null); intent = new Intent(TanyaActivity.this, LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); return true; case R.id.tentang: intent = new Intent(TanyaActivity.this, TentangActivity.class); startActivity(intent); return true; default: return true; } startActivity(intent); finish(); return true; } }); recyclerView = (RecyclerView) findViewById(R.id.scrollableview); recyclerView.setHasFixedSize(true); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.addOnScrollListener(new MyRecyclerScroll() { @Override public void show() { fab.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start(); } @Override public void hide() { fab.animate().translationY(fab.getHeight() + fabMargin) .setInterpolator(new AccelerateInterpolator(2)).start(); } }); tanyaGambar = (ImageView) findViewById(R.id.tanya_gambar); tanyaGambar.setVisibility(View.GONE); fab = (FrameLayout) findViewById(R.id.myfab_main); fab.setVisibility(View.GONE); fabBtn = (ImageButton) findViewById(R.id.myfab_main_btn); View fabShadow = findViewById(R.id.myfab_shadow); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { fabShadow.setVisibility(View.GONE); fabBtn.setBackground(getDrawable(R.drawable.ripple_accent)); } fabBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new MaterialDialog.Builder(TanyaActivity.this).title("TaniPedia").content("Kirim Pertanyaan") .inputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_CLASS_TEXT) .input("Ketik pertanyaan anda disini!", null, false, new MaterialDialog.InputCallback() { @Override public void onInput(MaterialDialog dialog, CharSequence input) { try { pertanyaan = URLEncoder.encode(input.toString(), "UTF-8"); new KirimSoal().execute(); } catch (UnsupportedEncodingException e) { Snackbar.make(fabBtn, "Terjadi kesalahan, silahkan coba lagi!", Snackbar.LENGTH_LONG).show(); e.printStackTrace(); } } }).positiveColorRes(R.color.primary_dark).positiveText("Kirim") .cancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { } }).negativeColorRes(R.color.primary_dark).negativeText("Batal").show(); } }); fabButton = (FabButton) findViewById(R.id.determinate); fabButton.showProgress(true); new DownloadData().execute(); fabButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { fabButton.showProgress(true); new DownloadData().execute(); } }); }
From source file:com.juliovaz.condio.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Adding Toolbar to Main screen Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);// ww w.jav a 2s .c o m fab = (FloatingActionButton) findViewById(R.id.btn_new_reservation); // Setting ViewPager for each Tabs viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); // Set Tabs inside Toolbar TabLayout tabs = (TabLayout) findViewById(R.id.tabs); tabs.setupWithViewPager(viewPager); // Create Navigation drawer and inlfate layout final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer); // Adding menu icon to Toolbar ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { VectorDrawableCompat indicator = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu, getTheme()); indicator.setTint(ResourcesCompat.getColor(getResources(), R.color.white, getTheme())); supportActionBar.setHomeAsUpIndicator(indicator); supportActionBar.setDisplayHomeAsUpEnabled(true); } // Set behavior of Navigation drawer navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { // This method will trigger on item Click of navigation menu @Override public boolean onNavigationItemSelected(MenuItem menuItem) { // Set item in checked state menuItem.setChecked(true); Context context = navigationView.getContext(); Intent intent; switch (menuItem.getItemId()) { case R.id.menu_item_home: intent = new Intent(context, MainActivity.class); context.startActivity(intent); break; case R.id.menu_item_reservation_history: intent = new Intent(context, ReservationHistoryActivity.class); context.startActivity(intent); fab.hide(); break; case R.id.menu_item_bills: intent = new Intent(context, BillActivity.class); context.startActivity(intent); break; default: break; } // Closing drawer on item click mDrawerLayout.closeDrawers(); return true; } }); /* --- checar se role == sindico ---- */ // Adding Floating Action Button to bottom right of main view fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Context context = view.getContext(); Intent intent = new Intent(context, ReservationActivity.class); context.startActivity(intent); } }); initGcm(); viewPagerPosition(); if (!isStoragePermissionGranted()) { Toast.makeText(this, "O App no ir funcionar direito sem essa permisso!", Toast.LENGTH_SHORT) .show(); } }
From source file:de.aw.monma.actions.FragmentWPList.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_onlyBestand: onlyBestand = !onlyBestand;/*from ww w. j av a 2 s .co m*/ item.setChecked(onlyBestand); args.putBoolean(ONLYBESTAND, onlyBestand); startOrRestartLoader(layout, args); return true; case R.id.menu_item_sortieren: sortieren = !sortieren; item.setChecked(sortieren); String mOrderBy; if (sortieren) { mOrderBy = column_amount + " DESC ," + orderBy; } else { mOrderBy = orderBy; } args.putBoolean(SORTIEREN, sortieren); args.putString(ORDERBY, mOrderBy); startOrRestartLoader(layout, args); return true; default: return super.onOptionsItemSelected(item); } }
From source file:io.github.protino.codewatch.ui.NavigationDrawerActivity.java
@Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { item.setChecked(!item.isChecked()); String text;/* w ww . j a v a2 s . com*/ switch (item.getItemId()) { case R.id.dashboard: text = getString(R.string.dashboard_title); replaceFragment(new DashboardFragment(), text); break; case R.id.goals: text = getString(R.string.goals_title); replaceFragment(new GoalsFragment(), text); break; case R.id.achievements: text = getString(R.string.achievements_title); replaceFragment(new AchievementFragment(), text); break; case R.id.leaderboards: text = getString(R.string.leaderboards); replaceFragment(new LeaderboardFragment(), text); break; case R.id.projects: text = getString(R.string.projects_title); replaceFragment(new ProjectsFragment(), text); break; case R.id.settings: text = getString(R.string.settings_title); replaceFragment(new SettingsFragment(), text); break; default: break; } drawerLayout.closeDrawers(); return true; }
From source file:com.example.ali.topcoderandroid.Activities.MainActivity.java
private void setNavigation(NavigationView navigationView, ChallengeType challengeType) { int preferredCheckItemId = 0; switch (challengeType) { case Design:/*w w w.j ava 2s . co m*/ 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:com.example.android0128.introductionmvp.tasks.TasksActivity.java
private void setupDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//from w w w. j a va2 s.c o m public boolean onNavigationItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { /*case R.id.list_navigation_menu_item: // Do nothing, we're already on that screen break;*/ default: break; } // Close the navigation drawer when an item is selected. menuItem.setChecked(true); mDrawerLayout.closeDrawers(); return true; } }); }