//获取Frgment的管理者 FragmentManager fragmentManager = getSupportFragmentManager(); //获取事务 FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); //添加Fragment到FramLatyout中 //提交事务 fragmentTransaction.replace(R.id.home_root, new HomeFragment(), "HOME"); fragmentTransaction.replace(R.id.ment_root, new MenuFragment(), "MENU"); fragmentTransaction.commit();
//根据标示获取 MenuFragment menuFragment = (MenuFragment) fragmentManager.findFragmentByTag("MENU");