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: 
In case you are passing a custom `Object` as parameter, you can use `navController.addOnDestinationChangedListener`.

```
navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {
    @Override
    public void onDestinationChanged(@NonNull NavController controller, @NonNull NavDestination destination, @Nullable Bundle arguments) {
        Log.i(TAG, "onDestinationChanged");
        switch (destination.getId()) {
            case R.id.mainFragment:
                updateToolbarAndBottomNavigation("Main Title", "Main Subtitle", View.VISIBLE);
                break;
            case R.id.shopFragment:
                updateToolbarAndBottomNavigation("custom title", null, View.VISIBLE);
                break;
            case R.id.shopcartFragment:
                StoreEntity store = (StoreEntity) arguments.get("storeEntity");
                Log.i(TAG, "onDestinationChanged: ShopCartFragment args: "+store.getName());
                updateToolbarAndBottomNavigation(store.getName(), null, View.GONE);
                break;
        }

    }
});

private void updateToolbarAndBottomNavigation(String title, String subtitle, int visibility) {
    getSupportActionBar().setTitle(title);
    getSupportActionBar().setSubtitle(subtitle);
    bottomNavigationView.setVisibility(visibility);
}

```

Where the `arguments.get()` was retrieved from `android:name` in the `nav_graph.xml`.

```
<fragment
        android:id="@+id/shopcartFragment"
        android:name="com.myapp.ShopcartFragment"
        tools:layout="@layout/fragment_shopcart" >
        <argument
            android:name="storeEntity" // GET ARGUMENTS NAME HERE
            app:argType="com.myapp.LocalDatabase.StoreEntity" />
    </fragment>

```

I hope it can help more people!
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"/>

```