我想根据条件更改开始导航片段。我的开始片段可能是一两个片段。有办法实现吗?
答案 0 :(得分:0)
Check out this question and it's solution
我还在答案下方添加了一条评论,以将其清除掉。
答案 1 :(得分:0)
Check out this question and its solution //在此还添加了Java代码
只需将Kotlin代码转换为Java
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.home_nav_fragment); // Hostfragment
NavInflater inflater = navHostFragment.getNavController().getNavInflater();
NavGraph graph = inflater.inflate(R.navigation.nav_main);
graph.setDefaultArguments(getIntent().getExtras());
graph.setStartDestination(R.id.fragment1);
navHostFragment.getNavController().setGraph(graph);
navHostFragment.getNavController().getGraph().setDefaultArguments(getIntent().getExtras());
NavigationView navigationView = findViewById(R.id.navigationView);
NavigationUI.setupWithNavController(navigationView, navHostFragment.getNavController());