向Chrome自定义标签关闭按钮添加监听器

Var*_*rma 4 android chrome-custom-tabs

我有一个chrome自定义选项卡,但我想在标题栏左上角的关闭(X)按钮中添加一个监听器.

我想在每次用户点击关闭按钮时触发回调.

我能够在Web视图中执行此操作,但无法确定是否可以使用chrome自定义选项卡.

这是我用来调用自定义标签的代码段:

     CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
                    builder.enableUrlBarHiding();
                    builder.setToolbarColor(getTitleBarBackgroundColor());
                    builder.setStartAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
                    builder.setExitAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
                    customTabsIntent = builder.build();
                    customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |  Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    customTabsIntent.launchUrl(this, Uri.parse(url));
Run Code Online (Sandbox Code Playgroud)

Fan*_*ock 8

已经有一些关于Chrome自定义选项卡关闭按钮定制的quires(此处此处)用于不同目的.从Chrome自定义选项卡的当前实现,无法将侦听器直接添加到chrome自定义选项卡关闭按钮.您只能自定义其图标的关闭按钮.

更新:虽然您无法直接向Chrome自定义标签关闭按钮添加监听器,但您可以通过使用打开chrome自定义选项卡的来电活动的onResume()onActivityResult()来解除对Chrome自定义标签的解除.但请记住,在这种情况下,无论Chrome自定义选项卡是通过关闭按钮还是设备返回键关闭,都将调用回调.

  • 如何知道 onresume 是否由于自定义选项卡关闭或其他原因而被调用(如果假设还有其他地方也可以恢复活动) (3认同)
  • 根据您的 Activity 的启动方式,如果用户导航到另一个应用程序(例如,如果他点击“在 chrome 中打开”)并返回,也会调用 onResume()。 (2认同)