There is no official way to animate startDestination
fragment and I believe you generally should not animate it. There are a few ways your startDestination
fragment comes into view and all of them have their own ways to run animations:
- Your
NavHost
is hosted by an activity and this activity is launched from launcher. Launchers normally override window transitions to make your activity appearing nicely.
- Your
NavHost
is hosted by an activity and this activity is launched by another activity. Use activity transitions to override default ones.
- Your
NavHost
is nested in a fragment. The containing fragment runs its own transition when comes into view.
As you can see in all cases another transition is involved when startDestination
fragment is appearing or disappearing, so fragment transition here would likely collide with existing transition, making it look unpleasant.
At the same time, if you really want to animate it, there are quite a few ways. In addition to mentioned in the question, I can think about these:
If you are using native fragments, set default fragment transitions in app theme with attributes fragmentOpenEnterAnimation
, fragmentOpenExitAnimation
and so on. Update: it does not make sense in context of the question and is not gonna work anyway.
- Override
Fragment.onCreateAnimation
or Fragment.onCreateAnimator
methods in your fragment and return animation / animator needed.