Code example for WebView: Displaying web pages

Methods: getSettingsloadUrlsetBackgroundColorsetWebChromeClientsetWebViewClient

0
        setContentView( R.layout.news_activity);
         
        m_szNewsURL = getIntent().getStringExtra( "news_url" );
        m_WebView = (WebView) findViewById( R.id.webview_news );
     
        m_WebView.getSettings().setJavaScriptEnabled(true);
        m_WebView.setBackgroundColor(0);
        m_WebView.getSettings().setBuiltInZoomControls(true);
        final Activity activity = this;
        m_WebView.setWebChromeClient(new WebChromeClient() {
          public void onProgressChanged(WebView view, int progress) {
            // Activities and WebViews measure progress with different scales. 
            // The progress meter will automatically disappear when we reach 100% 
            activity.setProgress(progress * 100);
          } 
        }); 
        m_WebView.setWebViewClient(new WebViewClient() {
          public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
          } 
        }); 
         
        m_WebView.loadUrl( m_szNewsURL );
    } 
} 
Experience pair programming with AI  Get Codota for Java