Android Programming Tutorials

Android Development Tutorial #3 : Android Webview – Example

Written by Jana Raj

Android Webview is a Simple Class To load a webpage in Your Android Application , Instead of loading the webpage directly in your Android browser .

Lets see a Tutorial in Creating A New Android App With Webview On MainActivity

Requirements :

  • Basic Android SDK Setup – View Our Tutorial
  • Creating Android Virtual Device – Check Out How to Create Android Debugging Via Wifi

Reference :

screenshot

Project :

  • Create a New Android Application Project.

MainActivity.java (MainActivity File)

package com.tech4bros.webview;

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

public class MainActivity extends Activity {

	private WebView webView;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		webView = (WebView) findViewById(R.id.webview);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.loadUrl("http://www.tech4bros.com");

	}

}

 

activity_main.xml (Main Layout)

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".WebView" >

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

In Order to use Internet , You Have to use The Following Permission Or Else You Will get a No Connection Error While Loading Your App

<uses-permission android:name="android.permission.INTERNET"/>

 Download Full Project :

About the author

Jana Raj

Janarthanan is the founder and Chief Editor of Tech4bros .He is a Student of Computer Science and Engineering ,a full time Geek, part time Blogger and Quarter time Coder. He loves Blogging, Web Designing and making new friends . Google Plus

Leave a Reply