Android Apps

How to Convert a Website into Android Application using Android Studio

In this tutorial I show you how to convert a website into an Android Application using Android Studio

Create a project.

Step 1 – Create a new Android project.

Provide Activity name as Themewerk

Step 2 – Add an webView to your activity as shown in the picture below.

convert-website-to-app

layout/activity_main.xml

 
 
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  3.     android:layout_height="match_parent"
  4.     tools:context=".MainActivity">
  5.     <WebView
  6.         android:layout_width="fill_parent"
  7.         android:layout_height="fill_parent"
  8.         android:id="@+id/webView"
  9.         android:layout_alignParentLeft="true"
  10.         android:layout_alignParentStart="true"
  11.         android:layout_alignParentTop="true"
  12.         android:layout_alignParentRight="true"
  13.         android:layout_alignParentEnd="true" />
  14. </RelativeLayout>


src/main/AndroidManifest.xml

 
 
  1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2.     package="com.themewerk" >
  3.     <uses-permission android:name="android.permission.INTERNET"></uses-permission>
  4.     <application
  5.         android:allowBackup="true"
  6.         android:icon="@drawable/ic_launcher"
  7.         android:label="@string/app_name"
  8.         android:theme="@style/AppTheme" >
  9.         <activity
  10.             android:name=".MainActivity"
  11.             android:label="@string/app_name" >
  12.             <intent-filter>
  13.                 <action android:name="android.intent.action.MAIN" />
  14.  
  15.                 <category android:name="android.intent.category.LAUNCHER" />
  16.             </intent-filter>
  17.         </activity>
  18.     </application>
  19.  
  20. </manifest>


MainActivity.java

 
 
  1. package com.themewerk;
  2. import android.support.v7.app.ActionBarActivity;
  3. import android.os.Bundle;
  4. import android.view.Menu;
  5. import android.view.MenuItem;
  6. import android.webkit.WebSettings;
  7. import android.webkit.WebView;
  8. import android.webkit.WebViewClient;
  9. public class MainActivity extends ActionBarActivity {
  10.     private WebView myWebView;
  11.     @Override
  12.     protected void onCreate(Bundle savedInstanceState) {
  13.         super.onCreate(savedInstanceState);
  14.         setContentView(R.layout.activity_main);
  15.         myWebView = (WebView)findViewById(R.id.webView);
  16.         WebSettings webSettings = myWebView.getSettings();
  17.         webSettings.setJavaScriptEnabled(true);
  18.         myWebView.loadUrl("http://www.themewerk.com");
  19.         myWebView.setWebViewClient(new WebViewClient());
  20.     }
  21.     @Override
  22.     public void onBackPressed() {
  23.         if(myWebView.canGoBack()) {
  24.             myWebView.goBack();
  25.         } else {
  26.             super.onBackPressed();
  27.         }
  28.     }
  29.     @Override
  30.     public boolean onCreateOptionsMenu(Menu menu) {
  31.         // Inflate the menu; this adds items to the action bar if it is present.
  32.         getMenuInflater().inflate(R.menu.menu_main, menu);
  33.         return true;
  34.     }
  35.     @Override
  36.     public boolean onOptionsItemSelected(MenuItem item) {
  37.         // Handle action bar item clicks here. The action bar will
  38.         // automatically handle clicks on the Home/Up button, so long
  39.         // as you specify a parent activity in AndroidManifest.xml.
  40.         int id = item.getItemId();
  41.         //noinspection SimplifiableIfStatement
  42.         if (id == R.id.action_settings) {
  43.             return true;
  44.         }
  45.         return super.onOptionsItemSelected(item);
  46.     }
  47. }


menu/menu_main.xml

 
 
  1. <menu xmlns:android="http://schemas.android.com/apk/res/android"
  2.     xmlns:app="http://schemas.android.com/apk/res-auto"
  3.     xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
  4.     <item android:id="@+id/action_settings" android:title="@string/action_settings"
  5.         android:orderInCategory="100" app:showAsAction="never" />
  6. </menu>

Merken

Merken

Merken