WebView 

(Field Listing-FL App)

Contents

  • What is Webview?
  • How to use
  • Methods

What is Webview?

WebView app : Composed primarily of Javascript, CSS, and HTML files. Basically, app is one or more web pages. These web pages make up frontend interface.

 

WebView : The window through which the device displays these web pages.

How to use 

In order to add WebView to your application, you have to add <WebView> element to your xml layout file

Syntax : 

WebView  xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/webview"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
/>
<?xml version="1.0" encoding="utf-8"?>
<WebView 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:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

How to use 

To use it, get a reference of this view . To get a reference, create an object of the class WebView

Syntax : 

WebView browser = (WebView) findViewById(R.id.webview);
_webView = FindViewById<WebView>(Resource.Id.webview);

How to use 

To load a web url into the WebView, you need to call a method loadUrl(String url) of the WebView class, specifying the required url

Syntax : 

browser.loadUrl("http://www.tutorialspoint.com");
// Prepare Web App URL.
string baseUrl = $"http://127.0.0.1:{WebService.ServerPort}/index.html";
string appUrl = ViewModel.CreateRequestUrl(baseUrl);

_webView.LoadUrl(appUrl);

Methods in WebView

Methods Description
canGoBack() Specifies the WebView has a back history item
canGoForward() Specifies the WebView has a forward history item
clearHistory() Clear the WebView forward and backward history
destroy() Destroy the internal state of WebView
findAllAsync(String find) Find all instances of string and highlight them
getProgress() Gets the progress of the curent page
getTitle() Return the title of the current page
getUrl() Return the url of the current page

References

WebView

By nur amirah

WebView

  • 146