• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.uiAppearance (用户界面外观)(系统接口)
2
3用户界面外观提供管理系统外观的一些基础能力,目前仅包括深浅色模式配置。
4
5> **说明:**
6>
7> 从API version 10开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8>
9> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.uiAppearance (用户界面外观)](js-apis-uiappearance.md)。
10
11
12## 导入模块
13
14```ts
15import { uiAppearance } from '@kit.ArkUI';
16```
17
18
19## uiAppearance.setDarkMode
20
21setDarkMode(mode: DarkMode, callback: AsyncCallback\<void>): void
22
23设置系统深色模式。
24
25**需要权限:** ohos.permission.UPDATE_CONFIGURATION
26
27**系统能力:** SystemCapability.ArkUI.UiAppearance
28
29**参数:**
30
31| 参数名 | 类型 | 必填 | 说明 |
32| -- | -- | -- | -- |
33| mode | [DarkMode](js-apis-uiappearance.md#darkmode) | 是 | 指定系统的深色模式配置。 |
34| callback | AsyncCallback\<void>| 是 | 配置深色模式的异步回调。 |
35
36**错误码:**
37
38错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[errcode-uiappearance](errorcode-uiappearance.md)。
39
40| 错误码ID | 错误信息 |
41| -- | -- |
42| 201 | Permission denied. |
43| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameters types. 3. Parameter verification failed. |
44| 500001 | Internal error. |
45
46**示例:**
47
48  ```ts
49import { uiAppearance } from '@kit.ArkUI';
50import { BusinessError } from '@kit.BasicServicesKit';
51try {
52    uiAppearance.setDarkMode(uiAppearance.DarkMode.ALWAYS_DARK, (error) => {
53      if (error) {
54        console.error('Set dark-mode failed, ' + error.message);
55      } else {
56        console.info('Set dark-mode successfully.');
57      }
58    })
59} catch (error) {
60    let message = (error as BusinessError).message;
61    console.error('Set dark-mode failed, ' + message);
62}
63  ```
64
65
66## uiAppearance.setDarkMode
67
68setDarkMode(mode: DarkMode): Promise\<void>;
69
70设置系统深色模式。
71
72**需要权限:** ohos.permission.UPDATE_CONFIGURATION
73
74**系统能力:** SystemCapability.ArkUI.UiAppearance
75
76**参数:**
77
78| 参数名 | 类型 | 必填 | 说明 |
79| -- | -- | -- | -- |
80| mode | [DarkMode](js-apis-uiappearance.md#darkmode) | 是 | 指定系统深色模式配置。 |
81
82**返回值:**
83
84| 类型   | 说明                           |
85| ------ | ------------------------------ |
86| Promise\<void> | Promise对象。无返回结果的Promise对象。|
87
88**错误码:**
89
90错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[errcode-uiappearance](errorcode-uiappearance.md)。
91
92| 错误码ID | 错误信息 |
93| -- | -- |
94| 201 | Permission denied. |
95| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameters types. 3. Parameter verification failed. |
96| 500001 | Internal error. |
97
98**示例:**
99
100  ```ts
101import { uiAppearance } from '@kit.ArkUI';
102import { BusinessError } from '@kit.BasicServicesKit';
103try {
104    uiAppearance.setDarkMode(uiAppearance.DarkMode.ALWAYS_DARK).then(() => {
105      console.info('Set dark-mode successfully.');
106    }).catch((error:Error) => {
107      console.error('Set dark-mode failed, ' + error.message);
108    });
109} catch (error) {
110    let message = (error as BusinessError).message;
111    console.error('Set dark-mode failed, ' + message);
112}
113  ```
114
115
116## uiAppearance.setFontScale<sup>12+<sup>
117
118setFontScale(fontScale: number): Promise\<void>
119
120设置系统字体大小。
121
122**需要权限:** ohos.permission.UPDATE_CONFIGURATION
123
124**系统能力:** SystemCapability.ArkUI.UiAppearance
125
126**系统接口:** 此接口为系统接口。
127
128**参数:**
129
130| 参数名 | 类型 | 必填 | 说明 |
131| -- | -- | -- | -- |
132| fontScale | number | 是 | 需要设置的字体大小。 |
133
134**返回值:**
135
136| 类型 | 说明 |
137| -- | -- |
138| Promise\<void> | Promise对象。无返回结果的Promise对象。|
139
140**错误码:**
141
142错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[errcode-uiappearance](errorcode-uiappearance.md)。
143
144| 错误码ID | 错误信息 |
145| -- | -- |
146| 201 | Permission denied. |
147| 202 | Permission verification failed. A non-system application calls a system API. |
148| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameters types. 3. Parameter verification failed. |
149| 500001 | Internal error. |
150
151**示例:**
152
153  ```ts
154import { uiAppearance } from '@kit.ArkUI';
155import { BusinessError } from '@kit.BasicServicesKit';
156
157let fontScale = 10;
158
159try {
160    uiAppearance.setFontScale(fontScale).then(() => {
161      console.info('Set fontScale successfully.');
162    }).catch((error:Error) => {
163      console.error('Set fontScale failed, ' + error.message);
164    });
165} catch (error) {
166    let message = (error as BusinessError).message;
167    console.error('Set fontScale failed, ' + message);
168}
169  ```
170
171
172## uiAppearance.setFontWeightScale<sup>12+<sup>
173
174setFontWeightScale(fontWeightScale: number): Promise\<void>
175
176设置系统字体粗细。
177
178**需要权限:** ohos.permission.UPDATE_CONFIGURATION
179
180**系统能力:** SystemCapability.ArkUI.UiAppearance
181
182**系统接口:** 此接口为系统接口。
183
184**参数:**
185
186| 参数名 | 类型 | 必填 | 说明 |
187| -- | -- | -- | -- |
188| fontWeightScale | number | 是 | 需要设置的字体粗细。 |
189
190**返回值:**
191
192| 类型 | 说明 |
193| -- | -- |
194| Promise\<void> | Promise对象。无返回结果的Promise对象。|
195
196**错误码:**
197
198错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[errcode-uiappearance](errorcode-uiappearance.md)。
199
200| 错误码ID | 错误信息 |
201| -- | -- |
202| 201 | Permission denied. |
203| 202 | Permission verification failed. A non-system application calls a system API. |
204| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameters types. 3. Parameter verification failed.  |
205| 500001 | Internal error. |
206
207**示例:**
208
209  ```ts
210import { uiAppearance } from '@kit.ArkUI';
211import { BusinessError } from '@kit.BasicServicesKit';
212
213let fontWeightScale = 1;
214
215try {
216    uiAppearance.setFontWeightScale(fontWeightScale).then(() => {
217      console.info('Set fontWeightScale successfully.');
218    }).catch((error:Error) => {
219      console.error('Set fontWeightScale failed, ' + error.message);
220    });
221} catch (error) {
222    let message = (error as BusinessError).message;
223    console.error('Set fontWeightScale failed, ' + message);
224}
225 ```