“Hello, WebView” example

后端 未结 3 1226
谎友^
谎友^ 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:49

    Sorry about that – that link is a bit outdated. The fixed version of this tutorial is available here:

    http://developer.android.com/guide/webapps/webview.html

    We should remove the old link; I'll file a bug.

    And note, the error is that setContentView isn't being called.

    0 讨论(0)
  • 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);
        }
    }
    
    0 讨论(0)
  • 2021-01-07 16:06

    in oncreate method add WebView.enablePlatformNotifications();

    in manifest file add

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
    

    now it works fine...

    0 讨论(0)
提交回复
热议问题