首页 > 代码库 > WebView

WebView

//------------onCreate中----------------

 //找到控件webview
        web_view = (WebView) findViewById(R.id.web_view);
        //获得传来的Url
        Intent intent=getIntent();
        share_url = intent.getStringExtra("share_url");

        //获取WebView的设置对像,以便设置WebView中的属性
        WebSettings settings=web_view.getSettings();
        //设置WebView允许加载JS的代码
        settings.setJavaScriptEnabled(true);
        web_view.loadUrl(share_url);

        web_view.setWebViewClient(new WebViewClient(){
            ProgressDialog dialog;
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                if (dialog==null) {
                    dialog=new ProgressDialog(WebViewActivity.this);
                    dialog.setTitle("请等待");
                    dialog.setMessage("加载中....");

                }
                if (url.equals(share_url)) {
                    dialog.show();
                }
            }
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                dialog.dismiss();
            }
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //返回值是true的时候控制去WebView打开,为false调用系统浏览器或第三方浏览器
               // view.loadUrl(url);
               // return true;
                return super.shouldOverrideUrlLoading(view, url);
            }
        });

 

 

//---------------布局文件----------------------

<WebView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/web_view"></WebView>

WebView