Quantcast
Channel: Active questions tagged navigation - Stack Overflow
Viewing all articles
Browse latest Browse all 9839

Bottom navigation bar malfunctions when navigating from a fragment

$
0
0

I'm using the bottom navigation bar with the navigation component

To make the two components work together I called:

bottomNavigationView.setupWithNavController(navController)

Everything works as expected except when I navigate from inside a fragment instead of the bottom navigation bar

enter image description here

"View all" opens the same fragment as "Reports" from the bottom navigation bar

binding.viewAllScansTv.setOnClickListener {    val action = MainFragmentDirections.actionMainFragmentToReportsFragment()    navController.navigate(action)}

After clicking on "View all", the fragment is opened, the "Reports" button gets selected, however, navigating back "Home" does not work anymore

How can I fix this weird behavior?

The nav graph:

<navigation app:startDestination="@id/mainFragment"><fragment        android:id="@+id/mainFragment"        android:name="com.package.name.ui.main.MainFragment"        android:label="MainFragment"> <action                android:id="@+id/action_mainFragment_to_reportsFragment"            app:destination="@id/reportsFragment" /></fragment></navigation>

The bottom navigation menu:

<menu><item        android:id="@+id/mainFragment"        android:title="Home"/>    <item        android:id="@+id/reportsFragment"        android:title="Reports"/><item        android:id="@+id/settingsFragment"        android:title="My account"/></menu>

Viewing all articles
Browse latest Browse all 9839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>