本文整理汇总了Java中android.view.Menu类的典型用法代码示例。如果您正苦于以下问题:Java Menu类的具体用法?Java Menu怎么用?Java Menu使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Menu类属于android.view包,在下文中一共展示了Menu类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateOptionsMenu
import android.view.Menu; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (showReloadPlacesButton) {
getMenuInflater().inflate(R.menu.main_menu, menu);
final MenuItem myActionMenuItem = menu.findItem(R.id.action_refresh);
myActionMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
PlaceFragment placeFragment = (PlaceFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_container);
if (placeFragment.isAdded()) {
placeFragment.currentPlace();
}
return false;
}
});
}
return super.onCreateOptionsMenu(menu);
}
示例2: onCreateOptionsMenu
import android.view.Menu; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_switch, menu);
// Get the action view used in your toggleservice item
final MenuItem toggle = menu.findItem(R.id.menu_switch);
mSwitch = (SwitchCompat) toggle.getActionView().findViewById(R.id.switchInActionBar);
mSwitch.setEnabled(mTransportIdEditText.length() > 0 && mEmailEditText.length() > 0 &&
mPasswordEditText.length() > 0);
mSwitch.setChecked(mStartButton.getVisibility() != View.VISIBLE);
mSwitch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (((SwitchCompat) v).isChecked()) {
checkInputFields();
} else {
confirmStop();
}
}
});
return super.onCreateOptionsMenu(menu);
}
示例3: onPrepareOptionsMenu
import android.view.Menu; //导入依赖的package包/类
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs.getBoolean("manage_system", false)) {
menu.findItem(R.id.menu_app_user).setChecked(prefs.getBoolean("show_user", true));
menu.findItem(R.id.menu_app_system).setChecked(prefs.getBoolean("show_system", false));
} else {
Menu submenu = menu.findItem(R.id.menu_filter).getSubMenu();
submenu.removeItem(R.id.menu_app_user);
submenu.removeItem(R.id.menu_app_system);
}
menu.findItem(R.id.menu_app_nointernet).setChecked(prefs.getBoolean("show_nointernet", true));
menu.findItem(R.id.menu_app_disabled).setChecked(prefs.getBoolean("show_disabled", true));
String sort = prefs.getString("sort", "name");
if ("uid".equals(sort))
menu.findItem(R.id.menu_sort_uid).setChecked(true);
else
menu.findItem(R.id.menu_sort_name).setChecked(true);
menu.findItem(R.id.menu_lockdown).setChecked(prefs.getBoolean("lockdown", false));
return super.onPrepareOptionsMenu(menu);
}
示例4: onCreateContextMenu
import android.view.Menu; //导入依赖的package包/类
/**
* Create the context menu.
* @param menu The context menu.
* @param v The view.
* @param menuInfo The menu information.
*/
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
if (menu != null) {
((MainActivity)context).setSelectedPackageId(list.get(getLayoutPosition()).getNumber());
Package pack = list.get(getLayoutPosition());
menu.setHeaderTitle(pack.getName());
// Set different title according to the data({@link Package#readable})
if (pack.isReadable()) {
menu.add(Menu.NONE, R.id.action_set_readable, 0, R.string.set_read);
} else {
menu.add(Menu.NONE, R.id.action_set_readable, 0, R.string.set_unread);
}
menu.add(Menu.NONE, R.id.action_copy_code, 0, R.string.copy_code);
menu.add(Menu.NONE, R.id.action_share, 0, R.string.share);
}
}
示例5: onPanelClosed
import android.view.Menu; //导入依赖的package包/类
/**
* Default implementation of
* {@link android.view.Window.Callback#onPanelClosed(int, Menu)} for
* activities. This calls through to {@link #onOptionsMenuClosed(Menu)}
* method for the {@link android.view.Window#FEATURE_OPTIONS_PANEL} panel,
* so that subclasses of Activity don't need to deal with feature codes.
* For context menus ({@link Window#FEATURE_CONTEXT_MENU}), the
* {@link #onContextMenuClosed(Menu)} will be called.
*/
public void onPanelClosed(int featureId, Menu menu) {
switch (featureId) {
case Window.FEATURE_OPTIONS_PANEL:
mFragments.dispatchOptionsMenuClosed(menu);
onOptionsMenuClosed(menu);
break;
case Window.FEATURE_CONTEXT_MENU:
onContextMenuClosed(menu);
break;
case Window.FEATURE_ACTION_BAR:
initWindowDecorActionBar();
mActionBar.dispatchMenuVisibilityChanged(false);
break;
}
}
示例6: onCreateOptionsMenu
import android.view.Menu; //导入依赖的package包/类
@SuppressLint("SetTextI18n")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_question_detail, menu);
MenuItem item = menu.findItem(R.id.menu_comment);
if (item != null) {
View action = item.getActionView();
if (action != null) {
View tv = action.findViewById(R.id.tv_comment_count);
if (tv != null) {
mCommentCountView = (TextView) tv;
if (mBean.getStatistics() != null)
mCommentCountView.setText(mBean.getStatistics().getComment() + "");
}
}
}
// MenuItem menuItem = menu.findItem(R.id.menu_report);
// DrawableCompat.setTint(menuItem.getIcon(),Color.WHITE);
return true;
}
示例7: onCreateOptionsMenu
import android.view.Menu; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (isEnableScanFromPicture) {
getMenuInflater().inflate(R.menu.menu_scan, menu);
return true;
} else {
return super.onCreateOptionsMenu(menu);
}
}
示例8: onCreateOptionsMenu
import android.view.Menu; //导入依赖的package包/类
public boolean onCreateOptionsMenu(Menu menu) {
if(root != null && root.getChildAt(0) != null) {
Key key = backstackHolder.getBackstack().getKey(root.getChildAt(0).getContext());
MainActivity.get(getContext()).getMenuInflater().inflate(key.menu(), menu);
return true;
}
return false;
}
示例9: onCreateOptionsMenu
import android.view.Menu; //导入依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
MenuItem item = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
searchView.setOnQueryTextListener(this);
}
示例10: onCreateActionMode
import android.view.Menu; //导入依赖的package包/类
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate (R.menu.menu_home_contextual, menu);
menu.findItem(R.id.home_contextual_done).setVisible( (mReminderTypeToDisplay == ViewPagerTaskDisplayType.PROGRAMMED) );
menu.findItem(R.id.home_contextual_not_done).setVisible( (mReminderTypeToDisplay == ViewPagerTaskDisplayType.DONE) );
return true;
}
示例11: onCreateOptionsMenu
import android.view.Menu; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.conversation_actions, menu);
enableIntroductionActionIfAvailable(
menu.findItem(R.id.action_introduction));
return super.onCreateOptionsMenu(menu);
}
示例12: onMenuOpened
import android.view.Menu; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @return The default implementation returns true.
*/
public boolean onMenuOpened(int featureId, Menu menu) {
if (featureId == Window.FEATURE_ACTION_BAR) {
initWindowDecorActionBar();
if (mActionBar != null) {
mActionBar.dispatchMenuVisibilityChanged(true);
} else {
Log.e(TAG, "Tried to open action bar menu with no action bar");
}
}
return true;
}
示例13: onCreateOptionsMenu
import android.view.Menu; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.picture_view_menu, menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.action_share);
// Fetch ShareActionProvider
ShareActionProvider shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
if (shareActionProvider == null)
{
Log.w(TAG, "Failed to find share action provider");
return false;
}
if(imageFilename == null)
{
Log.w(TAG, "No receipt to share");
return false;
}
Intent shareIntent = new Intent(Intent.ACTION_SEND);
// Determine mimetype of image
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imageFilename, opt);
shareIntent.setType(opt.outMimeType);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imageFilename)));
shareActionProvider.setShareIntent(shareIntent);
return super.onCreateOptionsMenu(menu);
}
示例14: onCreateOptionMenu
import android.view.Menu; //导入依赖的package包/类
@Override
public boolean onCreateOptionMenu(Menu menu) {
this.menu = menu;
getSelfView().getCompatActivity().getMenuInflater().inflate(R.menu.menu_common, menu);
initCollect();
return true;
}
示例15: onCreateContextMenu
import android.view.Menu; //导入依赖的package包/类
@Override
public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
contextMenu.setHeaderTitle(dataList.get(contextMenuActiveItemPos).getLabel());
contextMenu.add(Menu.NONE, 0, Menu.NONE, R.string.menu_request_icon);
contextMenu.add(Menu.NONE, 1, Menu.NONE, R.string.menu_copy_code);
contextMenu.add(Menu.NONE, 2, Menu.NONE, R.string.menu_save_icon);
contextMenu.getItem(0).setOnMenuItemClickListener(this);
contextMenu.getItem(1).setOnMenuItemClickListener(this);
contextMenu.getItem(2).setOnMenuItemClickListener(this);
contextMenu.getItem(0).setVisible(enableStatsModule);
}