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

The renderer associated with this WebView is bound with the default priority for services.

static Int

The renderer associated with this WebView is bound with Context.BIND_IMPORTANT.

static Int

The renderer associated with this WebView is bound with Context.BIND_WAIVE_PRIORITY.

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

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

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

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!

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!

open AccessibilityNodeProvider!

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

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!

open Boolean

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

open Unit

open Boolean

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

open Boolean

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

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

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

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

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

open Boolean

open Boolean

open Unit

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

open Unit
onWindowFocusChanged(hasWindowFocus: Boolean)

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

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)

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

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

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?)

open Unit

open Unit

open Unit

Informs WebView of the network state.

open Unit

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

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

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

open Int

open Int

open Int

open Int

open Unit

open Unit

open Unit

open Unit
onDraw(canvas: Canvas)

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

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

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

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

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

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

open Unit

Inherited functions