问题
i'm using NavigationUI to tie destinations to menu items, but how to override the default animation transition?
Based on the doc https://developer.android.com/topic/libraries/architecture/navigation/navigation-ui#Tie-navdrawer, i cant find any method that can add the animation transition.
回答1:
NavigationUI does not offer that API. However, there's absolutely no requirement to use NavigationUI
- it is only optional helper methods.
Therefore you can copy / build a simplified version of what it actually does:
NavOptions navOptions = new NavOptions.Builder()
.setLaunchSingleTop(true) // Used to prevent multiple copies of the same destination
.setEnterAnim(R.anim.your_enter_anim)
.setExitAnim(R.anim.your_exit_anim)
.setPopEnterAnim(R.anim.your_pop_enter_anim)
.setPopExitAnim(R.anim.your_pop_exit_anim);
.build();
// Assuming you have a MenuItem named item
navController.navigate(item.getItemId(), null, options);
回答2:
This is an old thread but recently i encountered same problem . Here is the ideal solution to override default transition animations in NavigationUI
Click Here
来源:https://stackoverflow.com/questions/53699469/how-to-add-animation-transition-to-navigationui-in-android