Android:兩個Fragment在同一個Framelayout上切換顯示
阿新 • • 發佈:2019-01-31
private String[] TAGS = new String[]{"tag1", "tag2"};
private void showFragment(Fragment from, Fragment to, int position) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); boolean isAdded = to.isAdded(); if (!isAdded) { transaction.hide(from).add(R.id.layout_fragment, to, TAGS[position]).show(to).commitAllowingStateLoss(); } else { transaction.hide(from).show(to).commitAllowingStateLoss(); } }