首页 > 解决方案 > Chrome 自定义选项卡 Android 的滚动回调或侦听器

问题描述

我正在寻找以下 2 个与Android中的Chrome 自定义选项卡相关的解决方案:

  1. 如果页面 url 已完全加载(即 100%),则侦听器或回调

  2. 页面滚动或页面滚动到末尾/底部的侦听器或回调。

两者都可以通过实现WebView来实现,但我不知道如何对Chrome Custom Tab做同样的事情。我到处寻找可能的最佳解决方案,但没有找到方法。

那么任何人都可以指导我是否可以使用Chrome 自定义选项卡

如果是,我如何在 Android 中实现它?

更新:

我发现了一些可能与第一点CustomTabsCallback##NAVIGATION_FINISHED相关的东西,但没有找到一个有效的例子。

标签: androidandroid-intentchrome-custom-tabs

解决方案


对于您的第一个问题,以下是我们应该实现的回调方法。

void onNavigationEvent(int navigationEvent, Bundle extras)

navigationEvent如下_

/**
 * Sent when the tab has started loading a page.
 */
public static final int NAVIGATION_STARTED = 1;

/**
 * Sent when the tab has finished loading a page.
 */
public static final int NAVIGATION_FINISHED = 2;

/**
 * Sent when the tab couldn't finish loading due to a failure.
 */
public static final int NAVIGATION_FAILED = 3;

/**
 * Sent when loading was aborted by a user action before it finishes like 
   clicking on a link
 * or refreshing the page.
 */
public static final int NAVIGATION_ABORTED = 4;

/**
 * Sent when the tab becomes visible.
 */
public static final int TAB_SHOWN = 5;

/**
 * Sent when the tab becomes hidden.
 */
public static final int TAB_HIDDEN = 6;

您可以在https://github.com/GoogleChrome/custom-tabs-client/blob/master/Application/src/main/java/org/chromium/customtabsclient/MainActivity.java#L111中找到使用 onNavigationEvent 实现。这是来自 Google 本身的完整示例演示项目https://github.com/GoogleChrome/custom-tabs-client 。

参考:https ://github.com/GoogleChrome/custom-tabs-client/blob/master/Using.md#navigation

对于问题 2,我不确定目前是否有办法做到这一点,但我不是 100% 确定。


推荐阅读