上显示进度的WebView对话框 [英] show progress dialog on webview
问题描述
在我的Android应用程序,我打开webview.I想隐藏,这是获得加载的url,因此默认窗口进度条亘古不变的工作对我来说。
In my android application i am opening a webview.I want to hide url that is getting loaded,so the default window progress bar doesnot work for me.
有没有什么办法比,我可以添加进度对话的WebView。
Is there any way than that i can add progress dialogue on webview.
我使用的是下面的code。
I am using the below code.
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
mWebView.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle("My title");
}
});
mWebView.loadUrl(Url);
mWebView.setWebViewClient(new HelloWebViewClient());
}
catch(Exception e)
{
e.printStackTrace();
}
}
private class HelloWebViewClient extends WebViewClient {
ProgressDialog MyDialog=new ProgressDialog(context);
public boolean shouldOverrideUrlLoading(WebView view, String url) {
MyDialog.show();
view.loadUrl(url);
return true;
}
请分享您宝贵的建议。
在此先感谢:)
推荐答案
如果您通过隐藏应用程序标题安卓主题=@安卓风格/ Theme.NoTitleBar从清单,那么你将不会看到进度条,其中受此code显示在标题:
if you hide application title by "android:theme="@android:style/Theme.NoTitleBar"" from manifest then you won't see progress bar which is being displayed in title by this code:
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
// Makes Progress bar Visible
getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
所以,你可以显示进度条一个对话框,像这样的onCreate()里面的:
So you can show progress bar with a Dialog box like this inside the onCreate():
final Activity activity = this;
final ProgressDialog progressDialog = new ProgressDialog(activity);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setCancelable(false);
browser.setWebChromeClient(new WebChromeClient() {
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();
}
});
这篇关于上显示进度的WebView对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!