- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
当 NavigationView
与 DrawLayout
和 ActionBar
一起使用时,jetpack
提供了一些强大的便捷方法来 Hook 一切都放在一起,以便这些项目更容易实现。
NavigationUi
库中提供的方法 setupActionBarWithNavController
是 Activity 的扩展方法,它添加一个汉堡包按钮来打开您的抽屉,如果您覆盖 onSupportNavigateUp: Boolean
方法调用 navigateUp(drawLayout:DrawLayout, navController:NavController)
方法,该方法会将汉堡包按钮更改为后退按钮并自动返回并带有精美的动画,这 super 酷。
不过这个方法好像是这样实现的:
public static boolean navigateUp(@Nullable DrawerLayout drawerLayout,
@NonNull NavController navController) {
if (drawerLayout != null && navController.getCurrentDestination().getId()
== navController.getGraph().getStartDestination()) {
drawerLayout.openDrawer(GravityCompat.START);
return true;
} else {
return navController.navigateUp();
}
}
如你所见,这个方法的基本逻辑是:
如果您不在导航图的起始目的地,则该按钮为后退按钮,否则为汉堡包按钮
这意味着只有起始目的地可以通过操作栏按钮打开绘图菜单,而所有其他目的地都有一个后退按钮,并且必须滑动才能打开绘图菜单。
为什么会这样?看来这是 android 团队有意识的设计决定。在多个目的地提供汉堡包按钮是否令人不悦?
我希望有几个主分支有汉堡菜单,所有从这些分支出来的屏幕都有一个后退按钮。有没有一种方法可以实现多个 NavGraphs
并将它们链接到一个 NavigationView
中?
你_你
最佳答案
我在 bug 109868820 中报告了在 fragment 内使用工具栏和 NavigationUI
助手时遇到的问题。 .
帮助我的 Googler 明确指出(第 7 篇文章):
[...] the discussions with the material design team has made it clear that the navigation drawer is a global navigation pattern that should be available everywhere
因此 Material 设计抽屉必须在每个屏幕上都可用,包括当导航按钮是“向上”箭头(而不是汉堡包)时更深的抽屉。在这种情况下,抽屉只能通过滑动手势使用,因为导航按钮在应用程序堆栈中向上导航。
确实(错误中的#4):
You'll still get the title set from the android:label in your navigation graph and proper behavior when it comes to the Up button (particularly important if you're using the DrawerLayout versions)
因此您在源代码中发现的行为确实是“正确的”行为。
因此:
换句话说,汉堡包按钮只能用于顶级目的地。
关于android - 为什么 android jetpack NavigationUI navigateUp 方法仅在您位于导航图的起始目的地时才打开绘图菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50414021/
在我的 Activity onCreate方法中,我使用以下方式将我的actionBar设置为显示并处理向上按钮上的点击: val navController = this.findNavContro
我在 Window 中使用 Frame 来显示内容,并使用 添加了导航 并且在 Window.xsml.cs FrameContent.Navigate(new HomeView()); 导航栏是这
我正在研究 Google 的 Sunflower 示例 Jetpack 应用程序 (https://github.com/googlesamples/android-sunflower)。 NavGr
我刚开始使用 Android NavigationUI 通过抽屉菜单实现 fragment 导航。虽然它确实有点像魔术,但我有一个主要问题。也就是说,我在菜单中有一个 logout 项,它不应导航到任
我有 Fragment,我想添加选项菜单。我尝试了很多,但没有找到任何解决方案。 这是我的代码。 package com.code2hack.milkledger.fragment import an
所以我有一个场景,其中我有 5 个 fragment 与底部导航相连。 1.首页 2.收件箱 3.搜索 4.通知 5.个人资料 所以我有另一个名为 (BarcodeDetail) 的 fragment
无法找到导致 null 异常问题的原因。按照指南制作项目,它没有这个问题。使用与 guidr 中相同的库版本。 错误信息 Attempt to invoke virtual method 'void
背景: (如果你不想知道我是怎么得到问题的,可以忽略。只是一些关于 Android Studio 模板 Activity 的问题)我一直在研究底部导航,并尝试从 Android Studio 默认创建
当 NavigationView 与 DrawLayout 和 ActionBar 一起使用时,jetpack 提供了一些强大的便捷方法来 Hook 一切都放在一起,以便这些项目更容易实现。 Navi
我已经通过 navigation_view.setupWithNavController(navController) 连接了我的菜单 xml 和 Android 导航组件,并且一切正常。我的菜单的一
我是一名优秀的程序员,十分优秀!