Google se compromete a impulsar la igualdad racial para las comunidades afrodescendientes. Obtén información al respecto.

WebSettingsCompat

open class WebSettingsCompat
kotlin.Any
   ↳ androidx.webkit.WebSettingsCompat

Compatibility version of android.webkit.WebSettings

Summary

Constants
static Int

In this mode WebView content will be darkened by a user agent unless web page supports dark theme.

static Int

In this mode WebView content will be darkened by a user agent and it will ignore the web page's dark theme if it exists.

static Int

In this mode WebView content will always be darkened using dark theme provided by web page.

static Int

Enable force dark dependent on the state of the WebView parent view.

static Int

Disable force dark, irrespective of the force dark mode of the WebView parent.

static Int

Unconditionally enable force dark.

Public methods
open static Int

Gets the action mode menu items that are disabled, expressed in an integer field flag.

open static Int
getForceDark(@NonNull settings: WebSettings)

Get the force dark mode for this WebView.

open static Int
getForceDarkStrategy(@NonNull settings: WebSettings)

Get how content is darkened for this WebView.

open static Boolean
getOffscreenPreRaster(@NonNull settings: WebSettings)

Gets whether this WebView should raster tiles when it is offscreen but attached to a window.

open static Boolean
getSafeBrowsingEnabled(@NonNull settings: WebSettings)

Gets whether Safe Browsing is enabled.

open static Unit
setDisabledActionModeMenuItems(@NonNull settings: WebSettings, menuItems: Int)

Disables the action mode menu items according to menuItems flag.

open static Unit
setForceDark(@NonNull settings: WebSettings, forceDarkMode: Int)

Set the force dark mode for this WebView.

open static Unit
setForceDarkStrategy(@NonNull settings: WebSettings, forceDarkBehavior: Int)

Set how WebView content should be darkened.

open static Unit
setOffscreenPreRaster(@NonNull settings: WebSettings, enabled: Boolean)

Sets whether this WebView should raster tiles when it is offscreen but attached to a window.

open static Unit
setSafeBrowsingEnabled(@NonNull settings: WebSettings, enabled: Boolean)

Sets whether Safe Browsing is enabled.

Constants

DARK_STRATEGY_PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING

static val DARK_STRATEGY_PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING: Int

In this mode WebView content will be darkened by a user agent unless web page supports dark theme. WebView determines whether web pages supports dark theme by the presence of color-scheme metadata containing "dark" value. For example, <meta name="color-scheme" content="dark light">". If the metadata is not presented WebView content will be darkened by a user agent and prefers-color-scheme media query will evaluate to light.

See specification for more information.

Value: WebSettingsBoundaryInterface.ForceDarkBehavior.PREFER_MEDIA_QUERY_OVER_FORCE_DARK

DARK_STRATEGY_USER_AGENT_DARKENING_ONLY

static val DARK_STRATEGY_USER_AGENT_DARKENING_ONLY: Int

In this mode WebView content will be darkened by a user agent and it will ignore the web page's dark theme if it exists. To avoid mixing two different darkening strategies, the prefers-color-scheme media query will evaluate to light.

See specification for more information.

Value: WebSettingsBoundaryInterface.ForceDarkBehavior.FORCE_DARK_ONLY

DARK_STRATEGY_WEB_THEME_DARKENING_ONLY

static val DARK_STRATEGY_WEB_THEME_DARKENING_ONLY: Int

In this mode WebView content will always be darkened using dark theme provided by web page. If web page does not provide dark theme support WebView content will be rendered with a default theme.

See specification for more information.

Value: WebSettingsBoundaryInterface.ForceDarkBehavior.MEDIA_QUERY_ONLY

FORCE_DARK_AUTO

static val FORCE_DARK_AUTO: Int

Enable force dark dependent on the state of the WebView parent view. If the WebView parent view is being automatically force darkened (@see android.view.View#setForceDarkAllowed), then WebView content will be rendered so as to emulate a dark theme. WebViews that are not attached to the view hierarchy will not be inverted.

If your app uses a dark theme, WebView will not be inverted. Similarly, if your app's theme inherits from a DayNight theme, WebView will not be inverted. In either of these cases, you should control the mode manually with ForceDark#FORCE_DARK_ON or ForceDark#FORCE_DARK_OFF.

See Force Dark documentation for more information.

Value: WebSettings.FORCE_DARK_AUTO

See Also

FORCE_DARK_OFF

static val FORCE_DARK_OFF: Int

Disable force dark, irrespective of the force dark mode of the WebView parent. In this mode, WebView content will always be rendered as-is, regardless of whether native views are being automatically darkened.

Value: WebSettings.FORCE_DARK_OFF

See Also

FORCE_DARK_ON

static val FORCE_DARK_ON: Int

Unconditionally enable force dark. In this mode WebView content will always be rendered so as to emulate a dark theme.

Value: WebSettings.FORCE_DARK_ON

See Also

Public methods

getDisabledActionModeMenuItems

open static fun getDisabledActionModeMenuItems(@NonNull settings: WebSettings): Int

Gets the action mode menu items that are disabled, expressed in an integer field flag. The default value is WebSettings#MENU_ITEM_NONE

This method should only be called if WebViewFeature#isFeatureSupported(String) returns true for WebViewFeature#DISABLED_ACTION_MODE_MENU_ITEMS.

Return
Int all the disabled menu item flags combined with bitwise OR.

getForceDark

open static fun getForceDark(@NonNull settings: WebSettings): Int

Get the force dark mode for this WebView.

The default force dark mode is FORCE_DARK_AUTO.

This method should only be called if WebViewFeature#isFeatureSupported(String) returns true for WebViewFeature#FORCE_DARK.

Return
Int the currently set force dark mode.

See Also

getForceDarkStrategy

open static fun getForceDarkStrategy(@NonNull settings: WebSettings): Int

Get how content is darkened for this WebView.

The default force dark strategy is DARK_STRATEGY_PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING

This method should only be called if WebViewFeature#isFeatureSupported(String) returns true for WebViewFeature#FORCE_DARK_STRATEGY.

Return
Int the currently set force dark strategy.

getOffscreenPreRaster

open static fun getOffscreenPreRaster(@NonNull settings: WebSettings): Boolean

Gets whether this WebView should raster tiles when it is offscreen but attached to a window.

This method should only be called if WebViewFeature#isFeatureSupported(String) returns true for WebViewFeature#OFF_SCREEN_PRERASTER.

Return
Boolean true if this WebView will raster tiles when it is offscreen but attached to a window.

getSafeBrowsingEnabled

open static fun getSafeBrowsingEnabled(@NonNull settings: WebSettings): Boolean

Gets whether Safe Browsing is enabled. See setSafeBrowsingEnabled.

This method should only be called if WebViewFeature#isFeatureSupported(String) returns true for WebViewFeature#SAFE_BROWSING_ENABLE.

Return
Boolean true if Safe Browsing is enabled and false otherwise.

setDisabledActionModeMenuItems

open static fun setDisabledActionModeMenuItems(
    @NonNull settings: WebSettings,
    menuItems: Int
): Unit

Disables the action mode menu items according to menuItems flag.

This method should only be called if WebViewFeature#isFeatureSupported(String) returns true for WebViewFeature#DISABLED_ACTION_MODE_MENU_ITEMS.

Parameters
menuItems Int: an integer field flag for the menu items to be disabled.

setForceDark

open static fun setForceDark(
    @NonNull settings: WebSettings,
    forceDarkMode: Int
): Unit

Set the force dark mode for this WebView.

This method should only be called if WebViewFeature#isFeatureSupported(String) returns true for WebViewFeature#FORCE_DARK.

If equals to ForceDark#FORCE_DARK_ON then setForceDarkStrategy is used to specify darkening strategy.

Parameters
forceDarkMode Int: the force dark mode to set.

See Also

setForceDarkStrategy

open static fun setForceDarkStrategy(
    @NonNull settings: WebSettings,
    forceDarkBehavior: Int
): Unit

Set how WebView content should be darkened.

This method should only be called if WebViewFeature#isFeatureSupported(String) returns true for WebViewFeature#FORCE_DARK_STRATEGY.

The specified strategy is only used if force dark mode is on. See setForceDark.

Parameters
forceDarkBehavior Int: the force dark strategy to set.

setOffscreenPreRaster

open static fun setOffscreenPreRaster(
    @NonNull settings: WebSettings,
    enabled: Boolean
): Unit

Sets whether this WebView should raster tiles when it is offscreen but attached to a window. Turning this on can avoid rendering artifacts when animating an offscreen WebView on-screen. Offscreen WebViews in this mode use more memory. The default value is false.
Please follow these guidelines to limit memory usage:

  • WebView size should be not be larger than the device screen size.
  • Limit use of this mode to a small number of WebViews. Use it for visible WebViews and WebViews about to be animated to visible.

This method should only be called if WebViewFeature#isFeatureSupported(String) returns true for WebViewFeature#OFF_SCREEN_PRERASTER.

setSafeBrowsingEnabled

open static fun setSafeBrowsingEnabled(
    @NonNull settings: WebSettings,
    enabled: Boolean
): Unit

Sets whether Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links.

Safe Browsing can be disabled for all WebViews using a manifest tag (read general Safe Browsing info). The manifest tag has a lower precedence than this API.

Safe Browsing is enabled by default for devices which support it.

This method should only be called if WebViewFeature#isFeatureSupported(String) returns true for WebViewFeature#SAFE_BROWSING_ENABLE.

Parameters
enabled Boolean: Whether Safe Browsing is enabled.