List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:info.tongrenlu.MainActivity.java
private void setupDrawerContent(NavigationView navigationView) { ImageView userAvatar = (ImageView) navigationView.findViewById(R.id.avatar); if (mUser.isGuest()) { Glide.with(this).load(R.drawable.default_cover).into(userAvatar); } else {/*from w w w. j ava 2 s .c o m*/ Glide.with(this).load("http://files.tongrenlu.info/u" + mUser.getId() + "/cover_400.jpg") .into(userAvatar); } TextView username = (TextView) navigationView.findViewById(R.id.username); username.setText(mUser.getNickname()); navigationView.getMenu().findItem(R.id.nav_signup).setVisible(mUser.isGuest()); navigationView.getMenu().findItem(R.id.nav_signin).setVisible(mUser.isGuest()); navigationView.getMenu().findItem(R.id.nav_signout).setVisible(!mUser.isGuest()); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); mDrawerLayout.closeDrawers(); switch (menuItem.getItemId()) { case R.id.nav_signin: //mViewPager.setCurrentItem(0,true); //setupViewPager(mViewPager); break; case R.id.nav_signout: //mViewPager.setCurrentItem(1,true); //setupViewPager2(mViewPager); break; } return true; } }); // navigationView.findViewById(R.id.nav_signup).setVisibility(View.GONE); // navigationView.findViewById(R.id.nav_signout).setVisibility(View.GONE); }
From source file:com.f2prateek.dfg.ui.activities.MainActivity.java
void initMenuItem(MenuItem menuItem, Preference<Boolean> preference) { menuItem.setChecked(preference.get()); }
From source file:org.csploit.android.plugins.Traceroute.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem item = menu.findItem(R.id.resolve_names); if (item != null) { item.setChecked(resolveNames); }/*from w ww.j av a2 s . c o m*/ return super.onPrepareOptionsMenu(menu); }
From source file:com.commonsware.android.mapsv2.location.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.follow) { item.setChecked(!item.isChecked()); autoFollow = item.isChecked();// w w w .j a v a 2 s .c om follow(); return true; } return super.onOptionsItemSelected(item); }
From source file:com.support.android.zzh.activity.MainActivity.java
/** * menu ??/* w w w.j a v a 2 s.c o m*/ * * @param navigationView */ private void setupDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); mDrawerLayout.closeDrawers(); switch (menuItem.getItemId()) { // case R.id.nav_home: Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT).show(); break; //? case R.id.nav_messages: Toast.makeText(MainActivity.this, "?", Toast.LENGTH_SHORT).show(); break; //? case R.id.nav_friends: Toast.makeText(MainActivity.this, "?", Toast.LENGTH_SHORT).show(); break; // case R.id.nav_a: Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT).show(); break; // case R.id.nav_discussion: Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT).show(); break; } return true; } }); }
From source file:com.twolinessoftware.activities.BaseNavigationActivity.java
private void setMenuItemIcon(Menu menu, @IdRes int menuResourceId, Icon iconName, boolean checked) { MenuItem item = menu.findItem(menuResourceId); Timber.v("setup menu item icon: " + item + ", checked: " + checked); item.setChecked(checked); int primaryColor = ThemeUtil.getPrimaryColor(this); int accentColor = ThemeUtil.getAccentColor(this); item.setIcon(new IconDrawable(BaseNavigationActivity.this, iconName) .color(checked ? primaryColor : accentColor)); }
From source file:com.example.android.hacktxsafe.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);//from w ww.j a v a 2 s . c om // 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); // TODO: handle navigation // 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(); } }); phoneContacts = new ArrayList<>(); getPhoneContactsList(); }
From source file:com.jefftharris.passwdsafe.FileListNavDrawerFragment.java
/** * Update drawer for the fragments displayed in the activity */// w w w . j a v a 2 s .c o m public void updateView(Mode mode) { boolean openDrawer = false; NavMenuItem selNavItem = null; switch (mode) { case INIT: { break; } case ABOUT: { selNavItem = NavMenuItem.ABOUT; break; } case FILES: { // If the user hasn't 'learned' about the drawer, open it openDrawer = shouldOpenDrawer(); selNavItem = NavMenuItem.FILES; break; } case PREFERENCES: { selNavItem = NavMenuItem.PREFERENCES; break; } } updateDrawerToggle(true, 0); 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); } } itsSelNavItem = selNavItem; openDrawer(openDrawer); }
From source file:id.zelory.tanipedia.activity.KomoditasActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_komoditas); toolbar = (Toolbar) findViewById(R.id.anim_toolbar); setSupportActionBar(toolbar);//from ww w.j a va2 s . c o m getSupportActionBar().setDisplayHomeAsUpEnabled(true); CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbar.setTitle("Harga Komoditas"); animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow); drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer); setUpNavDrawer(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.getMenu().getItem(3).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(KomoditasActivity.this, CuacaActivity.class); break; case R.id.berita: intent = new Intent(KomoditasActivity.this, BeritaActivity.class); break; case R.id.tanya: intent = new Intent(KomoditasActivity.this, TanyaActivity.class); break; case R.id.harga: return true; case R.id.logout: PrefUtils.simpanString(KomoditasActivity.this, "nama", null); intent = new Intent(KomoditasActivity.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(KomoditasActivity.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); imageHeader = (ImageView) findViewById(R.id.header); imageHeader.setVisibility(View.GONE); 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:id.zelory.tanipedia.activity.BeritaActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_berita); toolbar = (Toolbar) findViewById(R.id.anim_toolbar); setSupportActionBar(toolbar);/* w ww .j a v a2 s . c o m*/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbar.setTitle("Berita Terbaru"); animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow); drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer); setUpNavDrawer(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.getMenu().getItem(1).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(BeritaActivity.this, CuacaActivity.class); break; case R.id.berita: return true; case R.id.tanya: intent = new Intent(BeritaActivity.this, TanyaActivity.class); break; case R.id.harga: intent = new Intent(BeritaActivity.this, KomoditasActivity.class); break; case R.id.logout: PrefUtils.simpanString(BeritaActivity.this, "nama", null); intent = new Intent(BeritaActivity.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(BeritaActivity.this, TentangActivity.class); startActivity(intent); return true; default: return true; } startActivity(intent); finish(); return true; } }); imageHeader = (ImageView) findViewById(R.id.header); recyclerView = (RecyclerView) findViewById(R.id.scrollableview); recyclerView.setHasFixedSize(true); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(linearLayoutManager); 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(); } }); }