Pratinjau Developer Android 11 kedua kini tersedia, uji dan sampaikan masukan Anda.

WebSettingsCompat

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

Compatibility version of android.webkit.WebSettings

Summary

Constants

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

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.

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

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.

Parameters
forceDarkMode Int: the force dark mode to set.

See Also

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.