How to make an app WebView in android (with source code)


 

Download APK Download Source Code Contact Us

Step1:­ Create new project in Android Studio.

How to make an app WebView in android
How to make an app WebView in android

What is WebView?

WebView is a view that dispaly web page inside your application. You can also specify HTML
string and can show it inside your application using WebView.

Step 2:­ You must add the internet permissions to your AndroidManifest file.

How to make an app WebView in android

step 3:­ Adding a WebView to your Application.

<WebView> element to your xml layout file.

Ex:­<?xml version="1.0" encoding="utf­8"?>

<WebView xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/webview"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

/>

Step 4:­ Accessing the WebView from code.

How to make an app WebView in android

Step 5:­ Loading the url into the WebView.

Load Web page in the WebView,use loadurl().
EX:­WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");

How to make an app WebView in android

Step:6­ Enabling JavaScript in the WebVIew.

By default the Android WebView component has JavaScript disabled. You can enable through the WebSetting attached to your WebView.

Ex:­WebView myWebView = (WebView) findViewById(R.id.webview);

WebSettings webSettings = myWebView.getSettings();

webSettings.setJavaScriptEnabled(true);

setMinimumFontSize(int size):­ Set the minimum font size. The default is 8.

webSettings.setMinimumFontSize(10);

setMediaPlaybackRequiresGesture(boolean require):­ Set whether the WebView requires a user

gesture to play media. The default is true.

webSettings. setMediaPlaybackRequiresGesture();

setTextZoom(int textZoom):­ Set the text zoom of the page in percent. The default is 100.

webSettins.setTextZoom(150);

Step:7­ Handling Page Navigation.

When the user click a link in the web page loaded into the WebView.the default behaviour is to load that URL of the link in the system Android browser.

To open links clicked by the user, simply provide a WebViewClient for your WebView, using

setWebViewClient().

Ex:­WebView myWebView = (WebView) findViewById(R.id.webview);

myWebView.setWebViewClient(new WebViewClient());

private class MyWebViewClient extends WebViewClient {

@Override

public boolean shouldOverrideUrlLoading(WebView webView, String url) {

return false;

}

}

How to make an app WebView in android

Download APK Download Source Code Contact Us

Posted in All Tutorials, Android Tutorials | Tagged | 1 Comment

One Response to How to make an app WebView in android (with source code)

  1. Arun says:

    WEBview helps to move the control to a WEB URL – is there an option to move back from WEB URL to app screen? I mean is there any option we can implement in our WEB application to move the control back to App?

Leave a Reply

Your email address will not be published. Required fields are marked *

Powered By: wpnova.com