WebSettings.AlgorithmicDarkeningAllowed Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Get if algorithmic darkening is allowed or not for this WebView. -or- Control whether algorithmic darkening is allowed.
public virtual bool AlgorithmicDarkeningAllowed { [Android.Runtime.Register("isAlgorithmicDarkeningAllowed", "()Z", "GetIsAlgorithmicDarkeningAllowedHandler", ApiSince=33)] get; [Android.Runtime.Register("setAlgorithmicDarkeningAllowed", "(Z)V", "GetSetAlgorithmicDarkeningAllowed_ZHandler", ApiSince=33)] set; }
[<get: Android.Runtime.Register("isAlgorithmicDarkeningAllowed", "()Z", "GetIsAlgorithmicDarkeningAllowedHandler", ApiSince=33)>]
[<set: Android.Runtime.Register("setAlgorithmicDarkeningAllowed", "(Z)V", "GetSetAlgorithmicDarkeningAllowed_ZHandler", ApiSince=33)>]
member this.AlgorithmicDarkeningAllowed : bool with get, set
Property Value
if the algorithmic darkening is allowed or not.
- Attributes
Remarks
Property getter documentation:
Get if algorithmic darkening is allowed or not for this WebView. The default is false.
Java documentation for android.webkit.WebSettings.isAlgorithmicDarkeningAllowed()
.
Property setter documentation:
Control whether algorithmic darkening is allowed.
<p class="note"> <b>Note:</b> This API and the behaviour described only apply to apps with targetSdkVersion
≥ android.os.Build.VERSION_CODES#TIRAMISU
.
WebView always sets the media query prefers-color-scheme
according to the app's theme attribute android.R.styleable#Theme_isLightTheme isLightTheme
, i.e. prefers-color-scheme
is light
if isLightTheme is true or not specified, otherwise it is dark
. This means that the web content's light or dark style will be applied automatically to match the app's theme if the content supports it.
Algorithmic darkening is disallowed by default.
If the app's theme is dark and it allows algorithmic darkening, WebView will attempt to darken web content using an algorithm, if the content doesn't define its own dark styles and doesn't explicitly disable darkening.
If Android is applying Force Dark to WebView then WebView will ignore the value of this setting and behave as if it were set to true.
The deprecated #setForceDark
and related API are no-ops in apps with targetSdkVersion
≥ android.os.Build.VERSION_CODES#TIRAMISU
, but they still apply to apps with targetSdkVersion
< android.os.Build.VERSION_CODES#TIRAMISU
.
The below table summarizes how APIs work with different apps.
<table border="2" width="85%" align="center" cellpadding="5"> <thead> <tr> <th>App</th> <th>Web content which uses prefers-color-scheme
</th> <th>Web content which does not use prefers-color-scheme
</th> </tr> </thead> <tbody> <tr> <td>App with isLightTheme
True or not set</td> <td>Renders with the light theme defined by the content author.</td> <td>Renders with the default styling defined by the content author.</td> </tr> <tr> <td>App with Android forceDark in effect</td> <td>Renders with the dark theme defined by the content author.</td> <td>Renders with the styling modified to dark colors by an algorithm if allowed by the content author.</td> </tr> <tr> <td>App with isLightTheme
False, targetSdkVersion
< android.os.Build.VERSION_CODES#TIRAMISU
, and has FORCE_DARK_AUTO
</td> <td>Renders with the dark theme defined by the content author.</td> <td>Renders with the default styling defined by the content author.</td> </tr> <tr> <td>App with isLightTheme
False, targetSdkVersion
≥ android.os.Build.VERSION_CODES#TIRAMISU
, and setAlgorithmicDarkening(false)
</td> <td>Renders with the dark theme defined by the content author.</td> <td>Renders with the default styling defined by the content author.</td> </tr> <tr> <td>App with isLightTheme
False, targetSdkVersion
≥ android.os.Build.VERSION_CODES#TIRAMISU
, and setAlgorithmicDarkening(true)
</td> <td>Renders with the dark theme defined by the content author.</td> <td>Renders with the styling modified to dark colors by an algorithm if allowed by the content author.</td> </tr> </tbody> </table>
Java documentation for android.webkit.WebSettings.setAlgorithmicDarkeningAllowed(boolean)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.