Common fragments lead app not select bottom nav icon

Viewed 14

I have a bottom nav bar with 5 tabs, each tab has its own graph and all are collected in home nav_graph in details: host_nav_graph has

  • Home Nav graph & all common fragments like ( product details or product listing )
  • include for Nav graph 1 ( Search )
  • include for Nav graph 2
  • include for Nav graph 3
  • include for Nav graph 4

I have the default mechanism for multi-back stack and everything is working perfectly except when I go to Nav graph 2 ( Search ) and select a product from the results to show product details once I selected a fragment from the common fragments ( product details ) and tried to select the home tab again it's not get selected till I click back multiple times till I go to home screen it gets selected.

FYI: when I select the home tab it shows me the back stack for the home tab as expected but no get selected

here's my host activity FragmentContainerView:

            <androidx.fragment.app.FragmentContainerView
            android:id="@+id/nav_host_host"
            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_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/homePageTitle"
            app:navGraph="@navigation/nav_graph_host" />

Bottom nav XML:

            <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottom_nav"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:elevation="@dimen/elevation"
            app:itemIconTint="@drawable/bottom_navigation_colors"
            app:itemTextAppearanceActive="@style/Widget.BottomNavigationView"
            app:itemTextAppearanceInactive="@style/Widget.BottomNavigationView"
            app:itemTextColor="@drawable/bottom_navigation_colors"
            app:labelVisibilityMode="labeled"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:menu="@menu/menu_bottom_nav" />

Fragment Container Nav Graph:

<?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/navigation_host"
app:startDestination="@id/navigation_home">

<!--  home  -->
<fragment
    android:id="@+id/navigation_home"
    android:name="HomeFragemnt"
    android:label=""
    tools:layout="@layout/fragment_home" />

<!--  product details  -->
<fragment
    android:id="@+id/dest_product_details"
    android:name="ProductDetailsFragment"
    android:label=""
    tools:layout="@layout/fragment_new_product_details" />

<!--  wishlist  -->
<fragment
    android:id="@+id/dest_wishList"
    android:name="WishListFragment"
    android:label="@string/label_wishlist"
    tools:layout="@layout/fragment_wish_list" />
<!--Product listing-->
<fragment
    android:id="@+id/dest_store"
    android:name="StoreFragment"
    android:label=""
    tools:layout="@layout/fragment_store" />

<include app:graph="@navigation/nav_graph_1_search" />
<include app:graph="@navigation/nav_graph_2" />
<include app:graph="@navigation/nav_graph_3" />
<include app:graph="@navigation/nav_graph_4" />
</navigation>
0 Answers
Related