android-architecture-navigation - Android navigation component- With Login screens
问题描述
When dealing with login screens, I am trying to work out the better approach - either execute navigation "action" to go to login fragment on first use (and hide back button to actual app), or start a new login activity (with its own nav graph). For the first approach (just using navigation components), I do not know the way to remove the back button without a hack "hide". I tried using navoptions, setpopupto etc., but it does not work. Code below:
val navOptions = NavOptions.Builder()
.setPopUpTo(R.id.home_fragment, true)
.build()
host?.navController?.navigate(R.id.action_global_signUpFragment_dest, null, navOptions)
Two questions then: 1) How to properly handle login transition with just navigation component? 2) Is starting a new login activity, with separate nav graph, a better idea?
解决方案
我认为第一种方法更好。要在 signUpFragment 内隐藏工具栏上的“后退”按钮,您可以使用 AppBarConfiguration,并自定义哪些目的地被视为顶级目的地。例如:
val appBarConfiguration = AppBarConfiguration.Builder(setOf(R.id.home_fragment, R.id.signUpFragment_dest)).build()
NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration)
这样 home_fragment 和 signUpFragment_dest 将被视为顶级目的地,并且工具栏上没有后退按钮。
推荐阅读
- python - Evenly divide a list of integers into a equal or larger list of integers with id's
- scala - 无法在 Scala 中编译和运行多个文件
- r - 如何解决此错误 - 缺少 $ 插入?
- mfc - MFC 对话框 - 如何调整和重新设置客户端“视图”矩形?
- stored-procedures - 存储过程未得到遵守
- javascript - 检查元素是否不包含 JavaScript 中的某个类
- python - 如何从 xlsx 导入列 > 创建 Json 数组 > 更新 SQLite DB
- javascript - 页面加载后 iframe 允许属性
- parallel-processing - 错误 - 分段错误 - 权限无效
- javascript - 页面刷新后初始化视差位置值