harmony 鸿蒙@ohos.uiAppearance (UI Appearance)

  • 2022-08-09
  • 浏览 (621)

@ohos.uiAppearance (UI Appearance)

The uiAppearance module provides basic capabilities for managing the system appearance. It allows for color mode configuration currently, and will introduce more features over time.

NOTE

The APIs of this module are supported since API version 10. Updates will be marked with a superscript to indicate their earliest API version.

The APIs provided by this module are system APIs.

Modules to Import

import uiAppearance from '@ohos.uiAppearance'

DarkMode

Enumerates the color modes.

System capability: SystemCapability.ArkUI.UiAppearance

|Name|Value|Description| |–|–|–| |ALWAYS_DARK|0|The system is always in dark mode.| |ALWAYS_LIGHT|1|The system is always in light mode.|

uiAppearance.setDarkMode

setDarkMode(mode: DarkMode, callback: AsyncCallback<void>): void

Sets the system color mode. This API uses an asynchronous callback to return the result.

Permission required: ohos.permission.UPDATE_CONFIGURATION

System capability: SystemCapability.ArkUI.UiAppearance

Parameters

|Name|Type|Mandatory|Description| |–|–|–|–| |mode|DarkMode|Yes|Color mode to set.| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Error codes

For details about the error codes, see UI Appearance Error Codes.

|ID|Error Message| |–|–| |500001|Internal error.|

Example

import uiAppearance from '@ohos.uiAppearance'
import { BusinessError } from '@ohos.base';
try {
    uiAppearance.setDarkMode(uiAppearance.DarkMode.ALWAYS_DARK, (error) => {
      if (error) {
        console.error('Set dark-mode failed, ' + error.message);
      } else {
        console.info('Set dark-mode successfully.');
      }
    })
} catch (error) {
    let message = (error as BusinessError).message;
    console.error('Set dark-mode failed, ' + message);
}

uiAppearance.setDarkMode

setDarkMode(mode: DarkMode): Promise<void>;

Sets the system color mode. This API uses a promise to return the result.

Permission required: ohos.permission.UPDATE_CONFIGURATION

System capability: SystemCapability.ArkUI.UiAppearance

Parameters

|Name|Type|Mandatory|Description| |–|–|–|–| |mode|DarkMode|Yes|Color mode to set.|

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see UI Appearance Error Codes.

|ID|Error Message| |–|–| |500001|Internal error.|

Example

import uiAppearance from '@ohos.uiAppearance'
import { BusinessError } from '@ohos.base';
try {
    uiAppearance.setDarkMode(uiAppearance.DarkMode.ALWAYS_DARK).then(() => {
      console.info('Set dark-mode successfully.');
    }).catch((error:Error) => {
      console.error('Set dark-mode failed, ' + error.message);
    });
} catch (error) {
    let message = (error as BusinessError).message;
    console.error('Set dark-mode failed, ' + message);
}

uiAppearance.getDarkMode

getDarkMode(): DarkMode;

Obtains the system color mode.

Permission required: ohos.permission.UPDATE_CONFIGURATION

System capability: SystemCapability.ArkUI.UiAppearance

Return value

|Type|Description| |–|–| |DarkMode|Color mode obtained.|

Error codes

For details about the error codes, see UI Appearance Error Codes.

|ID|Error Message| |–|–| |500001|Internal error.|

Example

import uiAppearance from '@ohos.uiAppearance'
import { BusinessError } from '@ohos.base';
try {
    let darkMode = uiAppearance.getDarkMode();
    console.info('Get dark-mode ' + darkMode);
} catch (error) {
    let message = (error as BusinessError).message;
    console.error('Get dark-mode failed, ' + message);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞