How to Convert Any Website to Android App in Android Studio?

Here, we are going to make an application for the “GeeksForGeeks” website. By making this application we will be able to learn that how we can convert a website to an Android Application just by following simple steps. You can use this concept for your personal website too and learn something new. What we are going to build in this article? In this application, we will learn that how we can use different portals of a website and show them as fragments in our android application. In this application three portals of Geeksforgeeks website- Home, Practice and Contribute will be used as fragments in our application. So, that you can see a live example to convert a website to an application. The concept of WebView is used to do this desired work. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language. Simple Steps to Convert Your Website into an Android Application:To add the logo of your application.To add a splash screen to your application.To use Navigation drawer in our application so that, different portals of our website can be used as fragments in the navigation drawer.To use a WebView so that, the web content can be accessed easily.To use WebViewController class so that the content on the Website can be directly shown in the application rather than opening it in the browser.To add a helpline activity.And by following these steps you can convert your website to an application in the simplest way. So, let us see step-by-step implementation to convert GeeksForGeeks Website to an application.Step by Step ImplementationStep 1: Creating a new projectOpen a new project.We will be working on Navigation Drawer Activity with language as Java. Leave all other options unchanged.You can change the name of the project at your convenience.There will be many default files. If you don’t know how to create a new project in Android Studio then you can refer to How to Create/Start a New Project in Android Studio? Step 2: To add a logo to our applicationStep 3: To add Splash Screen to our applicationFollow-“Creating a Splash Screen” to learn how to add a splash screen to our application. Sample design of splash screen of our application. Step 4: Working with xml filesOpen layout > nav_header_main.xml file to design the header of our Navigation Drawer. For that use the following code in it.XML                      After implementing the above code, the header of the Navigation Drawer looks like this: Change the color of the Action Bar to “#6C6B74” so that it can match the color code of the logo of our application and our UI can become more attractive. If you do not know how to change the color of the ActionBar then you can click here to learn it. Open menu > activity_main_drawer.xml file and use the following code in it so that we can add different items(portals of our website) to our navigation drawer and use their fragments.XML                                                                                                 After implementing the above code our design of the activity_main_drawer.xml file looks like this.  Go to the layout > activity_main.xml and use the following code in it.XML                               After implementing the above code design of activity_main.xml file looks like. Go to the navigation > mobile_navigation.xml file and use the following code in it so that we can specify the title and label of our website portals and can easily use them in java files.XML                                                              Now it’s time to insert WebView in all the fragments – Open fragment_home, fragment_gallery, fragment_slideshow XML files and use the code respectively. XML                                XML            XML            Now we have to create a new Activity named “help“. So that, the application user can get info to take help from the service provider. Go to layout > right-click > new > activity > empty activity Put the name of the activity according to your choice(name used in this application-“help”). Open layout > activity_help.xml and use the following code in it.XML                                             After implementing the above code, the design of the activity_help.xml file looks like this. Now we have added a piece of code to take permission for access to the internet so that our WebView can work easily. Go to manifests > AndroidManifest.xml file and add the following code to it.Step 5: Working with java filesCreate a new java class as shown below and name it as “WebViewController“ Use the following code in the WebViewController.java file so that code to use the URL of a website can be executed.Javapackage com.example.geeksforgeeks;  import android.webkit.WebView;import android.webkit.WebViewClient;  public class WebViewController extends WebViewClient {    @Override    public boolean shouldOverrideUrlLoading(WebView view, String url) {                        view.loadUrl(url);        return true;    }}Open HomeFragment, GalleryFragment, SlideshowFragment java files and use the code respectively.Javapackage com.example.geeksforgeeks.ui.home;  import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.webkit.WebView;  import androidx.annotation.NonNull;import androidx.fragment.app.Fragment;import androidx.lifecycle.ViewModelProvider;  import com.example.geeksforgeeks.R;import com.example.geeksforgeeks.WebViewController;  public class HomeFragment extends Fragment {      private HomeViewModel homeViewModel;      public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {                  homeViewModel = new ViewModelProvider(this).get(HomeViewModel.class);        View root = inflater.inflate(R.layout.fragment_home, container, false);                  WebView webView = root.findViewById(R.id.web_view_home);        webView.setWebViewClient(new WebViewController());          return root;    }}Javapackage com.example.geeksforgeeks.ui.gallery;  import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.webkit.WebView;  import androidx.annotation.NonNull;import androidx.fragment.app.Fragment;import androidx.lifecycle.ViewModelProvider;  import com.example.geeksforgeeks.R;import com.example.geeksforgeeks.WebViewController;  public class GalleryFragment extends Fragment {      private GalleryViewModel galleryViewModel;      public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {                  galleryViewModel = new ViewModelProvider(this).get(GalleryViewModel.class);        View root = inflater.inflate(R.layout.fragment_gallery, container, false);          WebView webView = root.findViewById(R.id.web_view_practice);        webView.setWebViewClient(new WebViewController());        return root;    }}Javapackage com.example.geeksforgeeks.ui.slideshow;  import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.webkit.WebView;  import androidx.annotation.NonNull;import androidx.fragment.app.Fragment;import androidx.lifecycle.ViewModelProvider;  import com.example.geeksforgeeks.R;import com.example.geeksforgeeks.WebViewController;  public class SlideshowFragment extends Fragment {      private SlideshowViewModel slideshowViewModel;      public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {                  slideshowViewModel = new ViewModelProvider(this).get(SlideshowViewModel.class);        View root = inflater.inflate(R.layout.fragment_slideshow, container, false);          WebView webView = root.findViewById(R.id.web_view_contribute);        webView.setWebViewClient(new WebViewController());        return root;    }}Now all of our work is done and the last work is to connect the help activity to the floating button in our application with help of intent in the MainActivity.java file. Use the following code to do so.Javapackage com.example.geeksforgeeks;  import android.content.Intent;import android.os.Bundle;import android.view.Menu;import android.view.View;  import androidx.appcompat.app.AppCompatActivity;import androidx.appcompat.widget.Toolbar;import androidx.drawerlayout.widget.DrawerLayout;import androidx.navigation.NavController;import androidx.navigation.Navigation;import androidx.navigation.ui.AppBarConfiguration;import androidx.navigation.ui.NavigationUI;  import com.google.android.material.floatingactionbutton.FloatingActionButton;import com.google.android.material.navigation.NavigationView;  public class MainActivity extends AppCompatActivity {      private AppBarConfiguration mAppBarConfiguration;      @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        Toolbar toolbar = findViewById(R.id.toolbar);        setSupportActionBar(toolbar);                  FloatingActionButton fab = findViewById(R.id.fab);                          fab.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                                Intent activity2Intent = new Intent(getApplicationContext(), help.class);                startActivity(activity2Intent);            }        });                  DrawerLayout drawer = findViewById(R.id.drawer_layout);        NavigationView navigationView = findViewById(R.id.nav_view);                          mAppBarConfiguration = new AppBarConfiguration.Builder(                R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow)                .setDrawerLayout(drawer)                .build();                  NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);        NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);        NavigationUI.setupWithNavController(navigationView, navController);    }      @Override    public boolean onCreateOptionsMenu(Menu menu) {                        getMenuInflater().inflate(R.menu.main, menu);        return true;    }      @Override    public boolean onSupportNavigateUp() {        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);        return NavigationUI.navigateUp(navController, mAppBarConfiguration)                || super.onSupportNavigateUp();    }}Note: In MainActivity.java whole code is by default or pre-existing we have just added intent code to connect help activity with the floating button.Output:If you want to take help or import the project then you can visit the GitHub link: https://github.com/Karan-Jangir/GeeksForGeeks/tree/master