Friday, 31 July 2015

Android WebView

Android WebView is used to display web page in android. The web page can be loaded from same application or URL. It is used to display online content in android activity.

Android WebView uses webkit engine to display web page.

Sample Code:

File: activity_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
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>

File: MainActivity.java

package com.sneha.webview;

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

public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

WebView mywebview = (WebView) findViewById(R.id.webView1);
mywebview.loadUrl("http://www.javatpoint.com/");
}
}

Output:



























Download Full Source Code: Webview

Enjoy Coding...!!!

No comments:

Post a Comment