Search code examples
androidandroid-fragmentstransitionfragmenttransaction

FragmentTransaction setTransition() for remove() doesn't change the transition previously set in replace()


So, first of all I create a new Fragment like this

ft = fm.beginTransaction();
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.replace(R.id.main_content_frame, cFr, "CARS");
ft.addToBackStack(null);
ft.commit();

And later I remove it like this

fm.popBackStack();
ft = fm.beginTransaction();
ft.setTransition(FragmentTransaction.TRANSIT_NONE);
ft.remove(fm.findFragmentByTag("CARS")).commit();

But the close transition is done with the TRANSIT_FRAGMENT_OPEN animation (or its opposite by default, I think), and I clearly set TRANSIT_NONE.

Any thoughts?


Solution

  •   public void mRemoveFragment(android.app.Fragment fragment){
        android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
        ft.remove(fragment);
        ft.commit();
    }
    

    use this function to remove the fragment. Where in setCustomAnimation, you can give your scripts. I have currently used the default ones provided by android