9

I'm using the Android Navigation component with SafeArgs, and I want to add a shared element transition to an action. According to the documentation, I should be able to simply add an Extras object as a parameter to navigate(), so I try that:

FragmentNavigator.Extras extras = new FragmentNavigator.Extras.Builder()
                .addSharedElement(view, "group_transition")
                .build();
NavDirections action = HomeFragmentDirections.actionHomeFragmentToViewFragment(title);
Navigation.findNavController(view).navigate(action, extras);

but Android Studio gives an error, and says it can't resolve the method. I try to use

.navigate(int resId, Bundle args, NavOptions navOptions, Navigator.Extras navigatorExtras)

which narrows the problem down to the Navigator.Extras. Android Studios puts an error under that argument, telling me:

Required Type: androidx.navigation.Navigator.Extras,
Provided Type: androidx.navigation.fragment.FragmentNavigator.Extras"

Which I can't figure out. Navigator.Extras is an interface, which FragmentNavigator.Extras implements. What can I do about this, other than giving up on the transition I want?

0 Answers0