I am trying to bind toolbar to navigation controller, for that I am using the following code:
NavigationUI.setupWithNavController(toolbar, NavHostFragment.findNavController(nav_host))
and in the menu file, I provided the id of the fragment to which app should navigate like this:
<item
android:id="@+id/menuFragment"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
and I have a simple navigation graph file like this:
<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_graph"
app:startDestination="@id/homeFragment">
<fragment
android:id="@+id/homeFragment"
android:name="com.vapoyan.myapplication.HomeFragment"
android:label="fragment_home"
tools:layout="@layout/fragment_home" >
<action
android:id="@+id/action_homeFragment_to_menuFragment"
app:destination="@id/menuFragment" />
</fragment>
<fragment
android:id="@+id/menuFragment"
android:name="com.vapoyan.myapplication.MenuFragment"
android:label="fragment_menu"
tools:layout="@layout/fragment_menu" />
</navigation>
Does anyone have experience or can suggest how I can fix the issue and is toolbar supported by the navigation component?
Any example code or reference?