[英]Is it possible to move the screen without connecting in nav_graph?
I am using BottomNavigation.我正在使用底部导航。 The transition from the screen of menu A to another screen, not the screen transition from menu A to another, is as follows.
从菜单 A 的屏幕到另一个屏幕的转换,而不是从菜单 A 到另一个屏幕的转换,如下所示。
menu A(fragment) -> B screen(fragment) -> C screen(fragment) -> B screen(fragment)菜单 A(片段) -> B 画面(片段) -> C 画面(片段) -> B 画面(片段)
I hooked up these screen transitions in nav_graph
我在
nav_graph
连接了这些屏幕转换
I am using BottomNavigation
.我正在使用
BottomNavigation
。 The transition from the screen of menu A
to another screen, not the screen transition from menu A to another, is as follows.从
menu A
的屏幕到另一个屏幕的转换,而不是从菜单 A 到另一个屏幕的转换,如下所示。
menu A(fragment) -> B screen(fragment) -> C screen(fragment) -> D screen(fragment)菜单 A(片段) -> B 画面(片段) -> C 画面(片段) -> D 画面(片段)
I hooked up these screen transitions in nav_graph
我在
nav_graph
连接了这些屏幕转换
However, the screen transition from D
to C
was not connected, but it was possible to switch the screen using view.findNavController.navigate()
.但是,从
D
到C
的屏幕转换没有连接,但可以使用view.findNavController.navigate()
切换屏幕。
I thought transitioning the screen was impossible without connecting to the nav_graph
.我认为在不连接到
nav_graph
情况下转换屏幕是不可能的。
How is this possible?这怎么可能?
UPDATED更新
nav_graph.xml导航图.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@id/calendar">
<fragment
android:id="@+id/calendar"
android:name="com.example.writeweight.fragment.CalendarFragment"
android:label="fragment_calendar"
tools:layout="@layout/fragment_calendar" >
</fragment>
<fragment
android:id="@+id/list"
android:name="com.example.writeweight.fragment.WorkoutListFragment"
android:label="fragment_workout_list"
tools:layout="@layout/fragment_workout_list" />
<!-- menu A fragment -->
<fragment
android:id="@+id/write_home"
android:name="com.example.writeweight.fragment.WriteRoutineHomeFragment"
android:label="fragment_write_routine_home"
tools:layout="@layout/fragment_write_routine_home" >
<action
android:id="@+id/action_write_home_to_bodyPartDialog"
app:destination="@id/bodyPartDialog" />
</fragment>
<!-- B screen -->
<dialog
android:id="@+id/bodyPartDialog"
android:name="com.example.writeweight.fragment.BodyPartDialogFragment"
android:label="BodyPartDialogFragment"
tools:layout="@layout/fragment_body_part_dialog">
<action
android:id="@+id/action_bodyPartDialog_to_write"
app:destination="@id/write"/>
</dialog>
<!-- C screen -->
<fragment
android:id="@+id/write"
android:name="com.example.writeweight.fragment.WritingRoutineFragment"
android:label="WritingRoutineFragment"
tools:layout="@layout/fragment_writing_routine">
<action
android:id="@+id/action_write_to_bodyPartDialog"
app:destination="@id/bodyPartDialog" />
<argument
android:name="title"
app:argType="string"
android:defaultValue="" />
</fragment>
<!-- D screen -->
<fragment
android:id="@+id/workoutListTabFragment"
android:name="com.example.writeweight.fragment.WorkoutListTabFragment"
android:label="fragment_workout_list_tab"
tools:layout="@layout/fragment_workout_list_tab" />
</navigation>
As per the Navigate using ID documentation :根据使用 ID 文档导航:
navigate(int) takes the resource ID of either an action or a destination.
navigate(int)获取操作或目标的资源 ID。
So both directly navigating to any destination is possible (by using the ID of the destination) and navigating via an action is supported.因此,可以直接导航到任何目的地(通过使用目的地的 ID)并支持通过操作进行导航。
The documentation goes on to say:文档继续说:
Note: When navigating using IDs, we strongly recommend using actions where possible.
注意:使用 ID 导航时,我们强烈建议尽可能使用操作。 Actions provide additional information in your navigation graph, visually showing how your destinations connect to each other.
操作在您的导航图中提供额外信息,直观地显示您的目的地如何相互连接。 By creating actions, you can replace resource IDs with Safe Args-generated operations , providing additional compile-time safety.
通过创建操作,您可以使用Safe Args 生成的操作替换资源 ID,从而提供额外的编译时安全性。 By using an action, you can also animate transitions between the destinations.
通过使用动作,您还可以为目标之间的过渡设置动画。 For more information, see Animate transitions between destinations .
有关更多信息,请参阅为目标之间的过渡设置动画。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.