Udostępnij za pośrednictwem


UiModeManager.NightMode Property

Definition

Returns the currently configured night mode. -or- Sets the system-wide night mode.

public virtual Android.App.UiNightMode NightMode { [Android.Runtime.Register("getNightMode", "()I", "GetGetNightModeHandler")] get; [Android.Runtime.Register("setNightMode", "(I)V", "GetSetNightMode_IHandler")] set; }
[<get: Android.Runtime.Register("getNightMode", "()I", "GetGetNightModeHandler")>]
[<set: Android.Runtime.Register("setNightMode", "(I)V", "GetSetNightMode_IHandler")>]
member this.NightMode : Android.App.UiNightMode with get, set

Property Value

the current night mode, or -1 on error

Attributes

Remarks

Property getter documentation:

Returns the currently configured night mode.

May be one of: <ul> <li>#MODE_NIGHT_NO</li> <li>#MODE_NIGHT_YES</li> <li>#MODE_NIGHT_AUTO</li> <li>#MODE_NIGHT_CUSTOM</li> <li>-1 on error</li> </ul>

Java documentation for android.app.UiModeManager.getNightMode().

Property setter documentation:

Sets the system-wide night mode.

The mode can be one of: <ul> <li><em>#MODE_NIGHT_NO<em> sets the device into notnight mode</li> <li><em>#MODE_NIGHT_YES</em> sets the device into night mode</li> <li><em>#MODE_NIGHT_CUSTOM</em> automatically switches between night and notnight based on the custom time set (or default)</li> <li><em>#MODE_NIGHT_AUTO</em> automatically switches between night and notnight based on the device's current location and certain other sensors</li> </ul>

<strong>Note:</strong> On API 22 and below, changes to the night mode are only effective when the Configuration#UI_MODE_TYPE_CAR car or Configuration#UI_MODE_TYPE_DESK desk mode is enabled on a device. On API 23 through API 28, changes to night mode are always effective.

Starting in API 29, when the device is in car mode and this method is called, night mode will change, but the new setting is not persisted and the previously persisted setting will be restored when the device exits car mode.

Changes to night mode take effect globally and will result in a configuration change (and potentially an Activity lifecycle event) being applied to all running apps. Developers interested in an app-local implementation of night mode should consider using #setApplicationNightMode(int) to set and persist the -night qualifier locally or androidx.appcompat.app.AppCompatDelegate#setDefaultNightMode(int) for the backward compatible implementation.

Java documentation for android.app.UiModeManager.setNightMode(int).

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.

Applies to