I have no idea how to, using the new navigation architecture component, navigate from my main screen (with a FloatingActionButton attatched to a BottomAppBar) to another screen without the app bar.

当我点击晶圆厂时,我想要我的下一个屏幕(片段?)从右边滑进go .问题是我应该把我的BottomAppBar放在哪里?如果我把它放在我的MainActivity,那么我就有FloatingActionButton没有NavController的问题.我也不能把我的BottomAppBar放在我的碎片里.我不知所措.

推荐答案

Ran into this issue today and I found out that there is a simple and elegant solution for it.

val navController = findNavController(R.id.navHostFragment)

fabAdd.setOnClickListener {
   navController.navigate(R.id.yourFragment)
}  

This takes care of the navigation. Then you must control the visibility of your BottomAppBar inside your Activity.

Kotlin相关问答推荐

Android前台服务 list —Altbeacon

调用即发即忘方法--哪个作用域?

如何在Kotlin中为接受varargs的函数添加带有默认值的新参数?

如何优雅地声明一个StateFlow?

Webpack 配置未应用于 kotlin 多平台react 项目

Kotlin SIZE_BYTES

PRDownloader 即使在实现库后也无法工作.未知参考:Android Studio 中的 PRDownloader

如何在 Kotlin 中实现 Composition UML 关系?

使用 Kotlin 协程时 Room dao 类出错

Saripaar formvalidation 在 kotlin 中第二次不起作用

从列表中的每个对象中 Select 属性

Kotlin - 覆盖方法中的 IllegalArgumentException

变量后的Android问号

无法为 retrofit2.Call 调用无参数构造函数

Kotlin默认使用哪种排序?

哪里可以找到aapt2日志(log)?

如何使用kotlin中的反射查找包中的所有类

IllegalStateException:function = , count = 3, index = 3

在 Kotlin 中声明 Byte 会出现编译时错误The integer literal does not conform to the expected type Byte

在 IntelliJ Idea 中未为 Kotlin @ConfigurationProperties 类生成 spring-configuration-metadata.json 文件