0

I'm trying to change my appbar title that is labeled in my navigation graph within my fragment

I receive a value from arguments as the title of that destination, but I try to change it and I cant

 override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

        Navigation.findNavController(requireActivity(),R.id.nav_host_fragment).addOnDestinationChangedListener { controller, destination, arguments ->
            when(destination.id){
                R.id.navigation_landing -> {
                    requireActivity().title = category!!.name
                }
            }
        }
}

I'm not using toolbar, I'm just using the label of the destination , is there anything wrong here ?

SNM
  • 5,625
  • 9
  • 28
  • 77

1 Answers1

0

Solved it by adding

<fragment
        android:id="@+id/navigation_landing"
        android:name="ui.landing.LandingFragment"
        android:label="{dynamicTitle}"
        tools:layout="@layout/landing_fragment" >
        <argument
            android:name="dynamicTitle"
            app:argType="string"/>

    </fragment>

and passing dynamicTitle as a bundle

 bundle.putString("dynamicTitle","MyawesomeTitle")
        findNavController().navigate(R.id.action_navigation_home_to_landingFragment,bundle)

Thanks to Ian, go give him thumbs up

SNM
  • 5,625
  • 9
  • 28
  • 77