openharmony 鸿蒙 js-apis-uiappearance

2026-08-25 浏览 (1)

@ohos.uiAppearance (UI Appearance)

This module provides basic capabilities for obtaining system appearance configurations, including color mode (dark/light) settings, font size scale factors, and font weight scale factors.

NOTE

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

Modules to Import

import { uiAppearance } from '@kit.ArkUI';

DarkMode

Enumerates the color modes.

System capability: SystemCapability.ArkUI.UiAppearance

NameValueDescription
ALWAYS_DARK0The system is always in dark mode.
ALWAYS_LIGHT1The system is always in light mode.

uiAppearance.getDarkMode

getDarkMode(): DarkMode

Obtains the current system dark mode configuration.

NOTE

This API is a system API in API version 19 and earlier. Using this API requires the ohos.permission.UPDATE_CONFIGURATION permission.

System capability: SystemCapability.ArkUI.UiAppearance

Return value

TypeDescription
DarkModeColor mode obtained.

Error codes

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

IDError Message
500001Internal error.

Example

import { uiAppearance } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';

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);
}

uiAppearance.getFontScale

getFontScale(): number

Obtains the current font size scale factor.

NOTE

This API is a system API in API version 19 and earlier. Using this API requires the ohos.permission.UPDATE_CONFIGURATION permission.

System capability: SystemCapability.ArkUI.UiAppearance

Return value

TypeDescription
numberCurrent font size scale factor.

Error codes

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

IDError Message
500001Internal error.

Example

import { uiAppearance } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let fontScale = uiAppearance.getFontScale();
  console.info('Get fontScale ' + fontScale);
} catch (error) {
  let message = (error as BusinessError).message;
  console.error('Get fontScale failed, ' + message);
}

uiAppearance.getFontWeightScale

getFontWeightScale(): number

Obtains the current font weight scale factor.

NOTE

This API is a system API in API version 19 and earlier. Using this API requires the ohos.permission.UPDATE_CONFIGURATION permission.

System capability: SystemCapability.ArkUI.UiAppearance

Return value

TypeDescription
numberCurrent font weight scale factor.

Error codes

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

IDError Message
500001Internal error.

Example

import { uiAppearance } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let fontWeightScale = uiAppearance.getFontWeightScale();
  console.info('Get fontScale ' + fontWeightScale);
} catch (error) {
  let message = (error as BusinessError).message;
  console.error('Get fontWeightScale failed, ' + message);
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 arkts-apis-uicontext-contextmenucontroller

openharmony 鸿蒙 errorcode-canvas

openharmony 鸿蒙 capi-oh-nativexcomponent-native-xcomponent-oh-nativexcomponent

openharmony 鸿蒙 errorcode-bindSheet

openharmony 鸿蒙 js-apis-arkui-uiExtension-sys

openharmony 鸿蒙 capi-arkui-accessibility-arkui-accessibilityeventinfo

openharmony 鸿蒙 capi-arkui-rendernodeutils

openharmony 鸿蒙 js-apis-arkui-node

openharmony 鸿蒙 capi-native-node-h

openharmony 鸿蒙 capi-arkui-nativemodule-arkui-listitemswipeactionitem

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/En25159t