Search code examples
androidandroid-fragmentsbottomnavigationviewandroid-jetpackandroid-bottomnav

Android Jetpack BottomNavigationView how to apply custom Fragment Transition


I want to add new fragment transition when BottomNavigationView change its current fragment. I want to enter the next fragment from left to right.

I don't see this for Jetpack BottomNavigationView to add custom fragment transition animations because there are no actions available for BottomNavigationView.


Solution

  • As per this issue:

    NavigationUI follows the material design guidelines, which specifically calls [see the 'Transitions' section] for a cross fade animation between BottomNavigationView items.

    Setting your own listener is indeed the correct approach if you want to deviate from the guidelines and what NavigationUI provides.

    Therefore you'll want to look at the NavigationUI source code for its onNavDestinationSelected() method and make your own version that passes in what custom animations you want, calling it from your own OnNavigationItemSelectedListener.