List of usage examples for android.view MenuItem setIcon
public MenuItem setIcon(@DrawableRes int iconRes);
From source file:com.example.android.adaptertransition.AdapterTransitionFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { // We change the look of the icon every time the user toggles between list and grid. MenuItem item = menu.findItem(R.id.action_toggle); if (null != item) { if (mAbsListView instanceof ListView) { item.setIcon(R.drawable.ic_action_grid); item.setTitle(R.string.show_as_grid); } else {/*from w ww. j a v a2 s. c om*/ item.setIcon(R.drawable.ic_action_list); item.setTitle(R.string.show_as_list); } } }
From source file:th.in.ffc.person.visit.VisitEpiActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.edit_add_activity, menu); MenuItem item = menu.add(0, R.string.appoint, 2, R.string.appoint); item.setIcon(R.drawable.ic_action_epi_appoint); item.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM); return true;/*from w w w. j a va 2 s . c om*/ }
From source file:org.secu3.android.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem m = menu.findItem(R.id.menu_errors); m.setIcon(errors ? R.drawable.ic_menu_errors_highlighted : R.drawable.ic_menu_errors); m = menu.findItem(R.id.menu_raw_sensors); m.setChecked(rawSensors);// www. j a v a 2s . c o m return true; }
From source file:com.github.kimikage.uguisuan.MainActivity.java
private void setPlayAndPauseButton() { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar == null) { return;/* w w w .j av a 2 s . co m*/ } if (toolbar.getMenu() == null) { return; } boolean playing = isPlaying(); MenuItem menuItem = (MenuItem) toolbar.getMenu().findItem(R.id.action_play_pause); menuItem.setTitle(getResources().getString(playing ? R.string.action_pause : R.string.action_play)); menuItem.setIcon(playing ? R.drawable.ic_pause_circle_filled_white_48dp : R.drawable.ic_play_circle_filled_white_48dp); View v = findViewById(R.id.action_play_pause); if (v != null) { v.setSoundEffectsEnabled(playing); } }
From source file:syncthing.android.ui.LauncherActivity.java
void populateNavigationMenu(Credentials current, boolean goToCurrent) { List<Credentials> creds = mSettings.getSavedCredentialsSorted(); //TODO any way to just clear the devices group? mNavigation.getMenu().clear();/*from w w w . j a v a 2 s. c om*/ mNavigation.inflateMenu(R.menu.navigation); Menu menu = mNavigation.getMenu(); for (int ii = 0; ii < creds.size(); ii++) { Credentials c = creds.get(ii); MenuItem item = menu.add(R.id.nav_devices, Menu.NONE, ii + 1, c.alias); item.setIcon(new BitmapDrawable(getResources(), mIdenticonGenerator.generate(c.id))); item.setIntent(new Intent().putExtra(ManageActivity.EXTRA_CREDENTIALS, c)); if (goToCurrent && c.equals(current)) { item.setChecked(true); } } if (goToCurrent) { if (current != null) { openSession(current); } else if (creds.isEmpty()) { startWelcomeActivity(); } else { Timber.w("No current device"); openDrawer(GravityCompat.START); } } }
From source file:com.mifos.mifosxdroid.online.ClientChargeFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { menu.clear();//from w ww . j ava 2 s . c o m MenuItem menuItemAddNewDocument = menu.add(Menu.NONE, MENU_ITEM_ADD_NEW_CHARGES, Menu.NONE, getString(R.string.add_new)); menuItemAddNewDocument .setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_action_content_new, null)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) menuItemAddNewDocument.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); super.onPrepareOptionsMenu(menu); }
From source file:com.uwetrottmann.wpdisplay.ui.DisplayFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_display, menu); boolean paused = ConnectionTools.get().isPaused(); MenuItem item = menu.findItem(R.id.menu_action_display_pause); item.setIcon(paused ? R.drawable.ic_play_arrow_white_24dp : R.drawable.ic_pause_white_24dp); item.setTitle(paused ? R.string.action_resume : R.string.action_pause); item.setEnabled(isConnected);/*w w w .j a v a 2 s .c o m*/ item.setVisible(isConnected); }
From source file:com.google.android.gcm.demo.ui.MainMenu.java
public boolean onOverflowMenuItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.toggle_logs: { CharSequence showLogs = mActivity.getString(R.string.show_logs); if (showLogs.equals(item.getTitle())) { mActivity.toggleLogsView(true); item.setTitle(R.string.hide_logs); item.setIcon(R.drawable.visibility_off_white); } else {/*from w w w .ja va2s .c o m*/ mActivity.toggleLogsView(false); item.setTitle(R.string.show_logs); item.setIcon(R.drawable.visibility_white); } return true; } case R.id.clear_logs: { (new Logger(mActivity)).clearLogs(); return true; } default: return false; } }
From source file:com.iaraby.template.view.Master_Activity.java
public void updateFavButton(long selectedId) { if (menu != null && selectedId != Constants.EMPTY_INT) { MenuItem favItem = menu.findItem(R.id.action_fav); if (FavoriteManager.getInstance(this).isFav(selectedId)) { favItem.setTitle(getString(R.string.action_fav)); favItem.setIcon(R.drawable.menu_item_fav); } else {//from ww w. j a v a2 s .co m favItem.setTitle(getString(R.string.action_not_fav)); favItem.setIcon(R.drawable.menu_item_not_fav); } // check if selected item favorite or not } // make sure menu item not null }
From source file:org.orange.querysystem.content.ListPostsFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // Place an action bar item for searching. MenuItem item = menu.add(Menu.NONE, SEARCH, Menu.NONE, R.string.search); item.setIcon(R.drawable.ic_action_search); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); Context context = Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH ? getActivity().getApplicationContext() : getActivity().getActionBar().getThemedContext(); View searchView = SearchViewCompat.newSearchView(context); if (searchView != null) { SearchViewCompat.setOnQueryTextListener(searchView, new OnQueryTextListenerCompat() { @Override/* w w w .j a v a2 s . c o m*/ public boolean onQueryTextChange(String newText) { onSearchTextChanged(newText); return true; } }); MenuItemCompat.setActionView(item, searchView); } }