I'm trying to customize my FragmentTransaction
transitions and I came across the setTransitionStyle
method. It takes in an xml resource id for a style, but I have no idea what the xml resource would look like. I know you can define animation styles for activities, and I assume the xml needed for this method is similar, but I can't find any documentation on the required format (e.g. the xml attributes/nodes needed to make this work).
EDIT1 (this is what I'm doing now in my FragmentActivity):
public void pushFolderFrag(Fragment folderFrag, String backStackID) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.SplitView_MasterContainer, folderFrag);
transaction.addToBackStack(backStackID);
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
//transaction.setTransitionStyle(arg0);//what does the format for this resource look like??
// Commit the transaction
transaction.commit();
}
I found the answer on this link
https://github.com/kedzie/Support_v4_NineOldAndroids
Transition style resources
Specify transition animations in a style resource.
Create a style resource `res/values/styles.xml'
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- Override standard Transitions with a Style --> <style name="MyTransitionStyle"> <item name="fragmentFadeEnterAnimation">@animator/fade_enter</item> <item name="fragmentFadeExitAnimation">@animator/fade_exit</item> <item name="fragmentOpenEnterAnimation">@animator/flip_left_in</item> <item name="fragmentOpenExitAnimation">@animator/flip_left_out</item> <item name="fragmentCloseEnterAnimation">@animator/flip_right_in</item> <item name="fragmentCloseExitAnimation">@animator/flip_right_out</item> </style> </resources>
Specify the resource and transition in the transaction
tx.setTransitionStyle(R.style.MyTransitionStyle); tx.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With