Reputation: 521
That exception was thrown when trying to add animations to replacing fragments. According to this answer, stackoverflow, the transition framework cannot be applied to fragments but this post shows you can How to use Material Transitions in Fragment Transactions Code I tried is below
final JobFragment jobFragment = JobFragment.newInstance(job);
final Fragment previousFragment = fragmentManager.findFragmentById(R.id.content);
final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
//exit transition
Fade exitFade = new Fade();
exitFade.setDuration(1000);
previousFragment.setExitTransition(exitFade);
//enter transition
Explode enterExplode = new Explode();
enterExplode.setDuration(1000);
jobFragment.setEnterTransition(enterExplode);
fragmentTransaction.replace(R.id.content, jobFragment).addToBackStack("jobDetails")
.commit();
Upvotes: 2
Views: 1784
Reputation: 9929
The answer is in your title - you have the wrong import, one is for support library, the other isn't.. Check you have consistent imports.
Example:
import android.support.transition.Fade;
import android.support.transition.Transition;
or:
import android.transition.Fade;
import android.transition.Transition;
For compatibility use the support
(added in 24.2.0) version.
Upvotes: 2