View that displays web pages. This class is the basis upon which you can roll your own web browser or simply display some online content within your Activity. It uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, perform text searches and more.
Note that, in order for your Activity to access the Internet and load web pages in a WebView, you must add the
INTERNET
permissions to your
Android Manifest file:Here Below example source code shows webview in Android
UI Layout(webview.xml)
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Android Activity class(OpenWebView.java)
package com.androidsurya.webview;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class OpenWebView extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://androidsurya.blogspot.in/");
}
}
Note: To open webview your application should use Internet Permission
Permission in Android Manifest File
<uses-permission android:name="android.permission.INTERNET" />
Register Android Activity in Android Manifest File
<activity
android:name="com.androidsurya.webview.OpenWebView"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Output Screenshot:
No comments:
Post a Comment