当网页加载到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);

    WebView 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() {

        @Override
        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) {
            super.onPageStarted(view, url, favicon);
            pd.show();
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            pd.dismiss();
            String webUrl = mWebview.getUrl();
        }

    });

    mWebview .loadUrl("www.google.com");

10-08 10:58