Java Code Examples for android.support.v4.view.MenuItemCompat#setShowAsAction()
The following examples show how to use
android.support.v4.view.MenuItemCompat#setShowAsAction() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogActivity.java From COCOFramework with Apache License 2.0 | 6 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem item = menu.add(0, ACTION_FILTER, 0, "Filter"); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_NEVER); item = menu.add(0, ACTION_LEVEL, 0, "Level"); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_NEVER); item = menu.add(0, ACTION_CLEAR, 0, "Clear"); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_NEVER); item = menu.add(0, ACTION_SHARE, 0, "Share"); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_NEVER); return true; }
Example 2
Source File: BottomToolbar.java From android_maplibui with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void inflateMenu(@MenuRes int resId) { super.inflateMenu(resId); Menu menu = getMenu(); MenuItem item = menu.getItem(0); int size = item.getIcon().getIntrinsicWidth() + ControlHelper.dpToPx(30, getResources()); int width = getWidth(); for (int i = 0; i < menu.size(); i++) { item = menu.getItem(i); if (size * (i + 2) < width) MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); else break; } }
Example 3
Source File: Main.java From redalert-android with Apache License 2.0 | 6 votes |
void initializeSettingsButton(Menu OptionsMenu) { // Add refresh in Action Bar MenuItem settingsItem = OptionsMenu.add(Menu.NONE, Menu.NONE, Menu.NONE, getString(R.string.settings)); // Set up the view settingsItem.setIcon(R.drawable.ic_settings); // Specify the show flags MenuItemCompat.setShowAsAction(settingsItem, MenuItem.SHOW_AS_ACTION_ALWAYS); // On click, go to Settings settingsItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { // Start settings activity goToSettings(false); // Consume event return true; } }); }
Example 4
Source File: General.java From redalert-android with Apache License 2.0 | 5 votes |
void initializeShareButton(Menu OptionsMenu) { // Add share button MenuItem shareItem = OptionsMenu.add(Menu.NONE, Menu.NONE, Menu.NONE, getString(R.string.share)); // Set up the view shareItem.setIcon(R.drawable.ic_share); // Specify the show flags MenuItemCompat.setShowAsAction(shareItem, MenuItem.SHOW_AS_ACTION_ALWAYS); // On click, open share shareItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { // Prepare share intent Intent shareIntent = new Intent(Intent.ACTION_SEND); // Set as text/plain shareIntent.setType("text/plain"); // Add text shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.shareMessage)); // Show chooser startActivity(Intent.createChooser(shareIntent, getString(R.string.shareDesc))); // Consume event return true; } }); }
Example 5
Source File: ActionBarTransformationActivity.java From Painter with MIT License | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. mIcon1 = menu.add(0, R.id.icon1, 0, "").setIcon(getResources().getDrawable(R.drawable.ic_action_sun)); MenuItemCompat.setShowAsAction(mIcon1, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); mIcon2 = menu.add(0, R.id.icon2, 0, "").setIcon(getResources().getDrawable(R.drawable.ic_action_add)); MenuItemCompat.setShowAsAction(mIcon2, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); mColorSlider.onSlide(0, mIcon1, mIcon2); return true; }
Example 6
Source File: MainActivity.java From MaskEverywhere with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. MenuItemCompat.setShowAsAction(menu.add(0,0,0,"LoadingMask Demo"),MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); MenuItemCompat.setShowAsAction(menu.add(0,1,0,"GenericStatusMask Demo"),MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); return true; }
Example 7
Source File: GenericStatusLayoutDemo.java From MaskEverywhere with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. MenuItemCompat.setShowAsAction(menu.add(0,0,0,"loading"),MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); MenuItemCompat.setShowAsAction(menu.add(0,1,0,"empty"),MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); MenuItemCompat.setShowAsAction(menu.add(0,2,0,"error"),MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); return true; }
Example 8
Source File: SpydroidActivity.java From spydroid-ipcamera with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); MenuItemCompat.setShowAsAction(menu.findItem(R.id.quit), 1); MenuItemCompat.setShowAsAction(menu.findItem(R.id.options), 1); return true; }
Example 9
Source File: General.java From redalert-android with Apache License 2.0 | 5 votes |
void initializeLoadingIndicator(Menu OptionsMenu) { // Add refresh in Action Bar mLoadingItem = OptionsMenu.add(Menu.NONE, Menu.NONE, Menu.NONE, getString(R.string.signing_up)); // Set up the view MenuItemCompat.setActionView(mLoadingItem, R.layout.loading); // Specify the show flags MenuItemCompat.setShowAsAction(mLoadingItem, MenuItem.SHOW_AS_ACTION_ALWAYS); // Hide by default mLoadingItem.setVisible(false); }
Example 10
Source File: SharingSupport.java From V.FlyoutTest with MIT License | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { ShareCompat.IntentBuilder b = ShareCompat.IntentBuilder.from(this); b.setType("text/plain").setText("Share from menu"); MenuItem item = menu.add("Share"); ShareCompat.configureMenuItem(item, b); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); return true; }
Example 11
Source File: LoaderCustomSupport.java From V.FlyoutTest with MIT License | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // Place an action bar item for searching. MenuItem item = menu.add("Search"); item.setIcon(android.R.drawable.ic_menu_search); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); final View searchView = SearchViewCompat.newSearchView(getActivity()); if (searchView != null) { SearchViewCompat.setOnQueryTextListener(searchView, new OnQueryTextListenerCompat() { @Override public boolean onQueryTextChange(String newText) { // Called when the action bar search text has changed. Since this // is a simple array adapter, we can just have it do the filtering. mCurFilter = !TextUtils.isEmpty(newText) ? newText : null; mAdapter.getFilter().filter(mCurFilter); return true; } }); SearchViewCompat.setOnCloseListener(searchView, new OnCloseListenerCompat() { @Override public boolean onClose() { if (!TextUtils.isEmpty(SearchViewCompat.getQuery(searchView))) { SearchViewCompat.setQuery(searchView, null, true); } return true; } }); MenuItemCompat.setActionView(item, searchView); } }
Example 12
Source File: SwapWorkflowActivity.java From fdroidclient with GNU General Public License v3.0 | 5 votes |
private void setUpSearchView(Menu menu) { SearchView searchView = new SearchView(this); MenuItem searchMenuItem = menu.findItem(R.id.action_search); MenuItemCompat.setActionView(searchMenuItem, searchView); MenuItemCompat.setShowAsAction(searchMenuItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String newText) { String currentFilterString = currentView.getCurrentFilterString(); String newFilter = !TextUtils.isEmpty(newText) ? newText : null; if (currentFilterString == null && newFilter == null) { return true; } if (currentFilterString != null && currentFilterString.equals(newFilter)) { return true; } currentView.setCurrentFilterString(newFilter); if (currentView instanceof SelectAppsView) { getSupportLoaderManager().restartLoader(currentView.getLayoutResId(), null, (SelectAppsView) currentView); } else if (currentView instanceof SwapSuccessView) { getSupportLoaderManager().restartLoader(currentView.getLayoutResId(), null, (SwapSuccessView) currentView); } else { throw new IllegalStateException(currentView.getClass() + " does not have Loader!"); } return true; } @Override public boolean onQueryTextChange(String s) { return true; } }); }
Example 13
Source File: PopularList.java From COCOFramework with Apache License 2.0 | 4 votes |
@Override public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { MenuItem item = menu.add(Menu.NONE, 2, Menu.NONE, R.string.about); MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_NEVER); super.onCreateOptionsMenu(menu, inflater); }
Example 14
Source File: MainActivity.java From deviceinfo with Apache License 2.0 | 4 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem mi = menu.add("Refresh"); MenuItemCompat.setShowAsAction(mi, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); return true; }
Example 15
Source File: FragmentMenuSupport.java From V.FlyoutTest with MIT License | 4 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuItem item; item = menu.add("Menu 2"); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); }
Example 16
Source File: ActionBarFragmentMenu.java From V.FlyoutTest with MIT License | 4 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuItemCompat.setShowAsAction(menu.add("Menu 2"), MenuItem.SHOW_AS_ACTION_IF_ROOM); }
Example 17
Source File: LoaderThrottleSupport.java From V.FlyoutTest with MIT License | 4 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuItem populateItem = menu.add(Menu.NONE, POPULATE_ID, 0, "Populate"); MenuItemCompat.setShowAsAction(populateItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); MenuItem clearItem = menu.add(Menu.NONE, CLEAR_ID, 0, "Clear"); MenuItemCompat.setShowAsAction(clearItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); }
Example 18
Source File: GlideImageFragment.java From glide-support with The Unlicense | 4 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MenuItem clearImage = menu.add(0, 9, 0, "Clear image").setIcon(android.R.drawable.ic_menu_close_clear_cancel); MenuItemCompat.setShowAsAction(clearImage, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); }
Example 19
Source File: PopularRecyclerList.java From COCOFramework with Apache License 2.0 | 4 votes |
@Override public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { MenuItem item = menu.add(Menu.NONE, 2, Menu.NONE, R.string.about); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_NEVER); super.onCreateOptionsMenu(menu, inflater); }
Example 20
Source File: GlideImageActivity.java From glide-support with The Unlicense | 4 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuItem clearImage = menu.add(0, 9, 0, "Clear image").setIcon(android.R.drawable.ic_menu_close_clear_cancel); MenuItemCompat.setShowAsAction(clearImage, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); return true; }