如何在webview中添加加载器对话框?

时间:2012-10-11 08:43:29

标签: android android-webview

我正在尝试在我的应用程序中将加载程序对话框添加到我的webview中。所以,你能帮我解决这个问题吗?

这是我的webview 代码

public class AlTibbiWebViewActivity extends Activity {

private WebView wv;
private Intent incomingIntent = null;
private WebViewClient wvc = new WebViewClient() {

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

};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.web_view);
    this.wv = (WebView) findViewById(R.id.webView);
    this.wv.setWebViewClient(wvc);
    wv.getSettings().setJavaScriptEnabled(true);
    this.incomingIntent = getIntent();
    String urlToLoad = incomingIntent.getExtras().getString("urlToLoad");

    //EXTRA HEADER MAP (remove header from web view )

     Map<String, String> aMap = new HashMap<String, String>() ;
     aMap.put("app", "no");
     //myMap = Collections.unmodifiableMap(aMap);
     wv.loadUrl(urlToLoad , aMap);

}

1 个答案:

答案 0 :(得分:4)

webView.setWebViewClient(new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {              
            view.loadUrl(url);
            return true;
        }
        public void onLoadResource (WebView view, String url) {
            if (progrDialog == null) {
                progrDialog = new ProgressDialog(YourActivity.this);
                progrDialog.setMessage("Loading...");
                progrDialog.show();
            }
        }
        public void onPageFinished(WebView view, String url) {
            try{
            if (progrDialog.isShowing()) {
                progrDialog.dismiss();
                progrDialog = null;
            }
            }catch(Exception exception){
                exception.printStackTrace();
            }
        }
    });