Archive for December, 2010

Display Static HTML page in Android (Eclipse) emulator

Tuesday, December 28th, 2010 By Nikhil

For a few hours now I have been looking at solutions to run/test my static HTMLs in the Eclipse/Android emulator.  Have not been totally successful yet…. what I mean by “Totally” is the HTML gets loaded OK but all the CSS and JS, i.e. the visual expression is  not seen. In developer words, the CSS is not applied to the page…

Thought it would a few   fellow newbie Android  UI developers , If  I noted the snippet down that I used to  display the  HTML .

AND Android gurus, PLEASE add your comments to help us novices in mobile application UI developers further!

Sorry! but Im assuming that you  know how to create a  Android Mobile Application in Eclipse.

Create this as your activity; This will read the file ‘index.html’ from your project assets/ folder.

public class Test extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        WebView webview = new WebView(this);
        try {
            InputStream fin = getAssets().open("index.html");
                byte[] buffer = new byte[fin.available()];
                webview.loadData(new String(buffer), "text/html", "UTF-8");
        } catch (IOException e) {

get ExpressingIT News by Email Subscribe to ExpressingIT by Email or  Follow Me on Twitter

 Subscribe to ExpressingIT RSS
get ExpressingIT News by Email Subscribe to ExpressingIT by Email
 Follow Me on Twitter