本文整理汇总了Java中android.view.MenuItem类的典型用法代码示例。如果您正苦于以下问题:Java MenuItem类的具体用法?Java MenuItem怎么用?Java MenuItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MenuItem类属于android.view包,在下文中一共展示了MenuItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onOptionsItemSelected
import android.view.MenuItem; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
Intent i = new Intent(this, SettingsActivity.class);
startActivity(i);
return true;
case R.id.yaacc_about:
AboutActivity.showAbout(this);
return true;
case R.id.yaacc_log:
YaaccLogActivity.showLog(this);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
示例2: showMenu
import android.view.MenuItem; //导入依赖的package包/类
private void showMenu(Menu menu) {
if (currentMenu == menu) {
// no need to re-draw
return;
}
menuLayout.removeAllViews();
final int count = menu.size();
for (int i=0; i<count; i++) {
final MenuItem item = menu.getItem(i);
if (item.isVisible()) {
final View view = getMenuItemView(item);
menuLayout.addView(view);
}
}
currentMenu = menu;
}
示例3: onOptionsItemSelected
import android.view.MenuItem; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_logout:
Prefs.with(this).clear();
startActivity(new Intent(this, LoginActivity.class));
overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
finish();
return true;
case R.id.action_settings:
startActivity(new Intent(this, SettingsActivity.class));
overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
return true;
default:
return false;
}
}
示例4: onOptionsItemSelected
import android.view.MenuItem; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.users_action_filter:
sortItem.collapseActionView();
item.expandActionView();
return true;
case R.id.users_action_sort:
filterItem.collapseActionView();
item.expandActionView();
return true;
case R.id.filter_default:
presenter.sortDefault();
sortItem.collapseActionView();
return true;
case R.id.filter_name_asc:
presenter.sortByNameAsc();
sortItem.collapseActionView();
return true;
case R.id.filter_name_desc:
presenter.sortByNameDesc();
sortItem.collapseActionView();
return true;
}
return super.onOptionsItemSelected(item);
}
示例5: onOptionsItemSelected
import android.view.MenuItem; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.refresh_main:
if (isNetworkAvailable()) {
grabData();
}
break;
case R.id.more_apps:
moreApps();
break;
default:
}
return super.onOptionsItemSelected(item);
}
示例6: showMenu
import android.view.MenuItem; //导入依赖的package包/类
/**
* Shows a contextual popup menu anchored to the supplied view. Item selections are passed to
* the presenter.
*
* @param anchor
* the view to anchor the menu to, not null
* @param item
* the LibraryItem associated with the contextual menu, not null
*/
private void showMenu(final View anchor, final LibraryItem item) {
checkNotNull(item, "item cannot be null.");
checkNotNull(anchor, "overflowButton cannot be null.");
final PopupMenu menu = new PopupMenu(getContext(), anchor);
menu.inflate(contextualMenuResourceId);
menu.show();
// Propagate menu selections back to the presenter
menu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem menuItem) {
for (final MenuItemSelectedListener listener : menuItemSelectedListeners) {
listener.onContextualMenuItemSelected(RecyclerBodyView.this, item, menuItem);
}
return true;
}
});
}
示例7: onOptionsItemSelected
import android.view.MenuItem; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
case Menu.FIRST:
if (mRefreshLayout.isEnableCheckFingerInsideAnotherDirectionView()) {
mRefreshLayout.setEnableCheckFingerInsideAnotherDirectionView(false);
item.setTitle(R.string.enable_check_finger_inside_horizontal_view);
} else {
mRefreshLayout.setEnableCheckFingerInsideAnotherDirectionView(true);
item.setTitle(R.string.disable_check_finger_inside_horizontal_view);
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
示例8: onNavigationItemSelected
import android.view.MenuItem; //导入依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_lsf) {
NavigationController.getInstance().navigateToLSF();
} else if (id == R.id.nav_canteen) {
NavigationController.getInstance().navigateToCanteen();
} else if (id == R.id.nav_settings) {
NavigationController.getInstance().navigateToSettings();
} else if (id == R.id.nav_test) {
startActivity(new Intent(this, VmTestActivity.class));
}
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
示例9: onOptionsItemSelected
import android.view.MenuItem; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
}
switch (item.getItemId()) {
case R.id.action_about:
IntentUtils.openUrl(this, "https://github.com/hugeterry/CoordinatorTabLayout");
break;
case R.id.action_about_me:
IntentUtils.openUrl(this, "http://hugeterry.cn/about");
break;
}
return super.onOptionsItemSelected(item);
}
示例10: onOptionsItemSelected
import android.view.MenuItem; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId()){
case R.id.changeview:
if (recyclerView.getVisibility() == View.VISIBLE)
{
recyclerView.setVisibility(View.GONE);
layoutTest.setVisibility(View.VISIBLE);
}
else
{
recyclerView.setVisibility(View.VISIBLE);
layoutTest.setVisibility(View.GONE);
}
break;
}
return super.onOptionsItemSelected(item);
}
示例11: onContextItemSelected
import android.view.MenuItem; //导入依赖的package包/类
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getItemId() == R.string.copy_on_device_multi){
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
Tvshow tvshow = (Tvshow) mBrowserAdapter.getItem(info.position);
ArrayList<Uri> list = new ArrayList<>();
Cursor cursor2 = getEpisodeForShowCursor(tvshow.getTvshowId());
if(cursor2!=null) {
if (cursor2.getCount() > 0) {
cursor2.moveToFirst();
int uriCol = cursor2.getColumnIndex(VideoStore.MediaColumns.DATA);
do {
Uri uri = Uri.parse(cursor2.getString(uriCol));
if (!Utils.isLocal(uri))
list.add(uri);
} while (cursor2.moveToNext());
startDownloadingVideo(list);
}
}
cursor2.close();
return true;
}
else return super.onContextItemSelected(item);
}
示例12: onNavigationItemSelected
import android.view.MenuItem; //导入依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
if (id == R.id.n_home) {
setFragment(new Tab0Home(), getString(R.string.td_main),"");
} else if (id == R.id.n_news) {
setFragment(new TabBrowser(), getString(R.string.td_news),"");
} else if (id == R.id.n_drivers) {
setFragment(new Tab2Drivers(), getString(R.string.td_drivers),"");
} else if (id == R.id.n_stats) {
setFragment(new Tab3Stats(), getString(R.string.td_stats),"");
} else if (id == R.id.n_guide) {
setFragment(new TabBrowser(), getString(R.string.td_guide), getString(R.string.link_guide));
} else if (id == R.id.n_rules) {
setFragment(new TabBrowser(), getString(R.string.td_rules), getString(R.string.link_rules));
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
示例13: onOptionsItemSelected
import android.view.MenuItem; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
// Respond to the mToolbar's back/home button
case android.R.id.home:
onBackPressed();
return true;
case R.id.menu_place_save:
handleSaveOrUpdatePlace();
break;
case R.id.menu_place_delete:
handleDeletePlace();
break;
}
return super.onOptionsItemSelected(item);
}
示例14: initViewListener
import android.view.MenuItem; //导入依赖的package包/类
@Override
protected void initViewListener() {
super.initViewListener();
fabSpeed.setMenuListener(new SimpleMenuListenerAdapter() {
@Override
public boolean onMenuItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_new:
startActivityForResult(new Intent(OpportunityListActivity.this,
NewOpportunityActivity.class), ACTION_NEW);
break;
case R.id.action_search:
startActivityForResult(new Intent(OpportunityListActivity.this,
SearchActivity.class), ACTION_SEARCH);
break;
}
return super.onMenuItemSelected(menuItem);
}
});
}
示例15: onOptionsItemSelected
import android.view.MenuItem; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
if (itemId == R.id.scan_from_picture) {
//先申请权限
int checked = ContextCompat.checkSelfPermission(ScannerActivity.this
, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (checked == PackageManager.PERMISSION_GRANTED) {
goPicture();
} else {
ActivityCompat.requestPermissions(ScannerActivity.this
, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE_WRITE_EXTERNAL_STORAGE);
}
}
return true;
}