FragmentTransaction: set custom animations via code

35 Views Asked by At

Is it possible to set custom animations for FragmentTransaction via code? I see only setCustomAnimations(int, int) that works for XML.

1

There are 1 best solutions below

0
Fakhri Khairi On

maybe you can try this

FragmentTransaction transaction =
            getSupportFragmentManager().beginTransaction();

    //this is to add the animation
    transaction.setCustomAnimations(R.anim.activity_open_enter,
            R.anim.activity_open_exit);

    transaction.replace(R.id.fragment_container, fragment2);
    transaction.commit();

or you can read this Navigate between fragments using animations

hope can solve your problem :)