android架构组件: What is the alternative to fragment container in android architecture navigation?

标签 android android-fragments android-architecture-components android-jetpack android-architecture-navigation

我想获得与这段代码相同的结果,因为我正在使用 android 导航组件,我应该用什么来代替 fragment 容器,因为只有 NavHostFragment。

val newFragment = ExampleFragment()
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.fragment_container, newFragment)
transaction.addToBackStack(null)
transaction.commit()

最佳答案

假设您的导航图中有一个目的地,如下所示:

<fragment
  android:id="@+id/example"
  android:name=".ExampleFragment"/>

您只需调用 navController.navigate(R.id.example),通过 the documentation 中描述的方法之一获取对您的 NavController 的引用.

关于android架构组件: What is the alternative to fragment container in android architecture navigation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53855834/

相关文章:

java - 停止 fragment 的函数和调用并重置内部变量

android - 如何在 Android ViewModel 中等待多个作业?

java - fragment 未在启动时显示

java - fragment 自行重新实例化并添加到 Activity 中

android - 如何在后台线程上执行 LiveData 转换?

带有 MVP 的 Android 架构组件

java - 在 TabLayout 中以编程方式切换选项卡

android - 在 React-Native 中找不到 RCTConvert.h 文件

java - YouTubePlayerSupportFragment 滚动回收器 View 后视频变黑,但音频继续播放

android - jetpack compose,我想要两个间隙来填充剩余空间,比例是一比二