Wednesday, 20 November 2013

How to Open a HTML Page in Web View in android

This Tutorial helps you to understand how we can load or open an html page in webview in android. We can save over lot of time by saving the creating a HTML page because in creating a layout page we have to put lot of efforts.

To load a HTML page in WebView we have to paste the pages in assets folder. then follow these steps.

First Step:-

Take a Web View in your activity_main.xml and set the width and height of the webview as fill parent.

Second Step:-

Put the following code in the Main Activity of your assets folder.


Source Code:-
import android.os.Bundle;
import android.app.Activity;
import android.webkit.WebView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        WebView w1=(WebView)findViewById(R.id.webView);
        w1.loadUrl("file:///android_asset/it/htmlPage.html");
       
    }
}

Download the project

No comments:

Post a Comment