private void setItem(MenuItem item) {
      item.setChecked(itemChecked)
          .setVisible(itemVisible)
          .setEnabled(itemEnabled)
          .setCheckable(itemCheckable >= 1)
          .setTitleCondensed(itemTitleCondensed)
          .setIcon(itemIconResId)
          .setAlphabeticShortcut(itemAlphabeticShortcut)
          .setNumericShortcut(itemNumericShortcut);

      if (itemShowAsAction >= 0) {
        item.setShowAsAction(itemShowAsAction);
      }

      if (itemListenerMethodName != null) {
        if (mContext.isRestricted()) {
          throw new IllegalStateException(
              "The android:onClick attribute cannot " + "be used within a restricted context");
        }
        item.setOnMenuItemClickListener(
            new InflatedOnMenuItemClickListener(mRealOwner, itemListenerMethodName));
      }

      if (itemCheckable >= 2) {
        if (item instanceof MenuItemImpl) {
          MenuItemImpl impl = (MenuItemImpl) item;
          impl.setExclusiveCheckable(true);
        } else {
          menu.setGroupCheckable(groupId, true, true);
        }
      }

      boolean actionViewSpecified = false;
      if (itemActionViewClassName != null) {
        View actionView =
            (View)
                newInstance(
                    itemActionViewClassName,
                    ACTION_VIEW_CONSTRUCTOR_SIGNATURE,
                    mActionViewConstructorArguments);
        item.setActionView(actionView);
        actionViewSpecified = true;
      }
      if (itemActionViewLayout > 0) {
        if (!actionViewSpecified) {
          item.setActionView(itemActionViewLayout);
          actionViewSpecified = true;
        } else {
          Log.w(
              LOG_TAG,
              "Ignoring attribute 'itemActionViewLayout'." + " Action view already specified.");
        }
      }
      if (itemActionProvider != null) {
        item.setActionProvider(itemActionProvider);
      }
    }
Пример #2
0
 void initMenuItem(MenuItem menuItem, BooleanPreference preference) {
   menuItem.setChecked(preference.get());
 }
Пример #3
0
 /** {@inheritDoc} */
 @Override
 public boolean onPrepareOptionsMenu(Menu menu) {
   mWordWrapAction.setChecked(this.mWordWrap);
   mSaveAction.setVisible(this.mDirty);
   return super.onPrepareOptionsMenu(menu);
 }