MichaelThePotato
MichaelThePotato

Reputation: 1525

Using Jetpack's Navigation between screens with different toolbars

I want to migrate my multiple activities app to single activity/multiple fragments architecture and implement Jetpack's Navigation component, but I ran into a problem.

I have several activities with a visually identical toolbar, Some have different menu items/titles/logo but all those can be changed per fragment (note - this is a regular non-collapsing toolbar) so no problem yet.

However, I have an activity with a collapsing toolbar, and I just can't figure out how to integrate it into the graph.

Currently, my "single" activity contains the toolbar and each fragment can update its menu items and title as they see fit, but having a different toolbar seems to be forcing me to set it at a separate activity.

Is there a way to still integrate it into the graph? or is having a collapsing toolbar instead of regular toolbar forcing another activity?

Upvotes: 0

Views: 447

Answers (1)

Hussnain Haidar
Hussnain Haidar

Reputation: 2258

You can hide toolbar of your only activity by calling in your collapsing toolbar implemented fragment.

  override fun onStart() {
    super.onStart()
    (activity as MainActivity).supportActionBar?.hide()
}

override fun onStop() {
    super.onStop()
    (activity as MainActivity).supportActionBar?.show()
}

And implement collapsing toolbar in your desired fragment layout. Maybe there's any better solution for that but for me it's working fine and i don't need to create another activity for that.

Upvotes: 1

Related Questions