Final Out Put |
we should use html , why because html supports any web browser ,
creating html file in android project :
1- > create project and expand it
2-> right click on assets folder
-> choose New
-> choose others
->in general folder
-> choose file
-> type some file name with .html extension (index.html)
-> click on finish
writing some code into html file :
--> simply right click on html folder
--> choose open with text editor
write some html code ( like this ) :
index.html
<html>
<head><title>demo</title></head>
<body bgcolor="cyan">
<table align=""center">
<th cellpadding=3 align="right">Vizser Employees</th>
<tr> <th> Name </th> <th> Platform </th> <th> Role</th> </tr>
<tr> <td> Subbu </td> <td> Java </td> <td> MD</td> </tr>
<tr> <td> RajKumar </td> <td> Testing </td> <td> Admin</td> </tr>
<tr> <td> Satish </td> <td> Php </td> <td> Senior Developer</td> </tr>
<tr> <td> Madan </td> <td> Designer </td> <td> Senior Designer</td> </tr>
<tr> <td> Ramu </td> <td> Iphone </td> <td> Developer</td> </tr>
</table>
</body>
</html>
mainclass :
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class SravanWebView extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webview=(WebView)findViewById(R.id.webview1);
webview.loadUrl("file:///android_asset/index.html"); // opening html page from assets folder
webview.setWebViewClient(new SravanWebViewClient());
}
}
client view :
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class SravanWebViewClient extends WebViewClient
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
}
main.xml code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sravan Web View Demo"
android:textColor="#ffffff"
android:textSize="15dp"
android:layout_gravity="center_horizontal"
/>
<WebView
android:id="@+id/webview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Then in your activities onCreate method you'll need to find the reference to your webview and call the load URL method with the filepath to your html file.
WebView wv = (WebView) findViewById(R.id.web_engine);
wv.loadUrl("file:///android_asset/HTML_FILE_NAME.html");
for this example to work you'll have to put your html file into the assets folder in your project. If you are trying to view your html file without creating an application it may be trickier. On actual devices I know you can put an html file onto the SD card and navigate to it with a file manager program and open it with Offline Browser
for project source code click here (SravanWebView): ClickMe
Creatin Html File in project |
for Loading any web site code : Click Here
nice post... i want edit the html file ... or i want to underline the word or sentence in run time..
ReplyDeleteplease help, thanks in advance