在Webview中添加进度对话框 [英] Adding a Progress Dialog in a webview
本文介绍了在Webview中添加进度对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当网页加载到网页视图中时,我一直在尝试将进度对话框纳入我的应用程序,因此不仅仅是一个空白的白屏。我知道这个问题是无处不在的,但我似乎无法找出有用的东西。我是新的编程和工作与Android,所以任何信息将是有帮助的。以下是我现在的代码。随着onPageStarted我收到Bitmap的编译错误,我不知道是什么问题。谢谢。
I have been trying to incorporate a progress dialog into my app when pages are loading in the webview so there isn't just a blank white screen. I know this question is posted everywhere but I can't seem to figure out anything that works for me. I am new to programming and working with android so any information would be helpful. Below is the code that I currently have now. With the onPageStarted I am getting a compile error for Bitmap and I'm not sure what the problem is. Thanks.
public class Grades extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//requesting system settings
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().requestFeature( Window.FEATURE_PROGRESS);
WebView webview = new WebView(this);
//web settings
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDisplayZoomControls(true);
webSettings.setBuiltInZoomControls(true);
setContentView(webview);
//loads webpages in webview instead of launching browser
webview.setWebViewClient(new WebViewClient() {
ProgressDialog prDialog;
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
prDialog = ProgressDialog.show(Grades.this, null, "loading, please wait...");
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
prDialog.dismiss();
super.onPageFinished(view, url);
}
});
//loading webpage
webview.loadUrl("page__link");
}
推荐答案
p>
Check this code,
final ProgressDialog pd = ProgressDialog.show(OnlinePaymentActivity.this, "", "Please wait, your transaction is being processed...", true);
mWebview = (WebView)findViewById(R.id.webView1);
mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
mWebview.getSettings().setLoadWithOverviewMode(true);
mWebview.getSettings().setUseWideViewPort(true);
mWebview.getSettings().setBuiltInZoomControls(true);
mWebview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
pd.show();
}
@Override
public void onPageFinished(WebView view, String url) {
pd.dismiss();
String webUrl = mWebview.getUrl();
}
}
});
mWebview .loadUrl("www.google.com");
这篇关于在Webview中添加进度对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文