Are Activity/Fragment Transitions compatible with pre-Lollipop devices?

谁都会走 提交于 2019-11-27 11:40:59
Alex Lockwood

No, Activity/Fragment Transitions are not possible on pre-Lollipop devices. According to the documentation:

Start an activity with additional launch information, if able.

In Android 4.1+ additional options were introduced to allow for more control on activity launch animations. Applications can use this method along with ActivityOptionsCompat to use these animations when available. When run on versions of the platform where this feature does not exist the activity will be launched normally.

See also George Mount's answer to this StackOverflow question.

You can check out this library for activity and fragment transitions for pre lollipop devices

dependencies {
        compile 'com.albinmathew:PreLollipopTransition:1.1.2'
}

https://github.com/albinmathew/PreLollipopTransition

Although the fancy Lollipop Activity/Fragment transitions are not available pre-Lollipop (without the use of a 3rd party library), you can still override the animation used to transition between activities.

Just before/after you start invoke startActivity() you can make a call to [Activity.overridePendingTransition](http://developer.android.com/reference/android/app/Activity.html#overridePendingTransition(int, int)). When you leave your activity, call the same method.

Similarly you can use ActivityOptionsCompat to define a custom animation to use during a transition.

ActivityOptionsCompat opts =
    ActivityOptionsCompat.makeCustomAnimation(getActivity(), R.anim.in, R.anim.out);
startActivity(intent, opts.toBundle());
Mdlc

There is a support library, but it does not support (all) transitions on Android versions below 5.0. There are however some alternatives:

Unofficial Compatibility libraries
https://github.com/andkulikov/transitions-everywhere
https://github.com/takahirom/PreLollipopTransition
https://github.com/lgvalle/Material-Animations

Android KitKat
http://www.doubleencore.com/2013/11/new-transitions-framework/ and a sample found in your SDK samples folder.

Posted earlier to a duplicate of this question here: https://stackoverflow.com/a/27344471/1683141

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!