<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
Navigate to the manifest.xml and add the internet permission, if you don’t add this permission you App won’t display because it can’t access the internet.
Add this above the <application></application>
<uses-permission android:name="android.permission.INTERNET"/>
Navigate to the activity_main.xml in the layout folder and add this following lines of code to display the website or blog
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!--This view is responsible for the display fo your website or blog-->
<WebView
android:id="@+id/webby"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!--This view is responsible for the display fo your website or blog-->
<WebView
android:id="@+id/webby"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
Navigate to the MainActivity.java and add this following lines of code
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
//Strore the URL of the website inside a String variable called //url
private String url = "https://wwww.rexandroid.blogspot.com";
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initialize the webview by calling findViewById
webView = findViewById(R.id.webby);
//get the web setiimgs
//set for javascript containing site
webView.getSettings().setJavaScriptEnabled(true);
//responsible for opening links inside the app
webView.setWebViewClient(new WebViewClient());
//load the url of the blog you stored inside @url
webView.loadUrl(url);
}
//This prevent the App from closing when you press the back key to //go to the previous page
@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}
}
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
//Strore the URL of the website inside a String variable called //url
private String url = "https://wwww.rexandroid.blogspot.com";
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initialize the webview by calling findViewById
webView = findViewById(R.id.webby);
//get the web setiimgs
//set for javascript containing site
webView.getSettings().setJavaScriptEnabled(true);
//responsible for opening links inside the app
webView.setWebViewClient(new WebViewClient());
//load the url of the blog you stored inside @url
webView.loadUrl(url);
}
//This prevent the App from closing when you press the back key to //go to the previous page
@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}
}
If you wanna add some other functionality to your App like progress bar etc., feel free to do so.
If you need any help, feel free to drop your comment in the comment box.
4 comments:
Hello,,
Very nice information you provide.In this blog the complete information about how to Convert our website into an Android App. Also knowledgable information to make website mobile friendly and responsive.
Thanks and Regards
paridhi
Thanks for sharing such valuable information I am also impressed by the creativity of the writer. This is
excellent information. It is amazing and wonderful to visit your site. how can your website be converted into a selling "
Hello,
The information provide by you is very useful for me.I get knowledge that how to develop and grow my business.
Thanks and Regards
Paridhi jain
Online training and short courses are a great way to learn and advance in career and I think more people should move towards it
Post a Comment