码迷,mamicode.com
首页 > Web开发 > 详细

WebView

时间:2016-08-26 12:14:04      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

//------------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

标签:

原文地址:http://www.cnblogs.com/wushanmanong/p/5809677.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!