Breaking News
Loading...

Hoe to Create and Use Html File in android

4:12 PM
Final Out Put 
 This is very Interesting Code ,Generally when you want to developing any web related pages that time
 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

0 komentar:

Post a Comment

 
Toggle Footer