android - 如何使用支持库 25.0.0 及更高版本的 getFragments()

标签 android android-fragments android-support-library

getFragments 方法在最新版本的支持库中被注释为@RestrictTo(LIBRARY_GROUP),这意味着它不供外部使用。 version history 中没有此更改的记录但对于早期版本,我可以在保留的 fragment 中使用此方法来获取对 UI fragment 的引用 - 并在配置更改后重新附加到新的 UI fragment (如 here 所示)。我如何使用新的支持库实现同样的目标?

最佳答案

最佳做法是通过 ID 或标签获取 fragment ,因为它们使用 ID 或标签附加到 Activity。

fragmentManager.findFragmentByTag("标签"); fragmentManager.findFragmentById(id);

关于android - 如何使用支持库 25.0.0 及更高版本的 getFragments(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41969694/

相关文章:

android - 如何在 phonegap/cordova 中运行 java 代码?

android - 在 android 中使用 animationSet() 动画

android - 如何在更改应用程序的主背景时保持 ActionBar 项目的背景不变?

android.app.Fragment$InstantiationException : Trying to instantiate a class ScannerFragment that is not a Fragment

android - BottomSheetDialogFragment 为深色主题设置了错误的背景颜色

findViewById 上的 android ClassCastException

Android ActionBarSherlock 选项卡、Android 2.3 或更低版本上的 NoClassDefFoundError

android - 在任何屏幕上通知用户用户未连接到互联网?

android - 如何从Android中的日历中提取日期?

安卓 RTL : Differences between Arabic and Hebrew languages support