0

the first rectangle is a container where bottomNavigationView is placed. The second one is a place where menu fragments open, I used the second nav_graph to work with menu

The problem is that I can't open fragment from nested nav_graph on fullscreen

Here is the container fragment

<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 nested inside it

<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"/>
Temur Isroilov
  • 417
  • 7
  • 8
  • So you're trying to hide the your ImageViews at the top and BottomNavigationView when you're on a specific destination? Which specific destination? Your graph seems to only include your four items that are on the bottom nav. – ianhanniballake Jun 24 '21 at 00:19
  • You can mention the container Activity as Full Screen. https://stackoverflow.com/a/2868052/10239870 Manually add AppBarLayout in each Fragment inside the navigation component if you want. – Arunachalam k Jun 24 '21 at 06:17

1 Answers1

0

In order to navigate from nested graph to specific destination on the main graph, I used this approach

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

Temur Isroilov
  • 417
  • 7
  • 8