How To Convert Website into Professional Android App Using Android Studio, Website-to-android-app

In this Article i will show you how to convert any Website into professional Android App using Android Studio.

 

just follow these steps and your app will be create.

Open Android Studio
Create New Project
File >> New >> New Project
Choose Empty Activity
 – Type Project Name
– Choose SDK version
– Choose Java

Double Click on AndroidManifest.xml

copy this permission and paste in AndroidManifest file before <application tag

step : 1 – <uses-permission android:name=”android.permission.INTERNET”></uses-permission>

step : 02 – open style.xml file form res >> values >> style
find this line
<style name=”AppTheme” parent=”Theme.AppCompat.Light.DarkActionBar”>
and replace with this line, i update DarkActionBar with NoActionBar
<style name=”AppTheme” parent=”Theme.AppCompat.Light.NoActionBar”>

step : 03 – Double Click on main_activity.xml from res >> layout >> activity_main.xml

remove androidx.constraintlayout.widget.ConstraintLayout and add ReletiveLayout
and add <WebView>
Like this

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout 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=”.MainActivity”>

<WebView
android:id=”@+id/webview”
android:layout_width=”match_parent”
android:layout_height=”match_parent” />

</RelativeLayout>

step : 04 – open MainActivity.java file

copy these 3 lines and add in paste after
import androidx.appcompat.app.AppCompatActivity;
this line

import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

step : 05 – type this line
private WebView webView;
after
public class MainActivity extends AppCompatActivity {

step : 05 – 
type these lines after

webView = (WebView) findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(“https://singlewebsolution.com/”);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);

after
setContentView(R.layout.activity_main);

Last Step : type this code at the end

public class mywebClient extends WebViewClient{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon){
super.onPageStarted(view,url,favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view,String url){
view.loadUrl(url);
return true;
}
}
@Override
public void onBackPressed(){
if(webView.canGoBack()) {
webView.goBack();
}
else{
super.onBackPressed();
}
}

Full app code here:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.singlewebsolution">
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

   <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

styles.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity">

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

</RelativeLayout>

MainActivity.java

package com.example.singlewebsolution;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Bitmap;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {
    private WebView webView;

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

        webView = (WebView) findViewById(R.id.webview);
        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl("https://singlewebsolution.com/");
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);

    }

    public class mywebClient extends WebViewClient{
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon){
            super.onPageStarted(view,url,favicon);
        }
        @Override
        public boolean shouldOverrideUrlLoading(WebView view,String url){
            view.loadUrl(url);
            return true;
        }
    }
    @Override
    public void onBackPressed(){
        if(webView.canGoBack()) {
            webView.goBack();
        }
        else{
            super.onBackPressed();
        }
    }

}



connect your device with Android Phone or Emulator and Run
Have a nice day!