导航到FAB单击上的片段(导航架构组件) [英] Navigate to fragment on FAB click (Navigation Architecture Components)
问题描述
我不知道如何使用新的导航体系结构组件从主屏幕(具有FloatingActionButton
附加到BottomAppBar
的主屏幕)导航到没有应用栏的另一个屏幕.
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.
当我单击晶圆厂时,我希望我的下一个屏幕(碎片?)从右侧滑入.问题是我将BottomAppBar
放在哪里?如果将其放在MainActivity
中,则会出现FloatingActionButton
没有设置NavController
的问题.我也无法将BottomAppBar
放入片段中.我很茫然.
When I click the fab I want my next screen (fragment?) to slide in from the right. The problem is where do I put my BottomAppBar
? If I put it in my MainActivity
then I have the issue of the FloatingActionButton
not having a NavController
set. I also cannot put my BottomAppBar
in my Fragment. I am at a loss.
推荐答案
今天遇到了这个问题,我发现有一个简单而优雅的解决方案.
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)
Navigation.setViewNavController(fabAdd, navController)
fabAdd.setOnClickListener {
navController.navigate(R.id.addSymbolFragment)
}
这将照顾导航.然后,您必须控制Activity
内部BottomAppBar
的可见性.
This takes care of the navigation. Then you must control the visibility of your BottomAppBar
inside your Activity
.
这篇关于导航到FAB单击上的片段(导航架构组件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!