这是main activity的方法
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navView, navController);
这是跳转我用的方法
public void replaceFragment(Fragment newFragment){
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.nav_host_fragment,newFragment).commit();
}
https://blog.csdn.net/chw12341/article/details/77744416?utm_source=blogxgwz0