Sunday, July 15, 2012

Display HTML content in Android using WebView



Click Here to download Source Code

Package Name  :  selva.web

Project Name   :  WebView

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:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <WebView
     android:id="@+id/webview1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
</LinearLayout>


WebViewActivity.java

package selva.web;

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


public class WebViewActivity 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);
               final String mimeType = "text/html";
               final String encoding = "UTF-8";
         
               String html = "<H1>A simple HTML page</H1><body>" + "<p>Android tutorial  programs present in www.androidprogramz.in</p>";
               wv.loadDataWithBaseURL("", html, mimeType, encoding, "");
    }
  
}



OUTPUT :






























Click Here to download Source Code


2 comments:

  1. Hello,

    I have a question regarding webview

    I have a shopping cart application.When user select a product next page will show product detail with a button of shop.When user clicks that button it will open this in a URl which in outside application but i want open this within our app using webview where URL will show show.

    URLs are coming from a xml in server.

    Please do you have any solution for this.

    Please reply and thank you.

    ReplyDelete
  2. Hi Hello Sir,
    My name is Amit Bhaliya i m developing a mobile android app but i have some problem is there.the problem is that how to put hyperlink in my code so please help to me send me your email id then i will send you my code please help to me.

    Thanking You.
    Amit Bhaliya
    Android Developer

    ReplyDelete