(1) 创建待添加Fragment 的实例。
(2) 获取FragmentManager,在Activity 中可以直接调用getSupportFragmentManager()
方法获取。
(3) 开启一个事务 ,通过调用beginTransaction()方法开启。
(4) 向容器内添加或替换Fragment ,一般使用replace()方法实现,需要传入容器的id和待添加的Fragment 实例。
(5) 提交事务 ,调用commit()方法来完成。
kt
moPubListFragment = MoPubListFragment().also {
it.arguments = intent.extras
supportFragmentManager.beginTransaction()
.replace(
R.id.fragment_container,
it,
LIST_FRAGMENT_TAG
).commit()
}