Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 646
Fori Avatar asked Feb 10 '20 23:02

Fori


1 Answers

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.

like image 127
Florian Walther Avatar answered Nov 13 '22 23:11

Florian Walther