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

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

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

暂无

代码示例

代码示例来源:origin: square/assertj-android

public MenuItemAssert isCheckable() {
 isNotNull();
 assertThat(actual.isCheckable()) //
   .overridingErrorMessage("Expected to be checkable but was not checkable.") //
   .isTrue();
 return this;
}

代码示例来源:origin: square/assertj-android

public MenuItemAssert isNotCheckable() {
 isNotNull();
 assertThat(actual.isCheckable()) //
   .overridingErrorMessage("Expected to not be checkable but was checkable.") //
   .isFalse();
 return this;
}

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

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

代码示例来源:origin: willowtreeapps/Hyperion-Android

public static Collection<ViewAttribute> createMenuAttributes(@NonNull Context context, @NonNull Menu menu) {
  final Resources res = context.getResources();
  List<ViewAttribute> attributes = new ArrayList<>();
  attributes.add(new ViewAttribute<>("MenuSize", menu.size()));
  attributes.add(new ViewAttribute<>("MenuHasVisibleItems", menu.hasVisibleItems()));
  for (int i = 0; i < menu.size(); i++) {
    MenuItem item = menu.getItem(i);
    String prefix = "Item " + i + ": ";
    attributes.add(new ViewAttribute<>(prefix + "Title", item.getTitle()));
    attributes.add(new ViewAttribute<>(prefix + "ContentDescription",
        MenuItemCompat.getContentDescription(item)));
    attributes.add(new ViewAttribute<>(prefix + "TooltipText", MenuItemCompat.getTooltipText(item)));
    attributes.add(new ViewAttribute<>(prefix + "Checkable", item.isCheckable()));
    attributes.add(new ViewAttribute<>(prefix + "Checked", item.isChecked()));
    attributes.add(new ViewAttribute<>(prefix + "Enabled", item.isEnabled()));
    attributes.add(new ViewAttribute<>(prefix + "Visible", item.isVisible()));
    attributes.add(new ViewAttribute<>(prefix + "Order", item.getOrder()));
    attributes.add(new ViewAttribute<Void>(prefix + "Icon", item.getIcon()));
    attributes.add(createColorAttribute("IconTint",
        MenuItemCompat.getIconTintList(item)));
    attributes.add(new ViewAttribute<>("IconTintMode",
        new PorterDuffModeValue(MenuItemCompat.getIconTintMode(item))));
    attributes.add(new ViewAttribute<>(prefix + "Id", new ResourceValue(res, item.getItemId())));
    attributes.add(new ViewAttribute<>(prefix + "GroupId", new ResourceValue(res, item.getGroupId())));
  }
  return attributes;
}

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

@Override
public boolean isCheckable() {
  return mNativeItem.isCheckable();
}

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

@Override
public boolean isCheckable() {
  return mNativeItem.isCheckable();
}

代码示例来源:origin: com.squareup.assertj/assertj-android

public MenuItemAssert isCheckable() {
 isNotNull();
 assertThat(actual.isCheckable()) //
   .overridingErrorMessage("Expected to be checkable but was not checkable.") //
   .isTrue();
 return this;
}

代码示例来源:origin: com.squareup.assertj/assertj-android

public MenuItemAssert isNotCheckable() {
 isNotNull();
 assertThat(actual.isCheckable()) //
   .overridingErrorMessage("Expected to not be checkable but was checkable.") //
   .isFalse();
 return this;
}

代码示例来源:origin: tupunco/tup.dota2recipe

/**
 * 
 * @param menu
 * @param isRecipe
 *            物品页面,当前物品是否是合成卷轴
 */
public static void configureStarredMenuItem(MenuItem menu, boolean isRecipe) {
  if (menu == null || !menu.isCheckable()) {
    return;
  }
  if (isRecipe) {
    menu.setVisible(false);
    return;
  }
  if (menu.isChecked()) {
    menu.setIcon(R.drawable.ic_action_favorite);
    menu.setTitle(R.string.menu_removefavorite);
  } else {
    menu.setIcon(R.drawable.ic_action_favorite2);
    menu.setTitle(R.string.menu_addfavorite);
  }
}

代码示例来源:origin: jruesga/rview

private boolean performSelectItem(int itemId, boolean force) {
  final Menu menu = mBinding.drawerNavigationView.getMenu();
  final MenuItem item = menu.findItem(itemId);
  if (item != null) {
    if (item.isCheckable()) {
      boolean changed = itemId != mModel.currentNavigationItemId;
      mBinding.drawerNavigationView.setCheckedItem(item.getItemId());
      mModel.currentNavigationItemId = itemId;
      return force || changed;
    } else {
      performNavigationAction(item);
    }
  }
  return false;
}

代码示例来源:origin: yayaa/Rotatable

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
  for (int i = 0; i < menu.size(); i++) {
    MenuItem item = menu.getItem(i);
    if (item.isCheckable()) {
      if (item.getItemId() == R.id.action_touch) {
        item.setTitle(isTouchEnabled() ? R.string.action_touch_enabled : R.string.action_touch_disabled);
        item.setChecked(isTouchEnabled());
      } else {
        item.setChecked(item.getItemId() == selectedRotationId);
      }
    }
  }
  return super.onPrepareOptionsMenu(menu);
}

代码示例来源:origin: Michenux/YourAppIdea

/**
 * Select a item in the menu
 *
 * @param menuItemId menu item id
 * @param deferred   wait for drawer to close, then select item.
 */
public void selectItem(@IdRes int menuItemId, boolean deferred) {
  MenuItem menuItem = mNavigationView.getMenu().findItem(menuItemId);
  if (menuItem.isCheckable()) {
    mNavigationView.setCheckedItem(menuItemId);
  }
  if (deferred) {
    this.mSelectItemOnClosed = menuItemId;
  } else {
    onNavItemSelected(menuItemId);
  }
  if (mNavConf.updateTitleWhenMenuItemClick(menuItemId)) {
    setTitle(menuItem.getTitle());
  }
  if (mNavConf.closeDrawerWhenMenuItemClick(menuItemId) && this.mDrawerLayoutView.isDrawerOpen(GravityCompat.START)) {
    mDrawerLayoutView.closeDrawer(GravityCompat.START);
  }
}

代码示例来源:origin: sjvc/Home-Assistant-Launcher

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  if (item.isCheckable()){
    item.setChecked(!item.isChecked());
  }
  switch (item.getItemId()) {
    case R.id.menu_lock_screen:
      Preferences.setUseLockScreen(item.isChecked());
      break;
    case R.id.menu_back_key_behavior:
      Preferences.setAdjustBackKeyBehavior(item.isChecked());
      mWebView.setAdjustBackKeyBehavior(Preferences.getAdjustBackKeyBehavior());
      break;
    case R.id.menu_hide_admin_menu_items:
      Preferences.setHideAdminMenuItems(item.isChecked());
      mWebView.setHideAdminMenuItems(Preferences.getHideAdminMenuItems());
      break;
    case R.id.menu_hide_top_bar:
      askHidingTopBar();
      break;
  }
  Preferences.save(this);
  return true;
}

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

@Test
public void testGetCurrentMenuItem() {
  // setup
  MenuItem expected = getMenuItem(NavigationMenu.ACCESS_POINTS);
  // execute
  MenuItem actual = fixture.getCurrentMenuItem();
  // validate
  assertEquals(expected, actual);
  assertTrue(actual.isCheckable());
  assertTrue(actual.isChecked());
}

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

@Test
public void testSetCurrentNavigationMenu() {
  // setup
  NavigationMenu expected = NavigationMenu.CHANNEL_GRAPH;
  // execute
  fixture.setCurrentNavigationMenu(expected);
  // validate
  assertEquals(expected, fixture.getCurrentNavigationMenu());
  assertTrue(getMenuItem(NavigationMenu.CHANNEL_GRAPH).isCheckable());
  assertTrue(getMenuItem(NavigationMenu.CHANNEL_GRAPH).isChecked());
  assertFalse(getMenuItem(NavigationMenu.ACCESS_POINTS).isCheckable());
  assertFalse(getMenuItem(NavigationMenu.ACCESS_POINTS).isChecked());
}

相关文章