Android
android.webkit
public class

android.webkit.WebSettings

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

Summary

Constants

      Value  
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.  0x00000001 
int  LOAD_CACHE_ONLY  Don't use the network, load from cache only.  0x00000003 
int  LOAD_DEFAULT  Default cache usage pattern Use with setCacheMode(int) -1  0xffffffff 
int  LOAD_NORMAL  Normal cache usage pattern Use with setCacheMode(int) 0x00000000 
int  LOAD_NO_CACHE  Don't use the cache, load from network Use with setCacheMode(int) 0x00000002 

Public Methods

  synchronized        boolean  getBlockNetworkImage()
Return true if the WebView will block network image.
          int  getCacheMode()
Return the current setting for overriding the cache mode.
  synchronized        String  getCursiveFontFamily()
Get the cursive font family name.
  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.
  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.
  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()
Return the current path used for plugins in the WebView.
  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()
Return true if the WebView is using the double tree rendering algorithm.
  synchronized        boolean  getUseWideViewPort()
  synchronized        int  getUserAgent()
Return user-agent as int
  synchronized        void  setBlockNetworkImage(boolean flag)
Tell the WebView to block network image.
          void  setCacheMode(int mode)
Override the way the cache is used.
  synchronized        void  setCursiveFontFamily(String font)
Set the cursive font family name.
  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.
  synchronized        void  setFantasyFontFamily(String font)
Set the fantasy font family name.
  synchronized        void  setFixedFontFamily(String font)
Set the fixed font family name.
  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.
  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)
Set a custom path to plugins used by the WebView.
  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)
Tell the WebView to use the double tree rendering algorithm.
  synchronized        void  setUseWideViewPort(boolean use)
Tell the WebView to use the wide viewport
  synchronized        void  setUserAgent(int ua)
Tell the WebView about user-agent string.
  synchronized        boolean  supportMultipleWindows()
          boolean  supportZoom()
Returns whether the WebView supports zoom
Methods inherited from class java.lang.Object

Details

Constants

public static final 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. Use with setCacheMode(int).
Constant Value: 1 (0x00000001)

public static final int LOAD_CACHE_ONLY

Don't use the network, load from cache only. Use with setCacheMode(int).
Constant Value: 3 (0x00000003)

public static final int LOAD_DEFAULT

Default cache usage pattern Use with setCacheMode(int).
Constant Value: -1 (0xffffffff)

public static final int LOAD_NORMAL

Normal cache usage pattern Use with setCacheMode(int).
Constant Value: 0 (0x00000000)

public static final int LOAD_NO_CACHE

Don't use the cache, load from network Use with setCacheMode(int).
Constant Value: 2 (0x00000002)

Public Methods

public synchronized boolean getBlockNetworkImage()

Return true if the WebView will block network image.

Returns

  • True if the WebView blocks network image.

public int getCacheMode()

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

public synchronized String getCursiveFontFamily()

Get the cursive font family name.

Returns

  • The cursive font family name as a string.

public synchronized int getDefaultFixedFontSize()

Get the default fixed font size.

Returns

  • A non-negative integer between 1 and 72.

public synchronized int getDefaultFontSize()

Get the default font size.

Returns

  • A non-negative integer between 1 and 72.

public synchronized String getDefaultTextEncodingName()

Get the default text encoding name.

Returns

  • The default text encoding name as a string.

public synchronized String getFantasyFontFamily()

Get the fantasy font family name.

Returns

  • The fantasy font family name as a string.

public synchronized String getFixedFontFamily()

Get the fixed font family name.

Returns

  • The fixed font family name as a string.

public synchronized boolean getJavaScriptCanOpenWindowsAutomatically()

Return true if javascript can open windows automatically.

Returns

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

public synchronized boolean getJavaScriptEnabled()

Return true if javascript is enabled.

Returns

  • True if javascript is enabled.

public synchronized WebSettings.LayoutAlgorithm getLayoutAlgorithm()

Return the current layout algorithm.

Returns

  • LayoutAlgorithm enum value describing the layout algorithm being used.

public boolean getLightTouchEnabled()

Returns true if light touches are enabled.

public synchronized boolean getLoadsImagesAutomatically()

Return true if the WebView will load image resources automatically.

Returns

  • True if the WebView loads images automatically.

public synchronized int getMinimumFontSize()

Get the minimum font size.

Returns

  • A non-negative integer between 1 and 72.

public synchronized int getMinimumLogicalFontSize()

Get the minimum logical font size.

Returns

  • A non-negative integer between 1 and 72.

public boolean getNavDump()

Returns true if dumping the navigation cache is enabled.

public synchronized boolean getPluginsEnabled()

Return true if plugins are enabled.

Returns

  • True if plugins are enabled.

public synchronized String getPluginsPath()

Return the current path used for plugins in the WebView.

Returns

  • The string path to the WebView plugins.

public synchronized String getSansSerifFontFamily()

Get the sans-serif font family name.

Returns

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

public boolean getSaveFormData()

Return whether the WebView is saving form data.

public boolean getSavePassword()

Return whether the WebView is saving password.

public synchronized String getSerifFontFamily()

Get the serif font family name.

Returns

  • The serif font family name as a string.

public synchronized String getStandardFontFamily()

Get the standard font family name.

Returns

  • The standard font family name as a string.

public synchronized WebSettings.TextSize getTextSize()

Get the text size of the page.

Returns

  • A TextSize enum value describing the text size.

public synchronized boolean getUseDoubleTree()

Return true if the WebView is using the double tree rendering algorithm.

Returns

  • True if the WebView is using the double tree rendering algorithm.

public synchronized boolean getUseWideViewPort()

Returns

  • True if the WebView is using a wide viewport

public synchronized int getUserAgent()

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. 2 if the WebView is using an iPhone user-agent string.

public synchronized void setBlockNetworkImage(boolean flag)

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 setCacheMode(int mode)

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)

Set the cursive font family name.

Parameters

font A font family name.

public synchronized void setDefaultFixedFontSize(int size)

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)

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)

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

Parameters

encoding The text encoding name.

public synchronized void setFantasyFontFamily(String font)

Set the fantasy font family name.

Parameters

font A font family name.

public synchronized void setFixedFontFamily(String font)

Set the fixed font family name.

Parameters

font A font family name.

public synchronized void setJavaScriptCanOpenWindowsAutomatically(boolean flag)

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)

Tell the WebView to enable javascript execution.

Parameters

flag True if the WebView should execute javascript.

public synchronized void setLayoutAlgorithm(WebSettings.LayoutAlgorithm l)

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)

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

public synchronized void setLoadsImagesAutomatically(boolean flag)

Tell the WebView to load image resources automatically.

Parameters

flag True if the WebView should load images automatically.

public synchronized void setMinimumFontSize(int size)

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)

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)

Enables dumping the pages navigation cache to a text file.

public 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.

public synchronized void setPluginsEnabled(boolean flag)

Tell the WebView to enable plugins.

Parameters

flag True if the WebView should load plugins.

public synchronized void setPluginsPath(String pluginsPath)

Set a custom path to plugins used by the WebView. The client must ensure it exists before this call.

Parameters

pluginsPath String path to the directory containing plugins.

public synchronized void setRenderPriority(WebSettings.RenderPriority priority)

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

Parameters

priority RenderPriority, can be normal, high or low.

public synchronized void setSansSerifFontFamily(String font)

Set the sans-serif font family name.

Parameters

font A font family name.

public void setSaveFormData(boolean save)

Store whether the WebView is saving form data.

public void setSavePassword(boolean save)

Store whether the WebView is saving password.

public synchronized void setSerifFontFamily(String font)

Set the serif font family name.

Parameters

font A font family name.

public synchronized void setStandardFontFamily(String font)

Set the standard font family name.

Parameters

font A font family name.

public synchronized void setSupportMultipleWindows(boolean support)

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

public void setSupportZoom(boolean support)

Set whether the WebView supports zoom

public synchronized void setTextSize(WebSettings.TextSize t)

Set the text size of the page.

Parameters

t A TextSize value for increasing or decreasing the text.

public synchronized void setUseDoubleTree(boolean use)

Tell the WebView to use the double tree rendering algorithm.

Parameters

use True if the WebView is to use double tree rendering, false otherwise.

public synchronized void setUseWideViewPort(boolean use)

Tell the WebView to use the wide viewport

public synchronized void setUserAgent(int ua)

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. 2 if the WebView should use an iPhone user-agent string.

public synchronized boolean supportMultipleWindows()

Returns

public boolean supportZoom()

Returns whether the WebView supports zoom
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48