EXIT_ANIMATION_BUNDLE 不适用于 Chrome 自定义选项卡

Mat*_*s89 7 android chrome-custom-tabs

我正在尝试将 Chrome 自定义选项卡合并到我的应用程序中,但我很难让退出动画正常工作。我正在关注此处找到的文档:
链接

我正在使用的代码如下所示:

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);
Run Code Online (Sandbox Code Playgroud)

该选项卡以所需的动画启动,但以默认的活动动画结束。有任何想法吗?

and*_*ban 1

将应用程序与自定义选项卡集成的推荐方法是使用Android 支持库

要使用它,请将其com.android.support:customtabs:23.0.0作为编译依赖项添加到您的 build.gradle 中。

然后,要设置退出动画并启动自定义选项卡,请执行以下操作:

    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"));
Run Code Online (Sandbox Code Playgroud)

查看GitHub 示例中的演示模块,了解有关如何将其与 Android 支持库一起使用的更多详细信息。

要在没有支持库的情况下打开它,您必须确保将会话设置为额外。下面的代码将打开一个自定义选项卡并正确设置退出动画。

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);
}
Run Code Online (Sandbox Code Playgroud)

希望能有所帮助。