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

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

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

暂无

代码示例

代码示例来源:origin: cbeyls/fosdem-companion-android

@Override
protected void onSaveInstanceState(Bundle outState) {
  // Ensure no fragment transaction attempt will occur after onSaveInstanceState()
  if (pendingNavigationMenuItem != null) {
    pendingNavigationMenuItem = null;
    if (currentSection != null) {
      navigationView.setCheckedItem(currentSection.getMenuItemId());
    }
  }
  super.onSaveInstanceState(outState);
}

代码示例来源: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: 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: morogoku/MTweaks-KernelAdiutorMOD

private void onItemSelected(final int res, boolean saveOpened) {
  mDrawer.closeDrawer(GravityCompat.START);
  getSupportActionBar().setTitle(getString(res));
  mNavigationView.setCheckedItem(res);
  mSelection = res;
  final Fragment fragment = getFragment(res);
  if (saveOpened) {
    AppSettings.saveFragmentOpened(fragment.getClass(),
        AppSettings.getFragmentOpened(fragment.getClass(), this) + 1,
        this);
  }
  setShortcuts();
  mDrawer.postDelayed(()
          -> {
        Log.crashlyticsI("open " + fragment.getClass().getSimpleName());
        getSupportFragmentManager().beginTransaction().replace(
            R.id.content_frame, fragment, res + "_key").commitAllowingStateLoss();
      },
      250);
}

代码示例来源: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: oliexdev/openScale

navDrawer.setCheckedItem(menuItemId);

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

mNavigationView.setCheckedItem(savedMenuEntry);

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

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);
  if (isSupportActionBar()) {
    ((AppCompatActivity) getActivity())
        .getSupportActionBar().setTitle(getTitle());
    ((AppCompatActivity) getActivity())
        .getSupportActionBar().setSubtitle(getSubtitle());
  }
  if (setNavigationViewCheckedItem()
      != DynamicResourceUtils.ADS_DEFAULT_RESOURCE_ID
      && getActivity() instanceof DynamicDrawerActivity) {
    ((DynamicDrawerActivity) getActivity()).getNavigationView()
        .setCheckedItem(setNavigationViewCheckedItem());
  }
}

代码示例来源:origin: gateship-one/odyssey

if (navigationView != null) {
  navigationView.setNavigationItemSelectedListener(this);
  navigationView.setCheckedItem(navId);

代码示例来源:origin: cbeyls/fosdem-companion-android

navigationView.setCheckedItem(currentSection.getMenuItemId());

相关文章