Android WebView

Stella981
• 阅读 810

Skip to content

Android WebView  Developers

Android WebView PLAY 控制台


navigation

参考网页

API: 

27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

                                               Android Platform                                                                       Android Support Library                                                                       Architecture Components                                                Constraint Library                                                                       Play Billing Library                                                Test Support Library                                                Wearable Library                      

added in  API level 1

Summary:  Nested Classes |  Inherited XML Attrs |  Constants |  Inherited Constants |  Inherited Fields |  CtorsMethods |  Protected Methods |  Inherited Methods |  [Expand All]

WebView

public class WebView
extends [AbsoluteLayout](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwidget%2FAbsoluteLayout.html) implements [ViewTreeObserver.OnGlobalFocusChangeListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewTreeObserver.OnGlobalFocusChangeListener.html), [ViewGroup.OnHierarchyChangeListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.OnHierarchyChangeListener.html)

java.lang.Object

   ↳

android.view.View

 

   ↳

android.view.ViewGroup

 

 

   ↳

android.widget.AbsoluteLayout

 

 

 

   ↳

android.webkit.WebView


A View that displays web pages. This class is the basis upon which you can roll your own web browser or simply display some online content within your Activity. It uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, perform text searches and more.

Note that, in order for your Activity to access the Internet and load web pages in a WebView, you must add the INTERNET permissions to your Android Manifest file:

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

This must be a child of the <manifest> element.

For more information, read Building Web Apps in WebView.

Basic usage

By default, a WebView provides no browser-like widgets, does not enable JavaScript and web page errors are ignored. If your goal is only to display some HTML as a part of your UI, this is probably fine; the user won't need to interact with the web page beyond reading it, and the web page won't need to interact with the user. If you actually want a full-blown web browser, then you probably want to invoke the Browser application with a URL Intent rather than show it with a WebView. For example:

 Uri uri = Uri.parse("https://www.example.com"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); 

See [Intent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2FIntent.html) for more information.

To provide a WebView in your own Activity, include a <WebView> in your layout, or set the entire Activity window as a WebView during [onCreate()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fapp%2FActivity.html%23onCreate%28android.os.Bundle%29):

 WebView webview = new WebView(this); setContentView(webview); 

Then load the desired web page:

// Simplest usage: note that an exception will NOT be thrown // if there is an error loading this page (see below). webview.loadUrl("https://example.com/"); // OR, you can also load from an HTML string: String summary = "You scored 192 points."; webview.loadData(summary, "text/html", null); // ... although note that there are restrictions on what this HTML can do. // See the JavaDocs for [loadData()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23loadData%28java.lang.String%2C+java.lang.String%2C+java.lang.String%29) and [loadDataWithBaseURL()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23loadDataWithBaseURL%28java.lang.String%2C+java.lang.String%2C+java.lang.String%2C+java.lang.String%2C+java.lang.String%29) for more info.

A WebView has several customization points where you can add your own behavior. These are:

  • Creating and setting a [WebChromeClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebChromeClient.html) subclass. This class is called when something that might impact a browser UI happens, for instance, progress updates and JavaScript alerts are sent here (see Debugging Tasks).
  • Creating and setting a [WebViewClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewClient.html) subclass. It will be called when things happen that impact the rendering of the content, eg, errors or form submissions. You can also intercept URL loading here (via [shouldOverrideUrlLoading()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewClient.html%23shouldOverrideUrlLoading%28android.webkit.WebView%2C+java.lang.String%29)).
  • Modifying the [WebSettings](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebSettings.html), such as enabling JavaScript with [setJavaScriptEnabled()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebSettings.html%23setJavaScriptEnabled%28boolean%29).
  • Injecting Java objects into the WebView using the [addJavascriptInterface(Object, String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23addJavascriptInterface%28java.lang.Object%2C+java.lang.String%29) method. This method allows you to inject Java objects into a page's JavaScript context, so that they can be accessed by JavaScript in the page.

Here's a more complicated example, showing error handling, settings, and progress notification:

 // Let's display the progress in the activity title bar, like the // browser app does. getWindow().requestFeature(Window.FEATURE_PROGRESS); webview.getSettings().setJavaScriptEnabled(true); final Activity activity = this; webview.setWebChromeClient(new WebChromeClient() {   public void onProgressChanged(WebView view, int progress) {     // Activities and WebViews measure progress with different scales.     // The progress meter will automatically disappear when we reach 100%     activity.setProgress(progress * 1000);   } }); webview.setWebViewClient(new WebViewClient() {   public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {     Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();   } }); webview.loadUrl("https://developer.android.com/"); 

Zoom

To enable the built-in zoom, set [WebSettings](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getSettings%28%29).[setBuiltInZoomControls(boolean)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebSettings.html%23setBuiltInZoomControls%28boolean%29) (introduced in API level [CUPCAKE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23CUPCAKE)).

NOTE: Using zoom if either the height or width is set to [WRAP_CONTENT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.LayoutParams.html%23WRAP_CONTENT) may lead to undefined behavior and should be avoided.

For obvious security reasons, your application has its own cache, cookie store etc.—it does not share the Browser application's data.

By default, requests by the HTML to open new windows are ignored. This is true whether they be opened by JavaScript or by the target attribute on a link. You can customize your [WebChromeClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebChromeClient.html) to provide your own behavior for opening multiple windows, and render them in whatever manner you want.

The standard behavior for an Activity is to be destroyed and recreated when the device orientation or any other configuration changes. This will cause the WebView to reload the current page. If you don't want that, you can set your Activity to handle the orientation and keyboardHidden changes, and then just leave the WebView alone. It'll automatically re-orient itself as appropriate. Read Handling Runtime Changes for more information about how to handle configuration changes during runtime.

Building web pages to support different screen densities

The screen density of a device is based on the screen resolution. A screen with low density has fewer available pixels per inch, where a screen with high density has more — sometimes significantly more — pixels per inch. The density of a screen is important because, other things being equal, a UI element (such as a button) whose height and width are defined in terms of screen pixels will appear larger on the lower density screen and smaller on the higher density screen. For simplicity, Android collapses all actual screen densities into three generalized densities: high, medium, and low.

By default, WebView scales a web page so that it is drawn at a size that matches the default appearance on a medium density screen. So, it applies 1.5x scaling on a high density screen (because its pixels are smaller) and 0.75x scaling on a low density screen (because its pixels are bigger). Starting with API level [ECLAIR](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23ECLAIR), WebView supports DOM, CSS, and meta tag features to help you (as a web developer) target screens with different screen densities.

Here's a summary of the features you can use to handle different screen densities:

  • The window.devicePixelRatio DOM property. The value of this property specifies the default scaling factor used for the current device. For example, if the value of window.devicePixelRatio is "1.0", then the device is considered a medium density (mdpi) device and default scaling is not applied to the web page; if the value is "1.5", then the device is considered a high density device (hdpi) and the page content is scaled 1.5x; if the value is "0.75", then the device is considered a low density device (ldpi) and the content is scaled 0.75x.

  • The -webkit-device-pixel-ratio CSS media query. Use this to specify the screen densities for which this style sheet is to be used. The corresponding value should be either "0.75", "1", or "1.5", to indicate that the styles are for devices with low density, medium density, or high density screens, respectively. For example:

     <link rel="stylesheet" media="screen and (-webkit-device-pixel-ratio:1.5)" href="hdpi.css" />
    

    The hdpi.css stylesheet is only used for devices with a screen pixel ration of 1.5, which is the high density pixel ratio.

HTML5 Video support

In order to support inline HTML5 video in your application you need to have hardware acceleration turned on.

Full screen support

In order to support full screen — for video or other HTML content — you need to set a [WebChromeClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebChromeClient.html) and implement both [onShowCustomView(View, WebChromeClient.CustomViewCallback)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebChromeClient.html%23onShowCustomView%28android.view.View%2C+android.webkit.WebChromeClient.CustomViewCallback%29) and [onHideCustomView()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebChromeClient.html%23onHideCustomView%28%29). If the implementation of either of these two methods is missing then the web contents will not be allowed to enter full screen. Optionally you can implement [getVideoLoadingProgressView()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebChromeClient.html%23getVideoLoadingProgressView%28%29) to customize the View displayed whilst a video is loading.

HTML5 Geolocation API support

For applications targeting Android N and later releases (API level > [M](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23M)) the geolocation api is only supported on secure origins such as https. For such applications requests to geolocation api on non-secure origins are automatically denied without invoking the corresponding[onGeolocationPermissionsShowPrompt(String, GeolocationPermissions.Callback)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebChromeClient.html%23onGeolocationPermissionsShowPrompt%28java.lang.String%2C+android.webkit.GeolocationPermissions.Callback%29) method.

Layout size

It is recommended to set the WebView layout height to a fixed value or to [MATCH_PARENT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.LayoutParams.html%23MATCH_PARENT) instead of using [WRAP_CONTENT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.LayoutParams.html%23WRAP_CONTENT). When using [MATCH_PARENT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.LayoutParams.html%23MATCH_PARENT) for the height none of the WebView's parents should use a [WRAP_CONTENT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.LayoutParams.html%23WRAP_CONTENT) layout height since that could result in incorrect sizing of the views.

Setting the WebView's height to [WRAP_CONTENT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.LayoutParams.html%23WRAP_CONTENT) enables the following behaviors:

  • The HTML body layout height is set to a fixed value. This means that elements with a height relative to the HTML body may not be sized correctly.
  • For applications targeting [KITKAT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23KITKAT) and earlier SDKs the HTML viewport meta tag will be ignored in order to preserve backwards compatibility.

Using a layout width of [WRAP_CONTENT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.LayoutParams.html%23WRAP_CONTENT) is not supported. If such a width is used the WebView will attempt to use the width of the parent instead.

Metrics

WebView may upload anonymous diagnostic data to Google when the user has consented. This data helps Google improve WebView. Data is collected on a per-app basis for each app which has instantiated a WebView. An individual app can opt out of this feature by putting the following tag in its manifest:

 <meta-data android:name="android.webkit.WebView.MetricsOptOut"            android:value="true" /> 

Data will only be uploaded for a given app if the user has consented AND the app has not opted out.

Safe Browsing

If Safe Browsing is enabled, WebView will block malicious URLs and present a warning UI to the user to allow them to navigate back safely or proceed to the malicious page.

The recommended way for apps to enable the feature is putting the following tag in the manifest:

 <meta-data android:name="android.webkit.WebView.EnableSafeBrowsing"            android:value="true" /> 

Summary


Nested classes

interface

[WebView.FindListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.FindListener.html)

Interface to listen for find results. 

class

[WebView.HitTestResult](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.HitTestResult.html)

interface

[WebView.PictureListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.PictureListener.html)

This interface was deprecated in API level 12. This interface is now obsolete.  

class

[WebView.VisualStateCallback](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.VisualStateCallback.html)

Callback interface supplied to [postVisualStateCallback(long, WebView.VisualStateCallback)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23postVisualStateCallback%28long%2C+android.webkit.WebView.VisualStateCallback%29) for receiving notifications about the visual state. 

class

[WebView.WebViewTransport](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.WebViewTransport.html)

Transportation object for returning WebView across thread boundaries. 

Inherited XML attributes

Android WebView From class [android.view.ViewGroup](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.html)

Android WebView From class [android.view.View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html)

Constants

int

[RENDERER_PRIORITY_BOUND](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23RENDERER_PRIORITY_BOUND)

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

int

[RENDERER_PRIORITY_IMPORTANT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23RENDERER_PRIORITY_IMPORTANT)

The renderer associated with this WebView is bound with [BIND_IMPORTANT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2FContext.html%23BIND_IMPORTANT).

int

[RENDERER_PRIORITY_WAIVED](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23RENDERER_PRIORITY_WAIVED)

The renderer associated with this WebView is bound with [BIND_WAIVE_PRIORITY](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2FContext.html%23BIND_WAIVE_PRIORITY).

[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)

[SCHEME_GEO](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23SCHEME_GEO)

URI scheme for map address.

[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)

[SCHEME_MAILTO](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23SCHEME_MAILTO)

URI scheme for email address.

[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)

[SCHEME_TEL](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23SCHEME_TEL)

URI scheme for telephone number.

Inherited constants

Android WebView From class [android.view.ViewGroup](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.html)

Android WebView From class [android.view.View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html)

Inherited fields

Android WebView From class [android.view.View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html)

Public constructors

[WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23WebView%28android.content.Context%29)([Context](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2FContext.html) context)

Constructs a new WebView with a Context object.

[WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23WebView%28android.content.Context%2C+android.util.AttributeSet%29)([Context](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2FContext.html) context, [AttributeSet](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Futil%2FAttributeSet.html) attrs)

Constructs a new WebView with layout parameters.

[WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23WebView%28android.content.Context%2C+android.util.AttributeSet%2C+int%29)([Context](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2FContext.html) context, [AttributeSet](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Futil%2FAttributeSet.html) attrs, int defStyleAttr)

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

[WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23WebView%28android.content.Context%2C+android.util.AttributeSet%2C+int%2C+int%29)([Context](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2FContext.html) context, [AttributeSet](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Futil%2FAttributeSet.html) attrs, int defStyleAttr, int defStyleRes)

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

[WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23WebView%28android.content.Context%2C+android.util.AttributeSet%2C+int%2C+boolean%29)([Context](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2FContext.html) context, [AttributeSet](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Futil%2FAttributeSet.html) attrs, int defStyleAttr, boolean privateBrowsing)

This constructor was deprecated in API level 17. Private browsing is no longer supported directly via WebView and will be removed in a future release. Prefer using [WebSettings](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebSettings.html)[WebViewDatabase](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewDatabase.html)[CookieManager](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FCookieManager.html) and [WebStorage](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebStorage.html) for fine-grained control of privacy data.

Public methods

void

[addJavascriptInterface](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23addJavascriptInterface%28java.lang.Object%2C+java.lang.String%29)([Object](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FObject.html) object, [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) name)

Injects the supplied Java object into this WebView.

void

[autofill](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23autofill%28android.util.SparseArray%3Candroid.view.autofill.AutofillValue%3E%29)([SparseArray](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Futil%2FSparseArray.html)<[AutofillValue](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Fautofill%2FAutofillValue.html)> values)

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

boolean

[canGoBack](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23canGoBack%28%29)()

Gets whether this WebView has a back history item.

boolean

[canGoBackOrForward](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23canGoBackOrForward%28int%29)(int steps)

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

boolean

[canGoForward](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23canGoForward%28%29)()

Gets whether this WebView has a forward history item.

boolean

[canZoomIn](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23canZoomIn%28%29)()

This method was deprecated in API level 17. This method is prone to inaccuracy due to race conditions between the web rendering and UI threads; prefer [onScaleChanged(WebView, float, float)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewClient.html%23onScaleChanged%28android.webkit.WebView%2C+float%2C+float%29).

boolean

[canZoomOut](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23canZoomOut%28%29)()

This method was deprecated in API level 17. This method is prone to inaccuracy due to race conditions between the web rendering and UI threads; prefer [onScaleChanged(WebView, float, float)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewClient.html%23onScaleChanged%28android.webkit.WebView%2C+float%2C+float%29).

[Picture](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FPicture.html)

[capturePicture](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23capturePicture%28%29)()

This method was deprecated in API level 19. Use [onDraw(Canvas)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onDraw%28android.graphics.Canvas%29) to obtain a bitmap snapshot of the WebView, or[saveWebArchive(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23saveWebArchive%28java.lang.String%29) to save the content to a file.

void

[clearCache](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23clearCache%28boolean%29)(boolean includeDiskFiles)

Clears the resource cache.

static void

[clearClientCertPreferences](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23clearClientCertPreferences%28java.lang.Runnable%29)([Runnable](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FRunnable.html) onCleared)

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

void

[clearFormData](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23clearFormData%28%29)()

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

void

[clearHistory](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23clearHistory%28%29)()

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

void

[clearMatches](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23clearMatches%28%29)()

Clears the highlighting surrounding text matches created by [findAllAsync(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23findAllAsync%28java.lang.String%29).

void

[clearSslPreferences](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23clearSslPreferences%28%29)()

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

void

[clearView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23clearView%28%29)()

This method was deprecated in API level 18. Use WebView.loadUrl("about:blank") to reliably reset the view state and release page resources (including any running JavaScript).

void

[computeScroll](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23computeScroll%28%29)()

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

[WebBackForwardList](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebBackForwardList.html)

[copyBackForwardList](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23copyBackForwardList%28%29)()

Gets the WebBackForwardList for this WebView.

[PrintDocumentAdapter](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fprint%2FPrintDocumentAdapter.html)

[createPrintDocumentAdapter](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23createPrintDocumentAdapter%28java.lang.String%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) documentName)

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

[PrintDocumentAdapter](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fprint%2FPrintDocumentAdapter.html)

[createPrintDocumentAdapter](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23createPrintDocumentAdapter%28%29)()

This method was deprecated in API level 21. Use [createPrintDocumentAdapter(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23createPrintDocumentAdapter%28java.lang.String%29) which requires user to provide a print document name.

[WebMessagePort[]](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebMessagePort.html)

[createWebMessageChannel](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23createWebMessageChannel%28%29)()

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

void

[destroy](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23destroy%28%29)()

Destroys the internal state of this WebView.

boolean

[dispatchKeyEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23dispatchKeyEvent%28android.view.KeyEvent%29)([KeyEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html) event)

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

void

[documentHasImages](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23documentHasImages%28android.os.Message%29)([Message](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FMessage.html) response)

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

static void

[enableSlowWholeDocumentDraw](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23enableSlowWholeDocumentDraw%28%29)()

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.

void

[evaluateJavascript](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23evaluateJavascript%28java.lang.String%2C+android.webkit.ValueCallback%3Cjava.lang.String%3E%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) script, [ValueCallback](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FValueCallback.html)<[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)> resultCallback)

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

static [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)

[findAddress](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23findAddress%28java.lang.String%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) addr)

Gets the first substring consisting of the address of a physical location.

int

[findAll](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23findAll%28java.lang.String%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) find)

This method was deprecated in API level 16. [findAllAsync(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23findAllAsync%28java.lang.String%29) is preferred.

void

[findAllAsync](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23findAllAsync%28java.lang.String%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) find)

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

[View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html)

[findFocus](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23findFocus%28%29)()

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

void

[findNext](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23findNext%28boolean%29)(boolean forward)

Highlights and scrolls to the next match found by [findAllAsync(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23findAllAsync%28java.lang.String%29), wrapping around page boundaries as necessary.

void

[flingScroll](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23flingScroll%28int%2C+int%29)(int vx, int vy)

void

[freeMemory](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23freeMemory%28%29)()

This method was deprecated in API level 19. Memory caches are automatically dropped when no longer needed, and in response to system memory pressure.

[CharSequence](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FCharSequence.html)

[getAccessibilityClassName](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getAccessibilityClassName%28%29)()

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

[AccessibilityNodeProvider](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Faccessibility%2FAccessibilityNodeProvider.html)

[getAccessibilityNodeProvider](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getAccessibilityNodeProvider%28%29)()

Gets the provider for managing a virtual view hierarchy rooted at this View and reported to [AccessibilityService](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Faccessibilityservice%2FAccessibilityService.html)s that explore the window content.

[SslCertificate](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fnet%2Fhttp%2FSslCertificate.html)

[getCertificate](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getCertificate%28%29)()

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

int

[getContentHeight](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getContentHeight%28%29)()

Gets the height of the HTML content.

static [PackageInfo](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2Fpm%2FPackageInfo.html)

[getCurrentWebViewPackage](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getCurrentWebViewPackage%28%29)()

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

[Bitmap](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FBitmap.html)

[getFavicon](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getFavicon%28%29)()

Gets the favicon for the current page.

[Handler](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FHandler.html)

[getHandler](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getHandler%28%29)()

[WebView.HitTestResult](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.HitTestResult.html)

[getHitTestResult](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getHitTestResult%28%29)()

Gets a HitTestResult based on the current cursor node.

[String[]](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)

[getHttpAuthUsernamePassword](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getHttpAuthUsernamePassword%28java.lang.String%2C+java.lang.String%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) host, [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) realm)

This method was deprecated in API level 26. Use [getHttpAuthUsernamePassword(String, String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewDatabase.html%23getHttpAuthUsernamePassword%28java.lang.String%2C+java.lang.String%29) instead

[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)

[getOriginalUrl](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getOriginalUrl%28%29)()

Gets the original URL for the current page.

int

[getProgress](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getProgress%28%29)()

Gets the progress for the current page.

boolean

[getRendererPriorityWaivedWhenNotVisible](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getRendererPriorityWaivedWhenNotVisible%28%29)()

Return whether this WebView requests a priority of [RENDERER_PRIORITY_WAIVED](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23RENDERER_PRIORITY_WAIVED) when not visible.

int

[getRendererRequestedPriority](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getRendererRequestedPriority%28%29)()

Get the requested renderer priority for this WebView.

static [Uri](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fnet%2FUri.html)

[getSafeBrowsingPrivacyPolicyUrl](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getSafeBrowsingPrivacyPolicyUrl%28%29)()

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

float

[getScale](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getScale%28%29)()

This method was deprecated in API level 17. This method is prone to inaccuracy due to race conditions between the web rendering and UI threads; prefer [onScaleChanged(WebView, float, float)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewClient.html%23onScaleChanged%28android.webkit.WebView%2C+float%2C+float%29).

[WebSettings](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebSettings.html)

[getSettings](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getSettings%28%29)()

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

[TextClassifier](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Ftextclassifier%2FTextClassifier.html)

[getTextClassifier](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getTextClassifier%28%29)()

Returns the [TextClassifier](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Ftextclassifier%2FTextClassifier.html) used by this WebView.

[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)

[getTitle](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getTitle%28%29)()

Gets the title for the current page.

[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)

[getUrl](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getUrl%28%29)()

Gets the URL for the current page.

[WebChromeClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebChromeClient.html)

[getWebChromeClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getWebChromeClient%28%29)()

Gets the chrome handler.

[WebViewClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewClient.html)

[getWebViewClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getWebViewClient%28%29)()

Gets the WebViewClient.

void

[goBack](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23goBack%28%29)()

Goes back in the history of this WebView.

void

[goBackOrForward](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23goBackOrForward%28int%29)(int steps)

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

void

[goForward](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23goForward%28%29)()

Goes forward in the history of this WebView.

void

[invokeZoomPicker](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23invokeZoomPicker%28%29)()

Invokes the graphical zoom picker widget for this WebView.

boolean

[isPrivateBrowsingEnabled](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23isPrivateBrowsingEnabled%28%29)()

Gets whether private browsing is enabled in this WebView.

void

[loadData](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23loadData%28java.lang.String%2C+java.lang.String%2C+java.lang.String%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) data, [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) mimeType, [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) encoding)

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

void

[loadDataWithBaseURL](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23loadDataWithBaseURL%28java.lang.String%2C+java.lang.String%2C+java.lang.String%2C+java.lang.String%2C+java.lang.String%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) baseUrl, [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) data, [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) mimeType, [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) encoding, [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)historyUrl)

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

void

[loadUrl](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23loadUrl%28java.lang.String%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) url)

Loads the given URL.

void

[loadUrl](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23loadUrl%28java.lang.String%2C+java.util.Map%3Cjava.lang.String%2C+java.lang.String%3E%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) url, [Map](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Futil%2FMap.html)<[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html), [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)> additionalHttpHeaders)

Loads the given URL with the specified additional HTTP headers.

void

[onChildViewAdded](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onChildViewAdded%28android.view.View%2C+android.view.View%29)([View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html) parent, [View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html) child)

This method was deprecated in API level 8. WebView no longer needs to implement ViewGroup.OnHierarchyChangeListener. This method does nothing now.

void

[onChildViewRemoved](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onChildViewRemoved%28android.view.View%2C+android.view.View%29)([View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html) p, [View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html) child)

This method was deprecated in API level 8. WebView no longer needs to implement ViewGroup.OnHierarchyChangeListener. This method does nothing now.

[InputConnection](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Finputmethod%2FInputConnection.html)

[onCreateInputConnection](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onCreateInputConnection%28android.view.inputmethod.EditorInfo%29)([EditorInfo](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Finputmethod%2FEditorInfo.html) outAttrs)

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

boolean

[onDragEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onDragEvent%28android.view.DragEvent%29)([DragEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FDragEvent.html) event)

Handles drag events sent by the system following a call to [startDragAndDrop()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23startDragAndDrop%28android.content.ClipData%2C+android.view.View.DragShadowBuilder%2C+java.lang.Object%2C+int%29).

void

[onFinishTemporaryDetach](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onFinishTemporaryDetach%28%29)()

Called after [onStartTemporaryDetach()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23onStartTemporaryDetach%28%29) when the container is done changing the view.

boolean

[onGenericMotionEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onGenericMotionEvent%28android.view.MotionEvent%29)([MotionEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FMotionEvent.html) event)

Implement this method to handle generic motion events.

void

[onGlobalFocusChanged](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onGlobalFocusChanged%28android.view.View%2C+android.view.View%29)([View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html) oldFocus, [View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html) newFocus)

This method was deprecated in API level 3. WebView should not have implemented ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now.

boolean

[onHoverEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onHoverEvent%28android.view.MotionEvent%29)([MotionEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FMotionEvent.html) event)

Implement this method to handle hover events.

boolean

[onKeyDown](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onKeyDown%28int%2C+android.view.KeyEvent%29)(int keyCode, [KeyEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html) event)

Default implementation of [KeyEvent.Callback.onKeyDown()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.Callback.html%23onKeyDown%28int%2C+android.view.KeyEvent%29): perform press of the view when [KEYCODE_DPAD_CENTER](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html%23KEYCODE_DPAD_CENTER) or [KEYCODE_ENTER](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html%23KEYCODE_ENTER) is released, if the view is enabled and clickable.

boolean

[onKeyMultiple](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onKeyMultiple%28int%2C+int%2C+android.view.KeyEvent%29)(int keyCode, int repeatCount, [KeyEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html) event)

Default implementation of [KeyEvent.Callback.onKeyMultiple()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.Callback.html%23onKeyMultiple%28int%2C+int%2C+android.view.KeyEvent%29): always returns false (doesn't handle the event).

boolean

[onKeyUp](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onKeyUp%28int%2C+android.view.KeyEvent%29)(int keyCode, [KeyEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html) event)

Default implementation of [KeyEvent.Callback.onKeyUp()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.Callback.html%23onKeyUp%28int%2C+android.view.KeyEvent%29): perform clicking of the view when [KEYCODE_DPAD_CENTER](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html%23KEYCODE_DPAD_CENTER)[KEYCODE_ENTER](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html%23KEYCODE_ENTER) or [KEYCODE_SPACE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html%23KEYCODE_SPACE) is released.

void

[onPause](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onPause%28%29)()

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

void

[onProvideAutofillVirtualStructure](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onProvideAutofillVirtualStructure%28android.view.ViewStructure%2C+int%29)([ViewStructure](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html) structure, int flags)

Populates a [ViewStructure](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html) containing virtual children to fullfil an autofill request.

The [ViewStructure](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html) traditionally represents a [View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html), while for web pages it represent HTML nodes.

void

[onProvideVirtualStructure](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onProvideVirtualStructure%28android.view.ViewStructure%29)([ViewStructure](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html) structure)

Called when assist structure is being retrieved from a view as part of [Activity.onProvideAssistData](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fapp%2FActivity.html%23onProvideAssistData%28android.os.Bundle%29) to generate additional virtual structure under this view.

void

[onResume](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onResume%28%29)()

Resumes a WebView after a previous call to [onPause()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onPause%28%29).

void

[onStartTemporaryDetach](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onStartTemporaryDetach%28%29)()

This is called when a container is going to temporarily detach a child, with [ViewGroup.detachViewFromParent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.html%23detachViewFromParent%28android.view.View%29).

boolean

[onTouchEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onTouchEvent%28android.view.MotionEvent%29)([MotionEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FMotionEvent.html) event)

Implement this method to handle touch screen motion events.

boolean

[onTrackballEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onTrackballEvent%28android.view.MotionEvent%29)([MotionEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FMotionEvent.html) event)

Implement this method to handle trackball motion events.

void

[onWindowFocusChanged](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onWindowFocusChanged%28boolean%29)(boolean hasWindowFocus)

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

boolean

[overlayHorizontalScrollbar](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23overlayHorizontalScrollbar%28%29)()

This method was deprecated in API level 23. This method is now obsolete.

boolean

[overlayVerticalScrollbar](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23overlayVerticalScrollbar%28%29)()

This method was deprecated in API level 23. This method is now obsolete.

boolean

[pageDown](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23pageDown%28boolean%29)(boolean bottom)

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

boolean

[pageUp](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23pageUp%28boolean%29)(boolean top)

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

void

[pauseTimers](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23pauseTimers%28%29)()

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

boolean

[performLongClick](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23performLongClick%28%29)()

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

void

[postUrl](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23postUrl%28java.lang.String%2C+byte%5B%5D%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) url, byte[] postData)

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

void

[postVisualStateCallback](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23postVisualStateCallback%28long%2C+android.webkit.WebView.VisualStateCallback%29)(long requestId, [WebView.VisualStateCallback](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.VisualStateCallback.html) callback)

Posts a [WebView.VisualStateCallback](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.VisualStateCallback.html), which will be called when the current state of the WebView is ready to be drawn.

void

[postWebMessage](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23postWebMessage%28android.webkit.WebMessage%2C+android.net.Uri%29)([WebMessage](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebMessage.html) message, [Uri](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fnet%2FUri.html) targetOrigin)

Post a message to main frame.

void

[reload](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23reload%28%29)()

Reloads the current URL.

void

[removeJavascriptInterface](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23removeJavascriptInterface%28java.lang.String%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) name)

Removes a previously injected Java object from this WebView.

boolean

[requestChildRectangleOnScreen](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23requestChildRectangleOnScreen%28android.view.View%2C+android.graphics.Rect%2C+boolean%29)([View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html) child, [Rect](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FRect.html) rect, boolean immediate)

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

boolean

[requestFocus](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23requestFocus%28int%2C+android.graphics.Rect%29)(int direction, [Rect](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FRect.html) previouslyFocusedRect)

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. Looks for a view to give focus to respecting the setting specified by [getDescendantFocusability()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.html%23getDescendantFocusability%28%29).

void

[requestFocusNodeHref](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23requestFocusNodeHref%28android.os.Message%29)([Message](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FMessage.html) hrefMsg)

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

void

[requestImageRef](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23requestImageRef%28android.os.Message%29)([Message](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FMessage.html) msg)

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

[WebBackForwardList](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebBackForwardList.html)

[restoreState](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23restoreState%28android.os.Bundle%29)([Bundle](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBundle.html) inState)

Restores the state of this WebView from the given Bundle.

void

[resumeTimers](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23resumeTimers%28%29)()

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

void

[savePassword](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23savePassword%28java.lang.String%2C+java.lang.String%2C+java.lang.String%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) host, [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) username, [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) password)

This method was deprecated in API level 18. Saving passwords in WebView will not be supported in future versions.

[WebBackForwardList](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebBackForwardList.html)

[saveState](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23saveState%28android.os.Bundle%29)([Bundle](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBundle.html) outState)

Saves the state of this WebView used in [onSaveInstanceState(Bundle)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fapp%2FActivity.html%23onSaveInstanceState%28android.os.Bundle%29).

void

[saveWebArchive](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23saveWebArchive%28java.lang.String%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) filename)

Saves the current view as a web archive.

void

[saveWebArchive](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23saveWebArchive%28java.lang.String%2C+boolean%2C+android.webkit.ValueCallback%3Cjava.lang.String%3E%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) basename, boolean autoname, [ValueCallback](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FValueCallback.html)<[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)> callback)

Saves the current view as a web archive.

void

[setBackgroundColor](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setBackgroundColor%28int%29)(int color)

Sets the background color for this view.

void

[setCertificate](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setCertificate%28android.net.http.SslCertificate%29)([SslCertificate](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fnet%2Fhttp%2FSslCertificate.html) certificate)

This method was deprecated in API level 17. Calling this function has no useful effect, and will be ignored in future releases.

void

[setDownloadListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setDownloadListener%28android.webkit.DownloadListener%29)([DownloadListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FDownloadListener.html) listener)

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

void

[setFindListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setFindListener%28android.webkit.WebView.FindListener%29)([WebView.FindListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.FindListener.html) listener)

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

void

[setHorizontalScrollbarOverlay](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setHorizontalScrollbarOverlay%28boolean%29)(boolean overlay)

This method was deprecated in API level 23. This method has no effect.

void

[setHttpAuthUsernamePassword](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setHttpAuthUsernamePassword%28java.lang.String%2C+java.lang.String%2C+java.lang.String%2C+java.lang.String%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) host, [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) realm, [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) username, [String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) password)

This method was deprecated in API level 26. Use [setHttpAuthUsernamePassword(String, String, String, String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewDatabase.html%23setHttpAuthUsernamePassword%28java.lang.String%2C+java.lang.String%2C+java.lang.String%2C+java.lang.String%29) instead

void

[setInitialScale](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setInitialScale%28int%29)(int scaleInPercent)

Sets the initial scale for this WebView.

void

[setLayerType](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setLayerType%28int%2C+android.graphics.Paint%29)(int layerType, [Paint](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FPaint.html) paint)

Specifies the type of layer backing this view.

void

[setLayoutParams](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setLayoutParams%28android.view.ViewGroup.LayoutParams%29)([ViewGroup.LayoutParams](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.LayoutParams.html) params)

Set the layout parameters associated with this view.

void

[setMapTrackballToArrowKeys](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setMapTrackballToArrowKeys%28boolean%29)(boolean setMap)

This method was deprecated in API level 17. Only the default case, true, will be supported in a future version.

void

[setNetworkAvailable](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setNetworkAvailable%28boolean%29)(boolean networkUp)

Informs WebView of the network state.

void

[setOverScrollMode](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setOverScrollMode%28int%29)(int mode)

Set the over-scroll mode for this view.

void

[setPictureListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setPictureListener%28android.webkit.WebView.PictureListener%29)([WebView.PictureListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.PictureListener.html) listener)

This method was deprecated in API level 12. This method is now obsolete.

void

[setRendererPriorityPolicy](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setRendererPriorityPolicy%28int%2C+boolean%29)(int rendererRequestedPriority, boolean waivedWhenNotVisible)

Set the renderer priority policy for this [WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html).

static void

[setSafeBrowsingWhitelist](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setSafeBrowsingWhitelist%28java.util.List%3Cjava.lang.String%3E%2C+android.webkit.ValueCallback%3Cjava.lang.Boolean%3E%29)([List](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Futil%2FList.html)<[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)> urls, [ValueCallback](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FValueCallback.html)<[Boolean](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FBoolean.html)> callback)

Sets the list of domains that are exempt from SafeBrowsing checks.

void

[setScrollBarStyle](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setScrollBarStyle%28int%29)(int style)

Specify the style of the scrollbars.

void

[setTextClassifier](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setTextClassifier%28android.view.textclassifier.TextClassifier%29)([TextClassifier](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Ftextclassifier%2FTextClassifier.html) textClassifier)

Sets the [TextClassifier](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Ftextclassifier%2FTextClassifier.html) for this WebView.

void

[setVerticalScrollbarOverlay](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setVerticalScrollbarOverlay%28boolean%29)(boolean overlay)

This method was deprecated in API level 23. This method has no effect.

void

[setWebChromeClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setWebChromeClient%28android.webkit.WebChromeClient%29)([WebChromeClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebChromeClient.html) client)

Sets the chrome handler.

static void

[setWebContentsDebuggingEnabled](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setWebContentsDebuggingEnabled%28boolean%29)(boolean enabled)

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

void

[setWebViewClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setWebViewClient%28android.webkit.WebViewClient%29)([WebViewClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewClient.html) client)

Sets the WebViewClient that will receive various notifications and requests.

boolean

[shouldDelayChildPressedState](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23shouldDelayChildPressedState%28%29)()

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

boolean

[showFindDialog](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23showFindDialog%28java.lang.String%2C+boolean%29)([String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html) text, boolean showIme)

This method was deprecated in API level 18. This method does not work reliably on all Android versions; implementing a custom find dialog using WebView.findAllAsync() provides a more robust solution.

static void

[startSafeBrowsing](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23startSafeBrowsing%28android.content.Context%2C+android.webkit.ValueCallback%3Cjava.lang.Boolean%3E%29)([Context](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2FContext.html) context, [ValueCallback](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FValueCallback.html)<[Boolean](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FBoolean.html)> callback)

Starts Safe Browsing initialization.

void

[stopLoading](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23stopLoading%28%29)()

Stops the current load.

void

[zoomBy](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23zoomBy%28float%29)(float zoomFactor)

Performs a zoom operation in this WebView.

boolean

[zoomIn](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23zoomIn%28%29)()

Performs zoom in in this WebView.

boolean

[zoomOut](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23zoomOut%28%29)()

Performs zoom out in this WebView.

Protected methods

int

[computeHorizontalScrollOffset](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23computeHorizontalScrollOffset%28%29)()

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

int

[computeHorizontalScrollRange](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23computeHorizontalScrollRange%28%29)()

Compute the horizontal range that the horizontal scrollbar represents.

int

[computeVerticalScrollExtent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23computeVerticalScrollExtent%28%29)()

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

int

[computeVerticalScrollOffset](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23computeVerticalScrollOffset%28%29)()

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

int

[computeVerticalScrollRange](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23computeVerticalScrollRange%28%29)()

Compute the vertical range that the vertical scrollbar represents.

void

[dispatchDraw](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23dispatchDraw%28android.graphics.Canvas%29)([Canvas](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FCanvas.html) canvas)

Called by draw to draw the child views.

void

[onAttachedToWindow](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onAttachedToWindow%28%29)()

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

void

[onConfigurationChanged](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onConfigurationChanged%28android.content.res.Configuration%29)([Configuration](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2Fres%2FConfiguration.html) newConfig)

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

void

[onDraw](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onDraw%28android.graphics.Canvas%29)([Canvas](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FCanvas.html) canvas)

Implement this to do your drawing.

void

[onFocusChanged](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onFocusChanged%28boolean%2C+int%2C+android.graphics.Rect%29)(boolean focused, int direction, [Rect](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FRect.html) previouslyFocusedRect)

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

void

[onMeasure](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onMeasure%28int%2C+int%29)(int widthMeasureSpec, int heightMeasureSpec)

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

void

[onOverScrolled](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onOverScrolled%28int%2C+int%2C+boolean%2C+boolean%29)(int scrollX, int scrollY, boolean clampedX, boolean clampedY)

Called by [overScrollBy(int, int, int, int, int, int, int, int, boolean)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23overScrollBy%28int%2C+int%2C+int%2C+int%2C+int%2C+int%2C+int%2C+int%2C+boolean%29) to respond to the results of an over-scroll operation.

void

[onScrollChanged](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onScrollChanged%28int%2C+int%2C+int%2C+int%29)(int l, int t, int oldl, int oldt)

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

void

[onSizeChanged](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onSizeChanged%28int%2C+int%2C+int%2C+int%29)(int w, int h, int ow, int oh)

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

void

[onVisibilityChanged](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onVisibilityChanged%28android.view.View%2C+int%29)([View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html) changedView, int visibility)

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

void

[onWindowVisibilityChanged](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onWindowVisibilityChanged%28int%29)(int visibility)

Called when the window containing has change its visibility (between [GONE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23GONE)[INVISIBLE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23INVISIBLE), and [VISIBLE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23VISIBLE)).

Inherited methods

Android WebView From class [android.widget.AbsoluteLayout](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwidget%2FAbsoluteLayout.html)

Android WebView From class [android.view.ViewGroup](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.html)

Android WebView From class [android.view.View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html)

Android WebView From class [java.lang.Object](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FObject.html)

Android WebView From interface [android.view.ViewParent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewParent.html)

Android WebView From interface [android.view.ViewManager](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewManager.html)

Android WebView From interface [android.graphics.drawable.Drawable.Callback](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2Fdrawable%2FDrawable.Callback.html)

Android WebView From interface [android.view.KeyEvent.Callback](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.Callback.html)

Android WebView From interface [android.view.accessibility.AccessibilityEventSource](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Faccessibility%2FAccessibilityEventSource.html)

Android WebView From interface [android.view.ViewTreeObserver.OnGlobalFocusChangeListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewTreeObserver.OnGlobalFocusChangeListener.html)

Android WebView From interface [android.view.ViewGroup.OnHierarchyChangeListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.OnHierarchyChangeListener.html)

Constants


RENDERER_PRIORITY_BOUND

added in  API level 26

int RENDERER_PRIORITY_BOUND

The renderer associated with this WebView is bound with the default priority for services. Use with [setRendererPriorityPolicy(int, boolean)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setRendererPriorityPolicy%28int%2C+boolean%29).

Constant Value: 1 (0x00000001)

RENDERER_PRIORITY_IMPORTANT

added in  API level 26

int RENDERER_PRIORITY_IMPORTANT

The renderer associated with this WebView is bound with [BIND_IMPORTANT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2FContext.html%23BIND_IMPORTANT). Use with [setRendererPriorityPolicy(int, boolean)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setRendererPriorityPolicy%28int%2C+boolean%29).

Constant Value: 2 (0x00000002)

RENDERER_PRIORITY_WAIVED

added in  API level 26

int RENDERER_PRIORITY_WAIVED

The renderer associated with this WebView is bound with [BIND_WAIVE_PRIORITY](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2FContext.html%23BIND_WAIVE_PRIORITY). At this priority level [WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html) renderers will be strong targets for out of memory killing. Use with [setRendererPriorityPolicy(int, boolean)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setRendererPriorityPolicy%28int%2C+boolean%29).

Constant Value: 0 (0x00000000)

SCHEME_GEO

added in  API level 1

String SCHEME_GEO

URI scheme for map address.

Constant Value: "geo:0,0?q="

SCHEME_MAILTO

added in  API level 1

String SCHEME_MAILTO

URI scheme for email address.

Constant Value: "mailto:"

SCHEME_TEL

added in  API level 1

String SCHEME_TEL

URI scheme for telephone number.

Constant Value: "tel:"

Public constructors


WebView

added in  API level 1

WebView (Context context)

Constructs a new WebView with a Context object.

Parameters

context

Context: a Context object used to access application assets

WebView

added in  API level 1

WebView (Context context, 
                AttributeSet attrs)

Constructs a new WebView with layout parameters.

Parameters

context

Context: a Context object used to access application assets

attrs

AttributeSet: an AttributeSet passed to our parent

WebView

added in  API level 1

WebView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

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

Parameters

context

Context: a Context object used to access application assets

attrs

AttributeSet: an AttributeSet passed to our parent

defStyleAttr

int: an attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults.

WebView

added in  API level 21

WebView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

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

Parameters

context

Context: a Context object used to access application assets

attrs

AttributeSet: an AttributeSet passed to our parent

defStyleAttr

int: an attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults.

defStyleRes

int: a resource identifier of a style resource that supplies default values for the view, used only if defStyleAttr is 0 or can not be found in the theme. Can be 0 to not look for defaults.

WebView

added in  API level 11

WebView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                boolean privateBrowsing)

This constructor was deprecated in API level 17.
Private browsing is no longer supported directly via WebView and will be removed in a future release. Prefer using [WebSettings](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebSettings.html)[WebViewDatabase](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewDatabase.html)[CookieManager](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FCookieManager.html) and [WebStorage](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebStorage.html) for fine-grained control of privacy data.

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

Parameters

context

Context: a Context object used to access application assets

attrs

AttributeSet: an AttributeSet passed to our parent

defStyleAttr

int: an attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults.

privateBrowsing

boolean: whether this WebView will be initialized in private mode

Public methods


addJavascriptInterface

added in  API level 1

void addJavascriptInterface (Object object, 
                String name)

Injects the supplied Java object into this WebView. The object is injected into the JavaScript context of the main frame, using the supplied name. This allows the Java object's methods to be accessed from JavaScript. For applications targeted to API level [JELLY_BEAN_MR1](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23JELLY_BEAN_MR1) and above, only public methods that are annotated with [JavascriptInterface](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FJavascriptInterface.html) can be accessed from JavaScript. For applications targeted to API level [JELLY_BEAN](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23JELLY_BEAN) or below, all public methods (including the inherited ones) can be accessed, see the important security note below for implications.

Note that injected objects will not appear in JavaScript until the page is next (re)loaded. JavaScript should be enabled before injecting the object. For example:

 class JsObject {    @JavascriptInterface    public String toString() { return "injectedObject"; } } webview.getSettings().setJavaScriptEnabled(true); webView.addJavascriptInterface(new JsObject(), "injectedObject"); webView.loadData("", "text/html", null); webView.loadUrl("javascript:alert(injectedObject.toString())");

IMPORTANT:

  • This method can be used to allow JavaScript to control the host application. This is a powerful feature, but also presents a security risk for apps targeting [JELLY_BEAN](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23JELLY_BEAN) or earlier. Apps that target a version later than [JELLY_BEAN](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23JELLY_BEAN) are still vulnerable if the app runs on a device running Android earlier than 4.2. The most secure way to use this method is to target [JELLY_BEAN_MR1](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23JELLY_BEAN_MR1) and to ensure the method is called only when running on Android 4.2 or later. With these older versions, JavaScript could use reflection to access an injected object's public fields. Use of this method in a WebView containing untrusted content could allow an attacker to manipulate the host application in unintended ways, executing Java code with the permissions of the host application. Use extreme care when using this method in a WebView which could contain untrusted content.
  • JavaScript interacts with Java object on a private, background thread of this WebView. Care is therefore required to maintain thread safety.
  • The Java object's fields are not accessible.
  • For applications targeted to API level [LOLLIPOP](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23LOLLIPOP) and above, methods of injected Java objects are enumerable from JavaScript.

Parameters

object

Object: the Java object to inject into this WebView's JavaScript context. Null values are ignored.

name

String: the name used to expose the object in JavaScript

autofill

added in  API level 26

void autofill (SparseArray<AutofillValue> values)

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

Views with virtual children support the Autofill Framework mainly by:

  • Providing the metadata defining what the virtual children mean and how they can be autofilled.
  • Implementing the methods that autofill the virtual children.

[onProvideAutofillVirtualStructure(ViewStructure, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23onProvideAutofillVirtualStructure%28android.view.ViewStructure%2C+int%29) is responsible for the former, this method is responsible for the latter - see [autofill(AutofillValue)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23autofill%28android.view.autofill.AutofillValue%29) and [onProvideAutofillVirtualStructure(ViewStructure, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23onProvideAutofillVirtualStructure%28android.view.ViewStructure%2C+int%29) for more info about autofill.

If a child value is updated asynchronously, the next call to [notifyValueChanged(View, int, AutofillValue)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Fautofill%2FAutofillManager.html%23notifyValueChanged%28android.view.View%2C+int%2C+android.view.autofill.AutofillValue%29) must happen after the value was changed to the autofilled value. If not, the child will not be considered autofilled.

Note: To indicate that a virtual view was autofilled, ?android:attr/autofilledHighlight should be drawn over it until the data changes.

Parameters

values

SparseArray: map of values to be autofilled, keyed by virtual child id.

canGoBack

added in  API level 1

boolean canGoBack ()

Gets whether this WebView has a back history item.

Returns

boolean

true iff this WebView has a back history item

canGoBackOrForward

added in  API level 1

boolean canGoBackOrForward (int steps)

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

Parameters

steps

int: the negative or positive number of steps to move the history

Returns

boolean

 

canGoForward

added in  API level 1

boolean canGoForward ()

Gets whether this WebView has a forward history item.

Returns

boolean

true iff this WebView has a forward history item

canZoomIn

added in  API level 11

boolean canZoomIn ()

This method was deprecated in API level 17.
This method is prone to inaccuracy due to race conditions between the web rendering and UI threads; prefer [onScaleChanged(WebView, float, float)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewClient.html%23onScaleChanged%28android.webkit.WebView%2C+float%2C+float%29).

Gets whether this WebView can be zoomed in.

Returns

boolean

true if this WebView can be zoomed in

canZoomOut

added in  API level 11

boolean canZoomOut ()

This method was deprecated in API level 17.
This method is prone to inaccuracy due to race conditions between the web rendering and UI threads; prefer [onScaleChanged(WebView, float, float)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewClient.html%23onScaleChanged%28android.webkit.WebView%2C+float%2C+float%29).

Gets whether this WebView can be zoomed out.

Returns

boolean

true if this WebView can be zoomed out

capturePicture

added in  API level 1

Picture capturePicture ()

This method was deprecated in API level 19.
Use [onDraw(Canvas)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onDraw%28android.graphics.Canvas%29) to obtain a bitmap snapshot of the WebView, or [saveWebArchive(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23saveWebArchive%28java.lang.String%29) to save the content to a file.

Gets a new picture that captures the current contents of this WebView. The picture is of the entire document being displayed, and is not limited to the area currently displayed by this WebView. Also, the picture is a static copy and is unaffected by later changes to the content being displayed.

Note that due to internal changes, for API levels between [HONEYCOMB](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23HONEYCOMB) and [ICE_CREAM_SANDWICH](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23ICE_CREAM_SANDWICH) inclusive, the picture does not include fixed position elements or scrollable divs.

Note that from [JELLY_BEAN_MR1](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23JELLY_BEAN_MR1) the returned picture should only be drawn into bitmap-backed Canvas - using any other type of Canvas will involve additional conversion at a cost in memory and performance. Also the [createFromStream(InputStream)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FPicture.html%23createFromStream%28java.io.InputStream%29) and [writeToStream(OutputStream)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FPicture.html%23writeToStream%28java.io.OutputStream%29) methods are not supported on the returned object.

Returns

[Picture](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FPicture.html)

a picture that captures the current contents of this WebView

clearCache

added in  API level 1

void clearCache (boolean includeDiskFiles)

Clears the resource cache. Note that the cache is per-application, so this will clear the cache for all WebViews used.

Parameters

includeDiskFiles

boolean: if false, only the RAM cache is cleared

clearClientCertPreferences

added in  API level 21

void clearClientCertPreferences (Runnable onCleared)

Clears the client certificate preferences stored in response to proceeding/cancelling client cert requests. Note that WebView automatically clears these preferences when it receives a [ACTION_STORAGE_CHANGED](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fsecurity%2FKeyChain.html%23ACTION_STORAGE_CHANGED) intent. The preferences are shared by all the WebViews that are created by the embedder application.

Parameters

onCleared

Runnable: A runnable to be invoked when client certs are cleared. The embedder can pass null if not interested in the callback. The runnable will be called in UI thread.

clearFormData

added in  API level 1

void clearFormData ()

Removes the autocomplete popup from the currently focused form field, if present. Note this only affects the display of the autocomplete popup, it does not remove any saved form data from this WebView's store. To do that, use [clearFormData()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewDatabase.html%23clearFormData%28%29).

clearHistory

added in  API level 1

void clearHistory ()

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

clearMatches

added in  API level 3

void clearMatches ()

Clears the highlighting surrounding text matches created by [findAllAsync(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23findAllAsync%28java.lang.String%29).

clearSslPreferences

added in  API level 1

void clearSslPreferences ()

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

clearView

added in  API level 1

void clearView ()

This method was deprecated in API level 18.
Use WebView.loadUrl("about:blank") to reliably reset the view state and release page resources (including any running JavaScript).

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

computeScroll

added in  API level 1

void computeScroll ()

Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary. This will typically be done if the child is animating a scroll using a [Scroller](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwidget%2FScroller.html) object.

copyBackForwardList

added in  API level 1

WebBackForwardList copyBackForwardList ()

Gets the WebBackForwardList for this WebView. This contains the back/forward list for use in querying each item in the history stack. This is a copy of the private WebBackForwardList so it contains only a snapshot of the current state. Multiple calls to this method may return different objects. The object returned from this method will not be updated to reflect any new state.

Returns

[WebBackForwardList](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebBackForwardList.html)

 

createPrintDocumentAdapter

added in  API level 21

PrintDocumentAdapter createPrintDocumentAdapter (String documentName)

Creates a PrintDocumentAdapter that provides the content of this WebView for printing. The adapter works by converting the WebView contents to a PDF stream. The WebView cannot be drawn during the conversion process - any such draws are undefined. It is recommended to use a dedicated off screen WebView for the printing. If necessary, an application may temporarily hide a visible WebView by using a custom PrintDocumentAdapter instance wrapped around the object returned and observing the onStart and onFinish methods. See [PrintDocumentAdapter](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fprint%2FPrintDocumentAdapter.html) for more information.

Parameters

documentName

String: The user-facing name of the printed document. See [PrintDocumentInfo](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fprint%2FPrintDocumentInfo.html)

Returns

[PrintDocumentAdapter](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fprint%2FPrintDocumentAdapter.html)

 

createPrintDocumentAdapter

added in  API level 19

PrintDocumentAdapter createPrintDocumentAdapter ()

This method was deprecated in API level 21.
Use [createPrintDocumentAdapter(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23createPrintDocumentAdapter%28java.lang.String%29) which requires user to provide a print document name.

Returns

[PrintDocumentAdapter](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fprint%2FPrintDocumentAdapter.html)

 

createWebMessageChannel

added in  API level 23

WebMessagePort[] createWebMessageChannel ()

Creates a message channel to communicate with JS and returns the message ports that represent the endpoints of this message channel. The HTML5 message channel functionality is described here

The returned message channels are entangled and already in started state.

Returns

[WebMessagePort[]](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebMessagePort.html)

the two message ports that form the message channel.

destroy

added in  API level 1

void destroy ()

Destroys the internal state of this WebView. This method should be called after this WebView has been removed from the view system. No other methods may be called on this WebView after destroy.

dispatchKeyEvent

added in  API level 1

boolean dispatchKeyEvent (KeyEvent event)

Dispatch a key event to the next view on the focus path. This path runs from the top of the view tree down to the currently focused view. If this view has focus, it will dispatch to itself. Otherwise it will dispatch the next node down the focus path. This method also fires any key listeners.

Parameters

event

KeyEvent: The key event to be dispatched.

Returns

boolean

True if the event was handled, false otherwise.

documentHasImages

added in  API level 1

void documentHasImages (Message response)

Queries the document to see if it contains any image references. The message object will be dispatched with arg1 being set to 1 if images were found and 0 if the document does not reference any images.

Parameters

response

Message: the message that will be dispatched with the result

enableSlowWholeDocumentDraw

added in  API level 21

void enableSlowWholeDocumentDraw ()

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. These optimizations are transparent to the developers. However, under certain circumstances, an App developer may want to disable them:

  1. When an app uses [onDraw(Canvas)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onDraw%28android.graphics.Canvas%29) to do own drawing and accesses portions of the page that is way outside the visible portion of the page.
  2. When an app uses [capturePicture()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23capturePicture%28%29) to capture a very large HTML document. Note that capturePicture is a deprecated API.

Enabling drawing the entire HTML document has a significant performance cost. This method should be called before any WebViews are created.

evaluateJavascript

added in  API level 19

void evaluateJavascript (String script, 
                ValueCallback<String> resultCallback)

Asynchronously evaluates JavaScript in the context of the currently displayed page. If non-null, |resultCallback| will be invoked with any result returned from that execution. This method must be called on the UI thread and the callback will be made on the UI thread.

Compatibility note. Applications targeting [N](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FBuild.VERSION_CODES.html%23N) or later, JavaScript state from an empty WebView is no longer persisted across navigations like[loadUrl(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23loadUrl%28java.lang.String%29). For example, global variables and functions defined before calling [loadUrl(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23loadUrl%28java.lang.String%29) will not exist in the loaded page. Applications should use [addJavascriptInterface(Object, String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23addJavascriptInterface%28java.lang.Object%2C+java.lang.String%29) instead to persist JavaScript objects across navigations.

Parameters

script

String: the JavaScript to execute.

resultCallback

ValueCallback: A callback to be invoked when the script execution completes with the result of the execution (if any). May be null if no notification of the result is required.

findAddress

added in  API level 1

String findAddress (String addr)

Gets the first substring consisting of the address of a physical location. Currently, only addresses in the United States are detected, and consist of:

  • a house number
  • a street name
  • a street type (Road, Circle, etc), either spelled out or abbreviated
  • a city name
  • a state or territory, either spelled out or two-letter abbr
  • an optional 5 digit or 9 digit zip code

All names must be correctly capitalized, and the zip code, if present, must be valid for the state. The street type must be a standard USPS spelling or abbreviation. The state or territory must also be spelled or abbreviated using USPS standards. The house number may not exceed five digits.

Parameters

addr

String: the string to search for addresses

Returns

[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)

the address, or if no address is found, null

findAll

added in  API level 3

int findAll (String find)

This method was deprecated in API level 16.
[findAllAsync(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23findAllAsync%28java.lang.String%29) is preferred.

Finds all instances of find on the page and highlights them. Notifies any registered [WebView.FindListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.FindListener.html).

Parameters

find

String: the string to find

Returns

int

the number of occurrences of the String "find" that were found

See also:

  • [setFindListener(WebView.FindListener)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setFindListener%28android.webkit.WebView.FindListener%29)

findAllAsync

added in  API level 16

void findAllAsync (String find)

Finds all instances of find on the page and highlights them, asynchronously. Notifies any registered [WebView.FindListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.FindListener.html). Successive calls to this will cancel any pending searches.

Parameters

find

String: the string to find.

See also:

  • [setFindListener(WebView.FindListener)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setFindListener%28android.webkit.WebView.FindListener%29)

findFocus

added in  API level 1

View findFocus ()

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

Returns

[View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html)

The view that currently has focus, or null if no focused view can be found.

findNext

added in  API level 3

void findNext (boolean forward)

Highlights and scrolls to the next match found by [findAllAsync(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23findAllAsync%28java.lang.String%29), wrapping around page boundaries as necessary. Notifies any registered [WebView.FindListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.FindListener.html). If [findAllAsync(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23findAllAsync%28java.lang.String%29) has not been called yet, or if [clearMatches()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23clearMatches%28%29) has been called since the last find operation, this function does nothing.

Parameters

forward

boolean: the direction to search

See also:

  • [setFindListener(WebView.FindListener)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setFindListener%28android.webkit.WebView.FindListener%29)

flingScroll

added in  API level 1

void flingScroll (int vx, 
                int vy)

Parameters

vx

int

vy

int

freeMemory

added in  API level 7

void freeMemory ()

This method was deprecated in API level 19.
Memory caches are automatically dropped when no longer needed, and in response to system memory pressure.

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

getAccessibilityClassName

added in  API level 23

CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in[AccessibilityNodeInfo.setClassName](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Faccessibility%2FAccessibilityNodeInfo.html%23setClassName%28java.lang.CharSequence%29).

Returns

[CharSequence](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FCharSequence.html)

 

getAccessibilityNodeProvider

added in  API level 16

AccessibilityNodeProvider getAccessibilityNodeProvider ()

Gets the provider for managing a virtual view hierarchy rooted at this View and reported to [AccessibilityService](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Faccessibilityservice%2FAccessibilityService.html)s that explore the window content.

If this method returns an instance, this instance is responsible for managing [AccessibilityNodeInfo](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Faccessibility%2FAccessibilityNodeInfo.html)s describing the virtual sub-tree rooted at this View including the one representing the View itself. Similarly the returned instance is responsible for performing accessibility actions on any virtual view or the root view itself.

If an [View.AccessibilityDelegate](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.AccessibilityDelegate.html) has been specified via calling [setAccessibilityDelegate(AccessibilityDelegate)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23setAccessibilityDelegate%28android.view.View.AccessibilityDelegate%29) its[getAccessibilityNodeProvider(View)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.AccessibilityDelegate.html%23getAccessibilityNodeProvider%28android.view.View%29) is responsible for handling this call.

Returns

[AccessibilityNodeProvider](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Faccessibility%2FAccessibilityNodeProvider.html)

The provider.

getCertificate

added in  API level 1

SslCertificate getCertificate ()

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

Returns

[SslCertificate](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fnet%2Fhttp%2FSslCertificate.html)

the SSL certificate for the main top-level page

getContentHeight

added in  API level 1

int getContentHeight ()

Gets the height of the HTML content.

Returns

int

the height of the HTML content

getCurrentWebViewPackage

added in  API level 26

PackageInfo getCurrentWebViewPackage ()

If WebView has already been loaded into the current process this method will return the package that was used to load it. Otherwise, the package that would be used if the WebView was loaded right now will be returned; this does not cause WebView to be loaded, so this information may become outdated at any time. The WebView package changes either when the current WebView package is updated, disabled, or uninstalled. It can also be changed through a Developer Setting. If the WebView package changes, any app process that has loaded WebView will be killed. The next time the app starts and loads WebView it will use the new WebView package instead.

Returns

[PackageInfo](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2Fpm%2FPackageInfo.html)

the current WebView package, or null if there is none.

getFavicon

added in  API level 1

Bitmap getFavicon ()

Gets the favicon for the current page. This is the favicon of the current page until WebViewClient.onReceivedIcon is called.

Returns

[Bitmap](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FBitmap.html)

the favicon for the current page

getHandler

added in  API level 1

Handler getHandler ()

Returns

[Handler](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fos%2FHandler.html)

A handler associated with the thread running the View. This handler can be used to pump events in the UI events queue.

getHitTestResult

added in  API level 1

WebView.HitTestResult getHitTestResult ()

Gets a HitTestResult based on the current cursor node. If a HTML::a tag is found and the anchor has a non-JavaScript URL, the HitTestResult type is set to SRC_ANCHOR_TYPE and the URL is set in the "extra" field. If the anchor does not have a URL or if it is a JavaScript URL, the type will be UNKNOWN_TYPE and the URL has to be retrieved through [requestFocusNodeHref(Message)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23requestFocusNodeHref%28android.os.Message%29) asynchronously. If a HTML::img tag is found, the HitTestResult type is set to IMAGE_TYPE and the URL is set in the "extra" field. A type of SRC_IMAGE_ANCHOR_TYPE indicates an anchor with a URL that has an image as a child node. If a phone number is found, the HitTestResult type is set to PHONE_TYPE and the phone number is set in the "extra" field of HitTestResult. If a map address is found, the HitTestResult type is set to GEO_TYPE and the address is set in the "extra" field of HitTestResult. If an email address is found, the HitTestResult type is set to EMAIL_TYPE and the email is set in the "extra" field of HitTestResult. Otherwise, HitTestResult type is set to UNKNOWN_TYPE.

Returns

[WebView.HitTestResult](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.HitTestResult.html)

 

getHttpAuthUsernamePassword

added in  API level 1

String[] getHttpAuthUsernamePassword (String host, 
                String realm)

This method was deprecated in API level 26.
Use [getHttpAuthUsernamePassword(String, String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewDatabase.html%23getHttpAuthUsernamePassword%28java.lang.String%2C+java.lang.String%29) instead

Retrieves HTTP authentication credentials for a given host and realm from the [WebViewDatabase](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewDatabase.html) instance.

Parameters

host

String: the host to which the credentials apply

realm

String: the realm to which the credentials apply

Returns

[String[]](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)

the credentials as a String array, if found. The first element is the username and the second element is the password. Null if no credentials are found.

getOriginalUrl

added in  API level 3

String getOriginalUrl ()

Gets the original URL for the current page. This is not always the same as the URL passed to WebViewClient.onPageStarted because although the load for that URL has begun, the current page may not have changed. Also, there may have been redirects resulting in a different URL to that originally requested.

Returns

[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)

the URL that was originally requested for the current page

getProgress

added in  API level 1

int getProgress ()

Gets the progress for the current page.

Returns

int

the progress for the current page between 0 and 100

getRendererPriorityWaivedWhenNotVisible

added in  API level 26

boolean getRendererPriorityWaivedWhenNotVisible ()

Return whether this WebView requests a priority of [RENDERER_PRIORITY_WAIVED](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23RENDERER_PRIORITY_WAIVED) when not visible.

Returns

boolean

whether this WebView requests a priority of [RENDERER_PRIORITY_WAIVED](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23RENDERER_PRIORITY_WAIVED) when not visible.

getRendererRequestedPriority

added in  API level 26

int getRendererRequestedPriority ()

Get the requested renderer priority for this WebView.

Returns

int

the requested renderer priority policy.

getSafeBrowsingPrivacyPolicyUrl

added in  API level 27

Uri getSafeBrowsingPrivacyPolicyUrl ()

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

Returns

[Uri](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fnet%2FUri.html)

the url pointing to a privacy policy document which can be displayed to users.

This value will never be null.

getScale

added in  API level 1

float getScale ()

This method was deprecated in API level 17.
This method is prone to inaccuracy due to race conditions between the web rendering and UI threads; prefer [onScaleChanged(WebView, float, float)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewClient.html%23onScaleChanged%28android.webkit.WebView%2C+float%2C+float%29).

Gets the current scale of this WebView.

Returns

float

the current scale

getSettings

added in  API level 1

WebSettings getSettings ()

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

Returns

[WebSettings](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebSettings.html)

a WebSettings object that can be used to control this WebView's settings

getTextClassifier

added in  API level 27

TextClassifier getTextClassifier ()

Returns the [TextClassifier](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Ftextclassifier%2FTextClassifier.html) used by this WebView. If no TextClassifier has been set, this WebView uses the default set by the system.

Returns

[TextClassifier](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Ftextclassifier%2FTextClassifier.html)

This value will never be null.

getTitle

added in  API level 1

String getTitle ()

Gets the title for the current page. This is the title of the current page until WebViewClient.onReceivedTitle is called.

Returns

[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)

the title for the current page

getUrl

added in  API level 1

String getUrl ()

Gets the URL for the current page. This is not always the same as the URL passed to WebViewClient.onPageStarted because although the load for that URL has begun, the current page may not have changed.

Returns

[String](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fjava%2Flang%2FString.html)

the URL for the current page

getWebChromeClient

added in  API level 26

WebChromeClient getWebChromeClient ()

Gets the chrome handler.

Returns

[WebChromeClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebChromeClient.html)

the WebChromeClient, or null if not yet set

See also:

  • [setWebChromeClient(WebChromeClient)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setWebChromeClient%28android.webkit.WebChromeClient%29)

getWebViewClient

added in  API level 26

WebViewClient getWebViewClient ()

Gets the WebViewClient.

Returns

[WebViewClient](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewClient.html)

the WebViewClient, or a default client if not yet set

See also:

  • [setWebViewClient(WebViewClient)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23setWebViewClient%28android.webkit.WebViewClient%29)

goBack

added in  API level 1

void goBack ()

Goes back in the history of this WebView.

goBackOrForward

added in  API level 1

void goBackOrForward (int steps)

Goes to the history item that is the number of steps away from the current item. Steps is negative if backward and positive if forward.

Parameters

steps

int: the number of steps to take back or forward in the back forward list

goForward

added in  API level 1

void goForward ()

Goes forward in the history of this WebView.

invokeZoomPicker

added in  API level 1

void invokeZoomPicker ()

Invokes the graphical zoom picker widget for this WebView. This will result in the zoom widget appearing on the screen to control the zoom level of this WebView.

isPrivateBrowsingEnabled

added in  API level 11

boolean isPrivateBrowsingEnabled ()

Gets whether private browsing is enabled in this WebView.

Returns

boolean

 

loadData

added in  API level 1

void loadData (String data, 
                String mimeType, 
                String encoding)

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

Note that JavaScript's same origin policy means that script running in a page loaded using this method will be unable to access content loaded using any scheme other than 'data', including 'http(s)'. To avoid this restriction, use [loadDataWithBaseURL()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23loadDataWithBaseURL%28java.lang.String%2C+java.lang.String%2C+java.lang.String%2C+java.lang.String%2C+java.lang.String%29) with an appropriate base URL.

The encoding parameter specifies whether the data is base64 or URL encoded. If the data is base64 encoded, the value of the encoding parameter must be 'base64'. For all other values of the parameter, including null, it is assumed that the data uses ASCII encoding for octets inside the range of safe URL characters and use the standard %xx hex encoding of URLs for octets outside that range. For example, '#', '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively.

The 'data' scheme URL formed by this method uses the default US-ASCII charset. If you need need to set a different charset, you should form a 'data' scheme URL which explicitly specifies a charset parameter in the mediatype portion of the URL and call [loadUrl(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23loadUrl%28java.lang.String%29) instead. Note that the charset obtained from the mediatype portion of a data URL always overrides that specified in the HTML or XML document itself.

Parameters

data

String: a String of data in the given encoding

mimeType

String: the MIME type of the data, e.g. 'text/html'

encoding

String: the encoding of the data

loadDataWithBaseURL

added in  API level 1

void loadDataWithBaseURL (String baseUrl, 
                String data, 
                String mimeType, 
                String encoding, 
                String historyUrl)

Loads the given data into this WebView, using baseUrl as the base URL for the content. The base URL is used both to resolve relative URLs and when applying JavaScript's same origin policy. The historyUrl is used for the history entry.

Note that content specified in this way can access local device files (via 'file' scheme URLs) only if baseUrl specifies a scheme other than 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.

If the base URL uses the data scheme, this method is equivalent to calling [loadData()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23loadData%28java.lang.String%2C+java.lang.String%2C+java.lang.String%29) and the historyUrl is ignored, and the data will be treated as part of a data: URL. If the base URL uses any other scheme, then the data will be loaded into the WebView as a plain string (i.e. not part of a data URL) and any URL-encoded entities in the string will not be decoded.

Note that the baseUrl is sent in the 'Referer' HTTP header when requesting subresources (images, etc.) of the page loaded using this method.

Parameters

baseUrl

String: the URL to use as the page's base URL. If null defaults to 'about:blank'.

data

String: a String of data in the given encoding

mimeType

String: the MIMEType of the data, e.g. 'text/html'. If null, defaults to 'text/html'.

encoding

String: the encoding of the data

historyUrl

String: the URL to use as the history entry. If null defaults to 'about:blank'. If non-null, this must be a valid URL.

loadUrl

added in  API level 1

void loadUrl (String url)

Loads the given URL.

Also see compatibility note on [evaluateJavascript(String, ValueCallback)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23evaluateJavascript%28java.lang.String%2C+android.webkit.ValueCallback%3Cjava.lang.String%3E%29).

Parameters

url

String: the URL of the resource to load

loadUrl

added in  API level 8

void loadUrl (String url, 
                Map<String, String> additionalHttpHeaders)

Loads the given URL with the specified additional HTTP headers.

Also see compatibility note on [evaluateJavascript(String, ValueCallback)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23evaluateJavascript%28java.lang.String%2C+android.webkit.ValueCallback%3Cjava.lang.String%3E%29).

Parameters

url

String: the URL of the resource to load

additionalHttpHeaders

Map: the additional headers to be used in the HTTP request for this URL, specified as a map from name to value. Note that if this map contains any of the headers that are set by default by this WebView, such as those controlling caching, accept types or the User-Agent, their values may be overridden by this WebView's defaults.

onChildViewAdded

added in  API level 1

void onChildViewAdded (View parent, 
                View child)

This method was deprecated in API level 8.
WebView no longer needs to implement ViewGroup.OnHierarchyChangeListener. This method does nothing now.

Called when a new child is added to a parent view.

Parameters

parent

View: the view in which a child was added

child

View: the new child view added in the hierarchy

onChildViewRemoved

added in  API level 1

void onChildViewRemoved (View p, 
                View child)

This method was deprecated in API level 8.
WebView no longer needs to implement ViewGroup.OnHierarchyChangeListener. This method does nothing now.

Called when a child is removed from a parent view.

Parameters

p

View: the view from which the child was removed

child

View: the child removed from the hierarchy

onCreateInputConnection

added in  API level 3

InputConnection onCreateInputConnection (EditorInfo outAttrs)

Creates a new InputConnection for an InputMethod to interact with the WebView. This is similar to [onCreateInputConnection(EditorInfo)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23onCreateInputConnection%28android.view.inputmethod.EditorInfo%29) but note that WebView calls InputConnection methods on a thread other than the UI thread. If these methods are overridden, then the overriding methods should respect thread restrictions when calling View methods or accessing data.

Parameters

outAttrs

EditorInfo: Fill in with attribute information about the connection.

Returns

[InputConnection](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Finputmethod%2FInputConnection.html)

 

onDragEvent

added in  API level 11

boolean onDragEvent (DragEvent event)

Handles drag events sent by the system following a call to [startDragAndDrop()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23startDragAndDrop%28android.content.ClipData%2C+android.view.View.DragShadowBuilder%2C+java.lang.Object%2C+int%29).

When the system calls this method, it passes a [DragEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FDragEvent.html) object. A call to [getAction()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FDragEvent.html%23getAction%28%29) returns one of the action type constants defined in DragEvent. The method uses these to determine what is happening in the drag and drop operation.

Parameters

event

DragEvent: The [DragEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FDragEvent.html) sent by the system. The [getAction()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FDragEvent.html%23getAction%28%29) method returns an action type constant defined in DragEvent, indicating the type of drag event represented by this object.

Returns

boolean

true if the method was successful, otherwise false.

The method should return true in response to an action type of [ACTION_DRAG_STARTED](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FDragEvent.html%23ACTION_DRAG_STARTED) to receive drag events for the current operation.

The method should also return true in response to an action type of [ACTION_DROP](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FDragEvent.html%23ACTION_DROP) if it consumed the drop, or false if it didn't.

For all other events, the return value is ignored.

onFinishTemporaryDetach

added in  API level 3

void onFinishTemporaryDetach ()

Called after [onStartTemporaryDetach()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23onStartTemporaryDetach%28%29) when the container is done changing the view.

onGenericMotionEvent

added in  API level 12

boolean onGenericMotionEvent (MotionEvent event)

Implement this method to handle generic motion events.

Generic motion events describe joystick movements, mouse hovers, track pad touches, scroll wheel movements and other input events. The [source](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FMotionEvent.html%23getSource%28%29) of the motion event specifies the class of input that was received. Implementations of this method must examine the bits in the source before processing the event. The following code example shows how this is done.

Generic motion events with source class [SOURCE_CLASS_POINTER](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FInputDevice.html%23SOURCE_CLASS_POINTER) are delivered to the view under the pointer. All other generic motion events are delivered to the focused view.

 public boolean onGenericMotionEvent(MotionEvent event) {     if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) {         if (event.getAction() == MotionEvent.ACTION_MOVE) {             // process the joystick movement...             return true;         }     }     if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {         switch (event.getAction()) {             case MotionEvent.ACTION_HOVER_MOVE:                 // process the mouse hover movement...                 return true;             case MotionEvent.ACTION_SCROLL:                 // process the scroll wheel movement...                 return true;         }     }     return super.onGenericMotionEvent(event); }

Parameters

event

MotionEvent: The generic motion event being processed.

Returns

boolean

True if the event was handled, false otherwise.

onGlobalFocusChanged

added in  API level 1

void onGlobalFocusChanged (View oldFocus, 
                View newFocus)

This method was deprecated in API level 3.
WebView should not have implemented ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now.

Callback method to be invoked when the focus changes in the view tree. When the view tree transitions from touch mode to non-touch mode, oldFocus is null. When the view tree transitions from non-touch mode to touch mode, newFocus is null. When focus changes in non-touch mode (without transition from or to touch mode) either oldFocus or newFocus can be null.

Parameters

oldFocus

View: The previously focused view, if any.

newFocus

View: The newly focused View, if any.

onHoverEvent

added in  API level 14

boolean onHoverEvent (MotionEvent event)

Implement this method to handle hover events.

This method is called whenever a pointer is hovering into, over, or out of the bounds of a view and the view is not currently being touched. Hover events are represented as pointer events with action [ACTION_HOVER_ENTER](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FMotionEvent.html%23ACTION_HOVER_ENTER)[ACTION_HOVER_MOVE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FMotionEvent.html%23ACTION_HOVER_MOVE), or [ACTION_HOVER_EXIT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FMotionEvent.html%23ACTION_HOVER_EXIT).

  • The view receives a hover event with action [ACTION_HOVER_ENTER](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FMotionEvent.html%23ACTION_HOVER_ENTER) when the pointer enters the bounds of the view.
  • The view receives a hover event with action [ACTION_HOVER_MOVE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FMotionEvent.html%23ACTION_HOVER_MOVE) when the pointer has already entered the bounds of the view and has moved.
  • The view receives a hover event with action [ACTION_HOVER_EXIT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FMotionEvent.html%23ACTION_HOVER_EXIT) when the pointer has exited the bounds of the view or when the pointer is about to go down due to a button click, tap, or similar user action that causes the view to be touched.

The view should implement this method to return true to indicate that it is handling the hover event, such as by changing its drawable state.

The default implementation calls [setHovered(boolean)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23setHovered%28boolean%29) to update the hovered state of the view when a hover enter or hover exit event is received, if the view is enabled and is clickable. The default implementation also sends hover accessibility events.

Parameters

event

MotionEvent: The motion event that describes the hover.

Returns

boolean

True if the view handled the hover event.

onKeyDown

added in  API level 1

boolean onKeyDown (int keyCode, 
                KeyEvent event)

Default implementation of [KeyEvent.Callback.onKeyDown()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.Callback.html%23onKeyDown%28int%2C+android.view.KeyEvent%29): perform press of the view when [KEYCODE_DPAD_CENTER](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html%23KEYCODE_DPAD_CENTER) or [KEYCODE_ENTER](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html%23KEYCODE_ENTER) is released, if the view is enabled and clickable.

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters

keyCode

int: a key code that represents the button pressed, from [KeyEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html)

event

KeyEvent: the KeyEvent object that defines the button action

Returns

boolean

If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyMultiple

added in  API level 1

boolean onKeyMultiple (int keyCode, 
                int repeatCount, 
                KeyEvent event)

Default implementation of [KeyEvent.Callback.onKeyMultiple()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.Callback.html%23onKeyMultiple%28int%2C+int%2C+android.view.KeyEvent%29): always returns false (doesn't handle the event).

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters

keyCode

int: A key code that represents the button pressed, from [KeyEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html).

repeatCount

int: The number of times the action was made.

event

KeyEvent: The KeyEvent object that defines the button action.

Returns

boolean

If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyUp

added in  API level 1

boolean onKeyUp (int keyCode, 
                KeyEvent event)

Default implementation of [KeyEvent.Callback.onKeyUp()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.Callback.html%23onKeyUp%28int%2C+android.view.KeyEvent%29): perform clicking of the view when [KEYCODE_DPAD_CENTER](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html%23KEYCODE_DPAD_CENTER)[KEYCODE_ENTER](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html%23KEYCODE_ENTER) or [KEYCODE_SPACE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html%23KEYCODE_SPACE) is released.

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters

keyCode

int: A key code that represents the button pressed, from [KeyEvent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FKeyEvent.html).

event

KeyEvent: The KeyEvent object that defines the button action.

Returns

boolean

If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onPause

added in  API level 11

void onPause ()

Does a best-effort attempt to pause any processing that can be paused safely, such as animations and geolocation. Note that this call does not pause JavaScript. To pause JavaScript globally, use [pauseTimers()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23pauseTimers%28%29). To resume WebView, call [onResume()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onResume%28%29).

onProvideAutofillVirtualStructure

added in  API level 26

void onProvideAutofillVirtualStructure (ViewStructure structure, 
                int flags)

Populates a [ViewStructure](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html) containing virtual children to fullfil an autofill request.

This method should be used when the view manages a virtual structure under this view. For example, a view that draws input fields using [draw(Canvas)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23draw%28android.graphics.Canvas%29).

When implementing this method, subclasses must follow the rules below:

  • Add virtual children by calling the [newChild(int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html%23newChild%28int%29) or [asyncNewChild(int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html%23asyncNewChild%28int%29) methods, where the id is an unique id identifying the children in the virtual structure.
  • The children hierarchy can have multiple levels if necessary, but ideally it should exclude intermediate levels that are irrelevant for autofill; that would improve the autofill performance.
  • Also implement [autofill(SparseArray)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23autofill%28android.util.SparseArray%3Candroid.view.autofill.AutofillValue%3E%29) to autofill the virtual children.
  • Set the autofill properties of the child structure as defined by [onProvideAutofillStructure(ViewStructure, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23onProvideAutofillStructure%28android.view.ViewStructure%2C+int%29), using[setAutofillId(AutofillId, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html%23setAutofillId%28android.view.autofill.AutofillId%2C+int%29) to set its autofill id.
  • Call [notifyViewEntered(View, int, Rect)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Fautofill%2FAutofillManager.html%23notifyViewEntered%28android.view.View%2C+int%2C+android.graphics.Rect%29) and/or [notifyViewExited(View, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Fautofill%2FAutofillManager.html%23notifyViewExited%28android.view.View%2C+int%29) when the focused virtual child changed.
  • Call [notifyValueChanged(View, int, AutofillValue)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Fautofill%2FAutofillManager.html%23notifyValueChanged%28android.view.View%2C+int%2C+android.view.autofill.AutofillValue%29) when the value of a virtual child changed.
  • Call [notifyViewVisibilityChanged(View, int, boolean)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Fautofill%2FAutofillManager.html%23notifyViewVisibilityChanged%28android.view.View%2C+int%2C+boolean%29) when the visibility of a virtual child changed.
  • Call [commit()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Fautofill%2FAutofillManager.html%23commit%28%29) when the autofill context of the view structure changed and the current context should be committed (for example, when the user tapped a SUBMIT button in an HTML page).
  • Call [cancel()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Fautofill%2FAutofillManager.html%23cancel%28%29) when the autofill context of the view structure changed and the current context should be canceled (for example, when the user tapped a CANCEL button in an HTML page).
  • Provide ways for users to manually request autofill by calling [requestAutofill(View, int, Rect)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Fautofill%2FAutofillManager.html%23requestAutofill%28android.view.View%2C+int%2C+android.graphics.Rect%29).
  • The left and top values set in [setDimens(int, int, int, int, int, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html%23setDimens%28int%2C+int%2C+int%2C+int%2C+int%2C+int%29) must be relative to the next [isImportantForAutofill()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23isImportantForAutofill%28%29) predecessor view included in the structure.

Views with virtual children support the Autofill Framework mainly by:

  • Providing the metadata defining what the virtual children mean and how they can be autofilled.
  • Implementing the methods that autofill the virtual children.

This method is responsible for the former; [autofill(SparseArray)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23autofill%28android.util.SparseArray%3Candroid.view.autofill.AutofillValue%3E%29) is responsible for the latter.

The [ViewStructure](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html) traditionally represents a [View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html), while for web pages it represent HTML nodes. Hence, it's necessary to "map" the HTML properties in a way that is understood by the [AutofillService](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fservice%2Fautofill%2FAutofillService.html) implementations:

  1. Only the HTML nodes inside a FORM are generated.
  2. The source of the HTML is set using [setWebDomain(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html%23setWebDomain%28java.lang.String%29) in the node representing the WebView.
  3. If a web page has multiple FORMs, only the data for the current form is represented—if the user taps a field from another form, then the current autofill context is canceled (by calling [cancel()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Fautofill%2FAutofillManager.html%23cancel%28%29) and a new context is created for that FORM.
  4. Similarly, if the page has IFRAME nodes, they are not initially represented in the view structure until the user taps a field from a FORM inside the IFRAME, in which case it would be treated the same way as multiple forms described above, except that the [web domain](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html%23setWebDomain%28java.lang.String%29) of the FORM contains the src attribute from the IFRAME node.
  5. The W3C autofill field (autocomplete tag attribute) maps to [setAutofillHints(String[])](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html%23setAutofillHints%28java.lang.String%5B%5D%29).
  6. If the view is editable, the [setAutofillType(int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html%23setAutofillType%28int%29) and [setAutofillValue(AutofillValue)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html%23setAutofillValue%28android.view.autofill.AutofillValue%29) must be set.
  7. The placeholder attribute maps to [setHint(CharSequence)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html%23setHint%28java.lang.CharSequence%29).
  8. Other HTML attributes can be represented through [setHtmlInfo(android.view.ViewStructure.HtmlInfo)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewStructure.html%23setHtmlInfo%28android.view.ViewStructure.HtmlInfo%29).

If the WebView implementation can determine that the value of a field was set statically (for example, not through Javascript), it should also callstructure.setDataIsSensitive(false).

For example, an HTML form with 2 fields for username and password:

    <input type="text" name="username" id="user" value="Type your username" autocomplete="username" placeholder="Email or username">    <input type="password" name="password" id="pass" autocomplete="current-password" placeholder="Password"> 

Would map to:

     int index = structure.addChildCount(2);     ViewStructure username = structure.newChild(index);     username.setAutofillId(structure.getAutofillId(), 1); // id 1 - first child     username.setAutofillHints("username");     username.setHtmlInfo(username.newHtmlInfoBuilder("input")         .addAttribute("type", "text")         .addAttribute("name", "username")         .build());     username.setHint("Email or username");     username.setAutofillType(View.AUTOFILL_TYPE_TEXT);     username.setAutofillValue(AutofillValue.forText("Type your username"));     // Value of the field is not sensitive because it was created statically and not changed.     username.setDataIsSensitive(false);     ViewStructure password = structure.newChild(index + 1);     username.setAutofillId(structure, 2); // id 2 - second child     password.setAutofillHints("current-password");     password.setHtmlInfo(password.newHtmlInfoBuilder("input")         .addAttribute("type", "password")         .addAttribute("name", "password")         .build());     password.setHint("Password");     password.setAutofillType(View.AUTOFILL_TYPE_TEXT); 

Parameters

structure

ViewStructure: fill in with virtual children data for autofill purposes.

flags

int: optional flags.

onProvideVirtualStructure

added in  API level 23

void onProvideVirtualStructure (ViewStructure structure)

Called when assist structure is being retrieved from a view as part of [Activity.onProvideAssistData](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fapp%2FActivity.html%23onProvideAssistData%28android.os.Bundle%29) to generate additional virtual structure under this view. The defaullt implementation uses [getAccessibilityNodeProvider()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23getAccessibilityNodeProvider%28%29) to try to generate this from the view's virtual accessibility nodes, if any. You can override this for a more optimal implementation providing this data.

Parameters

structure

ViewStructure

onResume

added in  API level 11

void onResume ()

Resumes a WebView after a previous call to [onPause()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onPause%28%29).

onStartTemporaryDetach

added in  API level 3

void onStartTemporaryDetach ()

This is called when a container is going to temporarily detach a child, with [ViewGroup.detachViewFromParent](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.html%23detachViewFromParent%28android.view.View%29). It will either be followed by [onFinishTemporaryDetach()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23onFinishTemporaryDetach%28%29) or [onDetachedFromWindow()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23onDetachedFromWindow%28%29) when the container is done.

onTouchEvent

added in  API level 1

boolean onTouchEvent (MotionEvent event)

Implement this method to handle touch screen motion events.

If this method is used to detect click actions, it is recommended that the actions be performed by implementing and calling [performClick()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23performClick%28%29). This will ensure consistent system behavior, including:

  • obeying click sound preferences
  • dispatching OnClickListener calls
  • handling [ACTION_CLICK](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Faccessibility%2FAccessibilityNodeInfo.html%23ACTION_CLICK) when accessibility features are enabled

Parameters

event

MotionEvent: The motion event.

Returns

boolean

True if the event was handled, false otherwise.

onTrackballEvent

added in  API level 1

boolean onTrackballEvent (MotionEvent event)

Implement this method to handle trackball motion events. The relative movement of the trackball since the last event can be retrieve with [MotionEvent.getX()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FMotionEvent.html%23getX%28%29) and [MotionEvent.getY()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FMotionEvent.html%23getY%28%29). These are normalized so that a movement of 1 corresponds to the user pressing one DPAD key (so they will often be fractional values, representing the more fine-grained movement information available from a trackball).

Parameters

event

MotionEvent: The motion event.

Returns

boolean

True if the event was handled, false otherwise.

onWindowFocusChanged

added in  API level 1

void onWindowFocusChanged (boolean hasWindowFocus)

Called when the window containing this view gains or loses focus. Note that this is separate from view focus: to receive key events, both your view and its window must have focus. If a window is displayed on top of yours that takes input focus, then your own window will lose focus but the view focus will remain unchanged.

Parameters

hasWindowFocus

boolean: True if the window containing this view now has focus, false otherwise.

overlayHorizontalScrollbar

added in  API level 1

boolean overlayHorizontalScrollbar ()

This method was deprecated in API level 23.
This method is now obsolete.

Gets whether horizontal scrollbar has overlay style.

Returns

boolean

true

overlayVerticalScrollbar

added in  API level 1

boolean overlayVerticalScrollbar ()

This method was deprecated in API level 23.
This method is now obsolete.

Gets whether vertical scrollbar has overlay style.

Returns

boolean

false

pageDown

added in  API level 1

boolean pageDown (boolean bottom)

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

Parameters

bottom

boolean: true to jump to bottom of page

Returns

boolean

true if the page was scrolled

pageUp

added in  API level 1

boolean pageUp (boolean top)

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

Parameters

top

boolean: true to jump to the top of the page

Returns

boolean

true if the page was scrolled

pauseTimers

added in  API level 1

void pauseTimers ()

Pauses all layout, parsing, and JavaScript timers for all WebViews. This is a global requests, not restricted to just this WebView. This can be useful if the application has been paused.

performLongClick

added in  API level 1

boolean performLongClick ()

Calls this view's OnLongClickListener, if it is defined. Invokes the context menu if the OnLongClickListener did not consume the event.

Returns

boolean

true if one of the above receivers consumed the event, false otherwise

postUrl

added in  API level 5

void postUrl (String url, 
                byte[] postData)

Loads the URL with postData using "POST" method into this WebView. If url is not a network URL, it will be loaded with [loadUrl(String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23loadUrl%28java.lang.String%29) instead, ignoring the postData param.

Parameters

url

String: the URL of the resource to load

postData

byte: the data will be passed to "POST" request, which must be be "application/x-www-form-urlencoded" encoded.

postVisualStateCallback

added in  API level 23

void postVisualStateCallback (long requestId, 
                WebView.VisualStateCallback callback)

Posts a [WebView.VisualStateCallback](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.VisualStateCallback.html), which will be called when the current state of the WebView is ready to be drawn.

Because updates to the DOM are processed asynchronously, updates to the DOM may not immediately be reflected visually by subsequent [onDraw(Canvas)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23onDraw%28android.graphics.Canvas%29) invocations. The [WebView.VisualStateCallback](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.VisualStateCallback.html) provides a mechanism to notify the caller when the contents of the DOM at the current time are ready to be drawn the next time the [WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html) draws.

The next draw after the callback completes is guaranteed to reflect all the updates to the DOM up to the point at which the [WebView.VisualStateCallback](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.VisualStateCallback.html) was posted, but it may also contain updates applied after the callback was posted.

The state of the DOM covered by this API includes the following:

  • primitive HTML elements (div, img, span, etc..)
  • images
  • CSS animations
  • WebGL
  • canvas

It does not include the state of:

  • the video tag

To guarantee that the [WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html) will successfully render the first frame after the [onComplete(long)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.VisualStateCallback.html%23onComplete%28long%29) method has been called a set of conditions must be met:

  • If the [WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html)'s visibility is set to [VISIBLE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23VISIBLE) then the [WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html) must be attached to the view hierarchy.
  • If the [WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html)'s visibility is set to [INVISIBLE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23INVISIBLE) then the [WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html) must be attached to the view hierarchy and must be made [VISIBLE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23VISIBLE) from the [onComplete(long)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.VisualStateCallback.html%23onComplete%28long%29) method.
  • If the [WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html)'s visibility is set to [GONE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23GONE) then the [WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html) must be attached to the view hierarchy and its [LayoutParams](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwidget%2FAbsoluteLayout.LayoutParams.html)'s width and height need to be set to fixed values and must be made [VISIBLE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23VISIBLE) from the [onComplete(long)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.VisualStateCallback.html%23onComplete%28long%29) method.

When using this API it is also recommended to enable pre-rasterization if the [WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html) is off screen to avoid flickering. See [setOffscreenPreRaster(boolean)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebSettings.html%23setOffscreenPreRaster%28boolean%29) for more details and do consider its caveats.

Parameters

requestId

long: An id that will be returned in the callback to allow callers to match requests with callbacks.

callback

WebView.VisualStateCallback: The callback to be invoked.

postWebMessage

added in  API level 23

void postWebMessage (WebMessage message, 
                Uri targetOrigin)

Post a message to main frame. The embedded application can restrict the messages to a certain target origin. See HTML5 spec for how target origin can be used.

A target origin can be set as a wildcard ("*"). However this is not recommended. See the page above for security issues.

Parameters

message

WebMessage: the WebMessage

targetOrigin

Uri: the target origin.

reload

added in  API level 1

void reload ()

Reloads the current URL.

removeJavascriptInterface

added in  API level 11

void removeJavascriptInterface (String name)

Removes a previously injected Java object from this WebView. Note that the removal will not be reflected in JavaScript until the page is next (re)loaded. See [addJavascriptInterface(Object, String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23addJavascriptInterface%28java.lang.Object%2C+java.lang.String%29).

Parameters

name

String: the name used to expose the object in JavaScript

requestChildRectangleOnScreen

added in  API level 1

boolean requestChildRectangleOnScreen (View child, 
                Rect rect, 
                boolean immediate)

Called when a child of this group wants a particular rectangle to be positioned onto the screen. [ViewGroup](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.html)s overriding this can trust that:

  • child will be a direct child of this group
  • rectangle will be in the child's content coordinates

[ViewGroup](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.html)s overriding this should uphold the contract:

  • nothing will change if the rectangle is already visible
  • the view port will be scrolled only just enough to make the rectangle visible

Parameters

child

View: The direct child making the request.

rect

Rect: The rectangle in the child's coordinates the child wishes to be on the screen.

immediate

boolean: True to forbid animated or delayed scrolling, false otherwise

Returns

boolean

Whether the group scrolled to handle the operation

requestFocus

added in  API level 1

boolean requestFocus (int direction, 
                Rect previouslyFocusedRect)

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. The rectangle can help give larger views a finer grained hint about where focus is coming from, and therefore, where to show selection, or forward focus change internally. A view will not actually take focus if it is not focusable ([isFocusable()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23isFocusable%28%29) returns false), or if it is focusable and it is not focusable in touch mode ([isFocusableInTouchMode()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23isFocusableInTouchMode%28%29)) while the device is in touch mode. A View will not take focus if it is not visible. A View will not take focus if one of its parents has [getDescendantFocusability()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.html%23getDescendantFocusability%28%29) equal to [FOCUS_BLOCK_DESCENDANTS](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.html%23FOCUS_BLOCK_DESCENDANTS). See also [focusSearch(int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23focusSearch%28int%29), which is what you call to say that you have focus, and you want your parent to look for the next one. You may wish to override this method if your custom [View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html) has an internal [View](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html) that it wishes to forward the request to. Looks for a view to give focus to respecting the setting specified by[getDescendantFocusability()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.html%23getDescendantFocusability%28%29). Uses [onRequestFocusInDescendants(int, android.graphics.Rect)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FViewGroup.html%23onRequestFocusInDescendants%28int%2C+android.graphics.Rect%29) to find focus within the children of this group when appropriate.

Parameters

direction

int: One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT

previouslyFocusedRect

Rect: The rectangle (in this View's coordinate system) to give a finer grained hint about where focus is coming from. May be null if there is no hint.

Returns

boolean

Whether this view or one of its descendants actually took focus.

requestFocusNodeHref

added in  API level 1

void requestFocusNodeHref (Message hrefMsg)

Requests the anchor or image element URL at the last tapped point. If hrefMsg is null, this method returns immediately and does not dispatch hrefMsg to its target. If the tapped point hits an image, an anchor, or an image in an anchor, the message associates strings in named keys in its data. The value paired with the key may be an empty string.

Parameters

hrefMsg

Message: the message to be dispatched with the result of the request. The message data contains three keys. "url" returns the anchor's href attribute. "title" returns the anchor's text. "src" returns the image's src attribute.

requestImageRef

added in  API level 1

void requestImageRef (Message msg)

Requests the URL of the image last touched by the user. msg will be sent to its target with a String representing the URL as its object.

Parameters

msg

Message: the message to be dispatched with the result of the request as the data member with "url" as key. The result can be null.

restoreState

added in  API level 1

WebBackForwardList restoreState (Bundle inState)

Restores the state of this WebView from the given Bundle. This method is intended for use in [onRestoreInstanceState(Bundle)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fapp%2FActivity.html%23onRestoreInstanceState%28android.os.Bundle%29) and should be called to restore the state of this WebView. If it is called after this WebView has had a chance to build state (load pages, create a back/forward list, etc.) there may be undesirable side-effects. Please note that this method no longer restores the display data for this WebView.

Parameters

inState

Bundle: the incoming Bundle of state

Returns

[WebBackForwardList](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebBackForwardList.html)

the restored back/forward list or null if restoreState failed

resumeTimers

added in  API level 1

void resumeTimers ()

Resumes all layout, parsing, and JavaScript timers for all WebViews. This will resume dispatching all timers.

savePassword

added in  API level 1

void savePassword (String host, 
                String username, 
                String password)

This method was deprecated in API level 18.
Saving passwords in WebView will not be supported in future versions.

Sets a username and password pair for the specified host. This data is used by the WebView to autocomplete username and password fields in web forms. Note that this is unrelated to the credentials used for HTTP authentication.

Parameters

host

String: the host that required the credentials

username

String: the username for the given host

password

String: the password for the given host

See also:

  • [clearUsernamePassword()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewDatabase.html%23clearUsernamePassword%28%29)
  • [hasUsernamePassword()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewDatabase.html%23hasUsernamePassword%28%29)

saveState

added in  API level 1

WebBackForwardList saveState (Bundle outState)

Saves the state of this WebView used in [onSaveInstanceState(Bundle)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fapp%2FActivity.html%23onSaveInstanceState%28android.os.Bundle%29). Please note that this method no longer stores the display data for this WebView. The previous behavior could potentially leak files if [restoreState(Bundle)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23restoreState%28android.os.Bundle%29) was never called.

Parameters

outState

Bundle: the Bundle to store this WebView's state

Returns

[WebBackForwardList](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebBackForwardList.html)

the same copy of the back/forward list used to save the state. If saveState fails, the returned list will be null.

saveWebArchive

added in  API level 11

void saveWebArchive (String filename)

Saves the current view as a web archive.

Parameters

filename

String: the filename where the archive should be placed

saveWebArchive

added in  API level 11

void saveWebArchive (String basename, 
                boolean autoname, 
                ValueCallback<String> callback)

Saves the current view as a web archive.

Parameters

basename

String: the filename where the archive should be placed

autoname

boolean: if false, takes basename to be a file. If true, basename is assumed to be a directory in which a filename will be chosen according to the URL of the current page.

callback

ValueCallback: called after the web archive has been saved. The parameter for onReceiveValue will either be the filename under which the file was saved, or null if saving the file failed.

setBackgroundColor

added in  API level 1

void setBackgroundColor (int color)

Sets the background color for this view.

Parameters

color

int: the color of the background

setCertificate

added in  API level 1

void setCertificate (SslCertificate certificate)

This method was deprecated in API level 17.
Calling this function has no useful effect, and will be ignored in future releases.

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

Parameters

certificate

SslCertificate

setDownloadListener

added in  API level 1

void setDownloadListener (DownloadListener listener)

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

Parameters

listener

DownloadListener: an implementation of DownloadListener

setFindListener

added in  API level 16

void setFindListener (WebView.FindListener listener)

Registers the listener to be notified as find-on-page operations progress. This will replace the current listener.

Parameters

listener

WebView.FindListener: an implementation of [WebView.FindListener](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.FindListener.html)

setHorizontalScrollbarOverlay

added in  API level 1

void setHorizontalScrollbarOverlay (boolean overlay)

This method was deprecated in API level 23.
This method has no effect.

Specifies whether the horizontal scrollbar has overlay style.

Parameters

overlay

boolean: true if horizontal scrollbar should have overlay style

setHttpAuthUsernamePassword

added in  API level 1

void setHttpAuthUsernamePassword (String host, 
                String realm, 
                String username, 
                String password)

This method was deprecated in API level 26.
Use [setHttpAuthUsernamePassword(String, String, String, String)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewDatabase.html%23setHttpAuthUsernamePassword%28java.lang.String%2C+java.lang.String%2C+java.lang.String%2C+java.lang.String%29) instead

Stores HTTP authentication credentials for a given host and realm to the [WebViewDatabase](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewDatabase.html) instance.

Parameters

host

String: the host to which the credentials apply

realm

String: the realm to which the credentials apply

username

String: the username

password

String: the password

setInitialScale

added in  API level 1

void setInitialScale (int scaleInPercent)

Sets the initial scale for this WebView. 0 means default. The behavior for the default scale depends on the state of [getUseWideViewPort()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebSettings.html%23getUseWideViewPort%28%29) and[getLoadWithOverviewMode()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebSettings.html%23getLoadWithOverviewMode%28%29). If the content fits into the WebView control by width, then the zoom is set to 100%. For wide content, the behavior depends on the state of [getLoadWithOverviewMode()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebSettings.html%23getLoadWithOverviewMode%28%29). If its value is true, the content will be zoomed out to be fit by width into the WebView control, otherwise not. If initial scale is greater than 0, WebView starts with this value as initial scale. Please note that unlike the scale properties in the viewport meta tag, this method doesn't take the screen density into account.

Parameters

scaleInPercent

int: the initial scale in percent

setLayerType

added in  API level 11

void setLayerType (int layerType, 
                Paint paint)

Specifies the type of layer backing this view. The layer can be [LAYER_TYPE_NONE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23LAYER_TYPE_NONE)[LAYER_TYPE_SOFTWARE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23LAYER_TYPE_SOFTWARE) or [LAYER_TYPE_HARDWARE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23LAYER_TYPE_HARDWARE).

A layer is associated with an optional [Paint](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FPaint.html) instance that controls how the layer is composed on screen. The following properties of the paint are taken into account when composing the layer:

  • [Translucency (alpha)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FPaint.html%23getAlpha%28%29)
  • [Blending mode](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FPaint.html%23getXfermode%28%29)
  • [Color filter](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fgraphics%2FPaint.html%23getColorFilter%28%29)

If this view has an alpha value set to < 1.0 by calling [setAlpha(float)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23setAlpha%28float%29), the alpha value of the layer's paint is superseded by this view's alpha value.

Refer to the documentation of [LAYER_TYPE_NONE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23LAYER_TYPE_NONE)[LAYER_TYPE_SOFTWARE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23LAYER_TYPE_SOFTWARE) and [LAYER_TYPE_HARDWARE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23LAYER_TYPE_HARDWARE) for more information on when and how to use layers.

Parameters

layerType

int: The type of layer to use with this view, must be one of [LAYER_TYPE_NONE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23LAYER_TYPE_NONE)[LAYER_TYPE_SOFTWARE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23LAYER_TYPE_SOFTWARE) or [LAYER_TYPE_HARDWARE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23LAYER_TYPE_HARDWARE)

paint

Paint: The paint used to compose the layer. This argument is optional and can be null. It is ignored when the layer type is[LAYER_TYPE_NONE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23LAYER_TYPE_NONE)

setLayoutParams

added in  API level 1

void setLayoutParams (ViewGroup.LayoutParams params)

Set the layout parameters associated with this view. These supply parameters to the parent of this view specifying how it should be arranged. There are many subclasses of ViewGroup.LayoutParams, and these correspond to the different subclasses of ViewGroup that are responsible for arranging their children.

Parameters

params

ViewGroup.LayoutParams: The layout parameters for this view, cannot be null

setMapTrackballToArrowKeys

added in  API level 1

void setMapTrackballToArrowKeys (boolean setMap)

This method was deprecated in API level 17.
Only the default case, true, will be supported in a future version.

Parameters

setMap

boolean

setNetworkAvailable

added in  API level 3

void setNetworkAvailable (boolean networkUp)

Informs WebView of the network state. This is used to set the JavaScript property window.navigator.isOnline and generates the online/offline event as specified in HTML5, sec. 5.7.7

Parameters

networkUp

boolean: a boolean indicating if network is available

setOverScrollMode

added in  API level 9

void setOverScrollMode (int mode)

Set the over-scroll mode for this view. Valid over-scroll modes are [OVER_SCROLL_ALWAYS](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23OVER_SCROLL_ALWAYS) (default), [OVER_SCROLL_IF_CONTENT_SCROLLS](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23OVER_SCROLL_IF_CONTENT_SCROLLS) (allow over-scrolling only if the view content is larger than the container), or [OVER_SCROLL_NEVER](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23OVER_SCROLL_NEVER). Setting the over-scroll mode of a view will have an effect only if the view is capable of scrolling.

Parameters

mode

int: The new over-scroll mode for this view.

setPictureListener

added in  API level 1

void setPictureListener (WebView.PictureListener listener)

This method was deprecated in API level 12.
This method is now obsolete.

Sets the Picture listener. This is an interface used to receive notifications of a new Picture.

Parameters

listener

WebView.PictureListener: an implementation of WebView.PictureListener

setRendererPriorityPolicy

added in  API level 26

void setRendererPriorityPolicy (int rendererRequestedPriority, 
                boolean waivedWhenNotVisible)

Set the renderer priority policy for this [WebView](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html). The priority policy will be used to determine whether an out of process renderer should be considered to be a target for OOM killing. Because a renderer can be associated with more than one WebView, the final priority it is computed as the maximum of any attached WebViews. When a WebView is destroyed it will cease to be considerered when calculating the renderer priority. Once no WebViews remain associated with the renderer, the priority of the renderer will be reduced to [RENDERER_PRIORITY_WAIVED](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23RENDERER_PRIORITY_WAIVED). The default policy is to set the priority to[RENDERER_PRIORITY_IMPORTANT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23RENDERER_PRIORITY_IMPORTANT) regardless of visibility, and this should not be changed unless the caller also handles renderer crashes with[onRenderProcessGone(WebView, RenderProcessGoneDetail)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebViewClient.html%23onRenderProcessGone%28android.webkit.WebView%2C+android.webkit.RenderProcessGoneDetail%29). Any other setting will result in WebView renderers being killed by the system more aggressively than the application.

Parameters

rendererRequestedPriority

int: the minimum priority at which this WebView desires the renderer process to be bound.

waivedWhenNotVisible

boolean: if true, this flag specifies that when this WebView is not visible, it will be treated as if it had requested a priority of [RENDERER_PRIORITY_WAIVED](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23RENDERER_PRIORITY_WAIVED).

setSafeBrowsingWhitelist

added in  API level 27

void setSafeBrowsingWhitelist (List<String> urls, 
                ValueCallback<Boolean> callback)

Sets the list of domains that are exempt from SafeBrowsing checks. The list is global for all the WebViews.

Each rule should take one of these:

Rule

Example

Matches Subdomain

HOSTNAME

example.com

Yes

.HOSTNAME

.example.com

No

IPV4_LITERAL

192.168.1.1

No

IPV6_LITERAL_WITH_BRACKETS

[10:20:30:40:50:60:70:80]

No

All other rules, including wildcards, are invalid.

Parameters

urls

List: the list of URLs

This value must never be null.

callback

ValueCallback: will be called with true if URLs are successfully added to the whitelist. It will be called with false if any URLs are malformed. The callback will be run on the UI thread

This value may be null.

setScrollBarStyle

added in  API level 1

void setScrollBarStyle (int style)

Specify the style of the scrollbars. The scrollbars can be overlaid or inset. When inset, they add to the padding of the view. And the scrollbars can be drawn inside the padding area or on the edge of the view. For example, if a view has a background drawable and you want to draw the scrollbars inside the padding specified by the drawable, you can use SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to appear at the edge of the view, ignoring the padding, then you can use SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.

Parameters

style

int: the style of the scrollbars. Should be one of SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.

setTextClassifier

added in  API level 27

void setTextClassifier (TextClassifier textClassifier)

Sets the [TextClassifier](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2Ftextclassifier%2FTextClassifier.html) for this WebView.

Parameters

textClassifier

TextClassifier

This value may be null.

setVerticalScrollbarOverlay

added in  API level 1

void setVerticalScrollbarOverlay (boolean overlay)

This method was deprecated in API level 23.
This method has no effect.

Specifies whether the vertical scrollbar has overlay style.

Parameters

overlay

boolean: true if vertical scrollbar should have overlay style

setWebChromeClient

added in  API level 1

void setWebChromeClient (WebChromeClient client)

Sets the chrome handler. This is an implementation of WebChromeClient for use in handling JavaScript dialogs, favicons, titles, and the progress. This will replace the current handler.

Parameters

client

WebChromeClient: an implementation of WebChromeClient

See also:

  • [getWebChromeClient()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getWebChromeClient%28%29)

setWebContentsDebuggingEnabled

added in  API level 19

void setWebContentsDebuggingEnabled (boolean enabled)

Enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of this application. This flag can be enabled in order to facilitate debugging of web layouts and JavaScript code running inside WebViews. Please refer to WebView documentation for the debugging guide. The default is false.

Parameters

enabled

boolean: whether to enable web contents debugging

setWebViewClient

added in  API level 1

void setWebViewClient (WebViewClient client)

Sets the WebViewClient that will receive various notifications and requests. This will replace the current handler.

Parameters

client

WebViewClient: an implementation of WebViewClient

See also:

  • [getWebViewClient()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebView.html%23getWebViewClient%28%29)

shouldDelayChildPressedState

added in  API level 14

boolean shouldDelayChildPressedState ()

Return true if the pressed state should be delayed for children or descendants of this ViewGroup. Generally, this should be done for containers that can scroll, such as a List. This prevents the pressed state from appearing when the user is actually trying to scroll the content. The default implementation returns true for compatibility reasons. Subclasses that do not scroll should generally override this method and return false.

Returns

boolean

 

showFindDialog

added in  API level 11

boolean showFindDialog (String text, 
                boolean showIme)

This method was deprecated in API level 18.
This method does not work reliably on all Android versions; implementing a custom find dialog using WebView.findAllAsync() provides a more robust solution.

Starts an ActionMode for finding text in this WebView. Only works if this WebView is attached to the view system.

Parameters

text

String: if non-null, will be the initial text to search for. Otherwise, the last String searched for in this WebView will be used to start.

showIme

boolean: if true, show the IME, assuming the user will begin typing. If false and text is non-null, perform a find all.

Returns

boolean

true if the find dialog is shown, false otherwise

startSafeBrowsing

added in  API level 27

void startSafeBrowsing (Context context, 
                ValueCallback<Boolean> callback)

Starts Safe Browsing initialization.

URL loads are not guaranteed to be protected by Safe Browsing until after callback is invoked with true. Safe Browsing is not fully supported on all devices. For those devices callback will receive false.

This does not enable the Safe Browsing feature itself, and should only be called if Safe Browsing is enabled by the manifest tag or [setSafeBrowsingEnabled(boolean)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fwebkit%2FWebSettings.html%23setSafeBrowsingEnabled%28boolean%29). This prepares resources used for Safe Browsing.

This should be called with the Application Context (and will always use the Application context to do its work regardless).

Parameters

context

Context: Application Context.

callback

ValueCallback: will be called on the UI thread with true if initialization is successful, false otherwise.

stopLoading

added in  API level 1

void stopLoading ()

Stops the current load.

zoomBy

added in  API level 21

void zoomBy (float zoomFactor)

Performs a zoom operation in this WebView.

Parameters

zoomFactor

float: the zoom factor to apply. The zoom factor will be clamped to the WebView's zoom limits. This value must be in the range 0.01 to 100.0 inclusive.

zoomIn

added in  API level 1

boolean zoomIn ()

Performs zoom in in this WebView.

Returns

boolean

true if zoom in succeeds, false if no zoom changes

zoomOut

added in  API level 1

boolean zoomOut ()

Performs zoom out in this WebView.

Returns

boolean

true if zoom out succeeds, false if no zoom changes

Protected methods


computeHorizontalScrollOffset

added in  API level 1

int computeHorizontalScrollOffset ()

Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the position of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by [computeHorizontalScrollRange()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23computeHorizontalScrollRange%28%29) and[computeHorizontalScrollExtent()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23computeHorizontalScrollExtent%28%29).

The default offset is the scroll offset of this view.

Returns

int

the horizontal offset of the scrollbar's thumb

computeHorizontalScrollRange

added in  API level 1

int computeHorizontalScrollRange ()

Compute the horizontal range that the horizontal scrollbar represents.

The range is expressed in arbitrary units that must be the same as the units used by [computeHorizontalScrollExtent()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23computeHorizontalScrollExtent%28%29) and[computeHorizontalScrollOffset()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23computeHorizontalScrollOffset%28%29).

The default range is the drawing width of this view.

Returns

int

the total horizontal range represented by the horizontal scrollbar

computeVerticalScrollExtent

added in  API level 1

int computeVerticalScrollExtent ()

Compute the vertical extent of the vertical scrollbar's thumb within the vertical range. This value is used to compute the length of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by [computeVerticalScrollRange()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23computeVerticalScrollRange%28%29) and[computeVerticalScrollOffset()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23computeVerticalScrollOffset%28%29).

The default extent is the drawing height of this view.

Returns

int

the vertical extent of the scrollbar's thumb

computeVerticalScrollOffset

added in  API level 1

int computeVerticalScrollOffset ()

Compute the vertical offset of the vertical scrollbar's thumb within the horizontal range. This value is used to compute the position of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by [computeVerticalScrollRange()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23computeVerticalScrollRange%28%29) and[computeVerticalScrollExtent()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23computeVerticalScrollExtent%28%29).

The default offset is the scroll offset of this view.

Returns

int

the vertical offset of the scrollbar's thumb

computeVerticalScrollRange

added in  API level 1

int computeVerticalScrollRange ()

Compute the vertical range that the vertical scrollbar represents.

The range is expressed in arbitrary units that must be the same as the units used by [computeVerticalScrollExtent()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23computeVerticalScrollExtent%28%29) and[computeVerticalScrollOffset()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23computeVerticalScrollOffset%28%29).

Returns

int

the total vertical range represented by the vertical scrollbar

The default range is the drawing height of this view.

dispatchDraw

added in  API level 1

void dispatchDraw (Canvas canvas)

Called by draw to draw the child views. This may be overridden by derived classes to gain control just before its children are drawn (but after its own view has been drawn).

Parameters

canvas

Canvas: the canvas on which to draw the view

onAttachedToWindow

added in  API level 1

void onAttachedToWindow ()

This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before [onDraw(android.graphics.Canvas)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23onDraw%28android.graphics.Canvas%29), however it may be called any time before the first onDraw -- including before or after [onMeasure(int, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23onMeasure%28int%2C+int%29).

onConfigurationChanged

added in  API level 8

void onConfigurationChanged (Configuration newConfig)

Called when the current configuration of the resources being used by the application have changed. You can use this to decide when to reload resources that can changed based on orientation and other configuration characteristics. You only need to use this if you are not relying on the normal [Activity](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fapp%2FActivity.html) mechanism of recreating the activity instance upon a configuration change.

Parameters

newConfig

Configuration: The new resource configuration.

onDraw

added in  API level 1

void onDraw (Canvas canvas)

Implement this to do your drawing.

Parameters

canvas

Canvas: the canvas on which the background will be drawn

onFocusChanged

added in  API level 1

void onFocusChanged (boolean focused, 
                int direction, 
                Rect previouslyFocusedRect)

Called by the view system when the focus state of this view changes. When the focus change event is caused by directional navigation, direction and previouslyFocusedRect provide insight into where the focus is coming from. When overriding, be sure to call up through to the super class so that the standard focus handling will occur.

Parameters

focused

boolean: True if the View has focus; false otherwise.

direction

int: The direction focus has moved when requestFocus() is called to give this view focus. Values are [FOCUS_UP](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23FOCUS_UP)[FOCUS_DOWN](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23FOCUS_DOWN)[FOCUS_LEFT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23FOCUS_LEFT)[FOCUS_RIGHT](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23FOCUS_RIGHT)[FOCUS_FORWARD](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23FOCUS_FORWARD), or [FOCUS_BACKWARD](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23FOCUS_BACKWARD). It may not always apply, in which case use the default.

previouslyFocusedRect

Rect: The rectangle, in this view's coordinate system, of the previously focused view. If applicable, this will be passed in as finer grained information about where the focus is coming from (in addition to direction). Will be null otherwise.

onMeasure

added in  API level 1

void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by [measure(int, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23measure%28int%2C+int%29) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call [setMeasuredDimension(int, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23setMeasuredDimension%28int%2C+int%29) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by [measure(int, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23measure%28int%2C+int%29). Calling the superclass' [onMeasure(int, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23onMeasure%28int%2C+int%29) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override [onMeasure(int, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23onMeasure%28int%2C+int%29) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width ([getSuggestedMinimumHeight()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23getSuggestedMinimumHeight%28%29) and [getSuggestedMinimumWidth()](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23getSuggestedMinimumWidth%28%29)).

Parameters

widthMeasureSpec

int: horizontal space requirements as imposed by the parent. The requirements are encoded with [View.MeasureSpec](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.MeasureSpec.html).

heightMeasureSpec

int: vertical space requirements as imposed by the parent. The requirements are encoded with [View.MeasureSpec](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.MeasureSpec.html).

onOverScrolled

added in  API level 9

void onOverScrolled (int scrollX, 
                int scrollY, 
                boolean clampedX, 
                boolean clampedY)

Called by [overScrollBy(int, int, int, int, int, int, int, int, boolean)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23overScrollBy%28int%2C+int%2C+int%2C+int%2C+int%2C+int%2C+int%2C+int%2C+boolean%29) to respond to the results of an over-scroll operation.

Parameters

scrollX

int: New X scroll value in pixels

scrollY

int: New Y scroll value in pixels

clampedX

boolean: True if scrollX was clamped to an over-scroll boundary

clampedY

boolean: True if scrollY was clamped to an over-scroll boundary

onScrollChanged

added in  API level 1

void onScrollChanged (int l, 
                int t, 
                int oldl, 
                int oldt)

This is called in response to an internal scroll in this view (i.e., the view scrolled its own contents). This is typically as a result of [scrollBy(int, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23scrollBy%28int%2C+int%29) or [scrollTo(int, int)](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23scrollTo%28int%2C+int%29) having been called.

Parameters

l

int: Current horizontal scroll origin.

t

int: Current vertical scroll origin.

oldl

int: Previous horizontal scroll origin.

oldt

int: Previous vertical scroll origin.

onSizeChanged

added in  API level 1

void onSizeChanged (int w, 
                int h, 
                int ow, 
                int oh)

This is called during layout when the size of this view has changed. If you were just added to the view hierarchy, you're called with the old values of 0.

Parameters

w

int: Current width of this view.

h

int: Current height of this view.

ow

int: Old width of this view.

oh

int: Old height of this view.

onVisibilityChanged

added in  API level 8

void onVisibilityChanged (View changedView, 
                int visibility)

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

Parameters

changedView

View: The view whose visibility changed. May be this or an ancestor view.

visibility

int: The new visibility, one of [VISIBLE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23VISIBLE)[INVISIBLE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23INVISIBLE) or [GONE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23GONE).

onWindowVisibilityChanged

added in  API level 1

void onWindowVisibilityChanged (int visibility)

Called when the window containing has change its visibility (between [GONE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23GONE)[INVISIBLE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23INVISIBLE), and [VISIBLE](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fview%2FView.html%23VISIBLE)). Note that this tells you whether or not your window is being made visible to the window manager; this does not tell you whether or not your window is obscured by other windows on the screen, even if it is itself visible.

Parameters

visibility

int: The new visibility of the window.

  • Android WebView Twitter

    Follow @AndroidDev on Twitter

 * Android WebView Google+

Follow Android Developers on Google+

 * Android WebView YouTube

Check out Android Developers on YouTube

Newsletter  博客  支持  Join user studies


Except as noted, this content is licensed under Creative Commons Attribution 2.5. For details and restrictions, see the Content License.

Android.com Android Developers Android Studio Google Play Console Legal Notice

Bahasa Indonesia                                                Deutsch                                                English                                                español                                                Español (América Latina)                                                français                                                Português Brasileiro                                                Tiếng Việt                                                Türkçe                                                Русский                                                ภาษาไทย                                                日本語                                                简体中文                                                繁體中文                                                한국어

This site uses cookies to store your preferences for site-specific language and display options. OK

                          English                           Arabic                           Chinese (Simplified)                           Chinese (Traditional)                           French                           German                           Indonesian (Bahasa)                           Japanese                           Korean                           Portuguese (Brazilian)                           Russian                           Spanish (Latin American)                           Thai                           Turkish                           Vietnamese                        

Android WebView

Take a short survey?

Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Wesley13 Wesley13
2年前
Java获得今日零时零分零秒的时间(Date型)
publicDatezeroTime()throwsParseException{    DatetimenewDate();    SimpleDateFormatsimpnewSimpleDateFormat("yyyyMMdd00:00:00");    SimpleDateFormatsimp2newS
Stella981 Stella981
2年前
Android So动态加载 优雅实现与原理分析
背景:漫品Android客户端集成适配转换功能(基于目标识别(So库35M)和人脸识别库(5M)),导致apk体积50M左右,为优化客户端体验,决定实现So文件动态加载.!(https://oscimg.oschina.net/oscnet/00d1ff90e4b34869664fef59e3ec3fdd20b.png)点击上方“蓝字”关注我
Wesley13 Wesley13
2年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
5个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这