【问题标题】:Navigation graph with multiple top level destinations in JavaJava中具有多个顶级目的地的导航图
【发布时间】:2020-11-09 09:57:46
【问题描述】:

在堆栈溢出的以下链接中提出的问题中,我正在关注具有多个顶级目的地的导航图的实现:Navigation graph with multiple top level destinations

根据第二个答案,首先创建了一组顶级目的地

val topLevelDestinations = setOf(R.id.garden_fragment,
        R.id.plant_list_fragment)
appBarConfiguration = AppBarConfiguration.Builder(topLevelDestinations)
        .setDrawerLayout(drawerLayout)
        .build()

我遇到的问题是代码在 Kotlin 中,我了解如何在 java 中实现以下部分代码


appBarConfiguration = AppBarConfiguration.Builder(topLevelDestinations)
        .setDrawerLayout(drawerLayout)
        .build()

问题是我不知道如何在java中实现第一部分代码,这个

val topLevelDestinations = setOf(R.id.garden_fragment,
        R.id.plant_list_fragment)

【问题讨论】:

    标签: navigation uinavigationcontroller navigation-drawer drawerlayout appbar


    【解决方案1】:

    使用简单的集合与您的顶级目的地

    navController = Navigation
                .findNavController(binding.navHostFragment);
        Set<Integer> topLevelDestinations = new HashSet<>();
        topLevelDestinations.add(R.id.garden_fragment);
        topLevelDestinations.add(R.id.plant_fragment);
        topLevelDestinations.add(R.id.settingsFragment);
        appBarConfiguration = new AppBarConfiguration.Builder(topLevelDestinations).build();
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-04
      • 1970-01-01
      相关资源
      最近更新 更多