Webview in android

WebView is a view that display web pages inside your application. You can also specify HTML string and can show it inside your application using WebView. WebView makes turns your application to a web application.

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/webview"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
/>
WebView webview = (WebView) findViewById(R.id.webview);
webview.loadUrl("http://www.google.com");

If you click on any link inside the webpage of the webview, that page will not be loaded inside your webview so in that case we need to extend our class from WebViewClient and override its method.

private class MyBrowser extends WebViewClient {
   @Override
   public boolean shouldOverrideUrlLoading(WebView view, String url) {
      view.loadUrl(url);
      return true;
   }
}

Share this

Related Posts

Previous
Next Post »