gpt4 book ai didi

java - 加载时删除 webview 加载器

转载 作者:行者123 更新时间:2023-11-29 21:10:09 26 4
gpt4 key购买 nike

我正在尝试实现一个 webview 加载器,但是一旦页面加载完毕,加载器就会继续显示:

private WebView webView;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.webcontent);

webView = (WebView) findViewById(R.id.webView);
final ProgressDialog progDailog = ProgressDialog.show(WebActivity.this, "Loading ","Please wait... ", true);

progDailog.setCancelable(false);
webView.setWebChromeClient(new WebChromeClient() {

public boolean shouldOverrideUrlLoading(WebView view, String url) {
progDailog.show();
view.loadUrl(url);

return true;
}

public void onPageFinished(WebView view, final String url) {
progDailog.dismiss();
}
});

//webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
webView.loadDataWithBaseURL("www.example.com", null, "text/html", "UTF-8", null);
webView.loadUrl("www.example.com");

}

我认为“onPageFinished”应该在页面加载后删除加载器?

谢谢

最佳答案

替换这个:

webView.setWebChromeClient(new WebChromeClient() {

public boolean shouldOverrideUrlLoading(WebView view, String url) {
progDailog.show();
view.loadUrl(url);

return true;
}

public void onPageFinished(WebView view, final String url) {
progDailog.dismiss();
}
});

通过这个:

webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progDailog.show();
}

@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progDailog.dismiss();
}
});

它对我有用。

关于java - 加载时删除 webview 加载器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23192983/

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