Wednesday, May 2, 2012

HTML Viewer Example


HTML Viewer Example




This example shows how you can show HTML files into your application.
1.) Create a new project by File-> New -> Android Project name it HTMLViewerExample.
2.) Put a .htm file into your assets folder, name it “example.htm” and write following code into it:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>HTML viewer</title>
    <style type="text/css">
        body
        {
            padding: 0px;
            font-size: 11pt;
            color: white;
            font-family: Arial;
            background-color: #0000FF;
        }
       
        .style1
        {
            color: #FFFFFF;
            font-weight: bold;
        }
    </style>
</head>
<body>
        <div class="Help" id="Help" style="Z-INDEX: 1000; LEFT: 5%; OVERFLOW: visible; WIDTH: 90%; POSITION: absolute; TOP: 20px; HEIGHT: 500px">
            <h3>HTMLViewerExample: </h3>
            <p>
                You can place your information in this HTML document.
            </p>
    </div>
</body>
</html>
3.) Run for output.
Steps:
1.) Create a project named HTMLViewerExample and set the information as stated in the image.
Build Target: Android 2.2
Application Name: HTMLViewerExample
Package Name: com.org.HTMLViewerExample
Activity Name: HTMLViewerExampleActivity
Min SDK Version: 8
2.) Open HTMLViewerExampleActivity.java file and write following code there:
package com.example.HTMLViewerExample;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class HTMLViewerExampleActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                WebView wb = new WebView(this);
                wb.loadUrl("file:///android_asset/example.htm");
                setContentView(wb);
        }
}
4.) Compile and build the project.
Output
Share and Enjoy:

No comments: