Fori
Fori

Reputation: 485

Android Navigation Component remove toolbar animation

how can i remove toolbar animation when I am using navigation component with toolbar like this:

NavigationUI.setupWithNavController(toolbar, findNavController(R.id.nav_host_fragment))

Inside each fragment i have custom menu (and setHasOptionsMenu(true)). On every fragment transaction made by findNavController().popBackstack() toolbar menu items has ugly transition animation. If i remove setupWithNavController, animation disappers, but i need it.

Upvotes: 10

Views: 1707

Answers (1)

Florian Walther
Florian Walther

Reputation: 6971

I figured out that you don't get these animations if you call Activity.setupActionBarWithNavController or NavigationUI.setupActionBarWithNavController instead of the Toolbar-specific function.

You also have to override onSupportNavigateUp to handle the up button if you use this approach:

override fun onSupportNavigateUp(): Boolean {
    return navController.navigateUp() || super.onSupportNavigateUp()
}

And if you use a Toolbar, don't forget to call setSupportActionBar(toolbar) to make the Toolbar your default ActionBar.

Upvotes: 8

Related Questions