gpt4 book ai didi

javascript - 安卓网页 View

转载 作者:太空狗 更新时间:2023-10-29 15:35:29 24 4
gpt4 key购买 nike

引用这个WebView教程,特别是这个方法

private void setupWebView(){
String MAP_URL = "http://gmaps-samples.googlecode.com/svn/trunk/articles-android-webmap/simple-android-map.html";
String centerURL = "javascript:centerAt(" + mostRecentLocation.getLatitude() + ","+ mostRecentLocation.getLongitude()+ ")";
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
//Wait for the page to load then send the location information
webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url){
webView.loadUrl(centerURL);
}
});
webView.loadUrl(MAP_URL);
}

我注意到,如果我将 webView.loadUrl(centerURL); 直接放在webView.loadUrl(MAP_URL); 像这样

private void setupWebView(){
String MAP_URL = "http://gmaps-samples.googlecode.com/svn/trunk/articles-android-webmap/simple-android-map.html";
String centerURL = "javascript:centerAt(" + mostRecentLocation.getLatitude() + "," + mostRecentLocation.getLongitude()+ ")";
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
//Wait for the page to load then send the location information
webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url){
//DO NOTHING
}
});
webView.loadUrl(MAP_URL);
webView.loadUrl(centerURL);
}

它不再有效。因此 centreAt(..) javascript 方法包含在 MAP_URL 中。

我想知道 webView.loadUrl(..) 方法是否在实际加载 url 之前返回。看起来是这样,因为 top 方法在运行 javascript 之前等待它完全加载

最佳答案

是的,webView.loadUrl() 是异步的:它立即返回并且 WebView 继续在它自己的线程中工作。

要监控 WebView 页面加载,请使用 WebViewClient.onPageFinished(..) :

webview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// do something here
}
});

关于javascript - 安卓网页 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5207540/

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