我正在寻找以下 2 个与 Android 中的 Chrome 自定义标签相关的解决方案:
-
侦听器或回调,如果页面 URL 已完全加载(即 100%)
-
用于页面滚动或页面滚动到末尾/底部的侦听器或回调。
两者都可以通过实现WebView来实现,但我不知道如何使用Chrome自定义选项卡做同样的事情。我到处寻找最好的解决方案,但没有找到方法。
那么任何人都可以指导我是否可以使用 Chrome 自定义标签
?如果是,我如何在安卓中实现它?
更新:
我发现了可能与第一点自定义选项卡回调##NAVIGATION_FINISHED有关的东西,但没有找到有效的示例。
对于您的第一个问题,以下是我们应该实现的回调方法。
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 实现。这是来自谷歌本身的完整示例演示项目 https://github.com/GoogleChrome/custom-tabs-client。
参考: https://github.com/GoogleChrome/custom-tabs-client/blob/master/Using.md#navigation
对于问题2,我不确定目前是否有办法做到这一点,但我不是100%确定。