gpt4 book ai didi

java - Android Webview 应用程序上下文

转载 作者:太空宇宙 更新时间:2023-11-04 14:53:09 25 4
gpt4 key购买 nike

我想在 Activity 启动之前预加载 Web URL。那么我可以在应用程序上下文下实例化 fragment 吗?

编辑:- 在应用程序子类中创建 webview 并在 Activity 中检索它。但由于上下文不同而无法使用它。 <如果使用支持 fragment 库会发生这种情况>- 使用服务组件创建 webview 并在 Activity 中检索它。与在应用程序上下文下启动服务相同的上下文问题。 <如果使用支持 fragment 库就会发生这种情况>

更新:我能够在应用程序上下文下创建一个 webview 对象,并在任何 Activity 需要时以 fragment 形式检索它。它在 Android OS 4.0 及更高版本上运行良好。我已经在 Android OS 4 及更高版本上进行了测试。以防万一有人需要

最佳答案

你可以处理 WebViewClient当您的页面完全加载到 WebView 中时,监听器确实会收到消息然后添加/显示您的 fragment 。

mWebView.setWebViewClient(new WebViewClient() {

public void onPageFinished(WebView view, String url) {
// do your stuff here
}
});

文档说明:

Notify the host application that a page has finished loading. This method is called only for main frame. When onPageFinished() is called, the rendering picture may not be updated yet. To get the notification for the new Picture, use onNewPicture(WebView, Picture).

查看更多信息:onPageFinished (WebView view, String url)

关于java - Android Webview 应用程序上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23524211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com