1. 显示首次的Fragment

  1. FragmentManager fragmentManager = new FragmentManager(this, R.id.frame);
  2. fragmentManager.replaceFragment(HomeFragment());

2. 切换Fragment (会摧毁与重建)

  1. FragmentManager fragmentManager = new FragmentManager(this, R.id.frame);
  2. fragmentManager.replaceFragment(HomeFragment());

3. 隐藏Fragment (不会摧毁, 不会调用生命周期)

  1. FragmentManager fragmentManager = new FragmentManager(this, R.id.frame);
  2. fragmentManager.changeFragment(HomeFragment());