导航到FAB单击上的片段(导航架构组件) [英] Navigate to fragment on FAB click (Navigation Architecture Components)

查看:78
本文介绍了导航到FAB单击上的片段(导航架构组件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何使用新的导航体系结构组件从主屏幕(具有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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆