Android 导航组件子导航主机片段';视图未显示在父NavHost片段视图中

Android 导航组件子导航主机片段';视图未显示在父NavHost片段视图中,android,android-fragments,android-jetpack,android-architecture-navigation,Android,Android Fragments,Android Jetpack,Android Architecture Navigation,我正在从事一个有2个NavHost片段的项目。第一个/父NavHost片段附加到主活动XML文件,并根据父导航图显示登录片段和注册片段等目的地 现在,当用户登录时,新的Navhost片段或子Navhost片段,它附加到另一个XML文件并与另一个导航图或子Nav图关联 我面临的问题不是展示第二种观点,即;在与子NavHost片段xml文件关联的视图中,应用程序显示父NavHost片段中的子Nav图目标。 它完全忽略子NavHost片段文件的XML 主要活动XML <?xml version=

我正在从事一个有2个NavHost片段的项目。第一个/父NavHost片段附加到主活动XML文件,并根据父导航图显示登录片段和注册片段等目的地

现在,当用户登录时,新的Navhost片段或子Navhost片段,它附加到另一个XML文件并与另一个导航图或子Nav图关联

我面临的问题不是展示第二种观点,即;在与子NavHost片段xml文件关联的视图中,应用程序显示父NavHost片段中的子Nav图目标。 它完全忽略子NavHost片段文件的XML

主要活动XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_green_light">


    <fragment
        android:id="@+id/navHostFragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/nav_graph" />

</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_blue_light"
        android:layout_margin="24dp"
        android:padding="@dimen/dimen_24dp">

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/appbarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:translationZ="@dimen/dimen_1dp"
            app:elevation="@dimen/dimen_0dp">

            <include layout="@layout/toolbar" />

        </com.google.android.material.appbar.AppBarLayout>

        <fragment
            android:id="@+id/nestedNavHost"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            app:defaultNavHost="true"
            android:layout_height="wrap_content"
            app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
            app:navGraph="@navigation/restaurant_nav_graph" />
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/drawerNavView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_view_header"
        app:menu="@menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>

子片段容器XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_green_light">


    <fragment
        android:id="@+id/navHostFragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/nav_graph" />

</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_blue_light"
        android:layout_margin="24dp"
        android:padding="@dimen/dimen_24dp">

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/appbarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:translationZ="@dimen/dimen_1dp"
            app:elevation="@dimen/dimen_0dp">

            <include layout="@layout/toolbar" />

        </com.google.android.material.appbar.AppBarLayout>

        <fragment
            android:id="@+id/nestedNavHost"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            app:defaultNavHost="true"
            android:layout_height="wrap_content"
            app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
            app:navGraph="@navigation/restaurant_nav_graph" />
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/drawerNavView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_view_header"
        app:menu="@menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>

与上面的代码一样,子navhost xml文件中的工具栏、抽屉布局、填充等被完全忽略


请提供任何帮助以解决此问题。

这不是您应该如何按照和使用导航组件登录。问题不在于登录,而在于工具栏。登录后,工具栏需要根据某些片段进行操作。尝试在主活动xml文件中添加工具栏,但在使用不同片段以编程方式管理滚动标志和布局行为时出现问题。在某些片段中,工具栏需要透明。当工具栏透明时,“完整片段”将隐藏工具栏并在其上绘制。所以考虑过这样做。文档也包括。已经阅读了文档,观看了视频,做了codelabs项目,但与文档无关。这项工作与全屏幕布局、使用插图、根据某些片段处理状态栏颜色、管理滚动标志和布局行为、工具栏颜色等有一定的关系。试图找到解决方法。如果无法理解,将发布代码。谢谢如果您遵循文档,这些都不是问题。如果您在遵循文档中的方法时,对其中一项有特定问题,请在此处链接。