I am using the new Navigation component from Android Jetpack.
The root Activity setup is quite simple:
override fun onCreate(savedInstanceState: Bund
Until the issue will be fixed, simple listener is working to me:
/**
* Temporary solution to dynamically change title of actionbar controlled by Navigation component
* Should be removed as soon as the bug on Navigation will be fixed: (https://issuetracker.google.com/issues/80267266)
*/
interface TempToolbarTitleListener {
fun updateTitle(title: String)
}
class MainActivity : AppCompatActivity(), TempToolbarTitleListener {
...
override fun updateTitle(title: String) {
binding.toolbar.title = title
}
}
change title from fragment:
(activity as TempToolbarTitleListener).updateTitle("custom title")