Description

Android webView is used to display the content in the web browser content in Android devices. We are using Android palette toolbox to drag and drop the controls in design interface provided by Android Studio. Here, webView control is used to display the content of the web browser which has .htm or .html extension file. WebView can also be used by declaring html tags in string datatype. The content of the browser is adjustable according to the device size. It has two methods loadData and loadUrl.

In loadData, we have to declare string datatype variable which consists HTML tags and related data in it while in loadUrl you can declare URL of a webpage from where the data is coming. Along with these methods, we can also use other methods that can be used for full functioning web browser data. There are many methods as follow as: -

canGOBack() : This method is used to go backwards when browser has history or previously visited window.

canGoForForward(): This method can be used to move forward direction of the web browser or requesting for new content.

clearHistory(): It is used to clear the previously visited URL web pages from the browser.

clearCache(): This method is used to delete the cache data such as cookies, bookmarks etc.

Autofill(SpareArray[]): it is used when you want to fill all content which is same previously used then this feature fill the data corresponding to their child.

getTittle() : it holds the title of web page.

getUrl();- it brings the URL which the user has requested.

getProgress() :- it returns the progress going on the web browser. To show progress on the Activity title bar, we use getWindows().getFeatures(Windows.FEATURE_PROGRESS) , where FEATURE_PROGESSS is constant value.

 To get the settings of web browser, we can use webview object and followed by dot operator with getSettings() method and enable and disable features

                         Ex: - webviewObject.getSettings().SetJavaScriptEnabled(true);

 To handle the content on the web browser we can declare setWebChrome() listener with the webview object.

 To enable zoom in and out feature in your application, we can use setBultinZoomControls(true);

 For safe browsing ability in your application and devices, we can declare following tag in Android_Manifest.xml

<meta-data android:name=”android.webkit.WebView.EnabledSafeBrowsing” android:value=”true”/>

 To get content online from the browser URL and display it , we can declare tag in Android_Manifest.xml

	 <uses-permission android:name=”android.permission.INTERNET”
/>

Android_Mainfest.xml 

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mapsample.msclient009.webview">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Main_activity.xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.mapsample.msclient009.webview.MainActivity">


    <WebView
        android:id="@+id/webdata"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>
Main_Activity.java
package com.mapsample.msclient009.webview;


        import android.support.v7.app.AppCompatActivity;
        import android.os.Bundle;
        import android.view.Menu;
        import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {
    WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate ( savedInstanceState );
        setContentView ( R.layout.activity_main );
        webView =(WebView)findViewById ( R.id.webdata );
        String url = "<html><head></head><body><h1 style='font-family:sans-serif;color:#FF0044; font-size:1.2em;'>Hello Android</h1><p align=\"center\" style=\"font-family:new times roman\">\n" +
                "The content is design for webView technology in Android. In this technology, we learn about fetching and supplying into the devices.\n" +
                "</p></body></html>";
          webView.loadData ( url,"text/html","UTF-8" );
}

                                   Android WebView Control

  Modified On Mar-27-2018 04:00:34 AM

Leave Comment