Friday, September 20, 2013

Android WebView Example

WebView is a View that displays web pages. Using his class we can display some online content within our Activity.

If you want to deliver a web application (or just a web page) as a part of a client application, you can do it using WebView. The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout.

In this Example you will see how to use WebView in your activity.

Do not forget to add the Internet permission in your manifest file.
 <uses-permission android:name="android.permission.INTERNET" />

main.xml 


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
   
</RelativeLayout>

WebViewActivity

public class MainActivity extends Activity
{
   
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        WebView  webView = (WebView) findViewById(R.id.webView1);
        webView.loadUrl("http://www.google.com");

           
    }
}

No comments:

Post a Comment