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
element.
For more information, read Building Web Apps in WebView.
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("http://www.example.com"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent);
See Intent
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()
:
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("http://slashdot.org/"); // OR, you can also load from an HTML string: String summary = "<html><body>You scored <b>192</b> points.</body></html>"; webview.loadData(summary, "text/html", null); // ... although note that there are restrictions on what this HTML can do. // See the JavaDocs forloadData()
andloadDataWithBaseURL()
for more info.
A WebView has several customization points where you can add your own behavior. These are:
WebChromeClient
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).
WebViewClient
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()
).WebSettings
, such as
enabling JavaScript with setJavaScriptEnabled()
. addJavascriptInterface(Object, String)
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("http://developer.android.com/");
To enable the built-in zoom, set
WebSettings
.setBuiltInZoomControls(boolean)
(introduced in API level CUPCAKE
).
NOTE: Using zoom if either the height or width is set to
WRAP_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
to provide your own behaviour 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.
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
, 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:
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.-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.
In order to support inline HTML5 video in your application you need to have hardware acceleration turned on.
In order to support full screen — for video or other HTML content — you need to set a
WebChromeClient
and implement both
onShowCustomView(View, WebChromeClient.CustomViewCallback)
and onHideCustomView()
. 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()
to customize the View displayed whilst a video
is loading.
It is recommended to set the WebView layout height to a fixed value or to
MATCH_PARENT
instead of using
WRAP_CONTENT
.
When using MATCH_PARENT
for the height none of the WebView's parents should use a
WRAP_CONTENT
layout height since that could result in
incorrect sizing of the views.
Setting the WebView's height to WRAP_CONTENT
enables the following behaviors:
KITKAT
and earlier SDKs the
HTML viewport meta tag will be ignored in order to preserve backwards compatibility.
Using a layout width of WRAP_CONTENT
is not
supported. If such a width is used the WebView will attempt to use the width of the parent
instead.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
WebView.FindListener | Interface to listen for find results. | ||||||||||
WebView.HitTestResult | |||||||||||
WebView.PictureListener | This interface was deprecated in API level 12. This interface is now obsolete. | ||||||||||
WebView.VisualStateCallback |
Callback interface supplied to postVisualStateCallback(long, WebView.VisualStateCallback) for receiving
notifications about the visual state.
|
||||||||||
WebView.WebViewTransport | Transportation object for returning WebView across thread boundaries. |
[Expand]
Inherited XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.ViewGroup
| |||||||||||
From class
android.view.View
|
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | SCHEME_GEO | URI scheme for map address. | |||||||||
String | SCHEME_MAILTO | URI scheme for email address. | |||||||||
String | SCHEME_TEL | URI scheme for telephone number. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.ViewGroup
| |||||||||||
From class
android.view.View
|
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.View
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new WebView with a Context object.
| |||||||||||
Constructs a new WebView with layout parameters.
| |||||||||||
Constructs a new WebView with layout parameters and a default style.
| |||||||||||
Constructs a new WebView with layout parameters and a default style.
| |||||||||||
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 , WebViewDatabase , CookieManager
and WebStorage for fine-grained control of privacy data.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Injects the supplied Java object into this WebView.
| |||||||||||
Gets whether this WebView has a back history item.
| |||||||||||
Gets whether the page can go back or forward the given
number of steps.
| |||||||||||
Gets whether this WebView has a forward history item.
| |||||||||||
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) .
| |||||||||||
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) .
| |||||||||||
This method was deprecated
in API level 19.
Use
onDraw(Canvas) to obtain a bitmap snapshot of the WebView, or
saveWebArchive(String) to save the content to a file.
| |||||||||||
Clears the resource cache.
| |||||||||||
Clears the client certificate preferences stored in response
to proceeding/cancelling client cert requests.
| |||||||||||
Removes the autocomplete popup from the currently focused form field, if
present.
| |||||||||||
Tells this WebView to clear its internal back/forward list.
| |||||||||||
Clears the highlighting surrounding text matches created by
findAllAsync(String) .
| |||||||||||
Clears the SSL preferences table stored in response to proceeding with
SSL certificate errors.
| |||||||||||
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).
| |||||||||||
Called by a parent to request that a child update its values for mScrollX
and mScrollY if necessary.
| |||||||||||
Gets the WebBackForwardList for this WebView.
| |||||||||||
This method was deprecated
in API level 21.
Use
createPrintDocumentAdapter(String) which requires user
to provide a print document name.
| |||||||||||
Creates a PrintDocumentAdapter that provides the content of this Webview for printing.
| |||||||||||
Creates a message channel to communicate with JS and returns the message
ports that represent the endpoints of this message channel.
| |||||||||||
Destroys the internal state of this WebView.
| |||||||||||
Dispatch a key event to the next view on the focus path.
| |||||||||||
Queries the document to see if it contains any image references.
| |||||||||||
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.
| |||||||||||
Asynchronously evaluates JavaScript in the context of the currently displayed page.
| |||||||||||
Gets the first substring consisting of the address of a physical
location.
| |||||||||||
This method was deprecated
in API level 16.
findAllAsync(String) is preferred.
| |||||||||||
Finds all instances of find on the page and highlights them,
asynchronously.
| |||||||||||
Highlights and scrolls to the next match found by
findAllAsync(String) , wrapping around page boundaries as necessary.
| |||||||||||
This method was deprecated
in API level 19.
Memory caches are automatically dropped when no longer needed, and in response
to system memory pressure.
| |||||||||||
Return the class name of this object to be used for accessibility purposes.
| |||||||||||
Gets the provider for managing a virtual view hierarchy rooted at this View
and reported to
AccessibilityService s
that explore the window content.
| |||||||||||
Gets the SSL certificate for the main top-level page or null if there is
no certificate (the site is not secure).
| |||||||||||
Gets the height of the HTML content.
| |||||||||||
Gets the favicon for the current page.
| |||||||||||
Gets a HitTestResult based on the current cursor node.
| |||||||||||
Retrieves HTTP authentication credentials for a given host and realm.
| |||||||||||
Gets the original URL for the current page.
| |||||||||||
Gets the progress for the current page.
| |||||||||||
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) .
| |||||||||||
Gets the WebSettings object used to control the settings for this
WebView.
| |||||||||||
Gets the title for the current page.
| |||||||||||
Gets the URL for the current page.
| |||||||||||
Goes back in the history of this WebView.
| |||||||||||
Goes to the history item that is the number of steps away from
the current item.
| |||||||||||
Goes forward in the history of this WebView.
| |||||||||||
Invokes the graphical zoom picker widget for this WebView.
| |||||||||||
Gets whether private browsing is enabled in this WebView.
| |||||||||||
Loads the given data into this WebView using a 'data' scheme URL.
| |||||||||||
Loads the given data into this WebView, using baseUrl as the base URL for
the content.
| |||||||||||
Loads the given URL.
| |||||||||||
Loads the given URL with the specified additional HTTP headers.
| |||||||||||
This method was deprecated
in API level 8.
WebView no longer needs to implement
ViewGroup.OnHierarchyChangeListener. This method does nothing now.
| |||||||||||
This method was deprecated
in API level 8.
WebView no longer needs to implement
ViewGroup.OnHierarchyChangeListener. This method does nothing now.
| |||||||||||
Create a new InputConnection for an InputMethod to interact
with the view.
| |||||||||||
Called after
onStartTemporaryDetach() when the container is done
changing the view.
| |||||||||||
Implement this method to handle generic motion events.
| |||||||||||
This method was deprecated
in API level 3.
WebView should not have implemented
ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now.
| |||||||||||
Implement this method to handle hover events.
| |||||||||||
Default implementation of
KeyEvent.Callback.onKeyDown() : perform press of the view
when KEYCODE_DPAD_CENTER or KEYCODE_ENTER
is released, if the view is enabled and clickable.
| |||||||||||
Default implementation of
KeyEvent.Callback.onKeyMultiple() : always returns false (doesn't handle
the event).
| |||||||||||
Default implementation of
KeyEvent.Callback.onKeyUp() : perform clicking of the view
when KEYCODE_DPAD_CENTER or
KEYCODE_ENTER is released.
| |||||||||||
Pauses any extra processing associated with this WebView and its
associated DOM, plugins, JavaScript etc.
| |||||||||||
Called when assist structure is being retrieved from a view as part of
Activity.onProvideAssistData to
generate additional virtual structure under this view.
| |||||||||||
Resumes a WebView after a previous call to onPause().
| |||||||||||
This is called when a container is going to temporarily detach a child, with
ViewGroup.detachViewFromParent .
| |||||||||||
Implement this method to handle touch screen motion events.
| |||||||||||
Implement this method to handle trackball motion events.
| |||||||||||
Called when the window containing this view gains or loses focus.
| |||||||||||
This method was deprecated
in API level 23.
This method is now obsolete.
| |||||||||||
This method was deprecated
in API level 23.
This method is now obsolete.
| |||||||||||
Scrolls the contents of this WebView down by half the page size.
| |||||||||||
Scrolls the contents of this WebView up by half the view size.
| |||||||||||
Pauses all layout, parsing, and JavaScript timers for all WebViews.
| |||||||||||
Call this view's OnLongClickListener, if it is defined.
| |||||||||||
Loads the URL with postData using "POST" method into this WebView.
| |||||||||||
Posts a
WebView.VisualStateCallback , which will be called when
the current state of the WebView is ready to be drawn.
| |||||||||||
Post a message to main frame.
| |||||||||||
Reloads the current URL.
| |||||||||||
Removes a previously injected Java object from this WebView.
| |||||||||||
Called when a child of this group wants a particular rectangle to be
positioned onto the screen.
| |||||||||||
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() .
| |||||||||||
Requests the anchor or image element URL at the last tapped point.
| |||||||||||
Requests the URL of the image last touched by the user.
| |||||||||||
Restores the state of this WebView from the given Bundle.
| |||||||||||
Resumes all layout, parsing, and JavaScript timers for all WebViews.
| |||||||||||
This method was deprecated
in API level 18.
Saving passwords in WebView will not be supported in future versions.
| |||||||||||
Saves the state of this WebView used in
onSaveInstanceState(Bundle) .
| |||||||||||
Saves the current view as a web archive.
| |||||||||||
Saves the current view as a web archive.
| |||||||||||
Sets the background color for this view.
| |||||||||||
This method was deprecated
in API level 17.
Calling this function has no useful effect, and will be
ignored in future releases.
| |||||||||||
Registers the interface to be used when content can not be handled by
the rendering engine, and should be downloaded instead.
| |||||||||||
Registers the listener to be notified as find-on-page operations
progress.
| |||||||||||
This method was deprecated
in API level 23.
This method has no effect.
| |||||||||||
Stores HTTP authentication credentials for a given host and realm.
| |||||||||||
Sets the initial scale for this WebView.
| |||||||||||
Specifies the type of layer backing this view. | |||||||||||
Set the layout parameters associated with this view.
| |||||||||||
This method was deprecated
in API level 17.
Only the default case, true, will be supported in a future version.
| |||||||||||
Informs WebView of the network state.
| |||||||||||
Set the over-scroll mode for this view.
| |||||||||||
This method was deprecated
in API level 12.
This method is now obsolete.
| |||||||||||
Specify the style of the scrollbars. | |||||||||||
This method was deprecated
in API level 23.
This method has no effect.
| |||||||||||
Sets the chrome handler.
| |||||||||||
Enables debugging of web contents (HTML / CSS / JavaScript)
loaded into any WebViews of this application.
| |||||||||||
Sets the WebViewClient that will receive various notifications and
requests.
| |||||||||||
Return true if the pressed state should be delayed for children or descendants of this
ViewGroup.
| |||||||||||
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.
| |||||||||||
Stops the current load.
| |||||||||||
Performs a zoom operation in this WebView.
| |||||||||||
Performs zoom in in this WebView.
| |||||||||||
Performs zoom out in this WebView.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range. | |||||||||||
Compute the horizontal range that the horizontal scrollbar represents. | |||||||||||
Compute the vertical extent of the vertical scrollbar's thumb within the vertical range. | |||||||||||
Compute the vertical offset of the vertical scrollbar's thumb within the horizontal range. | |||||||||||
Compute the vertical range that the vertical scrollbar represents. | |||||||||||
Called by draw to draw the child views.
| |||||||||||
This is called when the view is attached to a window.
| |||||||||||
Called when the current configuration of the resources being used
by the application have changed.
| |||||||||||
Implement this to do your drawing.
| |||||||||||
Called by the view system when the focus state of this view changes.
| |||||||||||
Measure the view and its content to determine the measured width and the measured height. | |||||||||||
Called by
overScrollBy(int, int, int, int, int, int, int, int, boolean) to
respond to the results of an over-scroll operation.
| |||||||||||
This is called in response to an internal scroll in this view (i.e., the
view scrolled its own contents).
| |||||||||||
This is called during layout when the size of this view has changed.
| |||||||||||
Called when the visibility of the view or an ancestor of the view has
changed.
| |||||||||||
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.widget.AbsoluteLayout
| |||||||||||
From class
android.view.ViewGroup
| |||||||||||
From class
android.view.View
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
android.view.ViewParent
| |||||||||||
From interface
android.view.ViewManager
| |||||||||||
From interface
android.graphics.drawable.Drawable.Callback
| |||||||||||
From interface
android.view.KeyEvent.Callback
| |||||||||||
From interface
android.view.accessibility.AccessibilityEventSource
| |||||||||||
From interface
android.view.ViewTreeObserver.OnGlobalFocusChangeListener
| |||||||||||
From interface
android.view.ViewGroup.OnHierarchyChangeListener
|
URI scheme for map address.
URI scheme for email address.
URI scheme for telephone number.
Constructs a new WebView with a Context object.
context | a Context object used to access application assets |
---|
Constructs a new WebView with layout parameters.
context | a Context object used to access application assets |
---|---|
attrs | an AttributeSet passed to our parent |
Constructs a new WebView with layout parameters and a default style.
context | a Context object used to access application assets |
---|---|
attrs | an AttributeSet passed to our parent |
defStyleAttr | 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. |
Constructs a new WebView with layout parameters and a default style.
context | a Context object used to access application assets |
---|---|
attrs | an AttributeSet passed to our parent |
defStyleAttr | 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 | 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. |
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
, WebViewDatabase
, CookieManager
and WebStorage
for fine-grained control of privacy data.
Constructs a new WebView with layout parameters and a default style.
context | a Context object used to access application assets |
---|---|
attrs | an AttributeSet passed to our parent |
defStyleAttr | 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 | whether this WebView will be initialized in private mode |
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
and above, only public methods that are annotated with
JavascriptInterface
can be accessed from JavaScript.
For applications targeted to API level JELLY_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. For example:
class JsObject { @JavascriptInterface public String toString() { return "injectedObject"; } } webView.addJavascriptInterface(new JsObject(), "injectedObject"); webView.loadData("", "text/html", null); webView.loadUrl("javascript:alert(injectedObject.toString())");
IMPORTANT:
JELLY_BEAN
or earlier.
Apps that target a version later than JELLY_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
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.LOLLIPOP
and above, methods of injected Java objects are enumerable from
JavaScript.object | the Java object to inject into this WebView's JavaScript context. Null values are ignored. |
---|---|
name | the name used to expose the object in JavaScript |
Gets whether this WebView has a back history item.
Gets whether the page can go back or forward the given number of steps.
steps | the negative or positive number of steps to move the history |
---|
Gets whether this WebView has a forward history item.
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)
.
Gets whether this WebView can be zoomed in.
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)
.
Gets whether this WebView can be zoomed out.
This method was deprecated
in API level 19.
Use onDraw(Canvas)
to obtain a bitmap snapshot of the WebView, or
saveWebArchive(String)
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
and
ICE_CREAM_SANDWICH
inclusive, the
picture does not include fixed position elements or scrollable divs.
Note that from JELLY_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)
and
writeToStream(OutputStream)
methods are not supported on the
returned object.
Clears the resource cache. Note that the cache is per-application, so this will clear the cache for all WebViews used.
includeDiskFiles | if false, only the RAM cache is cleared |
---|
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
intent. The preferences are
shared by all the webviews that are created by the embedder application.
onCleared | 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. |
---|
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()
.
Tells this WebView to clear its internal back/forward list.
Clears the highlighting surrounding text matches created by
findAllAsync(String)
.
Clears the SSL preferences table stored in response to proceeding with SSL certificate errors.
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.
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
object.
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.
This method was deprecated
in API level 21.
Use createPrintDocumentAdapter(String)
which requires user
to provide a print document name.
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
for more information.
documentName | The user-facing name of the printed document. See
PrintDocumentInfo
|
---|
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.
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.
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.
event | The key event to be dispatched. |
---|
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.
response | the message that will be dispatched with the result |
---|
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:
onDraw(Canvas)
to do own drawing and accesses portions
of the page that is way outside the visible portion of the page.capturePicture()
to capture a very large HTML document.
Note that capturePicture is a deprecated API.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.
script | the JavaScript to execute. |
---|---|
resultCallback | A callback to be invoked when the script execution completes with the result of the execution (if any). May be null if no notificaion of the result is required. |
Gets the first substring consisting of the address of a physical location. Currently, only addresses in the United States are detected, and consist of:
addr | the string to search for addresses |
---|
This method was deprecated
in API level 16.
findAllAsync(String)
is preferred.
Finds all instances of find on the page and highlights them.
Notifies any registered WebView.FindListener
.
find | the string to find |
---|
Finds all instances of find on the page and highlights them,
asynchronously. Notifies any registered WebView.FindListener
.
Successive calls to this will cancel any pending searches.
find | the string to find. |
---|
Highlights and scrolls to the next match found by
findAllAsync(String)
, wrapping around page boundaries as necessary.
Notifies any registered WebView.FindListener
. If findAllAsync(String)
has not been called yet, or if clearMatches()
has been called since the
last find operation, this function does nothing.
forward | the direction to search |
---|
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.
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
.
Gets the provider for managing a virtual view hierarchy rooted at this View
and reported to AccessibilityService
s
that explore the window content.
If this method returns an instance, this instance is responsible for managing
AccessibilityNodeInfo
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
has been specified via calling
setAccessibilityDelegate(AccessibilityDelegate)
its
getAccessibilityNodeProvider(View)
is responsible for handling this call.
Gets the SSL certificate for the main top-level page or null if there is no certificate (the site is not secure).
Gets the height of the HTML content.
Gets the favicon for the current page. This is the favicon of the current page until WebViewClient.onReceivedIcon is called.
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)
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.
Retrieves HTTP authentication credentials for a given host and realm.
This method is intended to be used with
onReceivedHttpAuthRequest(WebView, HttpAuthHandler, String, String)
.
host | the host to which the credentials apply |
---|---|
realm | the realm to which the credentials apply |
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.
Gets the progress for the current page.
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)
.
Gets the current scale of this WebView.
Gets the WebSettings object used to control the settings for this WebView.
Gets the title for the current page. This is the title of the current page until WebViewClient.onReceivedTitle is called.
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.
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.
steps | the number of steps to take back or forward in the back forward list |
---|
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.
Gets whether private browsing is enabled in this WebView.
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()
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)
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.
data | a String of data in the given encoding |
---|---|
mimeType | the MIME type of the data, e.g. 'text/html' |
encoding | the encoding of the data |
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()
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.
baseUrl | the URL to use as the page's base URL. If null defaults to 'about:blank'. |
---|---|
data | a String of data in the given encoding |
mimeType | the MIMEType of the data, e.g. 'text/html'. If null, defaults to 'text/html'. |
encoding | the encoding of the data |
historyUrl | the URL to use as the history entry. If null defaults to 'about:blank'. If non-null, this must be a valid URL. |
Loads the given URL.
url | the URL of the resource to load |
---|
Loads the given URL with the specified additional HTTP headers.
url | the URL of the resource to load |
---|---|
additionalHttpHeaders | 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 overriden by this WebView's defaults. |
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.
parent | the view in which a child was added |
---|---|
child | the new child view added in the hierarchy |
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.
p | the view from which the child was removed |
---|---|
child | the child removed from the hierarchy |
Create a new InputConnection for an InputMethod to interact with the view. The default implementation returns null, since it doesn't support input methods. You can override this to implement such support. This is only needed for views that take focus and text input.
When implementing this, you probably also want to implement
onCheckIsTextEditor()
to indicate you will return a
non-null InputConnection.
Also, take good care to fill in the EditorInfo
object correctly and in its entirety, so that the connected IME can rely
on its values. For example, initialSelStart
and initialSelEnd
members
must be filled in with the correct cursor position for IMEs to work correctly
with your application.
outAttrs | Fill in with attribute information about the connection. |
---|
Called after onStartTemporaryDetach()
when the container is done
changing the view.
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
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
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); }
event | The generic motion event being processed. |
---|
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.
oldFocus | The previously focused view, if any. |
---|---|
newFocus | The newly focused View, if any. |
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
, ACTION_HOVER_MOVE
,
or ACTION_HOVER_EXIT
.
ACTION_HOVER_ENTER
when the pointer enters the bounds of the view.ACTION_HOVER_MOVE
when the pointer has already entered the bounds of the view and has moved.ACTION_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)
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.
event | The motion event that describes the hover. |
---|
Default implementation of KeyEvent.Callback.onKeyDown()
: perform press of the view
when KEYCODE_DPAD_CENTER
or KEYCODE_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.
keyCode | A key code that represents the button pressed, from
KeyEvent . |
---|---|
event | The KeyEvent object that defines the button action. |
Default implementation of KeyEvent.Callback.onKeyMultiple()
: 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.
keyCode | A key code that represents the button pressed, from
KeyEvent . |
---|---|
repeatCount | The number of times the action was made. |
event | The KeyEvent object that defines the button action. |
Default implementation of KeyEvent.Callback.onKeyUp()
: perform clicking of the view
when KEYCODE_DPAD_CENTER
or
KEYCODE_ENTER
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.
keyCode | A key code that represents the button pressed, from
KeyEvent . |
---|---|
event | The KeyEvent object that defines the button action. |
Pauses any extra processing associated with this WebView and its associated DOM, plugins, JavaScript etc. For example, if this WebView is taken offscreen, this could be called to reduce unnecessary CPU or network traffic. When this WebView is again "active", call onResume(). Note that this differs from pauseTimers(), which affects all WebViews.
Called when assist structure is being retrieved from a view as part of
Activity.onProvideAssistData
to
generate additional virtual structure under this view. The defaullt implementation
uses getAccessibilityNodeProvider()
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.
This is called when a container is going to temporarily detach a child, with
ViewGroup.detachViewFromParent
.
It will either be followed by onFinishTemporaryDetach()
or
onDetachedFromWindow()
when the container is done.
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()
. This will ensure consistent system behavior,
including:
ACTION_CLICK
when
accessibility features are enabled
event | The motion 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()
and
MotionEvent.getY()
. 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).
event | The motion event. |
---|
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.
hasWindowFocus | True if the window containing this view now has focus, false otherwise. |
---|
This method was deprecated
in API level 23.
This method is now obsolete.
Gets whether horizontal scrollbar has overlay style.
This method was deprecated
in API level 23.
This method is now obsolete.
Gets whether vertical scrollbar has overlay style.
Scrolls the contents of this WebView down by half the page size.
bottom | true to jump to bottom of page |
---|
Scrolls the contents of this WebView up by half the view size.
top | true to jump to the top of the page |
---|
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.
Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the OnLongClickListener did not consume the event.
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)
instead, ignoring the postData param.
url | the URL of the resource to load |
---|---|
postData | the data will be passed to "POST" request, which must be be "application/x-www-form-urlencoded" encoded. |
Posts a WebView.VisualStateCallback
, which will be called when
the current state of the WebView is ready to be drawn.
Because updates to the the DOM are processed asynchronously, updates to the DOM may not
immediately be reflected visually by subsequent onDraw(Canvas)
invocations. The
WebView.VisualStateCallback
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
draws.
The next draw after the callback completes is guaranteed to reflect all the updates to the
DOM up to the the point at which the WebView.VisualStateCallback
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:
To guarantee that the WebView
will successfully render the first frame
after the onComplete(long)
method has been called a set of conditions
must be met:
WebView
's visibility is set to VISIBLE
then
the WebView
must be attached to the view hierarchy.WebView
's visibility is set to INVISIBLE
then the WebView
must be attached to the view hierarchy and must be made
VISIBLE
from the onComplete(long)
method.WebView
's visibility is set to GONE
then the
WebView
must be attached to the view hierarchy and its
LayoutParams
's width and height need to be set to fixed
values and must be made VISIBLE
from the
onComplete(long)
method.When using this API it is also recommended to enable pre-rasterization if the WebView
is offscreen to avoid flickering. See setOffscreenPreRaster(boolean)
for
more details and do consider its caveats.
requestId | An id that will be returned in the callback to allow callers to match requests with callbacks. |
---|---|
callback | The callback to be invoked. |
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.
message | the WebMessage |
---|---|
targetOrigin | the target origin. This is the origin of the page that is intended to receive the message. For best security practices, the user should not specify a wildcard (*) when specifying the origin. |
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)
.
name | the name used to expose the object in JavaScript |
---|
Called when a child of this group wants a particular rectangle to be
positioned onto the screen. ViewGroup
s overriding this can trust
that:
ViewGroup
s overriding this should uphold the contract:
child | The direct child making the request. |
---|---|
rect | The rectangle in the child's coordinates the child wishes to be on the screen. |
immediate | True to forbid animated or delayed scrolling, false otherwise |
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()
returns
false), or if it is focusable and it is not focusable in touch mode
(isFocusableInTouchMode()
) 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()
equal to
FOCUS_BLOCK_DESCENDANTS
.
See also focusSearch(int)
, 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
has an internal
View
that it wishes to forward the request to.
Looks for a view to give focus to respecting the setting specified by
getDescendantFocusability()
.
Uses onRequestFocusInDescendants(int, android.graphics.Rect)
to
find focus within the children of this group when appropriate.
direction | One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
---|---|
previouslyFocusedRect | 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. |
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.
hrefMsg | 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. |
---|
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.
msg | the message to be dispatched with the result of the request as the data member with "url" as key. The result can be null. |
---|
Restores the state of this WebView from the given Bundle. This method is
intended for use in onRestoreInstanceState(Bundle)
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.
inState | the incoming Bundle of state |
---|
Resumes all layout, parsing, and JavaScript timers for all WebViews. This will resume dispatching all timers.
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.
host | the host that required the credentials |
---|---|
username | the username for the given host |
password | the password for the given host |
Saves the state of this WebView used in
onSaveInstanceState(Bundle)
. Please note that this
method no longer stores the display data for this WebView. The previous
behavior could potentially leak files if restoreState(Bundle)
was never
called.
outState | the Bundle to store this WebView's state |
---|
Saves the current view as a web archive.
filename | the filename where the archive should be placed |
---|
Saves the current view as a web archive.
basename | the filename where the archive should be placed |
---|---|
autoname | 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 | 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. |
Sets the background color for this view.
color | the color of the background |
---|
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.
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.
listener | an implementation of DownloadListener |
---|
Registers the listener to be notified as find-on-page operations progress. This will replace the current listener.
listener | an implementation of WebView.FindListener
|
---|
This method was deprecated
in API level 23.
This method has no effect.
Specifies whether the horizontal scrollbar has overlay style.
overlay | true if horizontal scrollbar should have overlay style |
---|
Stores HTTP authentication credentials for a given host and realm. This
method is intended to be used with
onReceivedHttpAuthRequest(WebView, HttpAuthHandler, String, String)
.
host | the host to which the credentials apply |
---|---|
realm | the realm to which the credentials apply |
username | the username |
password | the password |
Sets the initial scale for this WebView. 0 means default.
The behavior for the default scale depends on the state of
getUseWideViewPort()
and
getLoadWithOverviewMode()
.
If the content fits into the WebView control by width, then
the zoom is set to 100%. For wide content, the behavor
depends on the state of getLoadWithOverviewMode()
.
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.
scaleInPercent | the initial scale in percent |
---|
Specifies the type of layer backing this view. The layer can be
LAYER_TYPE_NONE
, LAYER_TYPE_SOFTWARE
or
LAYER_TYPE_HARDWARE
.
A layer is associated with an optional Paint
instance that controls how the layer is composed on screen. The following
properties of the paint are taken into account when composing the layer:
If this view has an alpha value set to < 1.0 by calling
setAlpha(float)
, the alpha value of the layer's paint is superseded
by this view's alpha value.
Refer to the documentation of LAYER_TYPE_NONE
,
LAYER_TYPE_SOFTWARE
and LAYER_TYPE_HARDWARE
for more information on when and how to use layers.
layerType | The type of layer to use with this view, must be one of
LAYER_TYPE_NONE , LAYER_TYPE_SOFTWARE or
LAYER_TYPE_HARDWARE |
---|---|
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 |
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.
params | The layout parameters for this view, cannot be null |
---|
This method was deprecated
in API level 17.
Only the default case, true, will be supported in a future version.
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
networkUp | a boolean indicating if network is available |
---|
Set the over-scroll mode for this view. Valid over-scroll modes are
OVER_SCROLL_ALWAYS
(default), OVER_SCROLL_IF_CONTENT_SCROLLS
(allow over-scrolling only if the view content is larger than the container),
or OVER_SCROLL_NEVER
.
Setting the over-scroll mode of a view will have an effect only if the
view is capable of scrolling.
mode | The new over-scroll mode for this view. |
---|
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.
listener | an implementation of WebView.PictureListener |
---|
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.
style | the style of the scrollbars. Should be one of SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. |
---|
This method was deprecated
in API level 23.
This method has no effect.
Specifies whether the vertical scrollbar has overlay style.
overlay | true if vertical scrollbar should have overlay style |
---|
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.
client | an implementation of WebChromeClient |
---|
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.
enabled | whether to enable web contents debugging |
---|
Sets the WebViewClient that will receive various notifications and requests. This will replace the current handler.
client | an implementation of WebViewClient |
---|
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.
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.
text | 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 | if true, show the IME, assuming the user will begin typing. If false and text is non-null, perform a find all. |
Performs a zoom operation in this WebView.
zoomFactor | 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. |
---|
Performs zoom in in this WebView.
Performs zoom out in this WebView.
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()
and
computeHorizontalScrollExtent()
.
The default offset is the scroll offset of this view.
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()
and
computeHorizontalScrollOffset()
.
The default range is the drawing width of this view.
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()
and
computeVerticalScrollOffset()
.
The default extent is the drawing height of this view.
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()
and
computeVerticalScrollExtent()
.
The default offset is the scroll offset of this view.
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()
and
computeVerticalScrollOffset()
.
The default range is the drawing height of this view.
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).
canvas | the canvas on which to draw the view |
---|
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)
,
however it may be called any time before the first onDraw -- including
before or after onMeasure(int, int)
.
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
mechanism of
recreating the activity instance upon a configuration change.
newConfig | The new resource configuration. |
---|
Implement this to do your drawing.
canvas | the canvas on which the background will be drawn |
---|
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.
focused | True if the View has focus; false otherwise. |
---|---|
direction | The direction focus has moved when requestFocus()
is called to give this view focus. Values are
FOCUS_UP , FOCUS_DOWN , FOCUS_LEFT ,
FOCUS_RIGHT , FOCUS_FORWARD , or FOCUS_BACKWARD .
It may not always apply, in which case use the default. |
previouslyFocusedRect | 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.
|
Measure the view and its content to determine the measured width and the
measured height. This method is invoked by measure(int, int)
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)
to store the
measured width and height of this view. Failure to do so will trigger an
IllegalStateException
, thrown by
measure(int, int)
. Calling the superclass'
onMeasure(int, int)
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)
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()
and
getSuggestedMinimumWidth()
).
widthMeasureSpec | horizontal space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec . |
---|---|
heightMeasureSpec | vertical space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec . |
Called by overScrollBy(int, int, int, int, int, int, int, int, boolean)
to
respond to the results of an over-scroll operation.
scrollX | New X scroll value in pixels |
---|---|
scrollY | New Y scroll value in pixels |
clampedX | True if scrollX was clamped to an over-scroll boundary |
clampedY | True if scrollY was clamped to an over-scroll boundary |
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)
or scrollTo(int, int)
having been
called.
l | Current horizontal scroll origin. |
---|---|
t | Current vertical scroll origin. |
oldl | Previous horizontal scroll origin. |
oldt | Previous vertical scroll origin. |
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.
w | Current width of this view. |
---|---|
h | Current height of this view. |
ow | Old width of this view. |
oh | Old height of this view. |
Called when the window containing has change its visibility
(between GONE
, INVISIBLE
, and VISIBLE
). 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.
visibility | The new visibility of the window. |
---|