【发布时间】:2019-11-22 11:37:50
【问题描述】:
我的场景就像我有一个包含(登录/注册片段)的 MainActivity。我有一个 HomeActivity(其中包含带有抽屉布局的导航视图。)
这两个活动都有各自的导航图。当我在 main_navigation_graph 中包含 home_navigation_graph 并导航到它时,DrawerLayout 不起作用。但是当我像没有嵌套一样单独执行时,只调用 home_navigation_graph(HomeActivity) 作为启动器,一切正常。 这是我的示例代码:
<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_login"
app:startDestination="@id/loginFragment">
<fragment
android:id="@+id/loginFragment"
android:name="com.example.app.ui.login.LoginFragment"
android:label="LoginFragment"
tools:layout="@layout/fragment_login">
<action
android:id="@+id/action_loginFragment_to_signupFragment"
app:destination="@id/signupFragment" />
<action
android:id="@+id/action_loginFragment_to_mobile_navigation"
app:destination="@id/mobile_navigation"
app:launchSingleTop="true"
app:popUpTo="@+id/nav_graph_login"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/signupFragment"
android:name="com.example.app.ui.signup.SignupFragment"
android:label="SignupFragment"
tools:layout="@layout/fragment_signup">
<action
android:id="@+id/action_signupFragment_to_loginFragment"
app:destination="@id/loginFragment"
app:launchSingleTop="true"
app:popUpTo="@id/signupFragment"
app:popUpToInclusive="true" />
</fragment>
<include app:graph="@navigation/mobile_navigation" />
</navigation>
当我在登录按钮单击时调用第二个移动导航图(使用下面的代码)时,HomeActivity 会打开,但只有 homeDestinationFragment 是可见的,其余什么都不起作用
findNavController().navigate(R.id.action_loginFragment_to_mobile_navigation)
下面的代码是 home_navigation_graph.xml
<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/mobile_navigation"
app:startDestination="@+id/nav_home">
<fragment
android:id="@+id/nav_home"
android:name="com.example.app.ui.home.HomeFragment"
android:label="@string/menu_home"
tools:layout="@layout/fragment_home" />
<fragment
android:id="@+id/nav_gallery"
android:name="com.example.app.ui.earnings.VendorEarningFragment"
android:label="@string/menu_vendor_earning"
tools:layout="@layout/fragment_vendor_earning" />
<fragment
android:id="@+id/nav_slideshow"
android:name="com.example.app.ui.slideshow.SlideshowFragment"
android:label="@string/menu_slideshow"
tools:layout="@layout/fragment_slideshow" />
<fragment
android:id="@+id/nav_tools"
android:name="com.example.app.ui.tools.ToolsFragment"
android:label="@string/menu_tools"
tools:layout="@layout/fragment_tools" />
<fragment
android:id="@+id/nav_share"
android:name="com.example.app.ui.share.ShareFragment"
android:label="@string/menu_share"
tools:layout="@layout/fragment_share" />
<fragment
android:id="@+id/nav_send"
android:name="com.example.app.ui.send.SendFragment"
android:label="@string/menu_send"
tools:layout="@layout/fragment_send" />
</navigation>
请让我知道我缺少什么。我被困在这几个星期了。
【问题讨论】:
标签: java android kotlin android-jetpack android-jetpack-navigation