Search code examples
androidandroid-fragmentsnavigationnavigation-drawerandroidx

NavHostFragment: Navigation icons at Toolbar not working (ie Menu, NavigationUp icons)


I am upgrading my app to support tablets. Currently implemented this to my project:

implementation "androidx.slidingpanelayout:slidingpanelayout:1.2.0-alpha03"

According to docs, to be able to apply dual pane, I need to use NavHostFragment.

However, got issues on my MainActivity's default NavHost.

The icons on my toolbar for navigation are working when I am using the code below

val navController = findNavController(R.id.nav_host_fragment_content_main)

But it started the icons to not working when I use NavHostFragment. See code below.

val navHostFragment = supportFragmentManager.findFragmentById(
        R.id.nav_host_fragment_content_main) as NavHostFragment
val navController = navHostFragment.navController

Any solution for this?


Solution

  • Already got the solution. The problem is on my activity's onOptionsItemSelected, it return's true.

    Fixed when I use return super.onOptionsItemSelected(item).