从嵌套的nav_graph导航到主nav_ggraph中的特定片段以在全屏上打开它



第一个矩形是放置bottomNavigationView的容器。第二个是打开菜单片段的地方,我使用了第二个nav_graph来处理菜单

问题是我无法在全屏上打开嵌套nav_graph中的片段

这是集装箱碎片

<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/common_bg"
tools:context=".ui.news.NavigationContainerFragment">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:src="@drawable/ic_logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/iv_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:src="@drawable/ic_settings"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<fragment
android:id="@+id/bottom_nav_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/bottom_nav"
app:layout_constraintTop_toBottomOf="@id/iv_settings"
app:navGraph="@navigation/nav_view_graph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bottom_nab_bg"
app:itemBackground="@drawable/nav_item_drawable"
app:itemIconTint="@color/bottom_nav_colors"
app:itemTextColor="@color/bottom_nav_colors"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/menu" />

<androidx.constraintlayout.widget.constraintlayout>

嵌套在中的Nav_graph

<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_view_graph"
app:startDestination="@id/newsListFragment">
<fragment
android:id="@+id/newsListFragment"
tools:layout="@layout/fragment_news_list"
android:name="com.winlineapp.ui.news.NewsListFragment"
android:label="NewsListFragment" />
<fragment
android:id="@+id/tableFragment"
android:name="com.winlineapp.ui.TableFragment"
android:label="fragment_calendar"
tools:layout="@layout/fragment_table" />
<fragment
android:id="@+id/calendarFragment"
android:name="com.winlineapp.ui.CalendarFragment"
android:label="fragment_calendar"
tools:layout="@layout/fragment_calendar" />
<fragment
android:id="@+id/statisticsFragment"
android:name="com.winlineapp.ui.StatisticsFragment"
android:label="fragment_statistics"
tools:layout="@layout/fragment_statistics" />

menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@id/newsListFragment"
android:icon="@drawable/ic_feed"
android:checked="true"
android:title="Feed"/>
<item android:id="@id/tableFragment"
android:icon="@drawable/ic_table"
android:title="Table"/>
<item android:id="@id/calendarFragment"
android:icon="@drawable/ic_calendar"
android:title="Calendar"/>
<item android:id="@id/statisticsFragment"
android:icon="@drawable/ic_statistics"
android:title="Statistics"/>

为了从嵌套图导航到主图上的特定目的地,我使用了这种方法

((parentFragment as NavHostFragment).parentFragment as {FragmentFromWhichYouNavigating}).findNavController() .navigate(R.id.newsFirstFragment)

最新更新