com.google.android.material.navigation.NavigationView.getMenu()方法的使用及代码示例

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

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

暂无

代码示例

代码示例来源:origin: ankidroid/Anki-Android

/** Sets selected navigation drawer item */
protected void selectNavigationItem(int itemId) {
  if (mNavigationView == null) {
    Timber.e("Could not select item in navigation drawer as NavigationView null");
    return;
  }
  Menu menu = mNavigationView.getMenu();
  if (itemId == -1) {
    for (int i = 0; i < menu.size(); i++) {
      menu.getItem(i).setChecked(false);
    }
  } else {
    MenuItem item = menu.findItem(itemId);
    if (item != null) {
      item.setChecked(true);
    } else {
      Timber.e("Could not find item %d", itemId);
    }
  }
}

代码示例来源:origin: ankidroid/Anki-Android

View actionLayout = mNavigationView.getMenu().findItem(R.id.nav_night_mode).getActionView();
mNightModeSwitch = actionLayout.findViewById(R.id.switch_compat);
mNightModeSwitch.setChecked(preferences.getBoolean("invertedColors", false));

代码示例来源:origin: iTXTech/Daedalus

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);
  menu = ((NavigationView) getActivity().findViewById(R.id.nav_view)).getMenu();
  toolbar = getActivity().findViewById(R.id.toolbar);
  toolbar.getMenu().clear();
  checkStatus();
}

代码示例来源:origin: offensive-security/nethunter-app

public static void setDrawerOptions() {
  Menu menuNav = navigationView.getMenu();
  if (prefs.getBoolean(CHROOT_INSTALLED_TAG, false)) {
    menuNav.setGroupEnabled(R.id.chrootDependentGroup, true);
  } else {
    menuNav.setGroupEnabled(R.id.chrootDependentGroup, false);
  }
}

代码示例来源:origin: cemrich/zapp

@Override
public void onPageSelected(int position) {
  MenuHelper.uncheckItems(navigationView.getMenu());
  searchView.clearFocus();
  switch (position) {
    case PAGE_MEDIATHEK_LIST:
      setTitle(R.string.activity_main_tab_mediathek);
      searchView.setVisibility(View.VISIBLE);
      navigationView.getMenu().findItem(R.id.menu_mediathek).setChecked(true);
      break;
    case PAGE_CHANNEL_LIST:
    default:
      setTitle(R.string.activity_main_tab_live);
      searchView.setVisibility(View.GONE);
      navigationView.getMenu().findItem(R.id.menu_live).setChecked(true);
      break;
  }
}

代码示例来源:origin: gotify/android

@Override
protected void onResume() {
  IntentFilter filter = new IntentFilter();
  filter.addAction(WebSocketService.NEW_MESSAGE_BROADCAST);
  registerReceiver(receiver, filter);
  new UpdateMissedMessages().execute(messages.getLastReceivedMessage());
  navigationView
      .getMenu()
      .findItem(appId == MessageState.ALL_MESSAGES ? R.id.nav_all_messages : appId)
      .setChecked(true);
  super.onResume();
}

代码示例来源:origin: martykan/webTube

bookmarkTitles = new ArrayList<>();
final Menu menu = navigationView.getMenu();
menu.clear();
String result = sp.getString("bookmarks", "[]");

代码示例来源:origin: pranavpandey/dynamic-support

/**
 * Set menu for the navigation view.
 *
 * @param menuRes The menu resource id for the navigation view.
 */
public void setNavigationViewMenu(@MenuRes int menuRes) {
  mNavigationView.getMenu().clear();
  mNavigationView.inflateMenu(menuRes);
}

代码示例来源:origin: offensive-security/nethunter-app

@Override
public void onBackPressed() {
  super.onBackPressed();
  if (titles.size() > 1) {
    titles.pop();
    mTitle = titles.peek();
  }
  Menu menuNav = navigationView.getMenu();
  int i = 0;
  int mSize = menuNav.size();
  while (i < mSize) {
    if (menuNav.getItem(i).getTitle() == mTitle) {
      MenuItem _current = menuNav.getItem(i);
      if (lastSelected != _current) {
        //remove last
        lastSelected.setChecked(false);
        // udpate for the next
        lastSelected = _current;
      }
      //set checked
      _current.setChecked(true);
      i = mSize;
    }
    i++;
  }
  restoreActionBar();
}

代码示例来源:origin: AlexMofer/ProjectX

if (savedInstanceState == null) {
  tag = TAG_WIDGETS;
  final MenuItem item = navigation.getMenu().findItem(R.id.main_nav_widgets);
  item.setChecked(true);
  setTitle(item.getTitle());
    default:
    case TAG_WIDGETS:
      item = navigation.getMenu().findItem(R.id.main_nav_widgets);
      break;
    case TAG_DRAWABLES:
      item = navigation.getMenu().findItem(R.id.main_nav_drawables);
      break;
    case TAG_OTHERS:
      item = navigation.getMenu().findItem(R.id.main_nav_others);
      break;
    case TAG_DEVELOP:
      item = navigation.getMenu().findItem(R.id.main_nav_develop);
      break;
  setTitle(item.getTitle());
final MenuItem develop = navigation.getMenu().findItem(R.id.main_nav_develop);
develop.setVisible(debug);
setFragment(tag);

代码示例来源:origin: KDE/kdeconnect-android

public void onDeviceSelected(String deviceId, boolean fromDeviceList) {
  mCurrentDevice = deviceId;
  preferences.edit().putString(STATE_SELECTED_DEVICE, deviceId).apply();
  if (mCurrentDevice != null) {
    mCurrentMenuEntry = deviceIdToMenuEntryId(deviceId);
    if (mCurrentMenuEntry == MENU_ENTRY_DEVICE_UNKNOWN) {
      uncheckAllMenuItems(mNavigationView.getMenu());
    } else {
      mNavigationView.setCheckedItem(mCurrentMenuEntry);
    }
    setContentFragment(DeviceFragment.newInstance(deviceId, fromDeviceList));
  } else {
    mCurrentMenuEntry = MENU_ENTRY_ADD_DEVICE;
    mNavigationView.setCheckedItem(mCurrentMenuEntry);
    setContentFragment(new PairingFragment());
  }
}

代码示例来源:origin: gotify/android

protected void onUpdateApps(List<Application> applications) {
  Menu menu = navigationView.getMenu();
  menu.removeGroup(R.id.apps);
  targetReferences.clear();
  updateMessagesAndStopLoading(messages.get(appId));
  for (Application app : applications) {
    MenuItem item = menu.add(R.id.apps, app.getId(), APPLICATION_ORDER, app.getName());
    item.setCheckable(true);
    Target t = Utils.toDrawable(getResources(), item::setIcon);
    targetReferences.add(t);
    picasso.load(app.getImage())
        .error(R.drawable.ic_alarm)
        .placeholder(R.drawable.ic_placeholder)
        .resize(100, 100)
        .into(t);
  }
}

代码示例来源:origin: morogoku/MTweaks-KernelAdiutorMOD

private void appendFragments(boolean setShortcuts) {
  mActualFragments.clear();
  Menu menu = mNavigationView.getMenu();
  menu.clear();
  SubMenu lastSubMenu = null;
  for (NavigationFragment navigationFragment : mFragments) {
    Class<? extends Fragment> fragmentClass = navigationFragment.mFragmentClass;
    int id = navigationFragment.mId;
    Drawable drawable = ContextCompat.getDrawable(this,
          AppSettings.isSectionIcons(this)
          && navigationFragment.mDrawable != 0 ? navigationFragment.mDrawable :
          R.drawable.ic_blank);
    if (fragmentClass == null) {
      lastSubMenu = menu.addSubMenu(id);
      mActualFragments.put(id, null);
    } else if (AppSettings.isFragmentEnabled(fragmentClass, this)) {
      MenuItem menuItem = lastSubMenu == null ? menu.add(0, id, 0, id) :
          lastSubMenu.add(0, id, 0, id);
      menuItem.setIcon(drawable);
      menuItem.setCheckable(true);
      if (mSelection != 0) {
        mNavigationView.setCheckedItem(mSelection);
      }
      mActualFragments.put(id, fragmentClass);
    }
  }
  if (setShortcuts) {
    setShortcuts();
  }
}

代码示例来源:origin: KDE/kdeconnect-android

private void updateDeviceList() {
  BackgroundService.RunCommand(MainActivity.this, service -> {
    Menu menu = mNavigationView.getMenu();
    menu.clear();
    mMapMenuToDeviceId.clear();
    SubMenu devicesMenu = menu.addSubMenu(R.string.devices);
    int id = MENU_ENTRY_DEVICE_FIRST_ID;
    Collection<Device> devices = service.getDevices().values();
    for (Device device : devices) {
      if (device.isReachable() && device.isPaired()) {
        MenuItem item = devicesMenu.add(Menu.FIRST, id++, 1, device.getName());
        item.setIcon(device.getIcon());
        item.setCheckable(true);
        mMapMenuToDeviceId.put(item, device.getDeviceId());
      }
    }
    MenuItem addDeviceItem = devicesMenu.add(Menu.FIRST, MENU_ENTRY_ADD_DEVICE, 1000, R.string.pair_new_device);
    addDeviceItem.setIcon(R.drawable.ic_action_content_add_circle_outline);
    addDeviceItem.setCheckable(true);
    MenuItem settingsItem = menu.add(Menu.FIRST, MENU_ENTRY_SETTINGS, 1000, R.string.settings);
    settingsItem.setIcon(R.drawable.ic_action_settings);
    settingsItem.setCheckable(true);
    //Ids might have changed
    if (mCurrentMenuEntry >= MENU_ENTRY_DEVICE_FIRST_ID) {
      mCurrentMenuEntry = deviceIdToMenuEntryId(mCurrentDevice);
    }
    mNavigationView.setCheckedItem(mCurrentMenuEntry);
  });
}

代码示例来源:origin: offensive-security/nethunter-app

titles.push(navigationView.getMenu().getItem(0).getTitle().toString());
  lastSelected = navigationView.getMenu().getItem(0);
  lastSelected.setChecked(true);

代码示例来源:origin: codeka/wwmmo

final MenuItem empireMenuItem = navigationView.getMenu().findItem(R.id.nav_empire);
App.i.getServer().waitForHello(() -> App.i.getTaskRunner().runTask(() -> {
 String url = ImageHelper.getEmpireImageUrl(activity, EmpireManager.i.getMyEmpire(), 48, 48);

相关文章