gpt4 book ai didi

android - 显示带有对话进度和 webchrome 客户端的 webview

转载 作者:行者123 更新时间:2023-11-29 14:40:23 24 4
gpt4 key购买 nike

我的应用程序有 webview,我添加了用于显示加载的进度对话框,直到 web 完成加载。我在谷歌搜索并得到了很好的解决方案

wv.setWebChromeClient(new MyWebChromeClient());
wv.setWebViewClient(new MyWebViewClient());
wv.loadUrl("http://www.google.com");

private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}

@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
alertdialog.setTitle("Error");
alertdialog.setMessage(description);
alertdialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//return;
finish();
}
});
alertdialog.show();
}
}


private class MyWebChromeClient extends WebChromeClient {

@Override
public void onProgressChanged(WebView view, int progress) {
progressDialog.show();
progressDialog.setProgress(0);
activity.setProgress(progress * 1000);

progressDialog.incrementProgressBy(progress);

if(progress == 100 && progressDialog.isShowing())
progressDialog.dismiss();
}

}

但我的问题是,如何让进度对话框在我启动后只出现一次,因为现在如果我单击图片示例(在 google.com 中),进度对话框将再次出现。

最佳答案

this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.info);

mProgressDialog = new ProgressDialog(this);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setMessage("Please wait...");
mProgressDialog.setCancelable(false);
mProgressDialog.setMax(100);
mProgressDialog.show();

WebView webView = (WebView) findViewById(R.id.webview);
webView.setVisibility(View.VISIBLE);
webView.getSettings().setJavaScriptEnabled(true);

webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, final int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
mProgressDialog.setProgress(progress );




if(progress == 100)
{
activity.setTitle(R.string.app_name);
mProgressDialog.dismiss();
}

}
});

webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});

webView.loadUrl("http://www.google.com");

关于android - 显示带有对话进度和 webchrome 客户端的 webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11733007/

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