android.view.MenuItem.setCheckable()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(146)

本文整理了Java中android.view.MenuItem.setCheckable()方法的一些代码示例,展示了MenuItem.setCheckable()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MenuItem.setCheckable()方法的具体详情如下:
包路径:android.view.MenuItem
类名称:MenuItem
方法名:setCheckable

暂无

代码示例

代码示例来源:origin: stackoverflow.com

mUiNavigationView.setNavigationItemSelectedListener(
     new NavigationView.OnNavigationItemSelectedListener() {
       @Override
       public boolean onNavigationItemSelected(MenuItem menuItem) {
         menuItem.setCheckable(true);
         menuItem.setChecked(true);
         if (mPreviousMenuItem != null) {
           mPreviousMenuItem.setChecked(false);
         }
         mPreviousMenuItem = menuItem;
         //...
         changeCurrentFragment(...);
         return true;
       }
     });

代码示例来源:origin: alexvasilkov/GestureViews

private void addBoolMenu(Menu menu, boolean checked, @StringRes int titleId) {
  MenuItem item = menu.add(Menu.NONE, titleId, 0, titleId);
  item.setCheckable(true);
  item.setChecked(checked);
}

代码示例来源:origin: alexvasilkov/GestureViews

private <T> void addSubMenu(Menu menu, T[] items, T selected, @StringRes int titleId) {
  SubMenu sub = menu.addSubMenu(titleId);
  sub.setGroupCheckable(Menu.NONE, true, true);
  for (int i = 0; i < items.length; i++) {
    MenuItem item = sub.add(Menu.NONE, titleId, i, items[i].toString());
    item.setCheckable(true);
    item.setChecked(items[i] == selected);
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldAllowSettingCheckable() throws Exception {
 assertThat(item.isCheckable()).isFalse();
 item.setCheckable(true);
 assertThat(item.isCheckable()).isTrue();
}

代码示例来源:origin: termux/termux-app

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
  TerminalSession currentSession = getCurrentTermSession();
  if (currentSession == null) return;
  menu.add(Menu.NONE, CONTEXTMENU_SELECT_URL_ID, Menu.NONE, R.string.select_url);
  menu.add(Menu.NONE, CONTEXTMENU_SHARE_TRANSCRIPT_ID, Menu.NONE, R.string.select_all_and_share);
  menu.add(Menu.NONE, CONTEXTMENU_RESET_TERMINAL_ID, Menu.NONE, R.string.reset_terminal);
  menu.add(Menu.NONE, CONTEXTMENU_KILL_PROCESS_ID, Menu.NONE, getResources().getString(R.string.kill_process, getCurrentTermSession().getPid())).setEnabled(currentSession.isRunning());
  menu.add(Menu.NONE, CONTEXTMENU_STYLING_ID, Menu.NONE, R.string.style_terminal);
  menu.add(Menu.NONE, CONTEXTMENU_TOGGLE_KEEP_SCREEN_ON, Menu.NONE, R.string.toggle_keep_screen_on).setCheckable(true).setChecked(mSettings.isScreenAlwaysOn());
  menu.add(Menu.NONE, CONTEXTMENU_HELP_ID, Menu.NONE, R.string.help);
}

代码示例来源:origin: robolectric/robolectric

item = item.setAlphabeticShortcut('a');
assertThat(item).isNotNull();
item = item.setCheckable(false);
assertThat(item).isNotNull();
item = item.setChecked(true);

代码示例来源:origin: stackoverflow.com

MenuItem item = drawer.getMenu().findItem(R.id.action_something);
item.setCheckable(true);
item.setChecked(true);

代码示例来源:origin: com.willowtreeapps/oak-demos

@Override
public MenuItem setCheckable(boolean checkable) {
  mNativeItem.setCheckable(checkable);
  return this;
}

代码示例来源:origin: com.actionbarsherlock/actionbarsherlock

@Override
public MenuItem setCheckable(boolean checkable) {
  mNativeItem.setCheckable(checkable);
  return this;
}

代码示例来源:origin: ywwynm/EverythingDone

private void checkDrawerItem(MenuItem menuItem) {
  menuItem.setCheckable(true);
  menuItem.setChecked(true);
  mPreviousItem.setChecked(false);
  mPreviousItem = menuItem;
}

代码示例来源:origin: materialos/android-icon-pack

public void addToMenu(Menu menu) {
    MenuItem item = menu.add(Menu.NONE, drawerId, Menu.NONE, titleRes);
    item.setIcon(iconRes);
    item.setCheckable(true);
  }
}

代码示例来源:origin: code-troopers/material-android-bootstrap

private void selectNewMenuItem(MenuItem menuItem) {
  mCurrentMenuItemChanged = true;
  menuItem.setCheckable(true);
  menuItem.setChecked(true);
  mNavigationView.getMenu().findItem(mCurrentMenuItem).setChecked(false);
  mCurrentMenuItem = menuItem.getItemId();
}

代码示例来源:origin: stackoverflow.com

@Override
  public boolean onNavigationItemSelected(MenuItem menuItem) {
  Menu m = navView.getMenu();
  for (int i=0;i<m.size();i++) {
    MenuItem mi = m.getItem(i);
    if (!(mi.getItemId() == menuItem.getItemId())) {
      mi.setCheckable(false);
    }
  }
  menuItem.setCheckable(true);
  menuItem.setChecked(true);
  return false;
}

代码示例来源:origin: code-troopers/material-android-bootstrap

private void setupDrawer() {
  mDrawer.setDrawerListener(this);
  mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, R.string.drawer_open, R.string.drawer_close);
  mDrawerToggle.syncState();
  mNavigationView.setNavigationItemSelectedListener(this);
  MenuItem firstItem = mNavigationView.getMenu().findItem(mCurrentMenuItem);
  firstItem.setCheckable(true);
  firstItem.setChecked(true);
  MenuItemUtil.setItemCounter(mNavigationView, R.id.nav_drawer_menu_1, 11);
}

代码示例来源:origin: clemensbartz/essential-launcher

/**
 * Add a menu item for the layout popup menu.
 * @param popupMenu the popup menu
 * @param widgetLayout the layout for the item
 * @param currentLayout the currently active item
 * @param resourceId the resource for the string
 */
private void addLayoutPopupMenuItem(final PopupMenu popupMenu, final int widgetLayout, final int currentLayout, final int resourceId) {
  final MenuItem menuItem = popupMenu.getMenu().add(0, widgetLayout, 0, resourceId);
  menuItem.setCheckable(true);
  menuItem.setChecked(currentLayout == widgetLayout);
}

代码示例来源:origin: smarek/Simple-Dilbert

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  menu.add(Menu.NONE, MENU_ACCEPT, Menu.NONE, R.string.folder_picker_select_this)
      .setIcon(R.drawable.ic_navigation_accept)
      .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
  menu.add(Menu.NONE, MENU_SHOW_HIDDEN, Menu.NONE, R.string.folder_picker_show_hidden).setCheckable(true);
  menu.add(Menu.NONE, MENU_SHOW_FILES, Menu.NONE, R.string.folder_picker_show_files).setCheckable(true);
  menu.add(Menu.NONE, MENU_GO_DEFAULT, Menu.NONE, R.string.folder_picker_go_to_default);
  super.onCreateOptionsMenu(menu, inflater);
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

@Override
public void setCurrentNavigationMenu(@NonNull NavigationMenu navigationMenu) {
  this.currentNavigationMenu = navigationMenu;
  Menu menu = navigationView.getMenu();
  if (menu != null) {
    for (int i = 0; i < menu.size(); i++) {
      MenuItem item = menu.getItem(i);
      item.setCheckable(navigationMenu.ordinal() == i);
      item.setChecked(navigationMenu.ordinal() == i);
    }
  }
}

代码示例来源:origin: qiubiteme/android_api_demos

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  menu.add(0, CLEAR_ID, 0, "Clear");
  menu.add(0, FADE_ID, 0, "Fade").setCheckable(true);
  return super.onCreateOptionsMenu(menu);
}

代码示例来源:origin: THEONE10211024/ApiDemos

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  menu.add(0, CLEAR_ID, 0, "Clear");
  menu.add(0, FADE_ID, 0, "Fade").setCheckable(true);
  return super.onCreateOptionsMenu(menu);
}

代码示例来源:origin: towavephone/MemoryCleaner

@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_ignore_setting, menu);
  SubMenu subMenu = menu.addSubMenu(GROUP_ID, BASE_ID, 0, "排序");
  subMenu.setIcon(R.drawable.ic_sort_white_24dp);
  subMenu.add(GROUP_ID + 1, BASE_ID + 1, 0, "应用名");
  subMenu.add(GROUP_ID + 1, BASE_ID + 2, 1, "选中");
  subMenu.add(GROUP_ID + 2, BASE_ID + 3, 2, "降序")
      .setCheckable(true)
      .setChecked(true);
  subMenu.setGroupCheckable(GROUP_ID + 1, true, true);
  mMenuItem = menu.findItem(R.id.allcheck);
  ActionItemBadge.update(this, mMenuItem, FontAwesome.Icon.faw_check,
      ActionItemBadge.BadgeStyles.DARK_GREY, 0);
  return true;
}

相关文章