Post Reply Subscribe to Thread Email Thread

Loading local html-page into webview?

28th March 2009, 03:12 PM |#1  
OP Junior Member
Thanks Meter: 0
15 posts
Join Date:Joined: Dec 2008
I have a large set of html-pages (css-formatted, + some javascript) that I want saved inside the project so the user dont have to go online to browse for them from the app.

1) My first question is how do I open a a local html-page (named, for instance "myWebPage.html") in a WebView?

I know I can make a WebView load a html-string with the following code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
<WebView android:id="@+id/webkit"
package com.androidspanishcourse.WebKitTest;

import android.os.Bundle;
import android.webkit.WebView;

public class WebKitTest extends Activity {
    // Declare webview
    WebView browser;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        // ?
        // Loads html-string into webview
        browser.loadData("<html><body>Hi dude<br><br>Hi again</body></html>", "text/html", "UTF-8");
But I dont know how to load a specific local html-page.

2) My second question is: where do I put the html-pages? I understand that resources are generally put in the /res/-folder of the project, but do I put them in a specific sub-folder of the res-folder?
28th March 2009, 03:56 PM |#2  
Thanks Meter: 7
77 posts
Join Date:Joined: Feb 2009

1.Webview.loadUrl(String url)

2.The prefix "file:///android_asset/" will cause WebView to load content from the current application's 'assets' folder. For example, a myimage.gif file in the /assets folder can be used in the html image tag as:
<img src="file:///android_asset/myimage.gif">. Same applies to html file.
The Following User Says Thank You to waacow For This Useful Post: [ View ]
28th March 2009, 05:48 PM |#3  
OP Junior Member
Thanks Meter: 0
15 posts
Join Date:Joined: Dec 2008
Thanks a lot, waacow

Also, apparently you need to add "browser.getSettings().setJavaScriptEnabled(true); " for the webview to be able to handle javascript.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes