Android WebView Tutorial

Author: | Posted in Android, Quick Tips 1 Comment

Basic tutorial for how to use android web view in android application.

In this Android WebView Tutorial we will learn how to implement a basic WebView in Android application.
We will also learn how to load a dynamic web page, How to load a local web page and how to load custom html as String in Android WebView.

First create a new android project. See here for how to create.
After that add a WebView in you layout file(eg.: activity_main.xml).

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""
    android:layout_height="match_parent" >
        android:layout_height="fill_parent" />
        android:visibility="gone" />
and define WebView in your Activity file(eg.: like this.
public class MainActivity extends Activity {
    // Declare a webviewobject
    private WebView webview;
    ProgressBar progressBar = null;
    public void onCreate(Bundle savedInstanceState) {
        // and define you web view object
        webview = (WebView) findViewById(;
        progressBar = (ProgressBar) findViewById(;
        // enable javascript so webview can load javascript enabled web pages
        // also
        // set a webviewclient to check loading status of page
        webview.setWebViewClient(new WebViewClient() {
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub
                super.onPageStarted(view, url, favicon);
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                super.onPageFinished(view, url);
        webview.loadUrl("<a href=""></a>");
and finally do not forget to add a permission in your AndroidManifest.xml for internet access to your application project.
<uses-permission android:name="android.permission.INTERNET" />

Now run your project on Emulator or Android device with a valid internet connection.

You can see is loaded in your WebView.

You can also load your own html file(s) in WebView. Place your html file(index.html) in Android asset folder “asset/www/” folder and load using.


Or WebView also allows you to load custom HTML String using

webview.loadData("<html><body><h1>Android WebView Tutorial</h1></body></html>");


  • Dharmendra Mishra

    How to download from webview ??