Added in API level 1

WebView


open class WebView : AbsoluteLayout, ViewGroup.OnHierarchyChangeListener, ViewTreeObserver.OnGlobalFocusChangeListener
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.AbsoluteLayout
   ↳ android.webkit.WebView

A View that displays web pages.

Basic usage

In most cases, we recommend using a standard web browser, like Chrome, to deliver content to the user. To learn more about web browsers, read the guide on invoking a browser with an intent.

WebView objects allow you to display web content as part of your activity layout, but lack some of the features of fully-developed browsers. A WebView is useful when you need increased control over the UI and advanced configuration options that will allow you to embed web pages in a specially-designed environment for your app.

To learn more about WebView and alternatives for serving web content, read the documentation on Web-based content.

Summary

Nested classes
abstract

Interface to listen for find results.

open

abstract

Interface to listen for new pictures as they change.

abstract

Callback interface supplied to postVisualStateCallback for receiving notifications about the visual state.

open

Transportation object for returning WebView across thread boundaries.

Inherited XML attributes
Constants
static Int

This is the medium binding priority for the WebView renderer process.

static Int

This is the highest binding priority for the WebView renderer process, and the default value WebView uses to bind to the renderer process.

static Int

This is the lowest binding priority for the WebView renderer process.

static String

URI scheme for map address.

static String

URI scheme for email address.

static String

URI scheme for telephone number.

Inherited constants
Public constructors
WebView(context: Context)

Constructs a new WebView with an Activity Context object.

WebView(context: Context, attrs: AttributeSet?)

Constructs a new WebView with layout parameters.

WebView(context: Context, attrs: AttributeSet?, defStyleAttr: Int)

Constructs a new WebView with layout parameters and a default style.

WebView(context: Context, attrs: AttributeSet?, defStyleAttr: Int, privateBrowsing: Boolean)

Constructs a new WebView with layout parameters and a default style.

WebView(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int)

Constructs a new WebView with layout parameters and a default style.

Public methods
open Unit

Injects the supplied Java object into this WebView.

open Unit

Automatically fills the content of the virtual children within this view.

open Boolean

Gets whether this WebView has a back history item.

open Boolean

Gets whether the page can go back or forward the given number of steps.

open Boolean

Gets whether this WebView has a forward history item.

open Boolean

Gets whether this WebView can be zoomed in.

open Boolean

Gets whether this WebView can be zoomed out.

open Picture!

Gets a new picture that captures the current contents of this WebView.

open Unit
clearCache(includeDiskFiles: Boolean)

Clears the resource cache.

open static Unit

Clears the client certificate preferences stored in response to proceeding/cancelling client cert requests.

open Unit

Removes the autocomplete popup from the currently focused form field, if present.

open Unit

Tells this WebView to clear its internal back/forward list.

open Unit

Clears the highlighting surrounding text matches created by findAllAsync.

open Unit

Clears the SSL preferences table stored in response to proceeding with SSL certificate errors.

open Unit

Clears this WebView so that onDraw() will draw nothing but white background, and onMeasure() will return 0 if MeasureSpec is not MeasureSpec.

open Unit

Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary.

open WebBackForwardList

Gets the WebBackForwardList for this WebView.

open PrintDocumentAdapter!

open PrintDocumentAdapter

Creates a PrintDocumentAdapter that provides the content of this WebView for printing.

open Array<WebMessagePort!>

Creates a message channel to communicate with JS and returns the message ports that represent the endpoints of this message channel.

open Unit

Destroys the internal state of this WebView.

open static Unit

Indicate that the current process does not intend to use WebView, and that an exception should be thrown if a WebView is created or any other methods in the android.

open Unit

Dispatch to collect the ViewTranslationRequests for translation purpose by traversing the hierarchy when the app requests ui translation.

open Boolean

Dispatch a key event to the next view on the focus path.

open Unit

Queries the document to see if it contains any image references.

open static Unit

For apps targeting the L release, WebView has a new default behavior that reduces memory footprint and increases performance by intelligently choosing the portion of the HTML document that needs to be drawn.

open Unit
evaluateJavascript(script: String, resultCallback: ValueCallback<String!>?)

Asynchronously evaluates JavaScript in the context of the currently displayed page.

open static String?

Gets the first substring which appears to be the address of a physical location.

open Int
findAll(find: String!)

Finds all instances of find on the page and highlights them.

open Unit

Finds all instances of find on the page and highlights them, asynchronously.

open View!

Find the view in the hierarchy rooted at this view that currently has focus.

open Unit
findNext(forward: Boolean)

Highlights and scrolls to the next match found by findAllAsync, wrapping around page boundaries as necessary.

open Unit
flingScroll(vx: Int, vy: Int)

open Unit

Informs this WebView that memory is low so that it can free any available memory.

open CharSequence!

Return the class name of this object to be used for accessibility purposes.

open AccessibilityNodeProvider!

Gets the provider for managing a virtual view hierarchy rooted at this View and reported to android.accessibilityservice.AccessibilityServices that explore the window content.

open SslCertificate?

Gets the SSL certificate for the main top-level page or null if there is no certificate (the site is not secure).

open Int

Gets the height of the HTML content.

open static PackageInfo?

If WebView has already been loaded into the current process this method will return the package that was used to load it.

open Bitmap?

Gets the favicon for the current page.

open Handler!

open WebView.HitTestResult

Gets a HitTestResult based on the current cursor node.

open Array<String!>?

Retrieves HTTP authentication credentials for a given host and realm from the WebViewDatabase instance.

open String?

Gets the original URL for the current page.

open Int

Gets the progress for the current page.

open Boolean

Return whether this WebView requests a priority of RENDERER_PRIORITY_WAIVED when not visible.

open Int

Get the requested renderer priority for this WebView.

open static Uri

Returns a URL pointing to the privacy policy for Safe Browsing reporting.

open Float

Gets the current scale of this WebView.

open WebSettings

Gets the WebSettings object used to control the settings for this WebView.

open TextClassifier

Returns the TextClassifier used by this WebView.

open String?

Gets the title for the current page.

open String?

Gets the URL for the current page.

open WebChromeClient?

Gets the chrome handler.

open static ClassLoader

Returns the ClassLoader used to load internal WebView classes.

open WebViewClient

Gets the WebViewClient.

open Looper

Returns the Looper corresponding to the thread on which WebView calls must be made.

open WebViewRenderProcess?

Gets a handle to the WebView renderer process associated with this WebView.

open WebViewRenderProcessClient?

Gets the renderer client object associated with this WebView.

open Unit

Goes back in the history of this WebView.

open Unit

Goes to the history item that is the number of steps away from the current item.

open Unit

Goes forward in the history of this WebView.

open Unit

Invokes the graphical zoom picker widget for this WebView.

open Boolean

Gets whether private browsing is enabled in this WebView.

open Boolean

Computes whether this virtual autofill view is visible to the user.

open Unit
loadData(data: String, mimeType: String?, encoding: String?)

Loads the given data into this WebView using a 'data' scheme URL.

open Unit
loadDataWithBaseURL(baseUrl: String?, data: String, mimeType: String?, encoding: String?, historyUrl: String?)

Loads the given data into this WebView, using baseUrl as the base URL for the content.

open Unit

Loads the given URL.

open Unit
loadUrl(url: String, additionalHttpHeaders: MutableMap<String!, String!>)

Loads the given URL with additional HTTP headers, specified as a map from name to value.

open WindowInsets!

Called when the view should apply WindowInsets according to its internal policy.

open Boolean

Check whether the called view is a text editor, in which case it would make sense to automatically display a soft input window for it.

open Unit
onChildViewAdded(parent: View!, child: View!)

open Unit
onChildViewRemoved(p: View!, child: View!)

open InputConnection!

Creates a new InputConnection for an InputMethod to interact with the WebView.

open Unit
onCreateVirtualViewTranslationRequests(virtualIds: LongArray, supportedFormats: IntArray, requestsCollector: Consumer<ViewTranslationRequest!>)

Collects ViewTranslationRequests which represents the content to be translated for the virtual views in the host view.

open Boolean

Handles drag events sent by the system following a call to startDragAndDrop().

open Unit

Called after onStartTemporaryDetach when the container is done changing the view.

open Boolean

Implement this method to handle generic motion events.

open Unit
onGlobalFocusChanged(oldFocus: View!, newFocus: View!)

open Boolean

Implement this method to handle hover events.

open Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)

Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KeyEvent.KEYCODE_DPAD_CENTER or KeyEvent.KEYCODE_ENTER is released, if the view is enabled and clickable.

open Boolean
onKeyMultiple(keyCode: Int, repeatCount: Int, event: KeyEvent!)

Default implementation of KeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle the event).

open Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)

Default implementation of KeyEvent.Callback.onKeyUp(): perform clicking of the view when KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER or KeyEvent.KEYCODE_SPACE is released.

open Unit

Does a best-effort attempt to pause any processing that can be paused safely, such as animations and geolocation.

open Unit

Populates a ViewStructure containing virtual children to fullfil an autofill request.

open Unit

Populates a ViewStructure for content capture.

open Unit

Called when assist structure is being retrieved from a view as part of Activity.onProvideAssistData to generate additional virtual structure under this view.

open PointerIcon?
onResolvePointerIcon(event: MotionEvent, pointerIndex: Int)

Resolve the pointer icon that should be used for specified pointer in the motion event.

open Unit

Resumes a WebView after a previous call to onPause.

open Unit

This is called when a container is going to temporarily detach a child, with ViewGroup.detachViewFromParent.

open Boolean

Implement this method to handle pointer events.

open Boolean

Implement this method to handle trackball motion events.

open Unit

Called when the content from View.onCreateVirtualViewTranslationRequests had been translated by the TranslationService.

open Unit
onWindowFocusChanged(hasWindowFocus: Boolean)

Called when the window containing this view gains or loses focus.

open Boolean

Gets whether horizontal scrollbar has overlay style.

open Boolean

Gets whether vertical scrollbar has overlay style.

open Boolean
pageDown(bottom: Boolean)

Scrolls the contents of this WebView down by half the page size.

open Boolean

Scrolls the contents of this WebView up by half the view size.

open Unit

Pauses all layout, parsing, and JavaScript timers for all WebViews.

open Boolean

Calls this view's OnLongClickListener, if it is defined.

open Unit
postUrl(url: String, postData: ByteArray)

Loads the URL with postData using "POST" method into this WebView.

open Unit

Posts a VisualStateCallback, which will be called when the current state of the WebView is ready to be drawn.

open Unit
postWebMessage(message: WebMessage, targetOrigin: Uri)

Post a message to main frame.

open Unit

Reloads the current URL.

open Unit

Removes a previously injected Java object from this WebView.

open Boolean
requestChildRectangleOnScreen(child: View, rect: Rect!, immediate: Boolean)

Called when a child of this group wants a particular rectangle to be positioned onto the screen.

open Boolean
requestFocus(direction: Int, previouslyFocusedRect: Rect!)

Call this to try to give focus to a specific view or to one of its descendants and give it hints about the direction and a specific rectangle that the focus is coming from.

open Unit

Requests the anchor or image element URL at the last tapped point.

open Unit

Requests the URL of the image last touched by the user.

open WebBackForwardList?
restoreState(inState: Bundle)

Restores the state of this WebView from the given Bundle.

open Unit

Resumes all layout, parsing, and JavaScript timers for all WebViews.

open Unit
savePassword(host: String!, username: String!, password: String!)

Sets a username and password pair for the specified host.

open WebBackForwardList?
saveState(outState: Bundle)

Saves the state of this WebView used in android.

open Unit

Saves the current view as a web archive.

open Unit
saveWebArchive(basename: String, autoname: Boolean, callback: ValueCallback<String!>?)

Saves the current view as a web archive.

open Unit

Sets the background color for this view.

open Unit

Sets the SSL certificate for the main top-level page.

open static Unit

Define the directory used to store WebView data for the current process.

open Unit

Registers the interface to be used when content can not be handled by the rendering engine, and should be downloaded instead.

open Unit

Registers the listener to be notified as find-on-page operations progress.

open Unit

Specifies whether the horizontal scrollbar has overlay style.

open Unit
setHttpAuthUsernamePassword(host: String!, realm: String!, username: String!, password: String!)

Stores HTTP authentication credentials for a given host and realm to the WebViewDatabase instance.

open Unit
setInitialScale(scaleInPercent: Int)

Sets the initial scale for this WebView.

open Unit
setLayerType(layerType: Int, paint: Paint?)

Specifies the type of layer backing this view.

open Unit

Set the layout parameters associated with this view.

open Unit

open Unit

Informs WebView of the network state.

open Unit

Set the over-scroll mode for this view.

open Unit

Sets the Picture listener.

open Unit
setRendererPriorityPolicy(rendererRequestedPriority: Int, waivedWhenNotVisible: Boolean)

Set the renderer priority policy for this WebView.

open static Unit

Sets the list of hosts (domain names/IP addresses) that are exempt from SafeBrowsing checks.

open Unit

Specify the style of the scrollbars.

open Unit

Sets the TextClassifier for this WebView.

open Unit

Specifies whether the vertical scrollbar has overlay style.

open Unit

Sets the chrome handler.

open static Unit

Enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of this application.

open Unit

Sets the WebViewClient that will receive various notifications and requests.

open Unit

Sets the renderer client object associated with this WebView.

open Unit
setWebViewRenderProcessClient(executor: Executor, webViewRenderProcessClient: WebViewRenderProcessClient)

Sets the renderer client object associated with this WebView.

open Boolean

Return true if the pressed state should be delayed for children or descendants of this ViewGroup.

open Boolean
showFindDialog(text: String?, showIme: Boolean)

Starts an ActionMode for finding text in this WebView.

open static Unit

Starts Safe Browsing initialization.

open Unit

Stops the current load.

open Unit
zoomBy(zoomFactor: Float)

Performs a zoom operation in this WebView.

open Boolean

Performs zoom in in this WebView.

open Boolean

Performs zoom out in this WebView.

Protected methods
open Int

Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range.

open Int

Compute the horizontal range that the horizontal scrollbar represents.

open Int

Compute the vertical extent of the vertical scrollbar's thumb within the vertical range.

open Int

Compute the vertical offset of the vertical scrollbar's thumb within the horizontal range.

open Int

Compute the vertical range that the vertical scrollbar represents.

open Unit

Called by draw to draw the child views.

open Unit

This is called when the view is attached to a window.

open Unit

Called when the current configuration of the resources being used by the application have changed.

open Unit
onDraw(canvas: Canvas)

Implement this to do your drawing.

open Unit
onFocusChanged(focused: Boolean, direction: Int, previouslyFocusedRect: Rect?)

Called by the view system when the focus state of this view changes.

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

Measure the view and its content to determine the measured width and the measured height.

open Unit
onOverScrolled(scrollX: Int, scrollY: Int, clampedX: Boolean, clampedY: Boolean)

Called by overScrollBy(int,int,int,int,int,int,int,int,boolean) to respond to the results of an over-scroll operation.

open Unit
onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int)

This is called in response to an internal scroll in this view (i.e., the view scrolled its own contents).

open Unit
onSizeChanged(w: Int, h: Int, ow: Int, oh: Int)

This is called during layout when the size of this view has changed.

open Unit
onVisibilityChanged(changedView: View, visibility: Int)

Called when the visibility of the view or an ancestor of the view has changed.

open Unit

Called when the window containing has change its visibility (between GONE, INVISIBLE, and VISIBLE).

Inherited functions