List of usage examples for android.view Menu add
public MenuItem add(int groupId, int itemId, int order, @StringRes int titleRes);
From source file:com.google.code.twisty.Twisty.java
@Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(MENUGROUP_SELECT, R.raw.violet, 0, "Violet").setShortcut('0', 'a'); menu.add(MENUGROUP_SELECT, R.raw.rover, 1, "Rover").setShortcut('1', 'b'); menu.add(MENUGROUP_SELECT, R.raw.glulxercise, 2, "glulxercise").setShortcut('2', 'c'); menu.add(MENUGROUP_SELECT, R.raw.windowtest, 2, "windowtest").setShortcut('6', 'd'); menu.add(MENUGROUP_SELECT, MENU_PICK_FILE, 3, "Open Game...").setShortcut('3', 'o'); //menu.add(MENUGROUP_SELECT, MENU_SHOW_HELP, 5, "Help!?").setShortcut('4', 'h'); menu.add(MENUGROUP_SELECT, MENU_PICK_SETTINGS, 5, "Settings").setShortcut('5', 's'); //menu.add(MENUGROUP_RUNNING, MENU_RESTART, 0, "Restart").setShortcut('7', 'r'); menu.add(MENUGROUP_RUNNING, MENU_STOP, 1, "Stop").setShortcut('9', 's'); menu.add(MENUGROUP_RUNNING, MENU_PICK_SETTINGS, 2, "Settings").setShortcut('4', 's'); return super.onCreateOptionsMenu(menu); }
From source file:com.grarak.kerneladiutor.fragments.RecyclerViewFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); if (!hideBanner()) return;/*from w w w . j ava 2s. c o m*/ if (showViewPager()) { menu.add(0, 0, Menu.NONE, R.string.options) .setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_launcher_preview)) .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM); } if (showTopFab()) { menu.add(0, 1, Menu.NONE, R.string.more).setIcon(getTopFabDrawable()) .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM); } else if (showBottomFab()) { menu.add(0, 1, Menu.NONE, R.string.more).setIcon(getBottomFabDrawable()) .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM); } }
From source file:com.freeme.filemanager.FileExplorerTabActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { if (mViewPager.getCurrentItem() != 1) { menu.add(0, GlobalConsts.MENU_SEARCH, 1, getResources().getString(R.string.menu_item_search)) .setIcon(R.drawable.ic_menu_searchs).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); }// ww w. j a va 2 s . co m if (!FeatureOption.CLEAN_BUTTON_SUPPORT) { menu.add(0, OPERATION_MENU_CLEAN, 1, getResources().getString(R.string.garbage_clean_title)) .setIcon(R.drawable.ic_menu_clean).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); } return super.onCreateOptionsMenu(menu); }
From source file:org.alfresco.mobile.android.application.activity.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { if (sessionState == SESSION_ERROR && getCurrentSession() == null) { MenuItem mi = menu.add(Menu.NONE, R.id.menu_account_reload, Menu.FIRST, R.string.retry_account_loading); mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT | MenuItem.SHOW_AS_ACTION_ALWAYS); }//from w w w . j av a 2 s. co m return super.onCreateOptionsMenu(menu); }
From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java
private void addNewItem(Menu menu, int group, int order, String text, MenuMetadata meta, @DrawableRes int icon, @DrawableRes Integer actionViewIcon) { if (BuildConfig.DEBUG && menu.findItem(order) != null) throw new IllegalStateException("Item already id exists: " + order); MenuItem item = menu.add(group, order, order, text).setIcon(icon); dataUtils.putDrawerMetadata(item, meta); if (actionViewIcon != null) { item.setActionView(R.layout.layout_draweractionview); ImageView imageView = item.getActionView().findViewById(R.id.imageButton); imageView.setImageResource(actionViewIcon); if (!mainActivity.getAppTheme().equals(AppTheme.LIGHT)) { imageView.setColorFilter(Color.WHITE); }/* w ww. j a v a 2s.c om*/ item.getActionView().setOnClickListener((view) -> onNavigationItemActionClick(item)); } }
From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java
private void addNewItem(Menu menu, int group, int order, @StringRes int text, MenuMetadata meta, @DrawableRes int icon, @DrawableRes Integer actionViewIcon) { if (BuildConfig.DEBUG && menu.findItem(order) != null) throw new IllegalStateException("Item already id exists: " + order); MenuItem item = menu.add(group, order, order, text).setIcon(icon); dataUtils.putDrawerMetadata(item, meta); if (actionViewIcon != null) { item.setActionView(R.layout.layout_draweractionview); ImageView imageView = item.getActionView().findViewById(R.id.imageButton); imageView.setImageResource(actionViewIcon); if (!mainActivity.getAppTheme().equals(AppTheme.LIGHT)) { imageView.setColorFilter(Color.WHITE); }//from w w w. ja va 2s . c om item.getActionView().setOnClickListener((view) -> onNavigationItemActionClick(item)); } }
From source file:de.sindzinski.wetter.MainActivity.java
private void addLocationToNavigation() { Cursor locationCursor = this.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING }, "", new String[] {}, null); final Menu menu = navigationView.getMenu(); int i = 0;// w w w . j a v a 2 s . c o m while (locationCursor.moveToNext()) { i++; String locationSetting = locationCursor.getString( locationCursor.getColumnIndex(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING)); menu.add(R.id.group1, i, Menu.NONE, locationSetting) .setIcon(ContextCompat.getDrawable(this, R.drawable.ic_home_black_24dp)); } locationCursor.close(); }
From source file:com.android.music.MusicBrowserActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); if (mPermissionReqProcessed == true) { menu.add(0, PLAY_ALL, 0, R.string.play_all); menu.add(0, PARTY_SHUFFLE, 0, R.string.party_shuffle); menu.add(0, SHUFFLE_ALL, 0, R.string.shuffle_all); menu.add(0, EFFECTS_PANEL, 0, R.string.effects_list_title); /// M: Add search view mSearchItem = MusicUtils.addSearchView(this, menu, mQueryTextListener, null); /// M:create menu ADD_FOLDER_TO_PLAY, ///ADD_FOLDER_AS_PLAYLIST,ADD_SONG_TO_PLAY when plugin need Bundle options = new Bundle(); options.putInt(PluginUtils.TAB_INDEX, mCurrentTab); mMusicPlugin.onCreateOptionsMenu(menu, ACTIVITY_NAME, options); }//from w w w. j av a 2s . c o m return true; }
From source file:com.he5ed.lib.cloudprovider.picker.CloudPickerActivity.java
/** * @hide/*ww w .j a v a 2 s . com*/ */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cp_activity_picker); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); // lock right drawer from been swiped open drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); navigationView.setItemIconTintList(null); // remove the auto grey tint to keep icon color Menu menu = navigationView.getMenu(); CloudProvider cloudProvider = CloudProvider.getInstance(this); // check whether individual account is assigned String accountId = getIntent().getStringExtra(EXTRA_PICK_ACCOUNT_ID); if (!TextUtils.isEmpty(accountId)) { mAccounts = new CloudAccount[1]; mAccounts[0] = cloudProvider.getAccountById(accountId); } else { mAccounts = cloudProvider.getCloudAccounts(); } // populate navigation menu for (int i = 0; i < mAccounts.length; i++) { CloudAccount account = mAccounts[i]; MenuItem item = menu.add(0, i, 0, account.getUser().email); // use cloud API class reflection try { Class clazz = Class.forName(account.api); Field iconResource = clazz.getField("ICON_RESOURCE"); item.setIcon(iconResource.getInt(null)); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); item.setIcon(R.drawable.ic_cloud_black_24dp); } catch (IllegalAccessException e) { e.printStackTrace(); } item.setCheckable(true); } mFragmentManager = getSupportFragmentManager(); mItemFragment = (ItemFragment) mFragmentManager.findFragmentById(R.id.right_drawer_view); if (mItemFragment == null) { mItemFragment = new ItemFragment(); mFragmentManager.beginTransaction().add(R.id.right_drawer_view, mItemFragment).commit(); } mProgressBar = (ProgressBar) findViewById(R.id.progress_bar); mErrorView = (LinearLayout) findViewById(R.id.error_view); if (savedInstanceState != null) { switch (savedInstanceState.getInt("empty_view_visibility")) { case View.VISIBLE: mErrorView.setVisibility(View.VISIBLE); ImageView icon = (ImageView) mErrorView.findViewById(R.id.empty_icon_image_view); TextView title = (TextView) mErrorView.findViewById(R.id.empty_title_text_view); TextView detail = (TextView) mErrorView.findViewById(R.id.empty_detail_text_view); Bitmap bitmap = savedInstanceState.getParcelable("icon_drawable"); icon.setImageBitmap(bitmap); title.setText(savedInstanceState.getCharSequence("title_text")); detail.setText(savedInstanceState.getCharSequence("detail_text")); break; case View.INVISIBLE: mErrorView.setVisibility(View.INVISIBLE); break; case View.GONE: mErrorView.setVisibility(View.GONE); break; } } else { // open drawer on first load drawer.openDrawer(GravityCompat.START); } }
From source file:com.koushikdutta.superuser.FragmentMain.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MenuItem mode = menu.add(Menu.NONE, Menu.NONE, 100, R.string.list_mode); mode.setTitle(pref.getBoolean("grid_mode", true) ? R.string.list_mode : R.string.grid_mode); mode.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); mode.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override//from w w w. j a v a 2 s .c om public boolean onMenuItemClick(MenuItem menuItem) { if (pref.edit().putBoolean("grid_mode", !pref.getBoolean("grid_mode", true)).commit()) getActivity().recreate(); return true; } }); if (!gridMode) return; MenuItem gridSize = menu.add(Menu.NONE, Menu.NONE, 101, R.string.grid_size); gridSize.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); gridSize.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { int sizePort = pref.getInt("grid_size_port", 3); int sizeLand = pref.getInt("grid_size_land", 4); final AlertDialog.Builder builder = new AlertDialog.Builder(context); View parent = LayoutInflater.from(context).inflate(R.layout.dialog_settings_grid_size, null); final AppCompatSeekBar seekPort = (AppCompatSeekBar) parent.findViewById(R.id.seek_port); seekPort.setProgress(sizePort - 3); final AppCompatSeekBar seekLand = (AppCompatSeekBar) parent.findViewById(R.id.seek_land); seekLand.setProgress(sizeLand - 3); builder.setView(parent); builder.setPositiveButton("?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { SharedPreferences.Editor editor = pref.edit(); editor.putInt("grid_size_port", seekPort.getProgress() + 3); editor.putInt("grid_size_land", seekLand.getProgress() + 3).apply(); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { int val = seekPort.getProgress() + 3; layoutManager.setSpanCount(val); callback.onGridSpanChanged(type, val); } else if (getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { int val = seekLand.getProgress() + 3; layoutManager.setSpanCount(val); callback.onGridSpanChanged(type, val); } } }); builder.show(); return true; } }); }