其他分享
首页 > 其他分享> > android – 在webview中添加进度对话框

android – 在webview中添加进度对话框

作者:互联网

当在webview中加载页面时,我一直在尝试将进度对话框合并到我的应用程序中,因此不仅有空白的白色屏幕.我知道这个问题随处可见,但我似乎无法找出对我有用的东西.我是编程和使用android的新手,所以任何信息都会有所帮助.下面是我现在拥有的代码.使用onPageStarted我得到了Bitmap的编译错误,我不确定是什么问题.谢谢.

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");
}

解决方法:

检查此代码,

    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");

标签:android,progress,webview,dialog,webpage
来源: https://codeday.me/bug/20190927/1822605.html