本文介绍了如何在Android中的NavigationUI中添加动画过渡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NavigationUI将目标绑定到菜单项,但是如何覆盖默认的动画过渡?

i'm using NavigationUI to tie destinations to menu items, but how to override the default animation transition?

基于文档 https://developer.android.com/topic/libraries/architecture/navigation/navigation-ui#Tie-navdrawer ,我找不到任何可以添加动画过渡的方法.

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.

推荐答案

NavigationUI不提供该API.但是,绝对不需要使用 NavigationUI -它只是可选的辅助方法.

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);

这篇关于如何在Android中的NavigationUI中添加动画过渡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 21:06