应用程序的导航是通过
BottomNavigationView
fragment
,始终为空。
下面是我的片段管理的样子:
fun navigateTo(
context: Context,
fragment: BaseFragment,
navigatable: Navigatable,
addToBackStack: Boolean
) {
val activity = ContextUtil.getActivityFromContext(context)
val tag = fragment.javaClass.toString()
val fragmentManager = (activity as BaseActivity).supportFragmentManager
val transaction = fragmentManager.beginTransaction()
if (fragmentManager.findFragmentByTag(fragment.javaClass.toString()) == null) {
transaction.add(R.id.container, fragment, tag).hide(fragment)
}
val activeFragment = findVisibleFragment(context)
transaction
.apply {
if (activeFragment != null) {
hide(activeFragment)
}
}
.show(fragment)
.apply {
if (addToBackStack) {
this.addToBackStack(tag)
}
}
.commit()
navigatable.afterScreenTransition(fragment).invoke()
}
onAttach()
在我的房间里被叫来
pager fragment
,但所有视图都为空,
onCreateView()
没有打电话。