public class

WebSettings

extends Object
java.lang.Object
   ↳ android.webkit.WebSettings

Class Overview

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.

Summary

Nested Classes
enum WebSettings.LayoutAlgorithm Enum for controlling the layout of html. 
enum WebSettings.RenderPriority  
enum WebSettings.TextSize Enum for specifying the text size. 
enum WebSettings.ZoomDensity Enum for specifying the WebView's desired density. 
Constants
int LOAD_CACHE_ELSE_NETWORK Use cache if content is there, even if expired (eg, history nav) If it is not in the cache, load from network.
int LOAD_CACHE_ONLY Don't use the network, load from cache only.
int LOAD_DEFAULT Default cache usage pattern Use with setCacheMode(int).
int LOAD_NORMAL Normal cache usage pattern Use with setCacheMode(int).
int LOAD_NO_CACHE Don't use the cache, load from network Use with setCacheMode(int).
Public Methods
boolean getAllowFileAccess()
Returns true if this WebView supports file access.
synchronized boolean getBlockNetworkImage()
Return true if the WebView will block network image.
boolean getBuiltInZoomControls()
Returns true if the zoom mechanism built into WebView is being used.
int getCacheMode()
Return the current setting for overriding the cache mode.
synchronized String getCursiveFontFamily()
Get the cursive font family name.
synchronized boolean getDatabaseEnabled()
Returns true if database storage API is enabled.
synchronized String getDatabasePath()
Return the path to where database storage API databases are saved for the current WebView.
synchronized int getDefaultFixedFontSize()
Get the default fixed font size.
synchronized int getDefaultFontSize()
Get the default font size.
synchronized String getDefaultTextEncodingName()
Get the default text encoding name.
WebSettings.ZoomDensity getDefaultZoom()
Get the default zoom density of the page.
synchronized boolean getDomStorageEnabled()
Returns true if the DOM Storage API's are enabled.
synchronized String getFantasyFontFamily()
Get the fantasy font family name.
synchronized String getFixedFontFamily()
Get the fixed font family name.
synchronized boolean getJavaScriptCanOpenWindowsAutomatically()
Return true if javascript can open windows automatically.
synchronized boolean getJavaScriptEnabled()
Return true if javascript is enabled.
synchronized WebSettings.LayoutAlgorithm getLayoutAlgorithm()
Return the current layout algorithm.
boolean getLightTouchEnabled()
Returns true if light touches are enabled.
boolean getLoadWithOverviewMode()
Returns true if this WebView loads page with overview mode
synchronized boolean getLoadsImagesAutomatically()
Return true if the WebView will load image resources automatically.
synchronized int getMinimumFontSize()
Get the minimum font size.
synchronized int getMinimumLogicalFontSize()
Get the minimum logical font size.
boolean getNavDump()
Returns true if dumping the navigation cache is enabled.
synchronized boolean getPluginsEnabled()
Return true if plugins are enabled.
synchronized String getPluginsPath()
TODO: need to add @Deprecated
synchronized String getSansSerifFontFamily()
Get the sans-serif font family name.
boolean getSaveFormData()
Return whether the WebView is saving form data.
boolean getSavePassword()
Return whether the WebView is saving password.
synchronized String getSerifFontFamily()
Get the serif font family name.
synchronized String getStandardFontFamily()
Get the standard font family name.
synchronized WebSettings.TextSize getTextSize()
Get the text size of the page.
synchronized boolean getUseDoubleTree()
This method is deprecated. This setting controlled a rendering optimization that is no longer present. Setting it now has no effect.
synchronized boolean getUseWideViewPort()
synchronized int getUserAgent()
This method is deprecated. Please use getUserAgentString instead.
synchronized String getUserAgentString()
Return the WebView's user-agent string.
void setAllowFileAccess(boolean allow)
Enable or disable file access within WebView.
synchronized void setAppCacheEnabled(boolean flag)
Tell the WebView to enable Application Caches API.
synchronized void setAppCacheMaxSize(long appCacheMaxSize)
Set the maximum size for the Application Caches content.
synchronized void setAppCachePath(String appCachePath)
Set a custom path to the Application Caches files.
synchronized void setBlockNetworkImage(boolean flag)
Tell the WebView to block network image.
void setBuiltInZoomControls(boolean enabled)
Sets whether the zoom mechanism built into WebView is used.
void setCacheMode(int mode)
Override the way the cache is used.
synchronized void setCursiveFontFamily(String font)
Set the cursive font family name.
synchronized void setDatabaseEnabled(boolean flag)
Set whether the database storage API is enabled.
synchronized void setDatabasePath(String databasePath)
Set the path to where database storage API databases should be saved.
synchronized void setDefaultFixedFontSize(int size)
Set the default fixed font size.
synchronized void setDefaultFontSize(int size)
Set the default font size.
synchronized void setDefaultTextEncodingName(String encoding)
Set the default text encoding name to use when decoding html pages.
void setDefaultZoom(WebSettings.ZoomDensity zoom)
Set the default zoom density of the page.
synchronized void setDomStorageEnabled(boolean flag)
Set whether the DOM storage API is enabled.
synchronized void setFantasyFontFamily(String font)
Set the fantasy font family name.
synchronized void setFixedFontFamily(String font)
Set the fixed font family name.
synchronized void setGeolocationDatabasePath(String databasePath)
Set the path where the Geolocation permissions database should be saved.
synchronized void setGeolocationEnabled(boolean flag)
Sets whether Geolocation is enabled.
synchronized void setJavaScriptCanOpenWindowsAutomatically(boolean flag)
Tell javascript to open windows automatically.
synchronized void setJavaScriptEnabled(boolean flag)
Tell the WebView to enable javascript execution.
synchronized void setLayoutAlgorithm(WebSettings.LayoutAlgorithm l)
Set the underlying layout algorithm.
void setLightTouchEnabled(boolean enabled)
Enables using light touches to make a selection and activate mouseovers.
void setLoadWithOverviewMode(boolean overview)
Set whether the WebView loads a page with overview mode.
synchronized void setLoadsImagesAutomatically(boolean flag)
Tell the WebView to load image resources automatically.
synchronized void setMinimumFontSize(int size)
Set the minimum font size.
synchronized void setMinimumLogicalFontSize(int size)
Set the minimum logical font size.
void setNavDump(boolean enabled)
Enables dumping the pages navigation cache to a text file.
void setNeedInitialFocus(boolean flag)
Tell the WebView whether it needs to set a node to have focus when requestFocus(int, android.graphics.Rect) is called.
synchronized void setPluginsEnabled(boolean flag)
Tell the WebView to enable plugins.
synchronized void setPluginsPath(String pluginsPath)
TODO: need to add @Deprecated
synchronized void setRenderPriority(WebSettings.RenderPriority priority)
Set the priority of the Render thread.
synchronized void setSansSerifFontFamily(String font)
Set the sans-serif font family name.
void setSaveFormData(boolean save)
Store whether the WebView is saving form data.
void setSavePassword(boolean save)
Store whether the WebView is saving password.
synchronized void setSerifFontFamily(String font)
Set the serif font family name.
synchronized void setStandardFontFamily(String font)
Set the standard font family name.
synchronized void setSupportMultipleWindows(boolean support)
Tell the WebView whether it supports multiple windows.
void setSupportZoom(boolean support)
Set whether the WebView supports zoom
synchronized void setTextSize(WebSettings.TextSize t)
Set the text size of the page.
synchronized void setUseDoubleTree(boolean use)
This method is deprecated. This setting controlled a rendering optimization that is no longer present. Setting it now has no effect.
synchronized void setUseWideViewPort(boolean use)
Tell the WebView to use the wide viewport
synchronized void setUserAgent(int ua)
This method is deprecated. Please use setUserAgentString instead.
synchronized void setUserAgentString(String ua)
Set the WebView's user-agent string.
synchronized boolean supportMultipleWindows()
boolean supportZoom()
Returns whether the WebView supports zoom
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int LOAD_CACHE_ELSE_NETWORK

Since: API Level 1

Use cache if content is there, even if expired (eg, history nav) If it is not in the cache, load from network. Use with setCacheMode(int).

Constant Value: 1 (0x00000001)

public static final int LOAD_CACHE_ONLY

Since: API Level 1

Don't use the network, load from cache only. Use with setCacheMode(int).

Constant Value: 3 (0x00000003)

public static final int LOAD_DEFAULT

Since: API Level 1

Default cache usage pattern Use with setCacheMode(int).

Constant Value: -1 (0xffffffff)

public static final int LOAD_NORMAL

Since: API Level 1

Normal cache usage pattern Use with setCacheMode(int).

Constant Value: 0 (0x00000000)

public static final int LOAD_NO_CACHE

Since: API Level 1

Don't use the cache, load from network Use with setCacheMode(int).

Constant Value: 2 (0x00000002)

Public Methods

public boolean getAllowFileAccess ()

Since: API Level 3

Returns true if this WebView supports file access.

public synchronized boolean getBlockNetworkImage ()

Since: API Level 1

Return true if the WebView will block network image. The default is false.

Returns
  • True if the WebView blocks network image.

public boolean getBuiltInZoomControls ()

Since: API Level 3

Returns true if the zoom mechanism built into WebView is being used.

public int getCacheMode ()

Since: API Level 1

Return the current setting for overriding the cache mode. For a full description, see the setCacheMode(int) function.

public synchronized String getCursiveFontFamily ()

Since: API Level 1

Get the cursive font family name. The default is "cursive".

Returns
  • The cursive font family name as a string.

public synchronized boolean getDatabaseEnabled ()

Since: API Level 5

Returns true if database storage API is enabled.

Returns
  • True if the database storage API is enabled.

public synchronized String getDatabasePath ()

Since: API Level 5

Return the path to where database storage API databases are saved for the current WebView.

Returns
  • the String path to the database storage API databases.

public synchronized int getDefaultFixedFontSize ()

Since: API Level 1

Get the default fixed font size. The default is 16.

Returns
  • A non-negative integer between 1 and 72.

public synchronized int getDefaultFontSize ()

Since: API Level 1

Get the default font size. The default is 16.

Returns
  • A non-negative integer between 1 and 72.

public synchronized String getDefaultTextEncodingName ()

Since: API Level 1

Get the default text encoding name. The default is "Latin-1".

Returns
  • The default text encoding name as a string.

public WebSettings.ZoomDensity getDefaultZoom ()

Since: API Level 7

Get the default zoom density of the page. This should be called from UI thread.

Returns
  • A ZoomDensity value

public synchronized boolean getDomStorageEnabled ()

Since: API Level 7

Returns true if the DOM Storage API's are enabled.

Returns
  • True if the DOM Storage API's are enabled.

public synchronized String getFantasyFontFamily ()

Since: API Level 1

Get the fantasy font family name. The default is "fantasy".

Returns
  • The fantasy font family name as a string.

public synchronized String getFixedFontFamily ()

Since: API Level 1

Get the fixed font family name. The default is "monospace".

Returns
  • The fixed font family name as a string.

public synchronized boolean getJavaScriptCanOpenWindowsAutomatically ()

Since: API Level 1

Return true if javascript can open windows automatically. The default is false.

Returns
  • True if javascript can open windows automatically during window.open().

public synchronized boolean getJavaScriptEnabled ()

Since: API Level 1

Return true if javascript is enabled. Note: The default is false.

Returns
  • True if javascript is enabled.

public synchronized WebSettings.LayoutAlgorithm getLayoutAlgorithm ()

Since: API Level 1

Return the current layout algorithm. The default is NARROW_COLUMNS.

Returns
  • LayoutAlgorithm enum value describing the layout algorithm being used.

public boolean getLightTouchEnabled ()

Since: API Level 1

Returns true if light touches are enabled.

public boolean getLoadWithOverviewMode ()

Since: API Level 7

Returns true if this WebView loads page with overview mode

public synchronized boolean getLoadsImagesAutomatically ()

Since: API Level 1

Return true if the WebView will load image resources automatically. The default is true.

Returns
  • True if the WebView loads images automatically.

public synchronized int getMinimumFontSize ()

Since: API Level 1

Get the minimum font size. The default is 8.

Returns
  • A non-negative integer between 1 and 72.

public synchronized int getMinimumLogicalFontSize ()

Since: API Level 1

Get the minimum logical font size. The default is 8.

Returns
  • A non-negative integer between 1 and 72.

public boolean getNavDump ()

Since: API Level 1

Returns true if dumping the navigation cache is enabled.

public synchronized boolean getPluginsEnabled ()

Since: API Level 1

Return true if plugins are enabled.

Returns
  • True if plugins are enabled.

public synchronized String getPluginsPath ()

Since: API Level 1

TODO: need to add @Deprecated

public synchronized String getSansSerifFontFamily ()

Since: API Level 1

Get the sans-serif font family name.

Returns
  • The sans-serif font family name as a string.

public boolean getSaveFormData ()

Since: API Level 1

Return whether the WebView is saving form data.

public boolean getSavePassword ()

Since: API Level 1

Return whether the WebView is saving password.

public synchronized String getSerifFontFamily ()

Since: API Level 1

Get the serif font family name. The default is "serif".

Returns
  • The serif font family name as a string.

public synchronized String getStandardFontFamily ()

Since: API Level 1

Get the standard font family name. The default is "sans-serif".

Returns
  • The standard font family name as a string.

public synchronized WebSettings.TextSize getTextSize ()

Since: API Level 1

Get the text size of the page.

Returns
  • A TextSize enum value describing the text size.

public synchronized boolean getUseDoubleTree ()

Since: API Level 1

This method is deprecated.
This setting controlled a rendering optimization that is no longer present. Setting it now has no effect.

public synchronized boolean getUseWideViewPort ()

Since: API Level 1

Returns
  • True if the WebView is using a wide viewport

public synchronized int getUserAgent ()

Since: API Level 1

This method is deprecated.
Please use getUserAgentString instead.

Return user-agent as int

Returns
  • int 0 if the WebView is using an Android user-agent string. 1 if the WebView is using a desktop user-agent string. -1 if the WebView is using user defined user-agent string.

public synchronized String getUserAgentString ()

Since: API Level 3

Return the WebView's user-agent string.

public void setAllowFileAccess (boolean allow)

Since: API Level 3

Enable or disable file access within WebView. File access is enabled by default.

public synchronized void setAppCacheEnabled (boolean flag)

Since: API Level 7

Tell the WebView to enable Application Caches API.

Parameters
flag True if the WebView should enable Application Caches.

public synchronized void setAppCacheMaxSize (long appCacheMaxSize)

Since: API Level 7

Set the maximum size for the Application Caches content.

Parameters
appCacheMaxSize the maximum size in bytes.

public synchronized void setAppCachePath (String appCachePath)

Since: API Level 7

Set a custom path to the Application Caches files. The client must ensure it exists before this call.

Parameters
appCachePath String path to the directory containing Application Caches files. The appCache path can be the empty string but should not be null. Passing null for this parameter will result in a no-op.

public synchronized void setBlockNetworkImage (boolean flag)

Since: API Level 1

Tell the WebView to block network image. This is only checked when getLoadsImagesAutomatically() is true.

Parameters
flag True if the WebView should block network image

public void setBuiltInZoomControls (boolean enabled)

Since: API Level 3

Sets whether the zoom mechanism built into WebView is used.

public void setCacheMode (int mode)

Since: API Level 1

Override the way the cache is used. The way the cache is used is based on the navigation option. 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 pulled from the cache. This function allows the client to override this behavior.

Parameters
mode One of the LOAD_ values.

public synchronized void setCursiveFontFamily (String font)

Since: API Level 1

Set the cursive font family name.

Parameters
font A font family name.

public synchronized void setDatabaseEnabled (boolean flag)

Since: API Level 5

Set whether the database storage API is enabled.

Parameters
flag boolean True if the WebView should use the database storage API.

public synchronized void setDatabasePath (String databasePath)

Since: API Level 5

Set the path to where database storage API databases should be saved. This will update WebCore when the Sync runs in the C++ side.

Parameters
databasePath String path to the directory where databases should be saved. May be the empty string but should never be null.

public synchronized void setDefaultFixedFontSize (int size)

Since: API Level 1

Set the default fixed font size.

Parameters
size A non-negative integer between 1 and 72. Any number outside the specified range will be pinned.

public synchronized void setDefaultFontSize (int size)

Since: API Level 1

Set the default font size.

Parameters
size A non-negative integer between 1 and 72. Any number outside the specified range will be pinned.

public synchronized void setDefaultTextEncodingName (String encoding)

Since: API Level 1

Set the default text encoding name to use when decoding html pages.

Parameters
encoding The text encoding name.

public void setDefaultZoom (WebSettings.ZoomDensity zoom)

Since: API Level 7

Set the default zoom density of the page. This should be called from UI thread.

Parameters
zoom A ZoomDensity value

public synchronized void setDomStorageEnabled (boolean flag)

Since: API Level 7

Set whether the DOM storage API is enabled.

Parameters
flag boolean True if the WebView should use the DOM storage API.

public synchronized void setFantasyFontFamily (String font)

Since: API Level 1

Set the fantasy font family name.

Parameters
font A font family name.

public synchronized void setFixedFontFamily (String font)

Since: API Level 1

Set the fixed font family name.

Parameters
font A font family name.

public synchronized void setGeolocationDatabasePath (String databasePath)

Since: API Level 5

Set the path where the Geolocation permissions database should be saved. This will update WebCore when the Sync runs in the C++ side.

Parameters
databasePath String path to the directory where the Geolocation permissions database should be saved. May be the empty string but should never be null.

public synchronized void setGeolocationEnabled (boolean flag)

Since: API Level 5

Sets whether Geolocation is enabled.

Parameters
flag Whether Geolocation should be enabled.

public synchronized void setJavaScriptCanOpenWindowsAutomatically (boolean flag)

Since: API Level 1

Tell javascript to open windows automatically. This applies to the javascript function window.open().

Parameters
flag True if javascript can open windows automatically.

public synchronized void setJavaScriptEnabled (boolean flag)

Since: API Level 1

Tell the WebView to enable javascript execution.

Parameters
flag True if the WebView should execute javascript.

public synchronized void setLayoutAlgorithm (WebSettings.LayoutAlgorithm l)

Since: API Level 1

Set the underlying layout algorithm. This will cause a relayout of the WebView.

Parameters
l A LayoutAlgorithm enum specifying the algorithm to use.

public void setLightTouchEnabled (boolean enabled)

Since: API Level 1

Enables using light touches to make a selection and activate mouseovers.

public void setLoadWithOverviewMode (boolean overview)

Since: API Level 7

Set whether the WebView loads a page with overview mode.

public synchronized void setLoadsImagesAutomatically (boolean flag)

Since: API Level 1

Tell the WebView to load image resources automatically.

Parameters
flag True if the WebView should load images automatically.

public synchronized void setMinimumFontSize (int size)

Since: API Level 1

Set the minimum font size.

Parameters
size A non-negative integer between 1 and 72. Any number outside the specified range will be pinned.

public synchronized void setMinimumLogicalFontSize (int size)

Since: API Level 1

Set the minimum logical font size.

Parameters
size A non-negative integer between 1 and 72. Any number outside the specified range will be pinned.

public void setNavDump (boolean enabled)

Since: API Level 1

Enables dumping the pages navigation cache to a text file.

public void setNeedInitialFocus (boolean flag)

Since: API Level 1

Tell the WebView whether it needs to set a node to have focus when requestFocus(int, android.graphics.Rect) is called.

public synchronized void setPluginsEnabled (boolean flag)

Since: API Level 1

Tell the WebView to enable plugins.

Parameters
flag True if the WebView should load plugins.

public synchronized void setPluginsPath (String pluginsPath)

Since: API Level 1

TODO: need to add @Deprecated

public synchronized void setRenderPriority (WebSettings.RenderPriority priority)

Since: API Level 1

Set the priority of the Render thread. Unlike the other settings, this one only needs to be called once per process. The default is NORMAL.

Parameters
priority RenderPriority, can be normal, high or low.

public synchronized void setSansSerifFontFamily (String font)

Since: API Level 1

Set the sans-serif font family name.

Parameters
font A font family name.

public void setSaveFormData (boolean save)

Since: API Level 1

Store whether the WebView is saving form data.

public void setSavePassword (boolean save)

Since: API Level 1

Store whether the WebView is saving password.

public synchronized void setSerifFontFamily (String font)

Since: API Level 1

Set the serif font family name. The default is "sans-serif".

Parameters
font A font family name.

public synchronized void setStandardFontFamily (String font)

Since: API Level 1

Set the standard font family name.

Parameters
font A font family name.

public synchronized void setSupportMultipleWindows (boolean support)

Since: API Level 1

Tell the WebView whether it supports multiple windows. TRUE means that onCreateWindow(WebView, boolean, boolean, Message) is implemented by the host application.

public void setSupportZoom (boolean support)

Since: API Level 1

Set whether the WebView supports zoom

public synchronized void setTextSize (WebSettings.TextSize t)

Since: API Level 1

Set the text size of the page.

Parameters
t A TextSize value for increasing or decreasing the text.

public synchronized void setUseDoubleTree (boolean use)

Since: API Level 1

This method is deprecated.
This setting controlled a rendering optimization that is no longer present. Setting it now has no effect.

public synchronized void setUseWideViewPort (boolean use)

Since: API Level 1

Tell the WebView to use the wide viewport

public synchronized void setUserAgent (int ua)

Since: API Level 1

This method is deprecated.
Please use setUserAgentString instead.

Tell the WebView about user-agent string.

Parameters
ua 0 if the WebView should use an Android user-agent string, 1 if the WebView should use a desktop user-agent string.

public synchronized void setUserAgentString (String ua)

Since: API Level 3

Set the WebView's user-agent string. If the string "ua" is null or empty, it will use the system default user-agent string.

public synchronized boolean supportMultipleWindows ()

Since: API Level 1

Returns

public boolean supportZoom ()

Since: API Level 1

Returns whether the WebView supports zoom