How to add animation transition to NavigationUI in android?

元气小坏坏 提交于 2021-02-11 07:19:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!