Android Activity transitions using Support v4 up to date with Android L

后端 未结 2 1794
谎友^
谎友^ 2021-02-05 11:10

I was implementing material design for my app. I saw that it is possible to make transitions between activities just here: http://android-developers.blogspot.com.es/2014/10/impl

相关标签:
2条回答
  • 2021-02-05 11:45

    Activity Transitions are exclusive to Android 5.0. ActivityOptionsCompat. makeSceneTransitionAnimation doesn't do anything if you're running 19 or below.

    0 讨论(0)
  • 2021-02-05 11:52

    ActivityOptionsCompat.makeSceneTransitionAnimation works only on api level >= 21. From docs:

    Some material design features like the material theme and custom activity transitions are only available on Android 5.0 (API level 21) and above. However, you can design your apps to make use of these features when running on devices that support material design and still be compatible with devices running previous releases of Android.

    Here is it's definition:

    public static ActivityOptionsCompat makeSceneTransitionAnimation(Activity activity,
            View sharedElement, String sharedElementName) {
        if (Build.VERSION.SDK_INT >= 21) {
            return new ActivityOptionsCompat.ActivityOptionsImpl21(
                    ActivityOptionsCompat21.makeSceneTransitionAnimation(activity,
                            sharedElement, sharedElementName));
        }
        return new ActivityOptionsCompat();
    }
    

    So why does that method exist in support package?

    It is done so in order to maintain backward compatibility with older versions (api level <=20). From maintaining compatibility docs:

    // Check if we're running on Android 5.0 or higher
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Call some material design APIs here
    } else {
        // Implement this feature without material design
    }
    
    0 讨论(0)
提交回复
热议问题