用XML硬编码的片段无法替换。如果需要用另一个片段替换片段,则应该首先动态添加它们。
注意:
R.id.fragment_container是你在将片段带入的活动中选择的布局或容器。
// Create new fragment and transactionFragment newFragment = new ExampleFragment();FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();// Replace whatever is in the fragment_container view with this fragment,// and add the transaction to the back stack if neededtransaction.replace(R.id.fragment_container, newFragment);transaction.addToBackStack(null);// Commit the transactiontransaction.commit();



