WebView in Android

In this tutorial we will learn how to use a WebView in Android. We use WebView to show webpages in Android. Using webview you can load webpage from same application or you can load webpage from any url. To use webview in android you must have internet permission in you android mainfest file. In this tutorial we will learn how to add WebView in Android XML file and how to load URL in this WebView using our Java file.

WebView in Android

Before doing anything we will add Internet permission in our AndroidManifest.xml file. Because without Internet permission our web view will not work.

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

Now we will move to our next step. So start with our XML file. In this we will add Web View widget in out activity.

XML Example: -
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:orientation="vertical" tools:context=".MainActivity"> <WebView android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>tStyle="bold" /> </LinearLayout>

After adding this XML code in XML layout file add this code to Java file where we will write code to load a web page in our WebView.


public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

       final WebView webView=findViewById(R.id.webView);


After adding this code in Java file run project and you will get Google Home page on your acivity because we have written URL of google in loadURl method of WebView class. Here you can try to load different URLs. Check Output of this project.

WebView in Android

Share this tutorial with your friends on your social Media..

WebView in Android WebView in Android WebView in Android WebView in Android

Now You Can Follow All These Tutorials on Your Android Mobile Just Download This App.