I would like to add a shared elements transition using the navigation architecture components, when navigating to an other fragment. But I have no idea how. Also in the document
For Java
To make shared element create a method like :
void sharedNavigation(int id, View... views) {
FragmentNavigator.Extras.Builder extras = new FragmentNavigator.Extras.Builder();
for (View view : views)
extras.addSharedElement(view, view.getTransitionName());
FragmentNavigator.Extras build = extras.build();
Navigation.findNavController(getView()).navigate(id,
null,
null,
build);
}
At the destination class or base class you have to add below code in your onCreate().
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setSharedElementEnterTransition(TransitionInflater.from(getContext())
.inflateTransition(android.R.transition.move));
}
And to make transition animation give the id and views to the sharedNavigation() like below :
sharedNavigation(R.id.action_splashFragment_to_loginFragment,
getView().findViewById(R.id.logo));