---
title: "WebView in Android: Display a URL"  
description: "WebView is a view widget that can be embedded in any layout to display web content, both local and remote, in your application.WebView is based on the"  
author: "Anonymous User"  
published: 2015-09-22  
updated: 2018-03-13  
canonical: https://www.mindstick.com/blog/10954/webview-in-android-display-a-url  
category: "android"  
tags: ["android", "android activity", "android controls"]  
reading_time: 5 minutes  

---

# WebView in Android: Display a URL

· WebView is a view widget that can be embedded in any layout to display [web content](https://www.mindstick.com/blog/303211/explore-the-web-content-accessibility-guidelines-wcag-2-1), both local and remote, in [your application](https://www.mindstick.com/forum/34702/please-tell-me-what-is-cross-site-scripting-and-how-is-it-harmful-for-your-application).

· WebView is based on the same [open source](https://www.mindstick.com/articles/337437/how-to-leverage-open-source-for-innovative-project-development) WebKit technology that powers the Android Browser application, affording applications the same level of power and capability.

· WebView has some very desirable properties when displaying assets downloaded from the Web, not the least of which are two-dimensional scrolling (horizontal and vertical at the same time) and zoom controls.

· A WebView can be the perfect place to house a large image, such as a stadium map, in which the user may want to pan and zoom around. Here we will discuss how to do this with both local and remote assets

Pre-Requisites:

1. Ellipse SDK

2. Android SDK

3. ADT plugin

Or [Android Studio](https://www.mindstick.com/blog/10942/android-studio-vs-eclipse) and a compatible version of JAVA SDK

Install and configure the above utilities.

Now create a new Android project namely “WebViewSample”.

[Implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp) objective:

Displaying an HTML page or image by supplying the URL of the resource to the WebView

Code Implementation:

##### Display a URL

The simplest case is displaying an HTML page or image by supplying the URL of the resource to the WebView. The following are a handful of [practical uses](https://answers.mindstick.com/qa/101954/how-do-drones-operate-and-what-are-their-practical-uses) for this technique in your applications:

· Provide access to your corporate site without leaving the application.

· Display a page of live content from a [web server](https://www.mindstick.com/articles/23199/digital-personal-server-the-premium-web-server), such as an FAQ section, that can be changed without requiring an upgrade to the application.

· Display a large image resource that the user would want to interact with using pan/zoom.

Now we see how to loads a very popular [web page](https://www.mindstick.com/forum/718/sql-server-report-alignment-to-center-of-web-page) inside the content view of an activity instead of within the browser

Now navigate toMainActivity.java and add this code:

```
package com.example.webviewsample;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.webkit.WebView;
public class MainActivity extends Activity {                @Override                protected void onCreate(Bundle savedInstanceState) {                                super.onCreate(savedInstanceState);                                setContentView(R.layout.activity_main);                                //Create a webview
                             WebView webView = new WebView(this);                                // Enable JavaScript support                                webView.getSettings().setJavaScriptEnabled(true);
                             //Load URL in web view                                webView.loadUrl("http://www.google.com/");
                             //set webview in UI                                setContentView(webView);
                }
                @Override                public boolean onCreateOptionsMenu(Menu menu) {
                                // Inflate the menu; this adds items to the action bar if it is present.
                                getMenuInflater().inflate(R.menu.main, menu);
                                return true;
                }
}
```

\

**Note:** By default, WebView has JavaScript support disabled. Be sure to enable JavaScript in the WebView.WebSettings object if the content you are displaying requires it.

**Important:** If the content you are loading into WebView is remote, [AndroidManifest.xml](https://www.mindstick.com/interview/2588/explain-androidmanifest-xml-file-in-detail) must declare that it uses the android.permission.INTERNET permission.

```
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.webviewsample"    android:versionCode="1"    android:versionName="1.0" >    <uses-permission android:name="android.permission.INTERNET"/>    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="18" />    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name="com.example.webviewsample.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>
```

##### Running the application:

Hit on run button,

Google Website (URL) will be loaded and displayed inside the Web view in our app

![WebView in Android: Display a URL](https://www.mindstick.com/blogs/a6152d3b-2ca3-4a03-b61f-f5e740e06444/images/9cbc541b-3ec0-45c3-8277-2afb11edf071.png)

Next, we see how to implement local assets to display in webview and use zooming feature in webview :\

##### [WebView in Android: Display Local Assets](https://www.mindstick.com/blog/10954/WebView%20in%20Android%20Display%20a%20URL#.VgFfbly6bIU)

Thanks for reading this post.

Happy Coding!! J

---

Original Source: https://www.mindstick.com/blog/10954/webview-in-android-display-a-url

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
