@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
| Name | Value | Description |
|---|---|---|
| ALWAYS_DARK | 0 | The system is always in dark mode. |
| ALWAYS_LIGHT | 1 | The 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
| 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 '@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
| Type | Description |
|---|---|
| number | Current font size scale factor. |
Error codes
For details about the error codes, see UI Appearance Error Codes.
| ID | Error Message |
|---|---|
| 500001 | Internal 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
| Type | Description |
|---|---|
| number | Current font weight scale factor. |
Error codes
For details about the error codes, see UI Appearance Error Codes.
| ID | Error Message |
|---|---|
| 500001 | Internal 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