Question: I'm trying to set the toolbar title dynamically, I don't know if it's possible or not. 

Assume I have list of items every item I clicked it's open new fragment, thus I trying to change toolbar title for each item dynamically.

I tried :

```
it.findNavController().navigate(direction)
it.findNavController().currentDestination!!.label = someTitle

```

But it doesn't work.

There are some related topics i.e:

[How to set title in app bar with Navigation Architecture Component](https://stackoverflow.com/questions/52511136/how-to-set-title-in-app-bar-with-navigation-architecture-component)

But it doesn't solve my problem efficiently, It's a work-around.

Answer: 
Navigation supports arguments in labels as of [Navigation 1.0.0-alpha08](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0-alpha08) or higher:

> 
> Destination labels, when used with NavigationUI methods, will now automatically replace `{argName}` instances in your `android:label` with the correct argument [b/80267266](https://issuetracker.google.com/80267266)
> 
> 
> 

Therefore you can set your label to `android:label="{dynamicTitle}"`, then pass in an argument to your `navigate` call. As you're using Safe Args, you'd want to add an argument to your destination:

```
<fragment
    android:id="@+id/myFragment"
    android:name=".MyFragment"
    android:label="{dynamicTitle}">
  <argument
      android:name="dynamicTitle"
      app:argType="string"/>
</fragment>

```

Then pass in your dynamic title when constructing your directions:

```
val directions = YourDirections.actionToMyFragment(someTitle)
it.findNavController().navigate(directions)

```

Of course, you can [listen for navigation events](https://developer.android.com/guide/navigation/navigation-ui#listen_for_navigation_events) yourself and use your own `OnDestinationChangedListener` to do whatever you want, including setting the label to whatever you want. There's no requirement to use NavigationUI and any listener to add after calling the NavigationUI methods will override whatever it sets.
you can add a method for updating the fragment title and call it in fragment onStart() method

```
fun updateToolbarTitle(title: String) {
    supportActionBar?.title = title
}

```

and remove lable attribute from tag in your nav\_graph.xml
so it'll be like that

```
<fragment
    android:id="@+id/myFragment"
    android:name=".MyFragment"/>

```