EXIT_ANIMATION_BUNDLE not working with Chrome Custom Tabs

眉间皱痕 提交于 2021-01-27 16:42:39

问题


I'm trying to incorporate Chrome Custom Tabs in my app and I'm having difficulty getting the exit animation working. I'm following the docs found here:
Link

The code I'm using is like the following:

String EXTRA_CUSTOM_TABS_EXIT_ANIMATION_BUNDLE = "android.support.customtabs.extra.EXIT_ANIMATION_BUNDLE";
Bundle finishBundle = ActivityOptions.makeCustomAnimation(mActivity, android.R.anim.slide_in_left, android.R.anim.slide_out_right).toBundle();
i.putExtra(EXTRA_CUSTOM_TABS_EXIT_ANIMATION_BUNDLE, finishBundle);

Bundle startBundle = ActivityOptions.makeCustomAnimation(mActivity, R.anim.slide_in_right, R.anim.slide_out_left).toBundle();
mActivity.startActivity(i, startBundle);

The tab launches with the desired animations but finishes with the default activity animation. Any ideas?


回答1:


The recommended way to integrate your app with Custom Tabs is to use the Android Support Library.

To use it, add com.android.support:customtabs:23.0.0 as a compile dependency to your build.gradle.

Then, to set the exit animations and start the Custom Tab, do:

    CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
            .setExitAnimations(this,
                    android.R.anim.slide_in_left, android.R.anim.slide_out_right)
            .build();
    customTabsIntent.launchUrl(this, Uri.parse("http://www.example.com"));

Check the demos module in the GitHub sample for more details on how to use it with the Android Support Library.

To open it without the Support Library, you have to make sure you are setting the session extra. The code below will open a Custom Tab and properly set the exit animation.

public static final String EXTRA_EXIT_ANIMATION_BUNDLE =
        "android.support.customtabs.extra.EXIT_ANIMATION_BUNDLE";

public static final String EXTRA_SESSION = "android.support.customtabs.extra.SESSION";

public void openCustomTab() {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));

    Bundle bundle = ActivityOptions
            .makeCustomAnimation(
                    this, android.R.anim.slide_in_left, android.R.anim.slide_out_right)
            .toBundle();

    Bundle extrasBundle = new Bundle();
    extrasBundle.putBinder(EXTRA_SESSION, null);
    intent.putExtras(extrasBundle);

    intent.putExtra(EXTRA_EXIT_ANIMATION_BUNDLE, bundle);
    startActivity(intent);
}

Hope to have helped.




回答2:


I stumbled upon the same issue, enter animation working like a charm but couldn't get it working for the exit animations until I realised I might have passed the wrong context to setExitAnimations. Therefore be sure to pass the context of activity from where the custom tab is opened.



来源:https://stackoverflow.com/questions/32371190/exit-animation-bundle-not-working-with-chrome-custom-tabs

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