“Hello, WebView” example

后端 未结 3 1232
谎友^
谎友^ 2021-01-07 15:22

I\'m new in android development and I am trying out the WebView example in the official android site.

http://developer.android.com/guide/tutorials/views/hello-webvie

3条回答
  •  天涯浪人
    2021-01-07 15:56

        webview_id = (WebView)findViewById(R.id.webview_id);
        webview_id.getSettings().setJavaScriptEnabled(true); // enable javascript
        WebSettings webSettings = webview_id.getSettings();
        webSettings.setBuiltInZoomControls(true);
        webSettings.setDisplayZoomControls(true);
        webSettings.setPluginState(WebSettings.PluginState.ON);
        webSettings.setJavaScriptEnabled(true);
        webview_id.setInitialScale(90);
        webSettings.setLoadWithOverviewMode(true);
        webview_id.requestFocusFromTouch();
        webview_id.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Snackbar.with(getApplicationContext()).dismiss();
                Snackbar.with(getApplicationContext()) // context
                        .text(description) // text to display
                        .show(MainActivity.this);
            }
            public void onPageFinished(WebView view, String url) {
                progressBar.setVisibility(View.GONE);
            }
        });
    
    
        if(isNetworkAvailable()){
    
            webview_id .loadUrl("http://helloworld.org/");
        }else{
            Snackbar.with(getApplicationContext()).dismiss();
            Snackbar.with(getApplicationContext()) // context
                    .text("Please Check your Internet Connection") // text to display
                    .show(MainActivity.this);
            progressBar.setVisibility(View.VISIBLE);
        }
    }
    

提交回复
热议问题