我有一个使用 AppCompatActivity 嵌套在另一个片段中的子片段的应用程序。子片段创建如下:
FragmentManager fragmentManager = getChildFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
SeriesFragment seriesFragment =SeriesFragment.newInstance();
fragmentTransaction.replace(container.getId(), seriesFragment);
fragmentTransaction.addToBackStack("seriesFragment");
fragmentTransaction.commit();
Activity 中的 onBackPressed 方法只有在显示子 Fragment 时才会触发。该应用程序只是退出而不是返回到上一个屏幕。不知道为什么。任何帮助是极大的赞赏。