• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.uiAppearance (用户界面外观)
2<!--Kit: ArkUI-->
3<!--Subsystem: ArkUI-->
4<!--Owner: @lushi871202-->
5<!--Designer: @lushi871202-->
6<!--Tester: @sally__-->
7<!--Adviser: @HelloCrease-->
8
9用户界面外观提供获取系统外观的一些基础能力,包括获取深浅色模式、字体大小缩放比例、字体粗细缩放比例。
10
11> **说明:**
12>
13> 从API version 20开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
14
15
16## 导入模块
17
18```ts
19import { uiAppearance } from '@kit.ArkUI';
20```
21
22
23## DarkMode
24
25深色模式枚举。
26
27
28**系统能力:** SystemCapability.ArkUI.UiAppearance
29
30| 名称 | 值 | 说明 |
31| -- | -- | -- |
32| ALWAYS_DARK | 0 | 系统始终为深色。  |
33| ALWAYS_LIGHT | 1 | 系统始终为浅色。 |
34
35## uiAppearance.getDarkMode
36
37getDarkMode(): DarkMode
38
39获取系统当前的深色模式配置。
40
41<!--Del-->
42> **说明:**
43>
44> 该接口在API version 19及之前版本中为系统接口。开发者使用该接口时需要申请ohos.permission.UPDATE_CONFIGURATION权限。
45<!--DelEnd-->
46
47**系统能力**:SystemCapability.ArkUI.UiAppearance
48
49**返回值:**
50
51| 类型 | 说明 |
52| -- | -- |
53|[DarkMode](#darkmode) | 系统当前的深色模式配置。 |
54
55**错误码:**
56
57错误码详细介绍请参考[errcode-uiappearance](errorcode-uiappearance.md)。
58
59| 错误码ID | 错误信息 |
60| -- | -- |
61| 500001 | Internal error. |
62
63**示例:**
64
65```ts
66import { uiAppearance } from '@kit.ArkUI';
67import { BusinessError } from '@kit.BasicServicesKit';
68
69try {
70  let darkMode = uiAppearance.getDarkMode();
71  console.info('Get dark-mode ' + darkMode);
72} catch (error) {
73  let message = (error as BusinessError).message;
74  console.error('Get dark-mode failed, ' + message);
75}
76```
77
78
79## uiAppearance.getFontScale
80
81getFontScale(): number
82
83获取系统当前的字体大小缩放比例。
84
85<!--Del-->
86> **说明:**
87>
88> 该接口在API version 19及之前版本中为系统接口。开发者使用该接口时需要申请ohos.permission.UPDATE_CONFIGURATION权限。
89<!--DelEnd-->
90
91**系统能力**:SystemCapability.ArkUI.UiAppearance
92
93**返回值:**
94
95| 类型 | 说明 |
96| -- | -- |
97| number | 系统当前的字体大小缩放比例。 |
98
99**错误码:**
100
101错误码详细介绍请参考[errcode-uiappearance](errorcode-uiappearance.md)。
102
103| 错误码ID | 错误信息 |
104| -- | -- |
105| 500001 | Internal error. |
106
107**示例:**
108
109```ts
110import { uiAppearance } from '@kit.ArkUI';
111import { BusinessError } from '@kit.BasicServicesKit';
112
113try {
114  let fontScale = uiAppearance.getFontScale();
115  console.info('Get fontScale ' + fontScale);
116} catch (error) {
117  let message = (error as BusinessError).message;
118  console.error('Get fontScale failed, ' + message);
119}
120```
121
122
123## uiAppearance.getFontWeightScale
124
125getFontWeightScale(): number
126
127获取系统当前的字体粗细缩放比例。
128
129<!--Del-->
130> **说明:**
131>
132> 该接口在API version 19及之前版本中为系统接口。开发者使用该接口时需要申请ohos.permission.UPDATE_CONFIGURATION权限。
133<!--DelEnd-->
134
135**系统能力**:SystemCapability.ArkUI.UiAppearance
136
137**返回值:**
138
139| 类型 | 说明 |
140| -- | -- |
141| number | 系统当前的字体粗细缩放比例。 |
142
143**错误码:**
144
145错误码详细介绍请参考[errcode-uiappearance](errorcode-uiappearance.md)。
146
147| 错误码ID | 错误信息 |
148| -- | -- |
149| 500001 | Internal error. |
150
151**示例:**
152
153```ts
154import { uiAppearance } from '@kit.ArkUI';
155import { BusinessError } from '@kit.BasicServicesKit';
156
157try {
158  let fontWeightScale = uiAppearance.getFontWeightScale();
159  console.info('Get fontScale ' + fontWeightScale);
160} catch (error) {
161  let message = (error as BusinessError).message;
162  console.error('Get fontWeightScale failed, ' + message);
163}
164```