Sunday, July 15, 2012

Create Html file and Displaying in Android



Click Here to Download Source Code

Package Name   :  selva.web

Project Name     :  WebView2

Version               : 1.5 ( Supports 1.5 and above versions)

main.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <WebView android:id="@+id/webview1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>


 Create ex.html under assets folder

<body>
<h1> Hi This is Simple Website </h1>
<a href="http://www.androidprogramz.in/"> Click Here </a>

</body>






 
 WebView2Activity.java

 package selva.web;

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

public class WebView2Activity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
      
        WebView wv = (WebView) findViewById(R.id.webview1);
        wv.loadUrl("file:///android_asset/ex.html");
 
    }
}


OUTPUT: 



 




















click On Click Here













































Click Here to Download Source Code


3 comments:

  1. Thanks for the source code . i'm trying to build an android app for my education site tnpsc exams

    ReplyDelete
  2. Thanks for this code .

    ReplyDelete