How to used Material Design Transition when fragment changed in Android?

3.2k views Asked by At

I like new Transitions introduced with Android material design like that :

enter image description here

But, I want used it when I replaced fragment after selected an item in my Drawer :

fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();

Is that possible? Used the same logic with EnterTransition / ExitTransition and Explode transition animation.

1

There are 1 answers

2
Akhil On BEST ANSWER

These transitions are for activities, not for fragments, See below from documentation these are specified for windowExitTransition & windowEnterTransition

<style name="BaseAppTheme" parent="android:Theme.Material">
  <!-- enable window content transitions -->
  <item name="android:windowContentTransitions">true</item>

  <!-- specify enter and exit transitions -->
  <item name="android:windowEnterTransition">@transition/explode</item>
  <item name="android:windowExitTransition">@transition/explode</item>

  <!-- specify shared element transitions -->
  <item name="android:windowSharedElementEnterTransition">
    @transition/change_image_transform</item>
  <item name="android:windowSharedElementExitTransition">
    @transition/change_image_transform</item>
</style>

You can try to achieve same for fragments as well specifying transitions in your fragmenttransanction.