1# @ohos.uiAppearance (UI Appearance) (System API) 2 3The **uiAppearance** module provides basic capabilities for managing the system appearance. It allows for color mode configuration currently, and will introduce more features over time. 4 5> **NOTE** 6> 7> The APIs of this module are supported since API version 10. Updates will be marked with a superscript to indicate their earliest API version. 8> 9> The APIs provided by this module are system APIs. 10 11 12## Modules to Import 13 14```ts 15import { uiAppearance } from '@kit.ArkUI' 16``` 17 18 19## DarkMode 20 21Enumerates the color modes. 22 23 24**System capability**: SystemCapability.ArkUI.UiAppearance 25 26| Name | Value | Description | 27| -- | -- | -- | 28| ALWAYS_DARK | 0 | The system is always in dark mode. | 29| ALWAYS_LIGHT | 1 | The system is always in light mode. | 30 31 32## uiAppearance.setDarkMode 33 34setDarkMode(mode: DarkMode, callback: AsyncCallback\<void>): void 35 36Sets the system color mode. This API uses an asynchronous callback to return the result. 37 38**Permission required**: ohos.permission.UPDATE_CONFIGURATION 39 40**System capability**: SystemCapability.ArkUI.UiAppearance 41 42**Parameters** 43 44| Name | Type | Mandatory | Description | 45| -- | -- | -- | -- | 46| mode | [DarkMode](#darkmode) | Yes | Color mode to set. | 47| callback | AsyncCallback\<void>| Yes | Callback used to return the result. | 48 49**Error codes** 50 51For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [UI Appearance Error Codes](errorcode-uiappearance.md). 52 53| ID | Error Message | 54| -- | -- | 55| 201 | Permission denied. | 56| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 57| 500001 | Internal error. | 58 59**Example** 60 61 ```ts 62import { uiAppearance } from '@kit.ArkUI' 63import { BusinessError } from '@kit.BasicServicesKit'; 64try { 65 uiAppearance.setDarkMode(uiAppearance.DarkMode.ALWAYS_DARK, (error) => { 66 if (error) { 67 console.error('Set dark-mode failed, ' + error.message); 68 } else { 69 console.info('Set dark-mode successfully.'); 70 } 71 }) 72} catch (error) { 73 let message = (error as BusinessError).message; 74 console.error('Set dark-mode failed, ' + message); 75} 76 ``` 77 78 79## uiAppearance.setDarkMode 80 81setDarkMode(mode: DarkMode): Promise\<void>; 82 83Sets the system color mode. This API uses a promise to return the result. 84 85**Permission required**: ohos.permission.UPDATE_CONFIGURATION 86 87**System capability**: SystemCapability.ArkUI.UiAppearance 88 89**Parameters** 90 91| Name | Type | Mandatory | Description | 92| -- | -- | -- | -- | 93| mode | [DarkMode](#darkmode) | Yes | Color mode to set. | 94 95**Return value** 96 97| Type | Description | 98| ------ | ------------------------------ | 99| Promise\<void> | Promise that returns no value.| 100 101**Error codes** 102 103For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [UI Appearance Error Codes](errorcode-uiappearance.md). 104 105| ID | Error Message | 106| -- | -- | 107| 201 | Permission denied. | 108| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 109| 500001 | Internal error. | 110 111**Example** 112 113 ```ts 114import { uiAppearance } from '@kit.ArkUI' 115import { BusinessError } from '@kit.BasicServicesKit'; 116try { 117 uiAppearance.setDarkMode(uiAppearance.DarkMode.ALWAYS_DARK).then(() => { 118 console.info('Set dark-mode successfully.'); 119 }).catch((error:Error) => { 120 console.error('Set dark-mode failed, ' + error.message); 121 }); 122} catch (error) { 123 let message = (error as BusinessError).message; 124 console.error('Set dark-mode failed, ' + message); 125} 126 ``` 127 128 129## uiAppearance.getDarkMode 130 131getDarkMode(): DarkMode; 132 133Obtains the system color mode. 134 135**Permission required**: ohos.permission.UPDATE_CONFIGURATION 136 137**System capability**: SystemCapability.ArkUI.UiAppearance 138 139**Return value** 140 141| Type | Description | 142| -- | -- | 143|[DarkMode](#darkmode) | Color mode obtained. | 144 145**Error codes** 146 147For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [UI Appearance Error Codes](errorcode-uiappearance.md). 148 149| ID | Error Message | 150| -- | -- | 151| 201 | Permission denied. | 152| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 153| 500001 | Internal error. | 154 155**Example** 156 157 ```ts 158import { uiAppearance } from '@kit.ArkUI' 159import { BusinessError } from '@kit.BasicServicesKit'; 160try { 161 let darkMode = uiAppearance.getDarkMode(); 162 console.info('Get dark-mode ' + darkMode); 163} catch (error) { 164 let message = (error as BusinessError).message; 165 console.error('Get dark-mode failed, ' + message); 166} 167 ``` 168