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

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

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

暂无

代码示例

代码示例来源:origin: Flipboard/bottomsheet

public boolean isEnabled() {
  // Separators and subheaders never respond to click
  return menuItem != null && !menuItem.hasSubMenu() && menuItem.isEnabled();
}

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

public MenuItemAssert isDisabled() {
 isNotNull();
 assertThat(actual.isEnabled()) //
   .overridingErrorMessage("Expected to be disabled but was enabled.") //
   .isFalse();
 return this;
}

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

public MenuItemAssert isEnabled() {
 isNotNull();
 assertThat(actual.isEnabled()) //
   .overridingErrorMessage("Expected to be enabled but was disabled.") //
   .isTrue();
 return this;
}

代码示例来源:origin: ZieIony/Carbon

public static Menu getMenu(Context context, android.view.Menu baseMenu) {
  Context contextWrapper = CarbonContextWrapper.wrap(context);
  Menu menu = new Menu(contextWrapper);
  for (int i = 0; i < baseMenu.size(); i++) {
    android.view.MenuItem menuItem = baseMenu.getItem(i);
    menu.add(menuItem.getGroupId(), menuItem.getItemId(), menuItem.getOrder(), menuItem.getTitle()).setIcon(menuItem.getIcon()).setVisible(menuItem.isVisible()).setEnabled(menuItem.isEnabled());
  }
  return menu;
}

代码示例来源:origin: hidroh/materialistic

@Test
public void testSendFailed() {
  doSend();
  assertFalse(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_send).isEnabled());
  assertFalse(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_quote).isVisible());
  assertFalse(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_save_draft).isEnabled());
  assertFalse(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_discard_draft).isEnabled());
  replyCallback.getValue().onError(new IOException());
  assertTrue(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_send).isEnabled());
  assertTrue(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_quote).isVisible());
  assertTrue(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_save_draft).isEnabled());
  assertTrue(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_discard_draft).isEnabled());
  assertThat(activity).isNotFinishing();
  assertEquals(activity.getString(R.string.comment_failed), ShadowToast.getTextOfLatestToast());
}

代码示例来源:origin: mikepenz/MaterialDrawer

.withIcon(mMenuItem.getIcon())
      .withIdentifier(mMenuItem.getItemId())
      .withEnabled(mMenuItem.isEnabled())
      .withSelectable(false);
  getItemAdapter().add(iDrawerItem);
      .withIcon(mMenuItem.getIcon())
      .withIdentifier(mMenuItem.getItemId())
      .withEnabled(mMenuItem.isEnabled());
  getItemAdapter().add(iDrawerItem);
} else {
      .withIcon(mMenuItem.getIcon())
      .withIdentifier(mMenuItem.getItemId())
      .withEnabled(mMenuItem.isEnabled());
  getItemAdapter().add(iDrawerItem);

代码示例来源: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 isEnabled() {
  return mNativeItem.isEnabled();
}

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

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

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

public MenuItemAssert isEnabled() {
 isNotNull();
 assertThat(actual.isEnabled()) //
   .overridingErrorMessage("Expected to be enabled but was disabled.") //
   .isTrue();
 return this;
}

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

public MenuItemAssert isDisabled() {
 isNotNull();
 assertThat(actual.isEnabled()) //
   .overridingErrorMessage("Expected to be disabled but was enabled.") //
   .isFalse();
 return this;
}

代码示例来源:origin: AndroidHardening/PdfViewer

private static void enableDisableMenuItem(MenuItem item, boolean enable) {
  if (enable) {
    if (!item.isEnabled()) {
      item.setEnabled(true);
      item.getIcon().setAlpha(ALPHA_HIGH);
    }
  } else if (item.isEnabled()) {
    item.setEnabled(false);
    item.getIcon().setAlpha(ALPHA_LOW);
  }
}

代码示例来源:origin: mkulesh/microMathematics

/**
 * Procedure updates menu item color depends its enabled state
 */
public static void updateMenuIconColor(Context context, MenuItem m)
{
  CompatUtils.setDrawableColorAttr(context, m.getIcon(),
      m.isEnabled() ? R.attr.colorMicroMathIcon : R.attr.colorPrimaryDark);
}

代码示例来源:origin: vbier/habpanelviewer

@SuppressLint("ResourceType")
  public static void tintItemPreV21(MenuItem item, Context ctx, Resources.Theme theme) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
      TypedValue typedValue = new TypedValue();
      theme.resolveAttribute(android.R.attr.textColorPrimary, typedValue, true);

      try {
        int color = ContextCompat.getColor(ctx, typedValue.resourceId);
        ColorStateList csl = AppCompatResources.getColorStateList(ctx, typedValue.resourceId);
        if (csl != null) {
          color = csl.getColorForState(new int[] {item.isEnabled() ? android.R.attr.state_enabled : 0}, color);
        }

        Drawable icon = item.getIcon();
        if (icon != null) {
          icon.mutate();
          icon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
        }
      } catch (Resources.NotFoundException e) {
        Log.e(TAG, "Could not tint action bar icon on pre-lollipop device", e);
      }
    }
  }
}

代码示例来源:origin: openmrs/openmrs-contrib-android-client

private void toggleDownloadButton() {
    if (actionMode != null) {
      MenuItem item = actionMode.getMenu().findItem(R.id.action_download);
      if (item.isEnabled()) {
        enableDownload = false;
        item.setEnabled(false);
        item.getIcon().setAlpha(128);
      } else {
        enableDownload = true;
        item.setEnabled(true);
        item.getIcon().setAlpha(255);
      }
    }
  }
}

代码示例来源:origin: derry/delion

/**
 * Handles clicks on the AppMenu popup.
 * @param menuItem The menu item in the popup that was clicked.
 */
void onItemClick(MenuItem menuItem) {
  if (menuItem.isEnabled()) {
    if (menuItem.getItemId() == R.id.update_menu_id) {
      UpdateMenuItemHelper.getInstance().setMenuItemClicked();
    }
    dismiss();
    mHandler.onOptionsItemSelected(menuItem);
  }
}

代码示例来源:origin: vbier/habpanelviewer

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  int id = item.getItemId();
  if (id == R.id.action_clear_log) {
    adapter.clear();
    if (mClearItem != null && mClearItem.isEnabled()) {
      mClearItem.setEnabled(false);
      UiUtil.tintItemPreV21(mClearItem, getApplicationContext(), getTheme());
    }
    return true;
  }
  return super.onOptionsItemSelected(item);
}

代码示例来源:origin: derry/delion

private void setupStandardMenuItemViewHolder(StandardMenuItemViewHolder holder,
    View convertView, final MenuItem item) {
  // Set up the icon.
  Drawable icon = item.getIcon();
  holder.image.setImageDrawable(icon);
  holder.image.setVisibility(icon == null ? View.GONE : View.VISIBLE);
  holder.image.setChecked(item.isChecked());
  holder.text.setText(item.getTitle());
  holder.text.setContentDescription(item.getTitleCondensed());
  boolean isEnabled = item.isEnabled();
  // Set the text color (using a color state list).
  holder.text.setEnabled(isEnabled);
  // This will ensure that the item is not highlighted when selected.
  convertView.setEnabled(isEnabled);
  convertView.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
      mAppMenu.onItemClick(item);
    }
  });
}

代码示例来源:origin: ViHtarb/Tooltip

public void setMenuItem(@NonNull MenuItem menuItem) {
  if (mMenuItem != menuItem) {
    mMenuItem = menuItem;
    View actionView = menuItem.getActionView();
    if (actionView == null) {
      actionView = this;
      menuItem.setActionView(this);
    }
    if (actionView == this) {
      super.setEnabled(menuItem.isEnabled());
      setVisible(menuItem.isVisible());
      if (menuItem.getIcon() != null) {
        mImageView.setImageDrawable(menuItem.getIcon());
      } else if (menuItem.getTitle() != null) {
        mTextView.setText(menuItem.getTitle());
      }
    } // TODO else menuItem.actionView not equals
  }
}

代码示例来源:origin: derry/delion

private void setupImageButton(TintedImageButton button, final MenuItem item) {
  // Store and recover the level of image as button.setimageDrawable
  // resets drawable to default level.
  int currentLevel = item.getIcon().getLevel();
  button.setImageDrawable(item.getIcon());
  item.getIcon().setLevel(currentLevel);
  if (item.isChecked()) {
    button.setTint(ApiCompatibilityUtils.getColorStateList(
        button.getResources(), R.color.blue_mode_tint));
  }
  button.setEnabled(item.isEnabled());
  button.setFocusable(item.isEnabled());
  button.setContentDescription(item.getTitleCondensed());
  button.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
      mAppMenu.onItemClick(item);
    }
  });
}

相关文章