How to display website in an android app using WebView component?

Please Share On:

Are you looking for a way to display your website in your android app page? Then, you are in the right page.

Today, I am going to show you how can you display your entire website in your android app.

Here are the thing you need to follow:

  1. Provide Internet Permission.
  2. Create your .XML file
  3. Your java code to open your website in android app page.

Let proceed from step 1 to step 3

1) Provide Internet Permission

You need to add a “user-permission”for the user to access the internet. So, add the below line of code inside your project’s AndroidManifest.xml file.

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

2) activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/background">


    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".BrowserActivity"
        android:id="@+id/webView"/>
</RelativeLayout>

3) MainActivity.java

package com.elsebazaar.webView;

import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;


public class MainActivity {
   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Get Reference of WebView
        WebView webview = findViewById(R.id.webView);

        //load webview
        webview.setWebViewClient(new WebViewClient());
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setDomStorageEnabled(true);
        webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
        webview.loadUrl("https://www.elsebazaar.com/blog");
    }
 }

Result:

That’s it. Now you run your app and see the output.



You may interest on the following topics:

Leave a Reply

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

Copyright @2023. All Right Reserved.


Social media & sharing icons powered by UltimatelySocial