{"id":90,"date":"2017-02-02T06:28:40","date_gmt":"2017-02-02T06:28:40","guid":{"rendered":"http:\/\/abhiandroid.com\/createandroidapp\/?page_id=90"},"modified":"2021-08-21T04:26:40","modified_gmt":"2021-08-21T04:26:40","slug":"webview-android-app","status":"publish","type":"page","link":"https:\/\/abhiandroid.com\/createandroidapp\/webview-android-app","title":{"rendered":"WebView Android App: Convert Website Into App Tutorial In Android Studio"},"content":{"rendered":"<p>Have you ever tried converting any website into Android App? If not then let me tell you it is very easy and you will need to use WebView for doing that.<\/p>\n<p>You\u00a0just need the follow the tutorial step by step and application will be ready to go. An element used for that is <strong>Webview<\/strong>, add this element to your XML(layout) file or you can also add it in java class.<\/p>\n<p><em>Also for the good reader we have added Bonus Tip at the end of tutorial to improve look of your WebView App.<\/em><\/p>\n<p>[cp_modal id=&#8221;cp_id_b0a5f&#8221;]<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-149\" src=\"\/createandroidapp\/wp-content\/uploads\/2017\/02\/Download-Code.png\" alt=\"Download-Code\" width=\"439\" height=\"65\" srcset=\"https:\/\/abhiandroid.com\/createandroidapp\/wp-content\/uploads\/2017\/02\/Download-Code.png 439w, https:\/\/abhiandroid.com\/createandroidapp\/wp-content\/uploads\/2017\/02\/Download-Code-300x44.png 300w\" sizes=\"auto, (max-width: 439px) 100vw, 439px\" \/>[\/cp_modal]<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-115\" src=\"\/createandroidapp\/wp-content\/uploads\/2017\/02\/Application-Using-Webview-In-Android-Studio.png\" alt=\"Application Using Webview In Android Studio\" width=\"286\" height=\"563\" srcset=\"https:\/\/abhiandroid.com\/createandroidapp\/wp-content\/uploads\/2017\/02\/Application-Using-Webview-In-Android-Studio.png 286w, https:\/\/abhiandroid.com\/createandroidapp\/wp-content\/uploads\/2017\/02\/Application-Using-Webview-In-Android-Studio-152x300.png 152w\" sizes=\"auto, (max-width: 286px) 100vw, 286px\" \/><br \/>\n<span style=\"color: #008000;\"><strong>Step 1:<\/strong><\/span> The first step is to take a responsive website that you want to convert in android app important point to note is that it should be a responsive(mobile friendly) website. Here we are using our own\u00a0<a href=\"https:\/\/abhiandroid.com\"> Abhiandroid.com<\/a> to convert into android application using WebView which is Mobile responsive site.<\/p>\n<p><span style=\"color: #008000;\"><strong>Step 2:<\/strong><\/span> Create a new project in Android Studio and name it WebViewApp.<\/p>\n<p><span style=\"color: #008000;\"><strong>Step 3:<\/strong><\/span> Open res -&gt; layout -&gt; activity_main.xml (or) main.xml, create the application interface and add webview element to it.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:id=\"@+id\/activity_main\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:paddingBottom=\"@dimen\/activity_vertical_margin\"\r\n    android:paddingLeft=\"@dimen\/activity_horizontal_margin\"\r\n   android:paddingRight=\"@dimen\/activity_horizontal_margin\"\r\n    android:paddingTop=\"@dimen\/activity_vertical_margin\"\r\n    tools:context=\"com.example.webviewapp.MainActivity\"&gt;\r\n \r\n &lt;WebView\r\n        android:id=\"@+id\/webview\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\" \/&gt;\r\n&lt;\/RelativeLayout&gt;\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 4:<\/strong> <\/span> Open src -&gt; package -&gt; MainActivity.java. Here firstly declare a webview variable, make JavaScript enable and load the URL of the website. See the whole code below.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>Important Note:<\/strong><\/span> You can replace our url in below code with any other url you want to convert it into Android App.<\/p>\n<pre>package com.example.webviewapp;\r\n\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.os.Bundle;\r\n        import android.webkit.WebSettings;\r\n        import android.webkit.WebView;\r\n        import android.webkit.WebViewClient;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n    private WebView mywebView;\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n        mywebView = (WebView) findViewById(R.id.webview);\r\n        WebSettings webSettings= mywebView.getSettings();\r\n        webSettings.setJavaScriptEnabled(true);\r\n        mywebView.loadUrl(\"https:\/\/abhiandroid.com\/\");\r\n    }\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 5:<\/strong> <\/span> Open <strong>AndroidManifest.xml file<\/strong> and add internet permission to it just after the package name. It is required because the App will load data directly from the website.<\/p>\n<pre>&lt;uses-permission android:name=\"android.permission.INTERNET\"&gt;&lt;\/uses-permission&gt;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-107\" src=\"\/createandroidapp\/wp-content\/uploads\/2017\/02\/Adding-Internet-Permission-In-Android-Studio.png\" alt=\"Adding Internet Permission In Android Studio\" width=\"615\" height=\"133\" srcset=\"https:\/\/abhiandroid.com\/createandroidapp\/wp-content\/uploads\/2017\/02\/Adding-Internet-Permission-In-Android-Studio.png 615w, https:\/\/abhiandroid.com\/createandroidapp\/wp-content\/uploads\/2017\/02\/Adding-Internet-Permission-In-Android-Studio-300x65.png 300w\" sizes=\"auto, (max-width: 615px) 100vw, 615px\" \/><br \/>\n<span style=\"color: #008000;\"><strong>Step 6:<\/strong><\/span> After adding the permissions the application is complete but when you run you will find that it will open the links in browser not in application itself. Solution for this is add this line of code in your <strong>MainActivity.java<\/strong> class.<\/p>\n<pre> mywebView.setWebViewClient(new WebViewClient());<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 7:<\/strong> <\/span>Now to add back buttons to the application to need to add following code to your <strong>MainActivity.java<\/strong> class.<\/p>\n<pre>    public void onBackPressed() {\r\n        if(mywebView.canGoBack())\r\n        {\r\n            mywebView.goBack();\r\n        }\r\n\r\n        else{\r\n            super.onBackPressed();\r\n        }\r\n    }\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 8:<\/strong> <\/span>Further if you want to remove the additional padding in the app, open activity_main.xml and in the layouts remove the padding(bottom, top, right, left). Here&#8217;s the final code.<br \/>\n<strong>activity_main.xml<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:id=\"@+id\/activity_main\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    tools:context=\"com.example.webviewapp.MainActivity\"&gt;\r\n\r\n\/\/ WebView Element\r\n    &lt;WebView\r\n        android:id=\"@+id\/webview\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\" \/&gt;\r\n&lt;\/RelativeLayout&gt;\r\n<\/pre>\n<p><strong>MainActivity.java complete code:<\/strong><\/p>\n<pre>package com.example.webviewapp;\r\n\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.os.Bundle;\r\nimport android.webkit.WebSettings;\r\nimport android.webkit.WebView;\r\nimport android.webkit.WebViewClient;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n    private WebView mywebView;\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n        mywebView = (WebView) findViewById(R.id.webview);\r\n        WebSettings webSettings= mywebView.getSettings();\r\n        webSettings.setJavaScriptEnabled(true);\r\n        mywebView.loadUrl(\"https:\/\/abhiandroid.com\/\");\r\n        \/\/ Line of Code for opening links in app\r\n        mywebView.setWebViewClient(new WebViewClient());\r\n    }\r\n    \r\n\/\/Code For Back Button\r\n@Override\r\n    public void onBackPressed() {\r\n        if(mywebView.canGoBack())\r\n        {\r\n            mywebView.goBack();\r\n        }\r\n\r\n        else\r\n        {\r\n            super.onBackPressed();\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p><span style=\"color: #ff0000;\"><strong>Bonus Tip For WebView App:<\/strong><\/span> In addition if you want to remove the default action bar, see in image the blue top header. You just need to make a little change in <strong>styles.xml<\/strong> file.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110\" src=\"\/createandroidapp\/wp-content\/uploads\/2017\/02\/Action-Bar-In-Android-Studio.png\" alt=\"Action Bar In Android Studio\" width=\"256\" height=\"229\" \/><br \/>\n<span style=\"color: #008000;\"><strong>app -&gt; res -&gt; values -&gt; styles.xml<\/strong><\/span><br \/>\nJust change theme as NoActionBar. Below code will do<\/p>\n<pre> &lt;style name=\"AppTheme\" parent=\"Theme.AppCompat.Light.NoActionBar\"&gt;<\/pre>\n<hr \/>\n<h4><strong>Output:<\/strong><\/h4>\n<p>Now run the App and you will see WebView App of AbhiAndroid website. You can simply replace the url with any website url you want to convert into Android App.<\/p>\n<h4><strong>How to add progressBar in webview &amp; convert website into advance android app<\/strong><\/h4>\n<p><script src=\"https:\/\/fast.wistia.com\/embed\/medias\/gxrjsqwnhr.jsonp\" async><\/script><script src=\"https:\/\/fast.wistia.com\/assets\/external\/E-v1.js\" async><\/script><\/p>\n<div class=\"wistia_responsive_padding\" style=\"padding: 62.5% 0 0 0; position: relative;\">\n<div class=\"wistia_responsive_wrapper\" style=\"height: 100%; left: 0; position: absolute; top: 0; width: 100%;\">\n<div class=\"wistia_embed wistia_async_gxrjsqwnhr videoFoam=true\" style=\"height: 100%; width: 100%;\"><\/div>\n<\/div>\n<\/div>\n<p><a href=\"\/sourcecode\/webview\/\" target=\"_blank\" rel=\"nofollow noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-271\" src=\"\/createandroidapp\/wp-content\/uploads\/2017\/02\/convert-website-into-android-app-banner.png\" alt=\"Convert-website-into-advance-android-app-banner\" width=\"487\" height=\"331\" srcset=\"https:\/\/abhiandroid.com\/createandroidapp\/wp-content\/uploads\/2017\/02\/convert-website-into-android-app-banner.png 487w, https:\/\/abhiandroid.com\/createandroidapp\/wp-content\/uploads\/2017\/02\/convert-website-into-android-app-banner-300x204.png 300w\" sizes=\"auto, (max-width: 487px) 100vw, 487px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever tried converting any website into Android App? If not then let me tell you it is very easy and you will need to use WebView for doing that. You\u00a0just need the follow the tutorial step by step and application will be ready to go. An element used for that is Webview, add &hellip; <a href=\"https:\/\/abhiandroid.com\/createandroidapp\/webview-android-app\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">WebView Android App: Convert Website Into App Tutorial In Android Studio<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"home.php","meta":{"footnotes":""},"class_list":["post-90","page","type-page","status-publish","hentry"],"psp_head":"<title>WebView Android App: Convert Website Into App Tutorial In Android Studio \u2013 Create Android App<\/title>\r\n<meta name=\"description\" content=\"Have you ever tried converting any website into Android App? If not then let me tell you it is very easy and you will need to use WebView for doing that.\" \/>\r\n<meta name=\"robots\" content=\"index,follow\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/abhiandroid.com\/createandroidapp\/webview-android-app\" \/>\r\n","_links":{"self":[{"href":"https:\/\/abhiandroid.com\/createandroidapp\/wp-json\/wp\/v2\/pages\/90","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/abhiandroid.com\/createandroidapp\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/abhiandroid.com\/createandroidapp\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/createandroidapp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/createandroidapp\/wp-json\/wp\/v2\/comments?post=90"}],"version-history":[{"count":3,"href":"https:\/\/abhiandroid.com\/createandroidapp\/wp-json\/wp\/v2\/pages\/90\/revisions"}],"predecessor-version":[{"id":322,"href":"https:\/\/abhiandroid.com\/createandroidapp\/wp-json\/wp\/v2\/pages\/90\/revisions\/322"}],"wp:attachment":[{"href":"https:\/\/abhiandroid.com\/createandroidapp\/wp-json\/wp\/v2\/media?parent=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}