向 Chrome 自定义选项卡关闭按钮添加侦听器
Add a listener to Chrome Custom Tab Close button
我有一个 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));
已经有一些查询(here and ) regarding chrome custom tab close button customization for different purpose. From current implementation of chrome custom tab, that's not possible to add a listener directly to chrome custom tab close button. You only can customize the close button 它的图标。
更新:
虽然您不能直接向 chrome 自定义选项卡关闭按钮添加侦听器,但您可以通过使用调用方 activity 的 or 在关闭 chrome 自定义选项卡时触发回调chrome 自定义选项卡已打开。但请记住,在这种情况下,无论 chrome 自定义选项卡是否已通过关闭按钮或设备后退键关闭,都会调用回调。
无法覆盖关闭按钮的行为。但是,如果您只想触发回调以跟踪关闭按钮上的点击,您可以在启动自定义选项卡的 Activity 上使用 onResume()
回调,因为调用者 Activity 将因自定义选项卡关闭而恢复。
我有一个 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));
已经有一些查询(here and
更新:
虽然您不能直接向 chrome 自定义选项卡关闭按钮添加侦听器,但您可以通过使用调用方 activity 的
无法覆盖关闭按钮的行为。但是,如果您只想触发回调以跟踪关闭按钮上的点击,您可以在启动自定义选项卡的 Activity 上使用 onResume()
回调,因为调用者 Activity 将因自定义选项卡关闭而恢复。