Free Education

Online Education

Android Studio

Webview Source Code for Android Studio

WebView Source Code, Hello android developer. in this article, I will tell you how to browse web site using WebView. using WebView you can display web pages inside your application.to create web view application you can apply this code. detail code has been given down the line.

Also, note that the Webview code will require the Internet so you will have to first modify the AndroidManifests.xml file and add the following code to it.

AndroidManifest.xml:

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

XML (activity_main.xml)

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".WebView">


    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/web"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

JAVA (MainActivity.java)

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebViewClient;

public class WebView extends Activity {

    private android.webkit.WebView m;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_view);

        m=(android.webkit.WebView)findViewById(R.id.web);
        WebSettings webSettings =m.getSettings();
        webSettings.setJavaScriptEnabled(true);
        m.setWebViewClient(new WebViewClient());
        m.loadUrl("https://www.google.com/");

    }
 }

You can directly copy our Webview code and paste it to your android studio, and they should work perfectly. Just save and run your project. Comment down below if you are facing any problems.

output

WebView Source Code

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *