java.lang.Object | |
↳ | android.webkit.WebSettings |
Manages settings state for a WebView. When a WebView is first created, it obtains a set of default settings. These default settings will be returned from any getter call. A WebSettings object obtained from WebView.getSettings() is tied to the life of the WebView. If a WebView has been destroyed, any method call on WebSettings will throw an IllegalStateException.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
WebSettings.LayoutAlgorithm | Enum for controlling the layout of html. | ||||||||||
WebSettings.PluginState | The plugin state effects how plugins are treated on a page. | ||||||||||
WebSettings.RenderPriority | |||||||||||
WebSettings.TextSize |
This enum was deprecated
in API level 14.
Use setTextZoom(int) and getTextZoom() instead.
|
||||||||||
WebSettings.ZoomDensity | Enum for specifying the WebView's desired density. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | LOAD_CACHE_ELSE_NETWORK | Use cached resources when they are available, even if they have expired. | |||||||||
int | LOAD_CACHE_ONLY | Don't use the network, load from the cache. | |||||||||
int | LOAD_DEFAULT | Default cache usage mode. | |||||||||
int | LOAD_NORMAL |
This constant was deprecated
in API level 17.
This value is obsolete, as from API level
HONEYCOMB and onwards it has the
same effect as LOAD_DEFAULT .
|
|||||||||
int | LOAD_NO_CACHE | Don't use the cache, load from the network. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method was deprecated
in API level 17.
This method is now obsolete, and will become a no-op in future.
| |||||||||||
Gets whether this WebView supports content URL access.
| |||||||||||
Gets whether this WebView supports file access.
| |||||||||||
Gets whether JavaScript running in the context of a file scheme URL can
access content from other file scheme URLs.
| |||||||||||
Gets whether JavaScript running in the context of a file scheme URL can
access content from any origin.
| |||||||||||
Gets whether the WebView does not load image resources from the network.
| |||||||||||
Gets whether the WebView does not load any resources from the network.
| |||||||||||
Gets whether the zoom mechanisms built into WebView are being used.
| |||||||||||
Gets the current setting for overriding the cache mode.
| |||||||||||
Gets the cursive font family name.
| |||||||||||
Gets whether the database storage API is enabled.
| |||||||||||
Gets the path to where database storage API databases are saved.
| |||||||||||
Gets the default fixed font size.
| |||||||||||
Gets the default font size.
| |||||||||||
Gets the default text encoding name.
| |||||||||||
Returns the default User-Agent used by a WebView.
| |||||||||||
Gets the default zoom density of the page.
| |||||||||||
Gets whether the WebView displays on-screen zoom controls when using
the built-in zoom mechanisms.
| |||||||||||
Gets whether the DOM Storage APIs are enabled.
| |||||||||||
Gets the fantasy font family name.
| |||||||||||
Gets the fixed font family name.
| |||||||||||
Gets whether JavaScript can open windows automatically.
| |||||||||||
Gets whether JavaScript is enabled.
| |||||||||||
Gets the current layout algorithm.
| |||||||||||
Gets whether light touches are enabled.
| |||||||||||
Gets whether this WebView loads pages in overview mode.
| |||||||||||
Gets whether the WebView loads image resources.
| |||||||||||
Gets whether the WebView requires a user gesture to play media.
| |||||||||||
Gets the minimum font size.
| |||||||||||
Gets the minimum logical font size.
| |||||||||||
Gets the current state regarding whether plugins are enabled.
| |||||||||||
This method was deprecated
in API level 8.
This method has been replaced by
getPluginState()
| |||||||||||
This method was deprecated
in API level 9.
This method is no longer used as plugins are loaded from
their own APK via the system's package manager.
| |||||||||||
Gets the sans-serif font family name.
| |||||||||||
Gets whether the WebView saves form data.
| |||||||||||
Gets whether the WebView saves passwords.
| |||||||||||
Gets the serif font family name.
| |||||||||||
Gets the standard font family name.
| |||||||||||
This method was deprecated
in API level 14.
Use
getTextZoom() instead.
| |||||||||||
Gets the text zoom of the page in percent.
| |||||||||||
Gets whether the WebView is using a wide viewport.
| |||||||||||
Gets the WebView's user-agent string.
| |||||||||||
Enables or disables content URL access within WebView.
| |||||||||||
Enables or disables file access within WebView.
| |||||||||||
Sets whether JavaScript running in the context of a file scheme URL
should be allowed to access content from other file scheme URLs.
| |||||||||||
Sets whether JavaScript running in the context of a file scheme URL
should be allowed to access content from any origin.
| |||||||||||
Sets whether the Application Caches API should be enabled.
| |||||||||||
Sets the maximum size for the Application Cache content.
| |||||||||||
Sets the path to the Application Caches files.
| |||||||||||
Sets whether the WebView should not load image resources from the
network (resources accessed via http and https URI schemes).
| |||||||||||
Sets whether the WebView should not load resources from the network.
| |||||||||||
Sets whether the WebView should use its built-in zoom mechanisms.
| |||||||||||
Overrides the way the cache is used.
| |||||||||||
Sets the cursive font family name.
| |||||||||||
Sets whether the database storage API is enabled.
| |||||||||||
Sets the path to where database storage API databases should be saved.
| |||||||||||
Sets the default fixed font size.
| |||||||||||
Sets the default font size.
| |||||||||||
Sets the default text encoding name to use when decoding html pages.
| |||||||||||
Sets the default zoom density of the page.
| |||||||||||
Sets whether the WebView should display on-screen zoom controls when
using the built-in zoom mechanisms.
| |||||||||||
Sets whether the DOM storage API is enabled.
| |||||||||||
This method was deprecated
in API level 17.
This method is now obsolete, and will become a no-op in future.
| |||||||||||
Sets the fantasy font family name.
| |||||||||||
Sets the fixed font family name.
| |||||||||||
Sets the path where the Geolocation databases should be saved.
| |||||||||||
Sets whether Geolocation is enabled.
| |||||||||||
Tells JavaScript to open windows automatically.
| |||||||||||
Tells the WebView to enable JavaScript execution.
| |||||||||||
Sets the underlying layout algorithm.
| |||||||||||
Enables using light touches to make a selection and activate mouseovers.
| |||||||||||
Sets whether the WebView loads pages in overview mode.
| |||||||||||
Sets whether the WebView should load image resources.
| |||||||||||
Sets whether the WebView requires a user gesture to play media.
| |||||||||||
Sets the minimum font size.
| |||||||||||
Sets the minimum logical font size.
| |||||||||||
Tells the WebView whether it needs to set a node to have focus when
requestFocus(int, android.graphics.Rect) is called. | |||||||||||
Tells the WebView to enable, disable, or have plugins on demand.
| |||||||||||
This method was deprecated
in API level 8.
This method has been deprecated in favor of
setPluginState(WebSettings.PluginState)
| |||||||||||
This method was deprecated
in API level 9.
This method is no longer used as plugins are loaded from
their own APK via the system's package manager.
| |||||||||||
Sets the priority of the Render thread.
| |||||||||||
Sets the sans-serif font family name.
| |||||||||||
Sets whether the WebView should save form data.
| |||||||||||
Sets whether the WebView should save passwords.
| |||||||||||
Sets the serif font family name.
| |||||||||||
Sets the standard font family name.
| |||||||||||
Sets whether the WebView whether supports multiple windows.
| |||||||||||
Sets whether the WebView should support zooming using its on-screen zoom
controls and gestures.
| |||||||||||
This method was deprecated
in API level 14.
Use
setTextZoom(int) instead.
| |||||||||||
Sets the text zoom of the page in percent.
| |||||||||||
Tells the WebView to use a wide viewport.
| |||||||||||
Sets the WebView's user-agent string.
| |||||||||||
Gets whether the WebView supports multiple windows.
| |||||||||||
Gets whether the WebView supports zoom.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Use cached resources when they are available, even if they have expired.
Otherwise load resources from the network.
Use with setCacheMode(int)
.
Don't use the network, load from the cache.
Use with setCacheMode(int)
.
Default cache usage mode. If the navigation type doesn't impose any
specific behavior, use cached resources when they are available
and not expired, otherwise load resources from the network.
Use with setCacheMode(int)
.
This constant was deprecated
in API level 17.
This value is obsolete, as from API level
HONEYCOMB
and onwards it has the
same effect as LOAD_DEFAULT
.
Normal cache usage mode. Use with setCacheMode(int)
.
Don't use the cache, load from the network.
Use with setCacheMode(int)
.
This method was deprecated
in API level 17.
This method is now obsolete, and will become a no-op in future.
Gets whether the WebView enables smooth transition while panning or zooming.
Gets whether this WebView supports content URL access.
Gets whether this WebView supports file access.
Gets whether JavaScript running in the context of a file scheme URL can access content from other file scheme URLs.
Gets whether JavaScript running in the context of a file scheme URL can access content from any origin. This includes access to content from other file scheme URLs.
Gets whether the WebView does not load image resources from the network.
Gets whether the WebView does not load any resources from the network.
Gets whether the zoom mechanisms built into WebView are being used.
Gets the current setting for overriding the cache mode.
Gets the cursive font family name.
Gets whether the database storage API is enabled.
Gets the path to where database storage API databases are saved.
Gets the default fixed font size.
Gets the default font size.
Gets the default text encoding name.
Returns the default User-Agent used by a WebView.
An instance of WebView could use a different User-Agent if a call
is made to setUserAgentString(String)
.
context | a Context object used to access application assets |
---|
Gets the default zoom density of the page. This should be called from the UI thread.
Gets whether the WebView displays on-screen zoom controls when using the built-in zoom mechanisms.
Gets whether the DOM Storage APIs are enabled.
Gets the fantasy font family name.
Gets the fixed font family name.
Gets whether JavaScript can open windows automatically.
Gets whether JavaScript is enabled.
Gets the current layout algorithm.
WebSettings.LayoutAlgorithm
valueGets whether light touches are enabled.
Gets whether this WebView loads pages in overview mode.
Gets whether the WebView loads image resources. This includes images embedded using the data URI scheme.
Gets whether the WebView requires a user gesture to play media.
Gets the minimum font size.
Gets the minimum logical font size.
Gets the current state regarding whether plugins are enabled.
WebSettings.PluginState
value
This method was deprecated
in API level 8.
This method has been replaced by getPluginState()
Gets whether plugins are enabled.
This method was deprecated
in API level 9.
This method is no longer used as plugins are loaded from
their own APK via the system's package manager.
Gets the directory that contains the plugin libraries. This method is obsolete since each plugin is now loaded from its own package.
Gets the sans-serif font family name.
Gets whether the WebView saves form data. Always false in private browsing mode.
Gets whether the WebView saves passwords.
Gets the serif font family name. The default is "serif".
Gets the standard font family name.
This method was deprecated
in API level 14.
Use getTextZoom()
instead.
Gets the text size of the page. If the text size was previously specified
in percent using setTextZoom(int)
, this will return the closest
matching WebSettings.TextSize
.
WebSettings.TextSize
valueGets the text zoom of the page in percent.
Gets whether the WebView is using a wide viewport.
Gets the WebView's user-agent string.
Enables or disables content URL access within WebView. Content URL access allows WebView to load content from a content provider installed in the system. The default is enabled.
Enables or disables file access within WebView. File access is enabled by default. Note that this enables or disables file system access only. Assets and resources are still accessible using file:///android_asset and file:///android_res.
Sets whether JavaScript running in the context of a file scheme URL
should be allowed to access content from other file scheme URLs. To
enable the most restrictive, and therefore secure policy, this setting
should be disabled. Note that the value of this setting is ignored if
the value of getAllowUniversalAccessFromFileURLs()
is true.
The default value is true for API level
ICE_CREAM_SANDWICH_MR1
and below,
and false for API level JELLY_BEAN
and above.
flag | whether JavaScript running in the context of a file scheme URL should be allowed to access content from other file scheme URLs |
---|
Sets whether JavaScript running in the context of a file scheme URL
should be allowed to access content from any origin. This includes
access to content from other file scheme URLs. See
setAllowFileAccessFromFileURLs(boolean)
. To enable the most restrictive,
and therefore secure policy, this setting should be disabled.
The default value is true for API level
ICE_CREAM_SANDWICH_MR1
and below,
and false for API level JELLY_BEAN
and above.
flag | whether JavaScript running in the context of a file scheme URL should be allowed to access content from any origin |
---|
Sets whether the Application Caches API should be enabled. The default
is false. Note that in order for the Application Caches API to be
enabled, a valid database path must also be supplied to
setAppCachePath(String)
.
flag | true if the WebView should enable Application Caches |
---|
Sets the maximum size for the Application Cache content. The passed size
will be rounded to the nearest value that the database can support, so
this should be viewed as a guide, not a hard limit. Setting the
size to a value less than current database size does not cause the
database to be trimmed. The default size is MAX_VALUE
.
appCacheMaxSize | the maximum size in bytes |
---|
Sets the path to the Application Caches files. In order for the Application Caches API to be enabled, this method must be called with a path to which the application can write. This method should only be called once: repeated calls are ignored.
appCachePath | a String path to the directory containing Application Caches files. |
---|
Sets whether the WebView should not load image resources from the
network (resources accessed via http and https URI schemes). Note
that this method has no effect unless
getLoadsImagesAutomatically()
returns true. Also note that
disabling all network loads using setBlockNetworkLoads(boolean)
will also prevent network images from loading, even if this flag is set
to false. When the value of this setting is changed from true to false,
network images resources referenced by content currently displayed by
the WebView are fetched automatically. The default is false.
flag | whether the WebView should not load image resources from the network |
---|
Sets whether the WebView should not load resources from the network.
Use setBlockNetworkImage(boolean)
to only avoid loading
image resources. Note that if the value of this setting is
changed from true to false, network resources referenced by content
currently displayed by the WebView are not fetched until
reload()
is called.
If the application does not have the
INTERNET
permission, attempts to set
a value of false will cause a SecurityException
to be thrown. The default value is false if the application has the
INTERNET
permission, otherwise it is
true.
flag | whether the WebView should not load any resources from the network |
---|
Sets whether the WebView should use its built-in zoom mechanisms. The
built-in zoom mechanisms comprise on-screen zoom controls, which are
displayed over the WebView's content, and the use of a pinch gesture to
control zooming. Whether or not these on-screen controls are displayed
can be set with setDisplayZoomControls(boolean)
. The default is false.
The built-in mechanisms are the only currently supported zoom mechanisms, so it is recommended that this setting is always enabled.
enabled | whether the WebView should use its built-in zoom mechanisms |
---|
Overrides the way the cache is used. The way the cache is used is based
on the navigation type. For a normal page load, the cache is checked
and content is re-validated as needed. When navigating back, content is
not revalidated, instead the content is just retrieved from the cache.
This method allows the client to override this behavior by specifying
one of LOAD_DEFAULT
, LOAD_NORMAL
,
LOAD_CACHE_ELSE_NETWORK
, LOAD_NO_CACHE
or
LOAD_CACHE_ONLY
. The default value is LOAD_DEFAULT
.
mode | the mode to use |
---|
Sets the cursive font family name. The default is "cursive".
font | a font family name |
---|
Sets whether the database storage API is enabled. The default value is
false. See also setDatabasePath(String)
for how to correctly set up the
database storage API.
flag | true if the WebView should use the database storage API |
---|
Sets the path to where database storage API databases should be saved. In order for the database storage API to function correctly, this method must be called with a path to which the application can write. This method should only be called once: repeated calls are ignored.
databasePath | a path to the directory where databases should be saved. |
---|
Sets the default fixed font size. The default is 16.
size | a non-negative integer between 1 and 72. Any number outside the specified range will be pinned. |
---|
Sets the default font size. The default is 16.
size | a non-negative integer between 1 and 72. Any number outside the specified range will be pinned. |
---|
Sets the default text encoding name to use when decoding html pages. The default is "Latin-1".
encoding | the text encoding name |
---|
Sets the default zoom density of the page. This must be called from the UI
thread. The default is MEDIUM
.
zoom | the zoom density |
---|
Sets whether the WebView should display on-screen zoom controls when
using the built-in zoom mechanisms. See setBuiltInZoomControls(boolean)
.
The default is true.
enabled | whether the WebView should display on-screen zoom controls |
---|
Sets whether the DOM storage API is enabled. The default value is false.
flag | true if the WebView should use the DOM storage API |
---|
This method was deprecated
in API level 17.
This method is now obsolete, and will become a no-op in future.
Sets whether the WebView will enable smooth transition while panning or zooming or while the window hosting the WebView does not have focus. If it is true, WebView will choose a solution to maximize the performance. e.g. the WebView's content may not be updated during the transition. If it is false, WebView will keep its fidelity. The default value is false.
Sets the fantasy font family name. The default is "fantasy".
font | a font family name |
---|
Sets the fixed font family name. The default is "monospace".
font | a font family name |
---|
Sets the path where the Geolocation databases should be saved. In order for Geolocation permissions and cached positions to be persisted, this method must be called with a path to which the application can write.
databasePath | a path to the directory where databases should be saved. |
---|
Sets whether Geolocation is enabled. The default is true. See also
setGeolocationDatabasePath(String)
for how to correctly set up
Geolocation.
flag | whether Geolocation should be enabled |
---|
Tells JavaScript to open windows automatically. This applies to the JavaScript function window.open(). The default is false.
flag | true if JavaScript can open windows automatically |
---|
Tells the WebView to enable JavaScript execution. The default is false.
flag | true if the WebView should execute JavaScript |
---|
Sets the underlying layout algorithm. This will cause a relayout of the
WebView. The default is NARROW_COLUMNS
.
l | the layout algorithm to use, as a WebSettings.LayoutAlgorithm value
|
---|
Enables using light touches to make a selection and activate mouseovers. The default is false.
Sets whether the WebView loads pages in overview mode. The default is false.
Sets whether the WebView should load image resources. Note that this method
controls loading of all images, including those embedded using the data
URI scheme. Use setBlockNetworkImage(boolean)
to control loading only
of images specified using network URI schemes. Note that if the value of this
setting is changed from false to true, all images resources referenced
by content currently displayed by the WebView are loaded automatically.
The default is true.
flag | whether the WebView should load image resources |
---|
Sets whether the WebView requires a user gesture to play media. The default is true.
require | whether the WebView requires a user gesture to play media |
---|
Sets the minimum font size. The default is 8.
size | a non-negative integer between 1 and 72. Any number outside the specified range will be pinned. |
---|
Sets the minimum logical font size. The default is 8.
size | a non-negative integer between 1 and 72. Any number outside the specified range will be pinned. |
---|
Tells the WebView whether it needs to set a node to have focus when
requestFocus(int, android.graphics.Rect)
is called. The
default value is true.
flag | whether the WebView needs to set a node |
---|
Tells the WebView to enable, disable, or have plugins on demand. On
demand mode means that if a plugin exists that can handle the embedded
content, a placeholder icon will be shown instead of the plugin. When
the placeholder is clicked, the plugin will be enabled. The default is
OFF
.
state | a PluginState value |
---|
This method was deprecated
in API level 8.
This method has been deprecated in favor of
setPluginState(WebSettings.PluginState)
Sets whether the WebView should enable plugins. The default is false.
flag | true if plugins should be enabled |
---|
This method was deprecated
in API level 9.
This method is no longer used as plugins are loaded from
their own APK via the system's package manager.
Sets a custom path to plugins used by the WebView. This method is obsolete since each plugin is now loaded from its own package.
pluginsPath | a String path to the directory containing plugins |
---|
Sets the priority of the Render thread. Unlike the other settings, this
one only needs to be called once per process. The default value is
NORMAL
.
priority | the priority |
---|
Sets the sans-serif font family name. The default is "sans-serif".
font | a font family name |
---|
Sets whether the WebView should save form data. The default is true, unless in private browsing mode, when the value is always false.
Sets whether the WebView should save passwords. The default is true.
Sets the serif font family name. The default is "sans-serif".
font | a font family name |
---|
Sets the standard font family name. The default is "sans-serif".
font | a font family name |
---|
Sets whether the WebView whether supports multiple windows. If set to
true, onCreateWindow(WebView, boolean, boolean, Message)
must be implemented by the
host application. The default is false.
support | whether to suport multiple windows |
---|
Sets whether the WebView should support zooming using its on-screen zoom
controls and gestures. The particular zoom mechanisms that should be used
can be set with setBuiltInZoomControls(boolean)
. This setting does not
affect zooming performed using the zoomIn()
and
zoomOut()
methods. The default is true.
support | whether the WebView should support zoom |
---|
This method was deprecated
in API level 14.
Use setTextZoom(int)
instead.
Sets the text size of the page. The default is NORMAL
.
t | the text size as a WebSettings.TextSize value |
---|
Sets the text zoom of the page in percent. The default is 100.
textZoom | the text zoom in percent |
---|
Tells the WebView to use a wide viewport. The default is false.
use | whether to use a wide viewport |
---|
Sets the WebView's user-agent string. If the string is null or empty, the system default value will be used.
Gets whether the WebView supports multiple windows.
Gets whether the WebView supports zoom.