• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.window (窗口)
2
3窗口提供管理窗口的一些基础能力,包括对当前窗口的创建、销毁、各属性设置,以及对各窗口间的管理调度。
4
5该模块提供以下窗口相关的常用功能:
6
7- [Window](#window):当前窗口实例,窗口管理器管理的基本单元。
8- [WindowStage](#windowstage9):窗口管理器。管理各个基本窗口单元。
9
10> **说明:**
11>
12> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
13
14## 导入模块
15
16```ts
17import { window } from '@kit.ArkUI';
18```
19
20## WindowType<sup>7+</sup>
21
22窗口类型枚举。
23
24**系统能力:** SystemCapability.WindowManager.WindowManager.Core
25
26| 名称                                  | 值 | 说明                                                                                     |
27|-------------------------------------| ------ |----------------------------------------------------------------------------------------|
28| TYPE_APP                            | 0      | 表示应用子窗口。<br>**模型约束:** 此接口仅可在FA模型下使用。                                                   |
29| TYPE_SYSTEM_ALERT                   | 1      | 表示系统告警窗口。<br>- **说明:** 从API version 11开始废弃。<br>- 从 API version 7开始支持。                               |
30| TYPE_FLOAT<sup>9+</sup>             | 8      | 表示悬浮窗。<br>**模型约束:** 此接口仅可在Stage模型下使用。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
31| TYPE_DIALOG<sup>10+</sup>           | 16      | 表示模态窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。                                                 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
32
33## Configuration<sup>9+</sup>
34
35创建子窗口或系统窗口时的参数。
36
37**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
38
39**系统能力:** SystemCapability.WindowManager.WindowManager.Core
40
41| 名称 | 类型 | 必填 | 说明                                                                          |
42| ---------- | -------------------------- | -- |-----------------------------------------------------------------------------|
43| name       | string                     | 是 | 窗口名字。                                                                       |
44| windowType | [WindowType](#windowtype7) | 是 | 窗口类型。                                                                       |
45| ctx        | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 否 | 当前应用上下文信息。不设置,则默认为空。<br>FA模型下不需要使用该参数,即可创建子窗口,使用该参数时会报错。<br>Stage模型必须使用该参数,用于创建悬浮窗、模态窗或系统窗口。 |
46| displayId  | number                     | 否 | 当前物理屏幕id。不设置,则默认为-1,该参数应为整数。                                             |
47| parentId   | number                     | 否 | 父窗口id。不设置,则默认为-1,该参数应为整数。                                                           |
48| decorEnabled<sup>12+</sup> | boolean | 否 | 是否显示窗口装饰,仅在windowType为TYPE_DIALOG时生效。true表示显示,false表示不显示。此参数默认值为false。<br>**系统能力:** SystemCapability.Window.SessionManager |
49| title<sup>12+</sup> | string| 否 | `decorEnabled`属性设置为true时,窗口的标题内容。不设置,则默认为空字符串。 <br>**系统能力:** SystemCapability.Window.SessionManager |
50
51## AvoidAreaType<sup>7+</sup>
52
53窗口内容需要规避区域的类型枚举。
54
55**系统能力:** SystemCapability.WindowManager.WindowManager.Core
56
57**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
58
59| 名称                             | 值   | 说明                                                         |
60| -------------------------------- | ---- | ------------------------------------------------------------ |
61| TYPE_SYSTEM                      | 0    | 表示系统默认区域。一般包括状态栏、导航栏,各设备系统定义可能不同。 |
62| TYPE_CUTOUT                      | 1    | 表示刘海屏区域。                                             |
63| TYPE_SYSTEM_GESTURE<sup>9+</sup> | 2    | 表示手势区域。                                               |
64| TYPE_KEYBOARD<sup>9+</sup>       | 3    | 表示软键盘区域。                                             |
65| TYPE_NAVIGATION_INDICATOR<sup>11+</sup> | 4    | 表示导航条区域。                                      |
66
67
68## SystemBarProperties
69
70状态栏、导航栏的属性。在设置窗口级状态栏、导航栏属性时使用。
71
72**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
73
74| 名称                                   | 类型 |  必填 | 说明                                                         |
75| -------------------------------------- | -------- | ---- | ------------------------------------------------------------ |
76| statusBarColor                         | string   |  否   | 状态栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。默认值:`'#0x66000000'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
77| isStatusBarLightIcon<sup>7+</sup>      | boolean  |  否   | 状态栏图标是否为高亮状态。true表示高亮;false表示不高亮。默认值:false。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
78| statusBarContentColor<sup>8+</sup>     | string   |  否   | 状态栏文字颜色。当设置此属性后, `isStatusBarLightIcon`属性设置无效。默认值:`'#0xE5FFFFFF'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
79| navigationBarColor                     | string   |  否   | 导航栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。默认值:`'#0x66000000'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
80| isNavigationBarLightIcon<sup>7+</sup>  | boolean  |  否   | 导航栏图标是否为高亮状态。true表示高亮;false表示不高亮。默认值:false。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
81| navigationBarContentColor<sup>8+</sup> | string   |  否   | 导航栏文字颜色。当设置此属性后, `isNavigationBarLightIcon`属性设置无效。默认值:`'#0xE5FFFFFF'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
82| enableStatusBarAnimation<sup>12+</sup> | boolean   |  否   | 是否使能状态栏属性变化时动画效果。true表示变化时使能动画效果;false表示没有使能动画效果。默认值:false。 <br> **系统能力:** SystemCapability.Window.SessionManager。|
83| enableNavigationBarAnimation<sup>12+</sup> | boolean   |  否   | 是否使能导航栏属性变化时动画效果。true表示变化时使能动画效果;false表示没有使能动画效果。默认值:false。 <br> **系统能力:** SystemCapability.Window.SessionManager。|
84
85## SystemBarStyle<sup>12+</sup>
86
87状态栏的属性。在设置页面级状态栏属性时使用。
88
89**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
90
91**系统能力:** SystemCapability.WindowManager.WindowManager.Core
92
93| 名称   | 类型 | 只读 | 可选 | 说明               |
94| ------ | -------- | ---- | ---- | ------------------ |
95| statusBarContentColor   | string   | 是   | 是   | 状态栏文字颜色。默认值:`'#0xE5FFFFFF'`。|
96
97## Orientation<sup>9+</sup>
98
99窗口显示方向类型枚举。
100
101| 名称                                  | 值   | 说明                          |
102| ------------------------------------- | ---- | ----------------------------- |
103| UNSPECIFIED                           | 0    | 表示未定义方向模式,由系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
104| PORTRAIT                              | 1    | 表示竖屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。|
105| LANDSCAPE                             | 2    | 表示横屏显示模式。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
106| PORTRAIT_INVERTED                     | 3    | 表示反向竖屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
107| LANDSCAPE_INVERTED                    | 4    | 表示反向横屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
108| AUTO_ROTATION                         | 5    | 跟随传感器自动旋转,可以旋转到竖屏、横屏、反向竖屏、反向横屏四个方向。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。|
109| AUTO_ROTATION_PORTRAIT                | 6    | 跟随传感器自动竖向旋转,可以旋转到竖屏、反向竖屏,无法旋转到横屏、反向横屏。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
110| AUTO_ROTATION_LANDSCAPE               | 7    | 跟随传感器自动横向旋转,可以旋转到横屏、反向横屏,无法旋转到竖屏、反向竖屏。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
111| AUTO_ROTATION_RESTRICTED              | 8    | 跟随传感器自动旋转,可以旋转到竖屏、横屏、反向竖屏、反向横屏四个方向,且受控制中心的旋转开关控制。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
112| AUTO_ROTATION_PORTRAIT_RESTRICTED     | 9    | 跟随传感器自动竖向旋转,可以旋转到竖屏、反向竖屏,无法旋转到横屏、反向横屏,且受控制中心的旋转开关控制。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
113| AUTO_ROTATION_LANDSCAPE_RESTRICTED    | 10   | 跟随传感器自动横向旋转,可以旋转到横屏、反向横屏,无法旋转到竖屏、反向竖屏,且受控制中心的旋转开关控制。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
114| LOCKED                                | 11   | 表示锁定模式。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
115| AUTO_ROTATION_UNSPECIFIED<sup>12+</sup>        | 12   | 跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定(如在某种设备,可以旋转到竖屏、横屏、反向横屏三个方向,无法旋转到反向竖屏)。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager。|
116| USER_ROTATION_PORTRAIT<sup>12+</sup>           | 13   | 调用时临时旋转到竖屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager。|
117| USER_ROTATION_LANDSCAPE<sup>12+</sup>          | 14   | 调用时临时旋转到横屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager。|
118| USER_ROTATION_PORTRAIT_INVERTED<sup>12+</sup>  | 15   | 调用时临时旋转到反向竖屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager。|
119| USER_ROTATION_LANDSCAPE_INVERTED<sup>12+</sup> | 16   | 调用时临时旋转到反向横屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager。|
120| FOLLOW_DESKTOP<sup>12+</sup>                   | 17   | 表示跟随桌面的旋转模式。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager。|
121
122## Rect<sup>7+</sup>
123
124窗口矩形区域。
125
126**系统能力:** SystemCapability.WindowManager.WindowManager.Core
127
128**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
129
130| 名称   | 类型 | 可读 | 可写 | 说明               |
131| ------ | -------- | ---- | ---- | ------------------ |
132| left   | number   | 是   | 是   | 矩形区域的左边界,单位为px,该参数为整数。 |
133| top    | number   | 是   | 是   | 矩形区域的上边界,单位为px,该参数应为整数。 |
134| width  | number   | 是   | 是   | 矩形区域的宽度,单位为px,该参数应为整数。 |
135| height | number   | 是   | 是   | 矩形区域的高度,单位为px,该参数应为整数。 |
136
137## AvoidArea<sup>7+</sup>
138
139窗口内容规避区域。如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。在规避区无法响应用户点击事件。
140
141除此之外还需注意规避区域的如下约束,具体为:
142
143- 底部手势区域中非导航条区域支持点击、长按事件透传,不支持拖入。
144
145- 左右侧边手势区域支持点击、长按以及上下滑动事件透传,不支持拖入。
146
147- 导航条区域支持长按、点击、拖入事件响应,不支持事件向下透传。
148
149**系统能力:** SystemCapability.WindowManager.WindowManager.Core
150
151**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
152
153| 名称       | 类型      | 可读 | 可写 | 说明               |
154| ---------- | ------------- | ---- | ---- | ------------------ |
155| visible<sup>9+</sup>    | boolean       | 是   | 是   | 规避区域是否可见。true表示可见;false表示不可见。 |
156| leftRect   | [Rect](#rect7) | 是   | 是   | 屏幕左侧的矩形区。 |
157| topRect    | [Rect](#rect7) | 是   | 是   | 屏幕顶部的矩形区。 |
158| rightRect  | [Rect](#rect7) | 是   | 是   | 屏幕右侧的矩形区。 |
159| bottomRect | [Rect](#rect7) | 是   | 是   | 屏幕底部的矩形区。 |
160
161## Size<sup>7+</sup>
162
163窗口大小。
164
165**系统能力:** SystemCapability.WindowManager.WindowManager.Core
166
167**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
168
169| 名称   | 类型 | 可读 | 可写 | 说明       |
170| ------ | -------- | ---- | ---- | ---------- |
171| width  | number   | 是   | 是   | 窗口宽度,单位为px,该参数应为整数。 |
172| height | number   | 是   | 是   | 窗口高度,单位为px,该参数应为整数。 |
173
174## RectChangeReason<sup>12+</sup>
175
176窗口矩形(窗口位置及窗口大小)变化的原因。
177
178**系统能力:** SystemCapability.Window.SessionManager
179
180**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
181
182| 名称                  | 值   | 说明                                                         |
183| --------------------- | ---- | ------------------------------------------------------------ |
184| UNDEFINED                 | 0    | 默认值。                                                   |
185| MAXIMIZE                | 1    | 窗口最大化。                                                   |
186| RECOVER              | 2    | 窗口恢复到上一次的状态。                                                   |
187| MOVE | 3    | 窗口拖拽移动。 |
188| DRAG  | 4    | 窗口拖拽缩放。 |
189| DRAG_START  | 5    | 窗口开始拖拽缩放。 |
190| DRAG_END  | 6    | 窗口结束拖拽缩放。 |
191
192## RectChangeOptions<sup>12+</sup>
193
194窗口矩形(窗口位置及窗口大小)变化返回的值及变化原因。
195
196**系统能力:** SystemCapability.Window.SessionManager
197
198**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
199
200| 名称       | 类型      | 可读 | 可写 | 说明               |
201| ---------- | ------------- | ---- | ---- | ------------------ |
202| rect   | [Rect](#rect7) | 是   | 是   | 窗口矩形变化后的值。 |
203| reason    | [RectChangeReason](#rectchangereason12) | 是   | 是   | 窗口矩形变化的原因。 |
204
205## AvoidAreaOptions<sup>12+</sup>
206
207系统规避区变化后返回当前规避区域以及规避区域类型。
208
209**系统能力:** SystemCapability.WindowManager.WindowManager.Core
210
211**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
212
213| 名称       | 类型      | 可读 | 可写 | 说明               |
214| ---------- | ------------- | ---- | ---- | ------------------ |
215| type   | [AvoidAreaType](#avoidareatype7) | 是   | 是   | 系统规避区变化后返回的规避区域类型。 |
216| area   | [AvoidArea](#avoidarea7)         | 是   | 是   | 系统规避区变化后返回的规避区域。 |
217
218## WindowProperties
219
220窗口属性。
221
222**系统能力:** SystemCapability.WindowManager.WindowManager.Core
223
224| 名称                                  | 类型                  | 只读 | 可选 | 说明                                                                                                     |
225| ------------------------------------- | ------------------------- | ---- | ---- |--------------------------------------------------------------------------------------------------------|
226| windowRect<sup>7+</sup>               | [Rect](#rect7)             | 否   | 否   | 窗口尺寸。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。                                                                                                  |
227| drawableRect<sup>11+</sup>            | [Rect](#rect7)             | 否   | 否   | 窗口内可绘制区域尺寸,其中左边界上边界是相对窗口计算。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                  |
228| type<sup>7+</sup>                     | [WindowType](#windowtype7) | 否   | 否   | 窗口类型。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                  |
229| isFullScreen                          | boolean                   | 否   | 否   | 是否全屏,默认为false。true表示全屏;false表示非全屏。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                                                  |
230| isLayoutFullScreen<sup>7+</sup>       | boolean                   | 否   | 否   | 窗口是否为沉浸式,默认为false。true表示沉浸式;false表示非沉浸式。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                                            |
231| focusable<sup>7+</sup>                | boolean                   | 是   | 否   | 窗口是否可聚焦,默认为true。true表示可聚焦;false表示不可聚焦。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                |
232| touchable<sup>7+</sup>                | boolean                   | 是   | 否   | 窗口是否可触摸,默认为true。true表示可触摸;false表示不可触摸。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                 |
233| brightness                            | number                    | 否   | 否   | 屏幕亮度。该参数为浮点数,可设置的亮度范围为[0.0, 1.0],其取1.0时表示最大亮度值。如果窗口没有设置亮度值,表示亮度跟随系统,此时获取到的亮度值为-1。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。                      |
234| dimBehindValue<sup>(deprecated)</sup> | number                    | 否   | 否   | 靠后窗口的暗度值。该参数为浮点数,取值范围为[0.0, 1.0],其取1.0表示最暗。<br>- **说明:** 从API version 9开始废弃。<br>- 从 API version 7开始支持。 |
235| isKeepScreenOn                        | boolean                   | 否   | 否   | 屏幕是否常亮,默认为false。true表示常亮;false表示不常亮。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。                                                                   |
236| isPrivacyMode<sup>7+</sup>            | boolean                   | 否   | 否   | 隐私模式,默认为false。true表示模式开启;false表示模式关闭。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                  |
237| isRoundCorner<sup>(deprecated)</sup>  | boolean                   | 否   | 否   | 窗口是否为圆角。默认为false。true表示圆角;false表示非圆角。<br>- **说明:** 从API version 9开始废弃。<br/>- 从 API version 7开始支持。      |
238| isTransparent<sup>7+</sup>            | boolean                   | 否   | 否   | 窗口是否透明。默认为false。true表示透明;false表示不透明。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                   |
239| id<sup>9+</sup>                       | number                    | 是   | 否   | 窗口ID,默认值为0,该参数应为整数。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                    |
240| displayId<sup>12+</sup>               | number                    | 是   | 是   | 窗口所在屏幕ID,默认返回主屏幕ID,该参数应为整数。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
241
242## ColorSpace<sup>8+</sup>
243
244色域模式。
245
246**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
247
248**系统能力:** SystemCapability.WindowManager.WindowManager.Core
249
250| 名称       | 值 | 说明           |
251| ---------- | ------ | -------------- |
252| DEFAULT    | 0      | 默认SRGB色域模式。 |
253| WIDE_GAMUT | 1      | 广色域模式。   |
254
255## WindowEventType<sup>10+</sup>
256
257窗口生命周期。
258
259**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
260
261| 名称       | 值 | 说明       |
262| ---------- | ------ | ---------- |
263| WINDOW_SHOWN      | 1      | 切到前台。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
264| WINDOW_ACTIVE     | 2      | 获焦状态。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
265| WINDOW_INACTIVE   | 3      | 失焦状态。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
266| WINDOW_HIDDEN     | 4      | 切到后台。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。|
267| WINDOW_DESTROYED<sup>11+</sup>  | 7      | 窗口销毁。<br> **系统能力:** SystemCapability.Window.SessionManager。|
268
269## WindowLimits<sup>11+</sup>
270
271窗口尺寸限制参数。可以通过[setWindowLimits](#setwindowlimits11)设置窗口尺寸限制,并且可以通过[getWindowLimits](#getwindowlimits11)获得当前的窗口尺寸限制。
272
273**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
274
275**系统能力:** SystemCapability.Window.SessionManager
276
277| 名称      | 类型   | 可读 | 可写 | 说明                                                         |
278| :-------- | :----- | :--- | :--- | :----------------------------------------------------------- |
279| maxWidth  | number | 是   | 是   | 窗口的最大宽度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最大宽度。  |
280| maxHeight | number | 是   | 是   | 窗口的最大高度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最大高度。  |
281| minWidth  | number | 是   | 是   | 窗口的最小宽度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最小宽度。  |
282| minHeight | number | 是   | 是   | 窗口的最小高度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最小高度。  |
283
284## WindowStatusType<sup>11+</sup>
285
286窗口模式枚举。
287
288**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
289
290**系统能力:** SystemCapability.Window.SessionManager
291
292| 名称       | 值   | 说明                          |
293| ---------- | ---- | ----------------------------- |
294| UNDEFINED  | 0    | 表示APP未定义窗口模式。       |
295| FULL_SCREEN | 1    | 表示APP全屏模式。             |
296| MAXIMIZE    | 2    | 表示APP窗口最大化模式。   |
297| MINIMIZE    | 3    | 表示APP窗口最小化模式。   |
298| FLOATING    | 4    | 表示APP自由悬浮形式窗口模式。   |
299| SPLIT_SCREEN  | 5    | 表示APP分屏模式。   |
300
301## TitleButtonRect<sup>11+</sup>
302
303标题栏上的最小化、最大化、关闭按钮矩形区域,该区域位置坐标相对窗口右上角。
304
305**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
306
307**系统能力:**  SystemCapability.Window.SessionManager
308
309| 名称   | 类型   | 可读 | 可写 | 说明                                       |
310| ------ | ------ | ---- | ---- | ------------------------------------------ |
311| right  | number | 是   | 是   | 矩形区域的右边界,单位为vp,该参数为整数。 |
312| top    | number | 是   | 是   | 矩形区域的上边界,单位为vp,该参数为整数。 |
313| width  | number | 是   | 是   | 矩形区域的宽度,单位为vp,该参数为整数。   |
314| height | number | 是   | 是   | 矩形区域的高度,单位为vp,该参数为整数。   |
315
316## MaximizePresentation<sup>12+</sup>
317
318窗口最大化时的布局枚举。
319
320**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
321
322**系统能力:**  SystemCapability.Window.SessionManager
323
324| 名称       | 值   | 说明                          |
325| ---------- | ---- | ----------------------------- |
326| FOLLOW_APP_IMMERSIVE_SETTING  | 0    | 最大化时,跟随应用app当前设置的沉浸式布局。       |
327| EXIT_IMMERSIVE | 1    | 最大化时,如果当前窗口设置了沉浸式布局会退出沉浸式布局。             |
328| ENTER_IMMERSIVE    | 2    | 最大化时,进入沉浸式布局。   |
329
330## window.createWindow<sup>9+</sup>
331
332createWindow(config: Configuration, callback: AsyncCallback&lt;Window&gt;): void
333
334创建子窗口或者系统窗口,使用callback异步回调。
335
336**需要权限:** 当创建窗口类型为window.WindowType.TYPE_FLOAT时,需要ohos.permission.SYSTEM_FLOAT_WINDOW权限
337
338**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
339
340**系统能力:** SystemCapability.WindowManager.WindowManager.Core
341
342**参数:**
343
344| 参数名 | 类型 | 必填 | 说明 |
345| -------- | -------------------------------------- | -- | --------------------------------- |
346| config   | [Configuration](#configuration9)       | 是 | 创建窗口时的参数。   |
347| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调函数。返回当前创建的窗口对象。 |
348
349**错误码:**
350
351以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
352
353| 错误码ID | 错误信息 |
354| ------- | -------------------------------- |
355| 201     | Permission verification failed. The application does not have the permission required to call the API. |
356| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
357| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
358| 1300001 | Repeated operation. |
359| 1300002 | This window state is abnormal. |
360| 1300004 | Unauthorized operation. |
361| 1300006 | This window context is abnormal. |
362| 1300008 | The display device is abnormal. |
363| 1300009 | The parent window is invalid. |
364
365**示例:**
366
367```ts
368import { BusinessError } from '@kit.BasicServicesKit';
369
370let windowClass: window.Window | undefined = undefined;
371let config: window.Configuration = {
372  name: "test",
373  windowType: window.WindowType.TYPE_DIALOG,
374  ctx: this.context
375};
376try {
377  window.createWindow(config, (err: BusinessError, data) => {
378    const errCode: number = err.code;
379    if (errCode) {
380      console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`);
381      return;
382    }
383    windowClass = data;
384    console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data));
385    windowClass.resize(500, 1000);
386  });
387} catch (exception) {
388  console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`);
389}
390```
391
392## window.createWindow<sup>9+</sup>
393
394createWindow(config: Configuration): Promise&lt;Window&gt;
395
396创建子窗口或者系统窗口,使用Promise异步回调。
397
398**需要权限:** 当创建窗口类型为window.WindowType.TYPE_FLOAT时,需要ohos.permission.SYSTEM_FLOAT_WINDOW权限
399
400**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
401
402**系统能力:** SystemCapability.WindowManager.WindowManager.Core
403
404**参数:**
405
406| 参数名 | 类型 | 必填 | 说明 |
407| ------ | -------------------------------- | -- | ------------------ |
408| config | [Configuration](#configuration9) | 是 | 创建窗口时的参数。 |
409
410**返回值:**
411
412| 类型 | 说明 |
413| -------------------------------- | ------------------------------------ |
414| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前创建的窗口对象。 |
415
416**错误码:**
417
418以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
419
420| 错误码ID | 错误信息 |
421| ------- | -------------------------------- |
422| 201     | Permission verification failed. The application does not have the permission required to call the API. |
423| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
424| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
425| 1300001 | Repeated operation. |
426| 1300002 | This window state is abnormal. |
427| 1300004 | Unauthorized operation. |
428| 1300006 | This window context is abnormal. |
429| 1300008 | The display device is abnormal. |
430| 1300009 | The parent window is invalid. |
431
432**示例:**
433
434```ts
435import { BusinessError } from '@kit.BasicServicesKit';
436
437let windowClass: window.Window | undefined = undefined;
438let config: window.Configuration = {
439  name: "test",
440  windowType: window.WindowType.TYPE_DIALOG,
441  ctx: this.context
442};
443try {
444  let promise = window.createWindow(config);
445  promise.then((data) => {
446    windowClass = data;
447    console.info('Succeeded in creating the window. Data:' + JSON.stringify(data));
448  }).catch((err: BusinessError) => {
449    console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`);
450  });
451} catch (exception) {
452  console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`);
453}
454```
455
456## window.findWindow<sup>9+</sup>
457
458findWindow(name: string): Window
459
460查找name所对应的窗口。
461
462**系统能力:** SystemCapability.WindowManager.WindowManager.Core
463
464**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
465
466**参数:**
467
468| 参数名 | 类型   | 必填 | 说明     |
469| ------ | ------ | ---- | -------- |
470| name   | string | 是   | 窗口名字,即[Configuration](#configuration9)中的name。 |
471
472**返回值:**
473
474| 类型 | 说明 |
475| ----------------- | ------------------- |
476| [Window](#window) | 当前查找的窗口对象。 |
477
478**错误码:**
479
480以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
481
482| 错误码ID | 错误信息 |
483| ------- | -------------------------------- |
484| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
485| 1300002 | This window state is abnormal. |
486
487**示例:**
488
489```ts
490let windowClass: window.Window | undefined = undefined;
491try {
492  windowClass = window.findWindow('test');
493} catch (exception) {
494  console.error(`Failed to find the Window. Cause code: ${exception.code}, message: ${exception.message}`);
495}
496```
497
498## window.getLastWindow<sup>9+</sup>
499
500getLastWindow(ctx: BaseContext, callback: AsyncCallback&lt;Window&gt;): void
501
502获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口,使用callback异步回调。
503
504**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
505
506**系统能力:** SystemCapability.WindowManager.WindowManager.Core
507
508**参数:**
509
510| 参数名 | 类型 | 必填 | 说明 |
511| -------- | -------------------------------------- | -- | ---------------------------------------- |
512| ctx      | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 |
513| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 |
514
515**错误码:**
516
517以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
518
519| 错误码ID | 错误信息 |
520| ------- | -------------------------------- |
521| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
522| 1300002 | This window state is abnormal.   |
523| 1300006 | This window context is abnormal. |
524
525**示例:**
526
527```ts
528// EntryAbility.ets
529import { UIAbility } from '@kit.AbilityKit';
530import { BusinessError } from '@kit.BasicServicesKit';
531
532export default class EntryAbility extends UIAbility {
533  // ...
534  onWindowStageCreate(windowStage: window.WindowStage) {
535    console.info('onWindowStageCreate');
536    let windowClass: window.Window | undefined = undefined;
537    try {
538      window.getLastWindow(this.context, (err: BusinessError, data) => {
539        const errCode: number = err.code;
540        if (errCode) {
541          console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
542          return;
543        }
544        windowClass = data;
545        console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
546      });
547    } catch (exception) {
548      console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`);
549    }
550  }
551}
552```
553
554## window.getLastWindow<sup>9+</sup>
555
556getLastWindow(ctx: BaseContext): Promise&lt;Window&gt;
557
558获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口,使用Promise异步回调。
559
560**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
561
562**系统能力:** SystemCapability.WindowManager.WindowManager.Core
563
564**参数:**
565
566| 参数名 | 类型 | 必填 | 说明 |
567| ------ | ----------- | ---- | ------------------------------------------------------------ |
568| ctx    | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用上下文信息。 |
569
570**返回值:**
571
572| 类型 | 说明 |
573| -------------------------------- | ------------------------------------------- |
574| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前应用内最后显示的窗口对象。 |
575
576**错误码:**
577
578以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
579
580| 错误码ID | 错误信息 |
581| ------- | -------------------------------- |
582| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
583| 1300002 | This window state is abnormal.   |
584| 1300006 | This window context is abnormal. |
585
586**示例:**
587
588```ts
589// EntryAbility.ets
590import { UIAbility } from '@kit.AbilityKit';
591import { BusinessError } from '@kit.BasicServicesKit';
592
593export default class EntryAbility extends UIAbility {
594  // ...
595  onWindowStageCreate(windowStage: window.WindowStage) {
596    console.info('onWindowStageCreate');
597    let windowClass: window.Window | undefined = undefined;
598    try {
599      let promise = window.getLastWindow(this.context);
600      promise.then((data) => {
601        windowClass = data;
602        console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
603      }).catch((err: BusinessError) => {
604        console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
605      });
606    } catch (exception) {
607      console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`);
608    }
609  }
610}
611```
612
613## window.shiftAppWindowFocus<sup>11+</sup>
614shiftAppWindowFocus(sourceWindowId: number, targetWindowId: number): Promise&lt;void&gt;
615
616在同应用内将窗口焦点从源窗口转移到目标窗口,仅支持应用主窗和子窗的焦点转移。
617
618**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
619
620**系统能力:** SystemCapability.Window.SessionManager
621
622**参数:**
623
624| 参数名          | 类型   | 必填  | 说明                    |
625| -------------- | ------ | ----- | ----------------------- |
626| sourceWindowId | number | 是    | 源窗口id,必须是获焦状态。|
627| targetWindowId | number | 是    | 目标窗口id。             |
628
629**返回值:**
630
631| 类型                | 说明                      |
632| ------------------- | ------------------------- |
633| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
634
635**错误码:**
636
637以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
638
639| 错误码ID | 错误信息                                      |
640| ------- | --------------------------------------------- |
641| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
642| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
643| 1300002 | This window state is abnormal.                |
644| 1300003 | This window manager service works abnormally. |
645| 1300004 | Unauthorized operation.                       |
646
647**示例:**
648
649```ts
650// EntryAbility.ets
651import { UIAbility } from '@kit.AbilityKit';
652import { BusinessError } from '@kit.BasicServicesKit';
653
654export default class EntryAbility extends UIAbility {
655  onWindowStageCreate(windowStage: window.WindowStage) {
656    // ...
657    console.info('onWindowStageCreate');
658    let windowClass: window.Window | undefined = undefined;
659    let subWindowClass: window.Window | undefined = undefined;
660    let windowClassId: number = -1;
661    let subWindowClassId: number = -1;
662
663    try {
664      // 获取应用主窗及ID
665      let promise = windowStage.getMainWindow();
666      promise.then((data) => {
667        if (data == null) {
668          console.error("Failed to obtaining the window. Cause: The data is empty");
669          return;
670        }
671        windowClass = data;
672        windowClass.setUIContent("pages/Index");
673        windowClassId = windowClass.getWindowProperties().id;
674        console.info('Succeeded in obtaining the window')
675      }).catch((err: BusinessError) => {
676        console.error(`Failed to obtaining the window. Cause code: ${err.code}, message: ${err.message}`);
677      });
678
679      // 创建或获取子窗及ID,此时子窗口获焦
680      let promiseSub = windowStage.createSubWindow("testSubWindow");
681      promiseSub.then((data) => {
682        if (data == null) {
683          console.error("Failed to obtaining the window. Cause: The data is empty");
684          return;
685        }
686        subWindowClass = data;
687        subWindowClassId = subWindowClass.getWindowProperties().id;
688        subWindowClass.resize(500, 500);
689        subWindowClass.setUIContent("pages/Index2");
690        subWindowClass.showWindow();
691
692        // 监听Window状态,确保已经就绪
693        subWindowClass.on("windowEvent", (windowEvent) => {
694          if (windowEvent == window.WindowEventType.WINDOW_ACTIVE) {
695            // 切换焦点
696            let promise = window.shiftAppWindowFocus(subWindowClassId, windowClassId);
697            promise.then(() => {
698              console.info('Succeeded in shifting app window focus');
699            }).catch((err: BusinessError) => {
700              console.error(`Failed to shift app window focus. Cause code: ${err.code}, message: ${err.message}`);
701            });
702          }
703        });
704      });
705    } catch (exception) {
706      console.error(`Failed to shift app focus. Cause code: ${exception.code}, message: ${exception.message}`);
707    }
708  }
709}
710```
711
712## window.create<sup>(deprecated)</sup>
713
714create(id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void
715
716创建子窗口,使用callback异步回调。
717
718> **说明:**
719>
720> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。
721
722**模型约束:** 此接口仅可在FA模型下使用。
723
724**系统能力:** SystemCapability.WindowManager.WindowManager.Core
725
726**参数:**
727
728| 参数名   | 类型                                   | 必填 | 说明                                 |
729| -------- | -------------------------------------- | ---- | ------------------------------------ |
730| id       | string                                 | 是   | 窗口名字,即[Configuration](#configuration9)中的name。|
731| type     | [WindowType](#windowtype7)              | 是   | 窗口类型。                           |
732| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前创建的子窗口对象。 |
733
734
735**示例:**
736
737```ts
738import { BusinessError } from '@kit.BasicServicesKit';
739
740let windowClass: window.Window | undefined = undefined;
741window.create('test', window.WindowType.TYPE_APP, (err: BusinessError, data) => {
742  const errCode: number = err.code;
743  if (errCode) {
744    console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`);
745    return;
746  }
747  windowClass = data;
748  console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data));
749});
750```
751
752## window.create<sup>(deprecated)</sup>
753
754create(id: string, type: WindowType): Promise&lt;Window&gt;
755
756创建子窗口,使用Promise异步回调。
757
758> **说明:**
759>
760> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。
761
762**模型约束:** 此接口仅可在FA模型下使用。
763
764**系统能力:** SystemCapability.WindowManager.WindowManager.Core
765
766**参数:**
767
768| 参数名 | 类型                      | 必填 | 说明       |
769| ------ | ------------------------- | ---- | ---------- |
770| id     | string                    | 是   | 窗口名字,即[Configuration](#configuration9)中的name。   |
771| type   | [WindowType](#windowtype7) | 是   | 窗口类型。 |
772
773**返回值:**
774
775| 类型                             | 说明                                    |
776| -------------------------------- | --------------------------------------- |
777| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前创建的子窗口对象。 |
778
779
780**示例:**
781
782```ts
783import { BusinessError } from '@kit.BasicServicesKit';
784
785let windowClass: window.Window | undefined = undefined;
786let promise = window.create('test', window.WindowType.TYPE_APP);
787promise.then((data) => {
788  windowClass = data;
789  console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data));
790}).catch((err: BusinessError) => {
791  console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`);
792});
793```
794
795## window.create<sup>(deprecated)</sup>
796
797create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void
798
799创建系统窗口,使用callback异步回调。
800
801> **说明:**
802>
803> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。
804
805**系统能力:** SystemCapability.WindowManager.WindowManager.Core
806
807**参数:**
808
809| 参数名   | 类型                                                    | 必填 | 说明                                 |
810| -------- | ------------------------------------------------------- | ---- | ------------------------------------ |
811| ctx      | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用上下文信息。                 |
812| id       | string                                                  | 是   | 窗口名字,即[Configuration](#configuration9)中的name。   |
813| type     | [WindowType](#windowtype7)                              | 是   | 窗口类型。                           |
814| callback | AsyncCallback&lt;[Window](#window)&gt;                  | 是   | 回调函数。返回当前创建的子窗口对象。 |
815
816
817**示例:**
818
819```ts
820import { BusinessError } from '@kit.BasicServicesKit';
821
822let windowClass: window.Window | undefined = undefined;
823window.create('test', window.WindowType.TYPE_SYSTEM_ALERT, (err: BusinessError, data) => {
824  const errCode: number = err.code;
825  if (errCode) {
826    console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`);
827    return;
828  }
829  windowClass = data;
830  console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data));
831  windowClass.resetSize(500, 1000);
832});
833```
834
835## window.create<sup>(deprecated)</sup>
836
837create(ctx: BaseContext, id: string, type: WindowType): Promise&lt;Window&gt;
838
839创建系统窗口,使用Promise异步回调。
840
841> **说明:**
842>
843> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。
844
845**系统能力:** SystemCapability.WindowManager.WindowManager.Core
846
847**参数:**
848
849| 参数名 | 类型                      | 必填 | 说明                                                         |
850| ------ | ------------------------- | ---- | ------------------------------------------------------------ |
851| ctx    | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用上下文信息。 |
852| id     | string                    | 是   | 窗口名字,即[Configuration](#configuration9)中的name。 |
853| type   | [WindowType](#windowtype7) | 是   | 窗口类型。                                                   |
854
855**返回值:**
856
857| 类型                             | 说明                                    |
858| -------------------------------- | --------------------------------------- |
859| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前创建的子窗口对象。 |
860
861
862**示例:**
863
864```ts
865import { BusinessError } from '@kit.BasicServicesKit';
866
867let windowClass: window.Window | undefined = undefined;
868let promise = window.create('test', window.WindowType.TYPE_SYSTEM_ALERT);
869promise.then((data) => {
870  windowClass = data;
871  console.info('Succeeded in creating the window. Data:' + JSON.stringify(data));
872}).catch((err: BusinessError) => {
873  console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`);
874});
875```
876
877## window.find<sup>(deprecated)</sup>
878
879find(id: string, callback: AsyncCallback&lt;Window&gt;): void
880
881查找id所对应的窗口,使用callback异步回调。
882
883> **说明:**
884>
885> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。
886
887**系统能力:** SystemCapability.WindowManager.WindowManager.Core
888
889**参数:**
890
891| 参数名   | 类型                                   | 必填 | 说明                                 |
892| -------- | -------------------------------------- | ---- | ------------------------------------ |
893| id       | string                                 | 是   | 窗口名字,即[Configuration](#configuration9)中的name。 |
894| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前查找到的窗口对象。 |
895
896**示例:**
897
898```ts
899import { BusinessError } from '@kit.BasicServicesKit';
900
901let windowClass: window.Window | undefined = undefined;
902window.find('test', (err: BusinessError, data) => {
903  const errCode: number = err.code;
904  if (errCode) {
905    console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`);
906    return;
907  }
908  windowClass = data;
909  console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data));
910});
911```
912
913## window.find<sup>(deprecated)</sup>
914
915find(id: string): Promise&lt;Window&gt;
916
917查找id所对应的窗口,使用Promise异步回调。
918
919> **说明:**
920>
921> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。
922
923**系统能力:** SystemCapability.WindowManager.WindowManager.Core
924
925**参数:**
926
927| 参数名 | 类型   | 必填 | 说明     |
928| ------ | ------ | ---- | -------- |
929| id     | string | 是   | 窗口名字,即[Configuration](#configuration9)中的name。 |
930
931**返回值:**
932
933| 类型                             | 说明                                  |
934| -------------------------------- | ------------------------------------- |
935| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前查找的窗口对象。 |
936
937**示例:**
938
939```ts
940import { BusinessError } from '@kit.BasicServicesKit';
941
942let windowClass: window.Window | undefined = undefined;
943let promise = window.find('test');
944promise.then((data) => {
945  windowClass = data;
946  console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data));
947}).catch((err: BusinessError) => {
948  console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`);
949});
950```
951
952## window.getTopWindow<sup>(deprecated)</sup>
953
954getTopWindow(callback: AsyncCallback&lt;Window&gt;): void
955
956获取当前应用内最后显示的窗口,使用callback异步回调。
957
958> **说明:**
959>
960> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。
961
962**模型约束:** 此接口仅可在FA模型下使用。
963
964**系统能力:** SystemCapability.WindowManager.WindowManager.Core
965
966**参数:**
967
968| 参数名   | 类型                                   | 必填 | 说明                                         |
969| -------- | -------------------------------------- | ---- | -------------------------------------------- |
970| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前应用内最后显示的窗口对象。 |
971
972**示例:**
973
974```ts
975import { BusinessError } from '@kit.BasicServicesKit';
976
977let windowClass: window.Window | undefined = undefined;
978window.getTopWindow((err: BusinessError, data) => {
979  const errCode: number = err.code;
980  if (errCode) {
981    console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
982    return;
983  }
984  windowClass = data;
985  console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
986});
987```
988
989## window.getTopWindow<sup>(deprecated)</sup>
990
991getTopWindow(): Promise&lt;Window&gt;
992
993获取当前应用内最后显示的窗口,使用Promise异步回调。
994
995> **说明:**
996>
997> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。
998
999**模型约束:** 此接口仅可在FA模型下使用。
1000
1001**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1002
1003**返回值:**
1004
1005| 类型                             | 说明                                            |
1006| -------------------------------- | ----------------------------------------------- |
1007| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前应用内最后显示的窗口对象。 |
1008
1009**示例:**
1010
1011```ts
1012import { BusinessError } from '@kit.BasicServicesKit';
1013
1014let windowClass: window.Window | undefined = undefined;
1015let promise = window.getTopWindow();
1016promise.then((data)=> {
1017    windowClass = data;
1018    console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1019}).catch((err: BusinessError)=>{
1020    console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
1021});
1022```
1023
1024## window.getTopWindow<sup>(deprecated)</sup>
1025
1026getTopWindow(ctx: BaseContext, callback: AsyncCallback&lt;Window&gt;): void
1027
1028获取当前应用内最后显示的窗口,使用callback异步回调。
1029
1030> **说明:**
1031>
1032> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。
1033
1034**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1035
1036**参数:**
1037
1038| 参数名   | 类型                                   | 必填 | 说明                                                         |
1039| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
1040| ctx      | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md)                            | 是   | 当前应用上下文信息。 |
1041| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前应用内最后显示的窗口对象。                 |
1042
1043**示例:**
1044
1045```ts
1046// EntryAbility.ets
1047import { UIAbility } from '@kit.AbilityKit';
1048import { BusinessError } from '@kit.BasicServicesKit';
1049
1050export default class EntryAbility extends UIAbility {
1051  onWindowStageCreate(windowStage:window.WindowStage){
1052    console.info('onWindowStageCreate');
1053    let windowClass: window.Window | undefined = undefined;
1054    try {
1055      window.getTopWindow(this.context, (err: BusinessError, data) => {
1056        const errCode: number = err.code;
1057        if(errCode){
1058          console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
1059          return ;
1060        }
1061        windowClass = data;
1062        console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1063      });
1064    } catch(error){
1065      console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`);
1066    }
1067  }
1068}
1069```
1070
1071## window.getTopWindow<sup>(deprecated)</sup>
1072
1073getTopWindow(ctx: BaseContext): Promise&lt;Window&gt;
1074
1075获取当前应用内最后显示的窗口,使用Promise异步回调。
1076
1077> **说明:**
1078>
1079> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。
1080
1081**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1082
1083**参数:**
1084
1085| 参数名 | 类型    | 必填 | 说明                                                         |
1086| ------ | ----------- | ---- | ------------------------------------------------------------ |
1087| ctx    | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用上下文信息。 |
1088
1089**返回值:**
1090
1091| 类型                             | 说明                                            |
1092| -------------------------------- | ----------------------------------------------- |
1093| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前应用内最后显示的窗口对象。 |
1094
1095**示例:**
1096
1097```ts
1098// EntryAbility.ets
1099import { UIAbility } from '@kit.AbilityKit';
1100import { BusinessError } from '@kit.BasicServicesKit';
1101
1102export default class EntryAbility extends UIAbility {
1103  onWindowStageCreate(windowStage:window.WindowStage) {
1104    console.info('onWindowStageCreate');
1105    let windowClass: window.Window | undefined = undefined;
1106    let promise = window.getTopWindow(this.context);
1107    promise.then((data) => {
1108      windowClass = data;
1109      console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1110    }).catch((error: BusinessError) => {
1111      console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`);
1112    });
1113  }
1114}
1115```
1116
1117## SpecificSystemBar<sup>11+</sup>
1118
1119type SpecificSystemBar = 'status' \| 'navigation' \| 'navigationIndicator'
1120
1121当前支持显示或隐藏的系统栏类型。
1122
1123**系统能力:** SystemCapability.Window.SessionManager
1124
1125**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1126
1127| 类型       | 说明     |
1128|------------|--------|
1129| 'status'   | 状态栏。   |
1130| 'navigation'   | 三键导航栏。   |
1131| 'navigationIndicator'   | 底部导航条。 |
1132
1133## Window
1134
1135当前窗口实例,窗口管理器管理的基本单元。
1136
1137下列API示例中都需先使用[getLastWindow()](#windowgetlastwindow9)、[createWindow()](#windowcreatewindow9)、[findWindow()](#windowfindwindow9)中的任一方法获取到Window实例(windowClass),再通过此实例调用对应方法。
1138
1139### showWindow<sup>9+</sup>
1140
1141showWindow(callback: AsyncCallback&lt;void&gt;): void
1142
1143显示当前窗口,使用callback异步回调,仅支持系统窗口及应用子窗口,或将已显示的应用主窗口的层级提升至顶部。
1144
1145**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1146
1147**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1148
1149**参数:**
1150
1151| 参数名 | 类型 | 必填 | 说明 |
1152| -------- | ------------------------- | -- | --------- |
1153| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
1154
1155**错误码:**
1156
1157以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
1158
1159| 错误码ID | 错误信息 |
1160| ------- | ------------------------------ |
1161| 1300002 | This window state is abnormal. |
1162
1163**示例:**
1164
1165```ts
1166import { BusinessError } from '@kit.BasicServicesKit';
1167
1168windowClass.showWindow((err: BusinessError) => {
1169  const errCode: number = err.code;
1170  if (errCode) {
1171    console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`);
1172    return;
1173  }
1174  console.info('Succeeded in showing the window.');
1175});
1176```
1177
1178### showWindow<sup>9+</sup>
1179
1180showWindow(): Promise&lt;void&gt;
1181
1182显示当前窗口,使用Promise异步回调,仅支持系统窗口及应用子窗口,或将已显示的应用主窗口的层级提升至顶部。
1183
1184**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1185
1186**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1187
1188**返回值:**
1189
1190| 类型 | 说明 |
1191| ------------------- | ----------------------- |
1192| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1193
1194**错误码:**
1195
1196以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
1197
1198| 错误码ID | 错误信息 |
1199| ------- | ------------------------------ |
1200| 1300002 | This window state is abnormal. |
1201
1202**示例:**
1203
1204```ts
1205import { BusinessError } from '@kit.BasicServicesKit';
1206
1207let promise = windowClass.showWindow();
1208promise.then(() => {
1209  console.info('Succeeded in showing the window.');
1210}).catch((err: BusinessError) => {
1211  console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`);
1212});
1213```
1214
1215### destroyWindow<sup>9+</sup>
1216
1217destroyWindow(callback: AsyncCallback&lt;void&gt;): void
1218
1219销毁当前窗口,使用callback异步回调,仅支持系统窗口及应用子窗口。
1220
1221**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1222
1223**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1224
1225**参数:**
1226
1227| 参数名 | 类型 | 必填 | 说明 |
1228| -------- | ------------------------- | -- | --------- |
1229| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
1230
1231**错误码:**
1232
1233以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
1234
1235| 错误码ID | 错误信息 |
1236| ------- | -------------------------------------------- |
1237| 1300002 | This window state is abnormal.               |
1238| 1300003 | This window manager service works abnormally. |
1239
1240**示例:**
1241
1242```ts
1243import { BusinessError } from '@kit.BasicServicesKit';
1244
1245windowClass.destroyWindow((err) => {
1246  const errCode: number = err.code;
1247  if (errCode) {
1248    console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`);
1249    return;
1250  }
1251  console.info('Succeeded in destroying the window.');
1252});
1253```
1254
1255### destroyWindow<sup>9+</sup>
1256
1257destroyWindow(): Promise&lt;void&gt;
1258
1259销毁当前窗口,使用Promise异步回调,仅支持系统窗口及应用子窗口。
1260
1261**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1262
1263**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1264
1265**返回值:**
1266
1267| 类型 | 说明 |
1268| ------------------- | ------------------------ |
1269| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1270
1271**错误码:**
1272
1273以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
1274
1275| 错误码ID | 错误信息 |
1276| ------- | -------------------------------------------- |
1277| 1300002 | This window state is abnormal.               |
1278| 1300003 | This window manager service works abnormally. |
1279
1280**示例:**
1281
1282```ts
1283import { BusinessError } from '@kit.BasicServicesKit';
1284
1285let promise = windowClass.destroyWindow();
1286promise.then(() => {
1287  console.info('Succeeded in destroying the window.');
1288}).catch((err: BusinessError) => {
1289  console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`);
1290});
1291```
1292
1293### moveWindowTo<sup>9+</sup>
1294
1295moveWindowTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void
1296
1297移动窗口位置,使用callback异步回调。
1298
1299<!--RP4-->
1300全屏模式下,本接口仅在2in1设备上生效。<!--RP4End-->
1301在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。
1302
1303**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1304
1305**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1306
1307**参数:**
1308
1309| 参数名 | 类型 | 必填 | 说明 |
1310| -------- | ------------------------- | -- | --------------------------------------------- |
1311| x        | number                    | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
1312| y        | number                    | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
1313| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                     |
1314
1315**错误码:**
1316
1317以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1318
1319| 错误码ID | 错误信息 |
1320| ------- | -------------------------------------------- |
1321| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1322| 1300002 | This window state is abnormal.               |
1323| 1300003 | This window manager service works abnormally. |
1324
1325**示例:**
1326
1327```ts
1328import { BusinessError } from '@kit.BasicServicesKit';
1329
1330try {
1331  windowClass.moveWindowTo(300, 300, (err: BusinessError) => {
1332    const errCode: number = err.code;
1333    if (errCode) {
1334      console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
1335      return;
1336    }
1337    console.info('Succeeded in moving the window.');
1338  });
1339} catch (exception) {
1340  console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`);
1341}
1342```
1343
1344### moveWindowTo<sup>9+</sup>
1345
1346moveWindowTo(x: number, y: number): Promise&lt;void&gt;
1347
1348移动窗口位置,使用Promise异步回调。调用成功即返回,该接口返回后无法立即获取最终生效结果,如需立即获取,建议使用接口[moveWindowToAsync()](#movewindowtoasync12)。
1349
1350<!--RP4-->
1351全屏模式下,本接口仅在2in1设备上生效。<!--RP4End-->
1352在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。
1353
1354**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1355
1356**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1357
1358**参数:**
1359
1360| 参数名 | 类型 | 必填 | 说明 |
1361| -- | ----- | -- | --------------------------------------------- |
1362| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
1363| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
1364
1365**返回值:**
1366
1367| 类型 | 说明 |
1368| ------------------- | ------------------------ |
1369| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1370
1371**错误码:**
1372
1373以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1374
1375| 错误码ID | 错误信息 |
1376| ------- | -------------------------------------------- |
1377| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1378| 1300002 | This window state is abnormal.               |
1379| 1300003 | This window manager service works abnormally. |
1380
1381**示例:**
1382
1383```ts
1384import { BusinessError } from '@kit.BasicServicesKit';
1385
1386try {
1387  let promise = windowClass.moveWindowTo(300, 300);
1388  promise.then(() => {
1389    console.info('Succeeded in moving the window.');
1390  }).catch((err: BusinessError) => {
1391    console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
1392  });
1393} catch (exception) {
1394  console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`);
1395}
1396```
1397
1398### moveWindowToAsync<sup>12+</sup>
1399
1400moveWindowToAsync(x: number, y: number): Promise&lt;void&gt;
1401
1402移动窗口位置,使用Promise异步回调。调用生效后返回,回调中可使用getWindowProperties(见示例)立即获取最终生效结果。
1403
1404仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效。
1405在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。
1406
1407**系统能力:** SystemCapability.Window.SessionManager
1408
1409**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1410
1411**参数:**
1412
1413| 参数名 | 类型 | 必填 | 说明 |
1414| -- | ----- | -- | --------------------------------------------- |
1415| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
1416| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
1417
1418**返回值:**
1419
1420| 类型 | 说明 |
1421| ------------------- | ------------------------ |
1422| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1423
1424**错误码:**
1425
1426以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1427
1428| 错误码ID | 错误信息 |
1429| ------- | -------------------------------------------- |
1430| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1431| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
1432| 1300002 | This window state is abnormal.               |
1433| 1300003 | This window manager service works abnormally. |
1434| 1300010 | The operation in the current window status is invalid. |
1435
1436**示例:**
1437
1438```ts
1439import { BusinessError } from '@kit.BasicServicesKit';
1440
1441try {
1442  let promise = windowClass.moveWindowToAsync(300, 300);
1443  promise.then(() => {
1444    console.info('Succeeded in moving the window.');
1445    let rect = windowClass?.getWindowProperties().windowRect;
1446    console.info(`Get window rect: ` + JSON.stringify(rect));
1447  }).catch((err: BusinessError) => {
1448    console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
1449  });
1450} catch (exception) {
1451  console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`);
1452}
1453```
1454
1455### moveWindowToGlobal<sup>13+</sup>
1456
1457moveWindowToGlobal(x: number, y: number): Promise&lt;void&gt;
1458
1459基于屏幕坐标移动窗口位置,使用Promise异步回调。调用生效后返回。
1460
1461全屏模式窗口不支持该操作。
1462
1463在非2in1设备下,子窗会跟随主窗移动。
1464
1465**系统能力:** SystemCapability.Window.SessionManager
1466
1467**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
1468
1469**参数:**
1470
1471| 参数名 | 类型 | 必填 | 说明 |
1472| -- | ----- | -- | --------------------------------------------- |
1473| x | number | 是 | 表示以屏幕左上角为起点,窗口在x轴方向移动的值,单位为px。值为正表示右移,值为负表示左移。该参数仅支持整数输入,浮点数输入将向下取整。 |
1474| y | number | 是 | 表示以屏幕左上角为起点,窗口在y轴方向移动的值,单位为px。值为正表示下移,值为负表示上移。该参数仅支持整数输入,浮点数输入将向下取整。 |
1475
1476**返回值:**
1477
1478| 类型 | 说明 |
1479| ------------------- | ------------------------ |
1480| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1481
1482**错误码:**
1483
1484以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1485
1486| 错误码ID | 错误信息 |
1487| ------- | -------------------------------------------- |
1488| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1489| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
1490| 1300002 | This window state is abnormal.               |
1491| 1300003 | This window manager service works abnormally. |
1492| 1300010 | The operation in the current window status is invalid. |
1493
1494**示例:**
1495
1496```ts
1497import { BusinessError } from '@kit.BasicServicesKit';
1498
1499try {
1500  let promise = windowClass.moveWindowToGlobal(300, 300);
1501  promise.then(() => {
1502    console.info('Succeeded in moving the window.');
1503  }).catch((err: BusinessError) => {
1504    console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
1505  });
1506} catch (exception) {
1507  console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`);
1508}
1509```
1510
1511### resize<sup>9+</sup>
1512
1513resize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void
1514
1515改变当前窗口大小,使用callback异步回调。
1516
1517应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为px。
1518应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
1519
1520系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为px。
1521
1522设置的宽度与高度受到此约束限制,规则:
1523若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
1524若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
1525
1526全屏模式窗口不支持该操作。
1527
1528**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1529
1530**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1531
1532**参数:**
1533
1534| 参数名 | 类型 | 必填 | 说明 |
1535| -------- | ------------------------- | -- | ------------------------ |
1536| width    | number                    | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
1537| height   | number                    | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
1538| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。                |
1539
1540**错误码:**
1541
1542以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1543
1544| 错误码ID | 错误信息 |
1545| ------- | -------------------------------------------- |
1546| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1547| 1300002 | This window state is abnormal.               |
1548| 1300003 | This window manager service works abnormally. |
1549
1550**示例:**
1551
1552```ts
1553import { BusinessError } from '@kit.BasicServicesKit';
1554
1555try {
1556  windowClass.resize(500, 1000, (err: BusinessError) => {
1557    const errCode: number = err.code;
1558    if (errCode) {
1559      console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
1560      return;
1561    }
1562    console.info('Succeeded in changing the window size.');
1563  });
1564} catch (exception) {
1565  console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`);
1566}
1567```
1568
1569### resize<sup>9+</sup>
1570
1571resize(width: number, height: number): Promise&lt;void&gt;
1572
1573改变当前窗口大小,使用Promise异步回调。调用成功即返回,该接口返回后无法立即获取最终生效结果,如需立即获取,建议使用接口[resizeAsync()](#resizeasync12)。
1574
1575应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为px。
1576应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
1577
1578系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为px。
1579
1580设置的宽度与高度受到此约束限制,规则:
1581若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
1582若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
1583
1584全屏模式窗口不支持该操作。
1585
1586**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1587
1588**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1589
1590**参数:**
1591
1592| 参数名 | 类型 | 必填 | 说明 |
1593| ------ | ------ | -- | ------------------------ |
1594| width  | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
1595| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
1596
1597**返回值:**
1598
1599| 类型 | 说明 |
1600| ------------------- | ------------------------ |
1601| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1602
1603**错误码:**
1604
1605以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1606
1607| 错误码ID | 错误信息 |
1608| ------- | -------------------------------------------- |
1609| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1610| 1300002 | This window state is abnormal.               |
1611| 1300003 | This window manager service works abnormally. |
1612
1613**示例:**
1614
1615```ts
1616import { BusinessError } from '@kit.BasicServicesKit';
1617
1618try {
1619  let promise = windowClass.resize(500, 1000);
1620  promise.then(() => {
1621    console.info('Succeeded in changing the window size.');
1622  }).catch((err: BusinessError) => {
1623    console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
1624  });
1625} catch (exception) {
1626  console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`);
1627}
1628```
1629
1630### resizeAsync<sup>12+</sup>
1631
1632resizeAsync(width: number, height: number): Promise&lt;void&gt;
1633
1634改变当前窗口大小,使用Promise异步回调。调用生效后返回,回调中可使用getWindowProperties(见示例)立即获取最终生效结果。
1635
1636应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为px。
1637应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
1638
1639系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为px。
1640
1641设置的宽度与高度受到此约束限制,规则:
1642若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
1643若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
1644
1645全屏模式窗口不支持该操作。
1646
1647**系统能力:** SystemCapability.Window.SessionManager
1648
1649**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1650
1651**参数:**
1652
1653| 参数名 | 类型 | 必填 | 说明 |
1654| ------ | ------ | -- | ------------------------ |
1655| width  | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
1656| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
1657
1658**返回值:**
1659
1660| 类型 | 说明 |
1661| ------------------- | ------------------------ |
1662| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1663
1664**错误码:**
1665
1666以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1667
1668| 错误码ID | 错误信息 |
1669| ------- | -------------------------------------------- |
1670| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1671| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
1672| 1300002 | This window state is abnormal.               |
1673| 1300003 | This window manager service works abnormally. |
1674| 1300010 | The operation in the current window status is invalid. |
1675
1676**示例:**
1677
1678```ts
1679import { BusinessError } from '@kit.BasicServicesKit';
1680
1681try {
1682  let promise = windowClass.resizeAsync(500, 1000);
1683  promise.then(() => {
1684    console.info('Succeeded in changing the window size.');
1685    let rect = windowClass?.getWindowProperties().windowRect;
1686    console.info(`Get window rect: ` + JSON.stringify(rect));
1687  }).catch((err: BusinessError) => {
1688    console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
1689  });
1690} catch (exception) {
1691  console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`);
1692}
1693```
1694
1695### getWindowProperties<sup>9+</sup>
1696
1697getWindowProperties(): WindowProperties
1698
1699获取当前窗口的属性,返回WindowProperties。
1700
1701**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1702
1703**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1704
1705**返回值:**
1706
1707| 类型 | 说明 |
1708| ------------------------------------- | ------------- |
1709| [WindowProperties](#windowproperties) | 当前窗口属性。 |
1710
1711**错误码:**
1712
1713以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
1714
1715| 错误码ID | 错误信息 |
1716| ------- | ------------------------------ |
1717| 1300002 | This window state is abnormal. |
1718
1719**示例:**
1720
1721```ts
1722try {
1723  let properties = windowClass.getWindowProperties();
1724} catch (exception) {
1725  console.error(`Failed to obtain the window properties. Cause code: ${exception.code}, message: ${exception.message}`);
1726}
1727```
1728
1729### getGlobalRect<sup>13+</sup>
1730
1731getGlobalRect(): Rect
1732
1733获取窗口在屏幕上的真实显示区域,同步接口。
1734
1735在某些设备上,窗口显示时可能经过了缩放,此接口可以获取缩放后窗口在屏幕上的真实位置和大小。
1736
1737**系统能力:** SystemCapability.Window.SessionManager
1738
1739**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
1740
1741**返回值:**
1742
1743| 类型 | 说明 |
1744| ------------------- | ------------------------ |
1745| [Rect](#rect7) | 四元组分别表示距离屏幕左上角的x坐标、距离屏幕左上角的y坐标、缩放后的窗口宽度和缩放后的窗口高度。 |
1746
1747**错误码:**
1748
1749以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1750
1751| 错误码ID | 错误信息 |
1752| ------- | -------------------------------------------- |
1753| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
1754| 1300002 | This window state is abnormal.               |
1755| 1300003 | This window manager service works abnormally. |
1756
1757**示例:**
1758
1759```ts
1760try {
1761  let rect = windowClass.getGlobalRect();
1762  console.info(`Succeeded in getting window rect: ` + JSON.stringify(rect));
1763} catch (exception) {
1764  console.error(`Failed to get window rect. Cause code: ${exception.code}, message: ${exception.message}`);
1765}
1766```
1767
1768### getWindowAvoidArea<sup>9+</sup>
1769
1770getWindowAvoidArea(type: AvoidAreaType): AvoidArea
1771
1772获取当前应用窗口内容规避的区域。如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。
1773
1774该接口一般适用于两种场景:1、在onWindowStageCreate方法中,获取应用启动时的初始布局避让区域时可调用该接口;2、当应用内子窗需要临时显示,对显示内容做布局避让时可调用该接口。
1775
1776**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1777
1778**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1779
1780**参数:**
1781
1782| 参数名 | 类型 | 必填 | 说明 |
1783| ---- |----------------------------------| -- | ------------------------------------------------------------ |
1784| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。 |
1785
1786**返回值:**
1787
1788| 类型 | 说明 |
1789|--------------------------| ----------------- |
1790| [AvoidArea](#avoidarea7) | 窗口内容规避区域。 |
1791
1792**错误码:**
1793
1794以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1795
1796| 错误码ID | 错误信息 |
1797| ------- | ------------------------------ |
1798| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1799| 1300002 | This window state is abnormal. |
1800
1801**示例:**
1802
1803```ts
1804let type = window.AvoidAreaType.TYPE_SYSTEM;
1805try {
1806  let avoidArea = windowClass.getWindowAvoidArea(type);
1807} catch (exception) {
1808  console.error(`Failed to obtain the area. Cause code: ${exception.code}, message: ${exception.message}`);
1809}
1810```
1811
1812### setWindowLayoutFullScreen<sup>9+</sup>
1813
1814setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise&lt;void&gt;
1815
1816设置主窗口或子窗口的布局是否为沉浸式布局,使用Promise异步回调。
1817沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
1818非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。
1819
1820**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1821
1822**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1823
1824**参数:**
1825
1826| 参数名 | 类型 | 必填 | 说明 |
1827| ------------------ | ------- | -- | ------------------------------------------------------------------------------------------------ |
1828| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 |
1829
1830**返回值:**
1831
1832| 类型 | 说明 |
1833| ------------------- | ------------------------ |
1834| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1835
1836**错误码:**
1837
1838以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1839
1840| 错误码ID | 错误信息 |
1841| ------- | -------------------------------------------- |
1842| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1843| 1300002 | This window state is abnormal.               |
1844| 1300003 | This window manager service works abnormally. |
1845
1846**示例:**
1847
1848```ts
1849// EntryAbility.ets
1850import { UIAbility } from '@kit.AbilityKit';
1851import { BusinessError } from '@kit.BasicServicesKit';
1852
1853export default class EntryAbility extends UIAbility {
1854  // ...
1855  onWindowStageCreate(windowStage: window.WindowStage): void {
1856    console.info('onWindowStageCreate');
1857    let windowClass: window.Window | undefined = undefined;
1858    windowStage.getMainWindow((err: BusinessError, data) => {
1859      const errCode: number = err.code;
1860      if (errCode) {
1861        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
1862        return;
1863      }
1864      windowClass = data;
1865      let isLayoutFullScreen = true;
1866      try {
1867        let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen);
1868        promise.then(() => {
1869          console.info('Succeeded in setting the window layout to full-screen mode.');
1870        }).catch((err: BusinessError) => {
1871          console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
1872        });
1873      } catch (exception) {
1874        console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`);
1875      }
1876    });
1877  }
1878}
1879```
1880
1881### setImmersiveModeEnabledState<sup>12+</sup>
1882
1883setImmersiveModeEnabledState(enabled: boolean): void
1884
1885设置当前窗口是否开启沉浸式布局,该调用不会改变窗口模式和窗口大小。
1886
1887**系统能力**:SystemCapability.WindowManager.WindowManager.Core
1888
1889**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1890
1891**参数:**
1892
1893| 参数名      | 类型    | 必填 | 说明                                                         |
1894| ---------- | ------- | ---- | ------------------------------------------------------------ |
1895| enabled    | boolean | 是   | 是否开启沉浸式布局。<br>true表示开启,false表示关闭。</br> |
1896
1897**错误码:**
1898
1899以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1900
1901| 错误码ID | 错误信息 |
1902| ------- | -------------------------------------------- |
1903| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1904| 1300002 | This window state is abnormal.               |
1905| 1300003 | This window manager service works abnormally. |
1906| 1300004 | Unauthorized operation.                |
1907
1908**示例:**
1909
1910```ts
1911try {
1912  let enabled = false;
1913  windowClass.setImmersiveModeEnabledState(enabled);
1914} catch (exception) {
1915  console.error(`Failed to set the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`);
1916}
1917```
1918
1919### getImmersiveModeEnabledState<sup>12+</sup>
1920
1921getImmersiveModeEnabledState(): boolean
1922
1923查询当前窗口是否已经开启沉浸式布局。
1924
1925**系统能力**:SystemCapability.WindowManager.WindowManager.Core
1926
1927**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1928
1929**返回值:**
1930| 类型     | 说明                                                                                 |
1931| ------- | ------------------------------------------------------------------------------------ |
1932| boolean | 是否已经开启沉浸式布局。<br>true表示开启,false表示关闭。</br> |
1933
1934**错误码:**
1935
1936以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1937
1938| 错误码ID | 错误信息 |
1939| -------- | -------------------------------------------- |
1940| 1300002  | This window state is abnormal.               |
1941| 1300003  | This window manager service works abnormally. |
1942| 1300004  | Unauthorized operation.               |
1943
1944**示例:**
1945
1946```ts
1947try {
1948  let isEnabled = windowClass.getImmersiveModeEnabledState();
1949} catch (exception) {
1950  console.error(`Failed to get the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`);
1951}
1952```
1953
1954### setWindowSystemBarEnable<sup>9+</sup>
1955
1956setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise&lt;void&gt;
1957
1958设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
1959
1960子窗口调用后不生效。
1961
1962**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1963
1964**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1965
1966**参数:**
1967
1968| 参数名 | 类型  | 必填 | 说明 |
1969| ----- | ---------------------------- | -- | --------------------------------- |
1970| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];不设置,则默认不显示。 |
1971
1972**返回值:**
1973
1974| 类型 | 说明 |
1975| ------------------- | ------------------------ |
1976| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1977
1978**错误码:**
1979
1980以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1981
1982| 错误码ID | 错误信息 |
1983| ------- | -------------------------------------------- |
1984| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1985| 1300002 | This window state is abnormal.               |
1986| 1300003 | This window manager service works abnormally. |
1987
1988**示例:**
1989
1990```ts
1991// 此处以不显示三键导航栏、状态栏、底部导航条为例
1992// EntryAbility.ets
1993import { UIAbility } from '@kit.AbilityKit';
1994import { BusinessError } from '@kit.BasicServicesKit';
1995
1996export default class EntryAbility extends UIAbility {
1997  // ...
1998  onWindowStageCreate(windowStage: window.WindowStage): void {
1999    console.info('onWindowStageCreate');
2000    let windowClass: window.Window | undefined = undefined;
2001    windowStage.getMainWindow((err: BusinessError, data) => {
2002      const errCode: number = err.code;
2003      if (errCode) {
2004        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2005        return;
2006      }
2007      windowClass = data;
2008      let names: Array<'status' | 'navigation'> = [];
2009      try {
2010        let promise = windowClass.setWindowSystemBarEnable(names);
2011        promise.then(() => {
2012          console.info('Succeeded in setting the system bar to be invisible.');
2013        }).catch((err: BusinessError) => {
2014          console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
2015        });
2016      } catch (exception) {
2017        console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`);
2018      }
2019    });
2020  }
2021}
2022```
2023
2024### setSpecificSystemBarEnabled<sup>11+</sup>
2025
2026setSpecificSystemBarEnabled(name: SpecificSystemBar, enable: boolean, enableAnimation?: boolean): Promise&lt;void&gt;
2027
2028设置主窗口三键导航栏、状态栏、底部导航条的显示和隐藏,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
2029
2030子窗口调用后不生效。
2031
2032**系统能力:** SystemCapability.Window.SessionManager
2033
2034**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2035
2036**参数:**
2037
2038| 参数名 | 类型  | 必填 | 说明 |
2039| ----- | ---------------------------- | -- | --------------------------------- |
2040| name  | [SpecificSystemBar](#specificsystembar11) | 是 | 设置窗口全屏模式时,显示或隐藏的系统栏类型。 |
2041| enable  | boolean | 是 | 设置窗口全屏模式时状态栏、三键导航栏或底部导航条是否显示,true表示显示, false表示隐藏。|
2042| enableAnimation<sup>12+</sup>  | boolean | 否 | 设置状态栏、三键导航栏或底部导航条显示状态变化时是否使用动画,true表示使用, false表示不使用,默认值为false。|
2043
2044**返回值:**
2045
2046| 类型 | 说明 |
2047| ------------------- | ------------------------ |
2048| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2049
2050**错误码:**
2051
2052以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2053
2054| 错误码ID | 错误信息 |
2055| ------- | -------------------------------------------- |
2056| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2057| 1300002 | This window state is abnormal.               |
2058| 1300003 | This window manager service works abnormally. |
2059
2060**示例:**
2061
2062```ts
2063// 此处以隐藏底部导航条为例
2064// EntryAbility.ets
2065import { UIAbility } from '@kit.AbilityKit';
2066import { BusinessError } from '@kit.BasicServicesKit';
2067
2068export default class EntryAbility extends UIAbility {
2069  // ...
2070  onWindowStageCreate(windowStage: window.WindowStage): void {
2071    console.info('onWindowStageCreate');
2072    let windowClass: window.Window | undefined = undefined;
2073    windowStage.getMainWindow((err: BusinessError, data) => {
2074      const errCode: number = err.code;
2075      if (errCode) {
2076        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2077        return;
2078      }
2079      windowClass = data;
2080      try {
2081        let promise = windowClass.setSpecificSystemBarEnabled('navigationIndicator', false);
2082        promise.then(() => {
2083          console.info('Succeeded in setting the system bar to be invisible.');
2084        }).catch((err: BusinessError) => {
2085          console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
2086        });
2087      } catch (exception) {
2088        console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`);
2089      }
2090    });
2091  }
2092}
2093```
2094
2095### setWindowSystemBarProperties<sup>9+</sup>
2096
2097setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise&lt;void&gt;
2098
2099设置主窗口三键导航栏、状态栏的属性,使用Promise异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
2100
2101子窗口调用后不生效。
2102
2103**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2104
2105**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2106
2107**参数:**
2108
2109| 参数名              | 类型                                        | 必填 | 说明                   |
2110| ------------------- | ------------------------------------------- | ---- | ---------------------- |
2111| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是   | 三键导航栏、状态栏的属性。 |
2112
2113**返回值:**
2114
2115| 类型                | 说明                      |
2116| ------------------- | ------------------------- |
2117| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2118
2119**错误码:**
2120
2121以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2122
2123| 错误码ID | 错误信息 |
2124| ------- | -------------------------------------------- |
2125| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2126| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
2127| 1300002 | This window state is abnormal.               |
2128| 1300003 | This window manager service works abnormally. |
2129
2130**示例:**
2131
2132```ts
2133// EntryAbility.ets
2134import { UIAbility } from '@kit.AbilityKit';
2135import { BusinessError } from '@kit.BasicServicesKit';
2136
2137export default class EntryAbility extends UIAbility {
2138  // ...
2139  onWindowStageCreate(windowStage: window.WindowStage): void {
2140    console.info('onWindowStageCreate');
2141    let windowClass: window.Window | undefined = undefined;
2142    windowStage.getMainWindow((err: BusinessError, data) => {
2143      const errCode: number = err.code;
2144      if (errCode) {
2145        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2146        return;
2147      }
2148      windowClass = data;
2149      let SystemBarProperties: window.SystemBarProperties = {
2150        statusBarColor: '#ff00ff',
2151        navigationBarColor: '#00ff00',
2152        //以下两个属性从API Version8开始支持
2153        statusBarContentColor: '#ffffff',
2154        navigationBarContentColor: '#00ffff'
2155      };
2156      try {
2157        let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties);
2158        promise.then(() => {
2159          console.info('Succeeded in setting the system bar properties.');
2160        }).catch((err: BusinessError) => {
2161          console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
2162        });
2163      } catch (exception) {
2164        console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`);
2165      }
2166    });
2167  }
2168}
2169```
2170
2171### getWindowSystemBarProperties<sup>12+</sup>
2172
2173getWindowSystemBarProperties(): SystemBarProperties
2174
2175主窗口获取三键导航栏、状态栏的属性。
2176
2177**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2178
2179**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2180
2181**返回值:**
2182
2183| 类型 | 说明 |
2184| ------------------------------------- | ------------- |
2185| [SystemBarProperties](#systembarproperties) | 当前三键导航栏、状态栏属性。 |
2186
2187**错误码:**
2188
2189以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
2190
2191| 错误码ID | 错误信息 |
2192| ------- | ------------------------------ |
2193| 1300002 | This window state is abnormal. |
2194| 1300003 | This window manager service works abnormally. |
2195| 1300004 | Unauthorized operation.                       |
2196
2197
2198**示例:**
2199
2200```ts
2201// EntryAbility.ets
2202import { UIAbility } from '@kit.AbilityKit';
2203import { BusinessError } from '@kit.BasicServicesKit';
2204
2205export default class EntryAbility extends UIAbility {
2206  // ...
2207
2208  onWindowStageCreate(windowStage: window.WindowStage) {
2209    let windowClass: window.Window | undefined = undefined;
2210    windowStage.getMainWindow((err: BusinessError, data) => {
2211      const errCode: number = err.code;
2212      if (errCode) {
2213        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2214        return;
2215      }
2216      windowClass = data;
2217      try {
2218        let systemBarProperty = windowClass.getWindowSystemBarProperties();
2219        console.info('Success in obtaining system bar properties. Property: ' + JSON.stringify(systemBarProperty));
2220      } catch (err) {
2221        console.error(`Failed to get system bar properties. Code: ${err.code}, message: ${err.message}`);
2222      }
2223    });
2224  }
2225};
2226```
2227
2228### setPreferredOrientation<sup>9+</sup>
2229
2230setPreferredOrientation(orientation: Orientation, callback: AsyncCallback&lt;void&gt;): void
2231
2232设置主窗口的显示方向属性,使用callback异步回调。仅在支持跟随sensor旋转的设备上生效,子窗口调用后不生效。
2233
2234**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2235
2236**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2237
2238**参数:**
2239
2240| 参数名              | 类型                                        | 必填 | 说明                   |
2241| ------------------- | ------------------------------------------- | ---- | ---------------------- |
2242| orientation         | [Orientation](#orientation9)                | 是   | 窗口显示方向的属性。         |
2243| callback            | AsyncCallback&lt;void&gt;                   | 是   | 回调函数。该回调函数返回调用结果是否成功,非应用旋转动效结束。 |
2244
2245**错误码:**
2246
2247以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2248
2249| 错误码ID | 错误信息 |
2250| ------- | ------------------------------ |
2251| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2252| 1300002 | This window state is abnormal. |
2253
2254**示例:**
2255
2256```ts
2257// EntryAbility.ets
2258import { UIAbility } from '@kit.AbilityKit';
2259import { BusinessError } from '@kit.BasicServicesKit';
2260
2261export default class EntryAbility extends UIAbility {
2262  // ...
2263  onWindowStageCreate(windowStage: window.WindowStage): void {
2264    console.info('onWindowStageCreate');
2265    let windowClass: window.Window | undefined = undefined;
2266    windowStage.getMainWindow((err: BusinessError, data) => {
2267      const errCode: number = err.code;
2268      if (errCode) {
2269        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2270        return;
2271      }
2272      windowClass = data;
2273      let orientation = window.Orientation.AUTO_ROTATION;
2274      try {
2275        windowClass.setPreferredOrientation(orientation, (err: BusinessError) => {
2276          const errCode: number = err.code;
2277          if (errCode) {
2278            console.error(`Failed to set window orientation. Cause code: ${err.code}, message: ${err.message}`);
2279            return;
2280          }
2281          console.info('Succeeded in setting window orientation.');
2282        });
2283      } catch (exception) {
2284        console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`);
2285      }
2286    });
2287  }
2288}
2289```
2290
2291### setPreferredOrientation<sup>9+</sup>
2292
2293setPreferredOrientation(orientation: Orientation): Promise&lt;void&gt;
2294
2295设置主窗口的显示方向属性,使用Promise异步回调。仅在支持跟随sensor旋转的设备上生效,子窗口调用后不生效。
2296
2297**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2298
2299**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2300
2301**参数:**
2302
2303| 参数名              | 类型                                        | 必填 | 说明                   |
2304| ------------------- | ------------------------------------------- | ---- | ---------------------- |
2305| orientation         | [Orientation](#orientation9)                | 是   | 窗口显示方向的属性。       |
2306
2307**返回值:**
2308
2309| 类型                | 说明                      |
2310| ------------------- | ------------------------- |
2311| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2312
2313**错误码:**
2314
2315以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2316
2317| 错误码ID | 错误信息 |
2318| ------- | ------------------------------ |
2319| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2320| 1300002 | This window state is abnormal. |
2321
2322**示例:**
2323
2324```ts
2325// EntryAbility.ets
2326import { UIAbility } from '@kit.AbilityKit';
2327import { BusinessError } from '@kit.BasicServicesKit';
2328
2329export default class EntryAbility extends UIAbility {
2330  // ...
2331  onWindowStageCreate(windowStage: window.WindowStage): void {
2332    console.info('onWindowStageCreate');
2333    let windowClass: window.Window | undefined = undefined;
2334    windowStage.getMainWindow((err: BusinessError, data) => {
2335      const errCode: number = err.code;
2336      if (errCode) {
2337        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2338        return;
2339      }
2340      windowClass = data;
2341      let orientation = window.Orientation.AUTO_ROTATION;
2342      try {
2343        let promise = windowClass.setPreferredOrientation(orientation);
2344        promise.then(() => {
2345          console.info('Succeeded in setting the window orientation.');
2346        }).catch((err: BusinessError) => {
2347          console.error(`Failed to set the window orientation. Cause code: ${err.code}, message: ${err.message}`);
2348        });
2349      } catch (exception) {
2350        console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`);
2351      }
2352    });
2353  }
2354}
2355```
2356
2357### getPreferredOrientation<sup>12+</sup>
2358
2359getPreferredOrientation(): Orientation
2360
2361主窗口调用,获取窗口的显示方向属性。
2362
2363**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2364
2365**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2366
2367**返回值:**
2368
2369| 类型 | 说明 |
2370|------------------------------| ------------------ |
2371| [Orientation](#orientation9) | 窗口显示方向的属性。 |
2372
2373**错误码:**
2374
2375以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
2376
2377| 错误码ID | 错误信息 |
2378| ------- | ------------------------------ |
2379| 1300002 | This window state is abnormal. |
2380
2381**示例:**
2382
2383```ts
2384// EntryAbility.ets
2385import { UIAbility } from '@kit.AbilityKit';
2386import { BusinessError } from '@kit.BasicServicesKit';
2387export default class EntryAbility extends UIAbility {
2388  // ...
2389
2390  onWindowStageCreate(windowStage: window.WindowStage) {
2391    console.info('onWindowStageCreate');
2392    let windowClass: window.Window | undefined = undefined;
2393    windowStage.getMainWindow((err: BusinessError, data) => {
2394      const errCode: number = err.code;
2395      if (errCode) {
2396        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2397        return;
2398      }
2399      windowClass = data;
2400      try {
2401        let orientation = windowClass.getPreferredOrientation();
2402      } catch (exception) {
2403        console.error(`Failed to get window orientation. Cause code: ${exception.code}, message: ${exception.message}`);
2404      }
2405    });
2406  }
2407};
2408```
2409
2410### getUIContext<sup>10+</sup>
2411
2412getUIContext(): UIContext
2413
2414获取UIContext实例。
2415
2416**模型约束:** 此接口仅可在Stage模型下使用。
2417
2418**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2419
2420**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2421
2422**返回值:**
2423
2424| 类型       | 说明                   |
2425| ---------- | ---------------------- |
2426| [UIContext](js-apis-arkui-UIContext.md#uicontext) | 返回UIContext实例对象。 |
2427
2428**错误码:**
2429
2430以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
2431
2432| 错误码ID | 错误信息 |
2433| ------- | ------------------------------ |
2434| 1300002 | This window state is abnormal. |
2435
2436**示例:**
2437
2438```ts
2439// EntryAbility.ets
2440import { UIAbility } from '@kit.AbilityKit';
2441import { window, UIContext } from '@kit.ArkUI';
2442import { BusinessError } from '@kit.BasicServicesKit';
2443
2444export default class EntryAbility extends UIAbility {
2445  onWindowStageCreate(windowStage: window.WindowStage) {
2446    // 为主窗口加载对应的目标页面。
2447    windowStage.loadContent("pages/page2", (err: BusinessError) => {
2448      let errCode: number = err.code;
2449      if (errCode) {
2450        console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2451        return;
2452      }
2453      console.info('Succeeded in loading the content.');
2454      // 获取应用主窗口。
2455      let windowClass: window.Window | undefined = undefined;
2456      windowStage.getMainWindow((err: BusinessError, data) => {
2457        let errCode: number = err.code;
2458        if (errCode) {
2459          console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2460          return;
2461        }
2462        windowClass = data;
2463        console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
2464        // 获取UIContext实例。
2465        let uiContext: UIContext | null = null;
2466        uiContext = windowClass.getUIContext();
2467      });
2468    });
2469  }
2470};
2471```
2472
2473### setUIContent<sup>9+</sup>
2474
2475setUIContent(path: string, callback: AsyncCallback&lt;void&gt;): void
2476
2477根据当前工程中某个页面的路径为窗口加载具体页面内容,使用callback异步回调。
2478
2479**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2480
2481**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2482
2483**参数:**
2484
2485| 参数名 | 类型 | 必填 | 说明 |
2486| -------- | ------------------------- | -- | -------------------- |
2487| path     | string                    | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 |
2488| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。          |
2489
2490**错误码:**
2491
2492以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2493
2494| 错误码ID | 错误信息 |
2495| ------- | -------------------------------------------- |
2496| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2497| 1300002 | This window state is abnormal.               |
2498| 1300003 | This window manager service works abnormally. |
2499
2500**示例:**
2501
2502```ts
2503import { BusinessError } from '@kit.BasicServicesKit';
2504
2505try {
2506  windowClass.setUIContent('pages/page2/page3', (err: BusinessError) => {
2507    const errCode: number = err.code;
2508    if (errCode) {
2509      console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2510      return;
2511    }
2512    console.info('Succeeded in loading the content.');
2513  });
2514} catch (exception) {
2515  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
2516}
2517```
2518
2519### setUIContent<sup>9+</sup>
2520
2521setUIContent(path: string): Promise&lt;void&gt;
2522
2523根据当前工程中某个页面的路径为窗口加载具体页面内容,使用Promise异步回调。
2524
2525**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2526
2527**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2528
2529**参数:**
2530
2531| 参数名 | 类型 | 必填 | 说明 |
2532| ---- | ------ | -- | ------------------ |
2533| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 |
2534
2535**返回值:**
2536
2537| 类型 | 说明 |
2538| ------------------- | ------------------------ |
2539| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2540
2541**错误码:**
2542
2543以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2544
2545| 错误码ID | 错误信息 |
2546| ------- | -------------------------------------------- |
2547| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2548| 1300002 | This window state is abnormal.               |
2549| 1300003 | This window manager service works abnormally. |
2550
2551**示例:**
2552
2553```ts
2554import { BusinessError } from '@kit.BasicServicesKit';
2555
2556try {
2557  let promise = windowClass.setUIContent('pages/page2/page3');
2558  promise.then(() => {
2559    console.info('Succeeded in loading the content.');
2560  }).catch((err: BusinessError) => {
2561    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2562  });
2563} catch (exception) {
2564  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
2565}
2566```
2567
2568### loadContent<sup>9+</sup>
2569
2570loadContent(path: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
2571
2572根据当前工程中某个页面的路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。
2573
2574**模型约束:** 此接口仅可在Stage模型下使用。
2575
2576**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2577
2578**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2579
2580**参数:**
2581
2582| 参数名   | 类型                                            | 必填 | 说明                                                         |
2583| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
2584| path     | string                                          | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 |
2585| storage  | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
2586| callback | AsyncCallback&lt;void&gt;                       | 是   | 回调函数。                                                   |
2587
2588**错误码:**
2589
2590以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2591
2592| 错误码ID | 错误信息 |
2593| ------- | -------------------------------------------- |
2594| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2595| 1300002 | This window state is abnormal.               |
2596| 1300003 | This window manager service works abnormally. |
2597
2598**示例:**
2599
2600```ts
2601import { BusinessError } from '@kit.BasicServicesKit';
2602
2603let storage: LocalStorage = new LocalStorage();
2604storage.setOrCreate('storageSimpleProp', 121);
2605windowClass.loadContent('pages/page2', storage, (err: BusinessError) => {
2606  const errCode: number = err.code;
2607  if (errCode) {
2608    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2609    return;
2610  }
2611  console.info('Succeeded in loading the content.');
2612});
2613```
2614
2615### loadContent<sup>9+</sup>
2616
2617loadContent(path: string, storage: LocalStorage): Promise&lt;void&gt;
2618
2619根据当前工程中某个页面的路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。
2620
2621**模型约束:** 此接口仅可在Stage模型下使用。
2622
2623**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2624
2625**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2626
2627**参数:**
2628
2629| 参数名  | 类型                                            | 必填 | 说明                                                         |
2630| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
2631| path    | string                                          | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 |
2632| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
2633
2634**返回值:**
2635
2636| 类型                | 说明                      |
2637| ------------------- | ------------------------- |
2638| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2639
2640**错误码:**
2641
2642以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2643
2644| 错误码ID | 错误信息 |
2645| ------- | -------------------------------------------- |
2646| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2647| 1300002 | This window state is abnormal.               |
2648| 1300003 | This window manager service works abnormally. |
2649
2650**示例:**
2651
2652```ts
2653import { BusinessError } from '@kit.BasicServicesKit';
2654
2655let storage: LocalStorage = new LocalStorage();
2656storage.setOrCreate('storageSimpleProp', 121);
2657let promise = windowClass.loadContent('pages/page2', storage);
2658promise.then(() => {
2659  console.info('Succeeded in loading the content.');
2660}).catch((err: BusinessError) => {
2661  console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2662});
2663```
2664
2665### loadContentByName<sup>11+</sup>
2666
2667loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
2668
2669为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。
2670
2671**模型约束:** 此接口仅可在Stage模型下使用。
2672
2673**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2674
2675**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2676
2677**参数:**
2678
2679| 参数名   | 类型                                                    | 必填 | 说明                                                         |
2680| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2681| name     | string                                                  | 是   | 命名路由页面的名称。                                             |
2682| storage  | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
2683| callback | AsyncCallback&lt;void&gt;                               | 是   | 回调函数。                                                   |
2684
2685**错误码:**
2686
2687以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2688
2689| 错误码ID | 错误信息                                      |
2690| -------- | --------------------------------------------- |
2691| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2692| 1300002  | This window state is abnormal.                |
2693| 1300003  | This window manager service works abnormally. |
2694
2695**示例:**
2696<!--code_no_check-->
2697```ts
2698import { BusinessError } from '@kit.BasicServicesKit';
2699import * as Index from '../pages/Index'; // 导入命名路由页面
2700
2701console.info('onWindowStageCreate');
2702let storage: LocalStorage = new LocalStorage();
2703storage.setOrCreate('storageSimpleProp', 121);
2704try {
2705  (windowClass as window.Window).loadContentByName(Index.entryName, storage, (err: BusinessError) => {
2706    const errCode: number = err.code;
2707    if (errCode) {
2708      console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2709      return;
2710    }
2711    console.info('Succeeded in loading the content.');
2712  });
2713} catch (exception) {
2714  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
2715}
2716```
2717<!--code_no_check-->
2718```ts
2719// ets/pages/Index.ets
2720export const entryName : string = 'Index';
2721@Entry({routeName: entryName, storage : LocalStorage.getShared()})
2722@Component
2723export struct Index {
2724  @State message: string = 'Hello World'
2725  build() {
2726    Row() {
2727      Column() {
2728        Text(this.message)
2729          .fontSize(50)
2730          .fontWeight(FontWeight.Bold)
2731      }
2732      .width('100%')
2733    }
2734    .height('100%')
2735  }
2736}
2737```
2738
2739### loadContentByName<sup>11+</sup>
2740
2741loadContentByName(name: string, callback: AsyncCallback&lt;void&gt;): void
2742
2743为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面内容,使用callback异步回调。
2744
2745**模型约束:** 此接口仅可在Stage模型下使用。
2746
2747**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2748
2749**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2750
2751**参数:**
2752
2753| 参数名   | 类型                      | 必填 | 说明             |
2754| -------- | ------------------------- | ---- | ---------------- |
2755| name     | string                    | 是   | 命名路由页面的名称。 |
2756| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。       |
2757
2758**错误码:**
2759
2760以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2761
2762| 错误码ID | 错误信息                                      |
2763| -------- | --------------------------------------------- |
2764| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2765| 1300002  | This window state is abnormal.                |
2766| 1300003  | This window manager service works abnormally. |
2767
2768**示例:**
2769<!--code_no_check-->
2770```ts
2771import { BusinessError } from '@kit.BasicServicesKit';
2772import * as Index from '../pages/Index'; // 导入命名路由页面
2773
2774try {
2775  (windowClass as window.Window).loadContentByName(Index.entryName, (err: BusinessError) => {
2776    const errCode: number = err.code;
2777    if (errCode) {
2778      console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2779      return;
2780    }
2781    console.info('Succeeded in loading the content.');
2782  });
2783} catch (exception) {
2784  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
2785}
2786```
2787<!--code_no_check-->
2788```ts
2789// ets/pages/Index.ets
2790export const entryName : string = 'Index';
2791@Entry({routeName: entryName})
2792@Component
2793export struct Index {
2794  @State message: string = 'Hello World'
2795  build() {
2796    Row() {
2797      Column() {
2798        Text(this.message)
2799          .fontSize(50)
2800          .fontWeight(FontWeight.Bold)
2801      }
2802      .width('100%')
2803    }
2804    .height('100%')
2805  }
2806}
2807```
2808
2809### loadContentByName<sup>11+</sup>
2810
2811loadContentByName(name: string, storage?: LocalStorage): Promise&lt;void&gt;
2812
2813为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。
2814
2815**模型约束:** 此接口仅可在Stage模型下使用。
2816
2817**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2818
2819**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2820
2821**参数:**
2822
2823| 参数名  | 类型                                                    | 必填 | 说明                                                         |
2824| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2825| name    | string                                                  | 是   | 命名路由页面的名称。                                             |
2826| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 否   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
2827
2828**返回值:**
2829
2830| 类型                | 说明                      |
2831| ------------------- | ------------------------- |
2832| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2833
2834**错误码:**
2835
2836以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2837
2838| 错误码ID | 错误信息                                      |
2839| -------- | --------------------------------------------- |
2840| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2841| 1300002  | This window state is abnormal.                |
2842| 1300003  | This window manager service works abnormally. |
2843
2844**示例:**
2845<!--code_no_check-->
2846```ts
2847import { BusinessError } from '@kit.BasicServicesKit';
2848import * as Index from '../pages/Index'; // 导入命名路由页面
2849
2850let storage: LocalStorage = new LocalStorage();
2851storage.setOrCreate('storageSimpleProp', 121);
2852try {
2853  let promise = (windowClass as window.Window).loadContentByName(Index.entryName, storage);
2854  promise.then(() => {
2855    console.info('Succeeded in loading the content.');
2856  }).catch((err: BusinessError) => {
2857    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2858  });
2859} catch (exception) {
2860  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
2861}
2862```
2863<!--code_no_check-->
2864```ts
2865// ets/pages/Index.ets
2866export const entryName : string = 'Index';
2867@Entry({routeName: entryName, storage : LocalStorage.getShared()})
2868@Component
2869export struct Index {
2870  @State message: string = 'Hello World'
2871  build() {
2872    Row() {
2873      Column() {
2874        Text(this.message)
2875          .fontSize(50)
2876          .fontWeight(FontWeight.Bold)
2877      }
2878      .width('100%')
2879    }
2880    .height('100%')
2881  }
2882}
2883```
2884
2885### isWindowShowing<sup>9+</sup>
2886
2887isWindowShowing(): boolean
2888
2889判断当前窗口是否已显示。
2890
2891**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2892
2893**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2894
2895**返回值:**
2896
2897| 类型 | 说明 |
2898| ------- | ------------------------------------------------------------------ |
2899| boolean | 当前窗口是否已显示。true表示当前窗口已显示,false则表示当前窗口未显示。 |
2900
2901**错误码:**
2902
2903以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
2904
2905| 错误码ID | 错误信息 |
2906| ------- | ------------------------------ |
2907| 1300002 | This window state is abnormal. |
2908
2909**示例:**
2910
2911```ts
2912try {
2913  let data = windowClass.isWindowShowing();
2914  console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
2915} catch (exception) {
2916  console.error(`Failed to check whether the window is showing. Cause code: ${exception.code}, message: ${exception.message}`);
2917}
2918```
2919
2920### on('windowSizeChange')<sup>7+</sup>
2921
2922on(type:  'windowSizeChange', callback: Callback&lt;Size&gt;): void
2923
2924开启窗口尺寸变化的监听。
2925
2926**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2927
2928**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2929
2930**参数:**
2931
2932| 参数名   | 类型                           | 必填 | 说明                                                     |
2933| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
2934| type     | string                         | 是   | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 |
2935| callback | Callback&lt;[Size](#size7)&gt; | 是   | 回调函数。返回当前的窗口尺寸。                           |
2936
2937**错误码:**
2938
2939以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2940
2941| 错误码ID | 错误信息 |
2942| ------- | -------------------------------------------- |
2943| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2944
2945**示例:**
2946
2947```ts
2948try {
2949  windowClass.on('windowSizeChange', (data) => {
2950    console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data));
2951  });
2952} catch (exception) {
2953  console.error(`Failed to enable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`);
2954}
2955```
2956
2957### off('windowSizeChange')<sup>7+</sup>
2958
2959off(type: 'windowSizeChange', callback?: Callback&lt;Size&gt;): void
2960
2961关闭窗口尺寸变化的监听。
2962
2963**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2964
2965**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2966
2967**参数:**
2968
2969| 参数名   | 类型                          | 必填 | 说明                                                     |
2970| -------- | ----------------------------- | ---- | -------------------------------------------------------- |
2971| type     | string                        | 是   | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 |
2972| callback | Callback&lt;[Size](#size7)&gt; | 否   | 回调函数。返回当前的窗口尺寸。如果传入参数,则关闭该监听。如果未传入参数,则关闭窗口尺寸变化的监听。                           |
2973
2974**错误码:**
2975
2976以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2977
2978| 错误码ID | 错误信息 |
2979| ------- | -------------------------------------------- |
2980| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
2981
2982**示例:**
2983
2984```ts
2985const callback = (size: window.Size) => {
2986  // ...
2987}
2988try {
2989  // 通过on接口开启监听
2990  windowClass.on('windowSizeChange', callback);
2991  // 关闭指定callback的监听
2992  windowClass.off('windowSizeChange', callback);
2993  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
2994  windowClass.off('windowSizeChange');
2995} catch (exception) {
2996  console.error(`Failed to disable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`);
2997}
2998```
2999
3000### on('avoidAreaChange')<sup>9+</sup>
3001
3002on(type: 'avoidAreaChange', callback: Callback&lt;AvoidAreaOptions&gt;): void
3003
3004开启当前应用窗口系统规避区变化的监听。
3005
3006**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3007
3008**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3009
3010**参数:**
3011
3012| 参数名   | 类型                              | 必填 | 说明                                  |
3013| -------- |----------------------------------| ---- |--------------------------------------|
3014| type     | string                           | 是   | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 |
3015| callback | Callback&lt;[AvoidAreaOptions](#avoidareaoptions12)&gt; | 是   | 回调函数。返回当前规避区以及规避区类型。|
3016
3017**错误码:**
3018
3019以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3020
3021| 错误码ID | 错误信息 |
3022| ------- | -------------------------------------------- |
3023| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3024
3025**示例:**
3026
3027```ts
3028try {
3029  windowClass.on('avoidAreaChange', (data) => {
3030    console.info('Succeeded in enabling the listener for system avoid area changes. type:' +
3031    JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area));
3032  });
3033} catch (exception) {
3034  console.error(`Failed to enable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`);
3035}
3036```
3037
3038### off('avoidAreaChange')<sup>9+</sup>
3039
3040off(type: 'avoidAreaChange', callback?: Callback&lt;AvoidAreaOptions&gt;): void
3041
3042关闭当前窗口系统规避区变化的监听。
3043
3044**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3045
3046**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3047
3048**参数:**
3049
3050| 参数名   | 类型                              | 必填 | 说明                                |
3051| -------- |----------------------------------|------|------------------------------------|
3052| type     | string                           | 是   | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 |
3053| callback | Callback&lt;[AvoidAreaOptions](#avoidareaoptions12)&gt; | 否   | 回调函数。返回当前规避区以及规避区类型。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有系统规避区变化的监听。|
3054
3055**错误码:**
3056
3057以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3058
3059| 错误码ID | 错误信息 |
3060| ------- | -------------------------------------------- |
3061| 401     | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed. |
3062
3063**示例:**
3064
3065```ts
3066interface Param {
3067  type: window.AvoidAreaType,
3068  area: window.AvoidArea
3069}
3070const callback = (data: Param) => {
3071  // ...
3072}
3073try {
3074  windowClass.on('avoidAreaChange', callback);
3075
3076  windowClass.off('avoidAreaChange', callback);
3077  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3078  windowClass.off('avoidAreaChange');
3079} catch (exception) {
3080  console.error(`Failed to enable or disable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`);
3081}
3082```
3083
3084### on('keyboardHeightChange')<sup>7+</sup>
3085
3086on(type: 'keyboardHeightChange', callback: Callback&lt;number&gt;): void
3087
3088开启固定态软键盘高度变化的监听,当软键盘由本窗口唤出并存在重叠区域时通知键盘高度变化。从API version 10开始,改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
3089
3090**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3091
3092**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3093
3094**参数:**
3095
3096| 参数名   | 类型                | 必填 | 说明                                        |
3097| -------- | ------------------- | ---- |-------------------------------------------|
3098| type     | string              | 是   | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 |
3099| callback | Callback&lt;number&gt; | 是   | 回调函数。返回当前的键盘高度,返回值为整数,单位为px。     |
3100
3101**错误码:**
3102
3103以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3104
3105| 错误码ID | 错误信息 |
3106| ------- | -------------------------------------------- |
3107| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3108
3109**示例:**
3110
3111```ts
3112import { BusinessError } from '@kit.BasicServicesKit';
3113
3114try {
3115  windowClass.on('keyboardHeightChange', (data) => {
3116    console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data));
3117  });
3118} catch (exception) {
3119  console.error(`Failed to enable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`);
3120}
3121```
3122
3123### off('keyboardHeightChange')<sup>7+</sup>
3124
3125off(type: 'keyboardHeightChange', callback?: Callback&lt;number&gt;): void
3126
3127关闭固定态软键盘高度变化的监听。从API version 10开始,改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
3128
3129**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3130
3131**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3132
3133**参数:**
3134
3135| 参数名   | 类型                   | 必填 | 说明                                                         |
3136| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
3137| type     | string                 | 是   | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 |
3138| callback | Callback&lt;number&gt; | 否   | 回调函数。返回当前的键盘高度,返回值为整数,单位为px。若传入参数,则关闭该监听。如果未传入参数,则关闭所有固定态软键盘高度变化的监听。                               |
3139
3140**错误码:**
3141
3142以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3143
3144| 错误码ID | 错误信息 |
3145| ------- | -------------------------------------------- |
3146| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3147
3148**示例:**
3149
3150```ts
3151import { BusinessError } from '@kit.BasicServicesKit';
3152
3153const callback = (height: number) => {
3154  // ...
3155}
3156try {
3157  windowClass.on('keyboardHeightChange', callback);
3158
3159  windowClass.off('keyboardHeightChange', callback);
3160  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3161  windowClass.off('keyboardHeightChange');
3162} catch (exception) {
3163  console.error(`Failed to disable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`);
3164}
3165```
3166
3167### on('touchOutside')<sup>11+</sup>
3168
3169on(type: 'touchOutside', callback: Callback&lt;void&gt;): void
3170
3171开启本窗口区域范围外的点击事件的监听。
3172
3173**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3174
3175**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3176
3177**参数:**
3178
3179| 参数名   | 类型                | 必填 | 说明                                                         |
3180| -------- | ------------------- | ---- | ------------------------------------------------------------ |
3181| type     | string              | 是   | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 |
3182| callback | Callback&lt;void&gt; | 是   | 回调函数。当点击事件发生在本窗口范围之外的回调。                               |
3183
3184**错误码:**
3185
3186以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3187
3188| 错误码ID | 错误信息 |
3189| ------- | -------------------------------------------- |
3190| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3191
3192**示例:**
3193
3194```ts
3195try {
3196  windowClass.on('touchOutside', () => {
3197    console.info('touch outside');
3198  });
3199} catch (exception) {
3200  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
3201}
3202```
3203
3204### off('touchOutside')<sup>11+</sup>
3205
3206off(type: 'touchOutside', callback?: Callback&lt;void&gt;): void
3207
3208关闭本窗口区域范围外的点击事件的监听。
3209
3210**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3211
3212**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3213
3214**参数:**
3215
3216| 参数名   | 类型                   | 必填 | 说明                                   |
3217| -------- |----------------------| ---- |--------------------------------------|
3218| type     | string               | 是   | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 |
3219| callback | Callback&lt;void&gt; | 否   | 回调函数。当点击事件发生在本窗口范围之外的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口区域范围外的点击事件的监听。            |
3220
3221**错误码:**
3222
3223以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3224
3225| 错误码ID | 错误信息 |
3226| ------- | -------------------------------------------- |
3227| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3228
3229**示例:**
3230
3231```ts
3232const callback = () => {
3233  // ...
3234}
3235try {
3236  windowClass.on('touchOutside', callback);
3237  windowClass.off('touchOutside', callback);
3238  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3239  windowClass.off('touchOutside');
3240} catch (exception) {
3241  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3242}
3243```
3244
3245### on('screenshot')<sup>9+</sup>
3246
3247on(type: 'screenshot', callback: Callback&lt;void&gt;): void
3248
3249开启截屏事件的监听。
3250
3251**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3252
3253**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3254
3255**参数:**
3256
3257| 参数名   | 类型                | 必填 | 说明                                                         |
3258| -------- | ------------------- | ---- | ------------------------------------------------------------ |
3259| type     | string              | 是   | 监听事件,固定为'screenshot',即截屏事件,对控制中心截屏、hdc命令截屏、整屏截屏接口生效。 |
3260| callback | Callback&lt;void&gt; | 是   | 回调函数。发生截屏事件时的回调。                               |
3261
3262**错误码:**
3263
3264以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3265
3266| 错误码ID | 错误信息 |
3267| ------- | -------------------------------------------- |
3268| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3269
3270**示例:**
3271
3272```ts
3273try {
3274  windowClass.on('screenshot', () => {
3275    console.info('screenshot happened');
3276  });
3277} catch (exception) {
3278  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
3279}
3280```
3281
3282### off('screenshot')<sup>9+</sup>
3283
3284off(type: 'screenshot', callback?: Callback&lt;void&gt;): void
3285
3286关闭截屏事件的监听。
3287
3288**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3289
3290**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3291
3292**参数:**
3293
3294| 参数名   | 类型                   | 必填 | 说明                                                         |
3295| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
3296| type     | string                 | 是   | 监听事件,固定为'screenshot',即截屏事件。 |
3297| callback | Callback&lt;void&gt; | 否   | 回调函数。发生截屏事件时的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有截屏事件的监听。 |
3298
3299**错误码:**
3300
3301以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3302
3303| 错误码ID | 错误信息 |
3304| ------- | -------------------------------------------- |
3305| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3306
3307**示例:**
3308
3309```ts
3310let callback = () => {
3311  console.info('screenshot happened');
3312};
3313try {
3314  windowClass.on('screenshot', callback);
3315  windowClass.off('screenshot', callback);
3316  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3317  windowClass.off('screenshot');
3318} catch (exception) {
3319  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3320}
3321```
3322
3323### on('dialogTargetTouch')<sup>10+</sup>
3324
3325on(type: 'dialogTargetTouch', callback: Callback&lt;void&gt;): void
3326
3327开启模态窗口所遮盖窗口的点击或触摸事件的监听,除模态窗口以外其他窗口调用此接口不生效。
3328
3329**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3330
3331**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3332
3333**参数:**
3334
3335| 参数名   | 类型                 | 必填 | 说明                                                          |
3336| -------- | ------------------- | ---- | ------------------------------------------------------------ |
3337| type     | string              | 是   | 监听事件,固定为'dialogTargetTouch',即模态窗口所遮盖窗口的点击或触摸事件。 |
3338| callback | Callback&lt;void&gt;| 是   | 回调函数。当点击或触摸事件发生在模态窗口所遮盖窗口的回调。 |
3339
3340**错误码:**
3341
3342以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3343
3344| 错误码ID | 错误信息 |
3345| ------- | -------------------------------------------- |
3346| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3347
3348**示例:**
3349
3350```ts
3351try {
3352  windowClass.on('dialogTargetTouch', () => {
3353    console.info('touch dialog target');
3354  });
3355} catch (exception) {
3356  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
3357}
3358```
3359
3360### off('dialogTargetTouch')<sup>10+</sup>
3361
3362off(type: 'dialogTargetTouch', callback?: Callback&lt;void&gt;): void
3363
3364关闭模态窗口目标窗口的点击事件的监听。
3365
3366**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3367
3368**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3369
3370**参数:**
3371
3372| 参数名   | 类型                    | 必填 | 说明                                                          |
3373| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
3374| type     | string                 | 是   | 监听事件,固定为'dialogTargetTouch',即模态窗口目标窗口的点击事件。 |
3375| callback | Callback&lt;void&gt;      | 否   | 回调函数。当点击事件发生在模态窗口目标窗口的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有模态窗口目标窗口的点击事件的监听。 |
3376
3377**错误码:**
3378
3379以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3380
3381| 错误码ID | 错误信息 |
3382| ------- | -------------------------------------------- |
3383| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3384
3385**示例:**
3386
3387```ts
3388const callback = () => {
3389  // ...
3390}
3391try {
3392  windowClass.on('dialogTargetTouch', callback);
3393  windowClass.off('dialogTargetTouch', callback);
3394  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3395  windowClass.off('dialogTargetTouch');
3396} catch (exception) {
3397  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3398}
3399```
3400
3401### on('windowEvent')<sup>10+</sup>
3402
3403on(type: 'windowEvent', callback: Callback&lt;WindowEventType&gt;): void
3404
3405开启窗口生命周期变化的监听。
3406
3407**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3408
3409**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3410
3411**参数:**
3412
3413| 参数名   | 类型                                                       | 必填 | 说明                                                         |
3414| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
3415| type     | string                                                     | 是   | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 |
3416| callback | Callback&lt;[WindowEventType](#windoweventtype10)&gt; | 是   | 回调函数。返回当前的窗口生命周期状态。                 |
3417
3418**错误码:**
3419
3420以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3421
3422| 错误码ID | 错误信息 |
3423| ------- | -------------------------------------------- |
3424| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3425
3426**示例:**
3427
3428```ts
3429try {
3430  windowClass.on('windowEvent', (data) => {
3431    console.info('Window event happened. Event:' + JSON.stringify(data));
3432  });
3433} catch (exception) {
3434  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
3435}
3436```
3437
3438### off('windowEvent')<sup>10+</sup>
3439
3440off(type: 'windowEvent', callback?: Callback&lt;WindowEventType&gt;): void
3441
3442关闭窗口生命周期变化的监听。
3443
3444**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3445
3446**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3447
3448**参数:**
3449
3450| 参数名   | 类型                                                       | 必填 | 说明                                                         |
3451| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
3452| type     | string                                                     | 是   | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 |
3453| callback | Callback&lt;[WindowEventType](#windoweventtype10)&gt; | 否   | 回调函数。返回当前的窗口生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有窗口生命周期变化的监听。                 |
3454
3455**错误码:**
3456
3457以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3458
3459| 错误码ID | 错误信息 |
3460| ------- | -------------------------------------------- |
3461| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3462
3463**示例:**
3464
3465```ts
3466const callback = (windowEventType: window.WindowEventType) => {
3467  // ...
3468}
3469try {
3470  // 通过on接口开启监听
3471  windowClass.on('windowEvent', callback);
3472  // 关闭指定callback的监听
3473  windowClass.off('windowEvent', callback);
3474  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3475  windowClass.off('windowEvent');
3476} catch (exception) {
3477  console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3478}
3479```
3480
3481### on('windowVisibilityChange')<sup>11+</sup>
3482
3483on(type: 'windowVisibilityChange', callback: Callback&lt;boolean&gt;): void
3484
3485开启本窗口可见状态变化事件的监听。
3486
3487**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3488
3489**系统能力:** SystemCapability.Window.SessionManager
3490
3491**参数:**
3492
3493| 参数名   | 类型                       | 必填 | 说明                                                         |
3494| -------- | --------------------------| ---- | ------------------------------------------------------------ |
3495| type     | string                    | 是   | 监听事件,固定为'windowVisibilityChange',即本窗口可见状态变化的事件。 |
3496| callback | Callback&lt;boolean&gt;   | 是   | 回调函数。当本窗口可见状态发生变化后的回调。回调函数返回boolean类型参数,当返回参数为true时表示窗口可见,否则表示窗口不可见。                               |
3497
3498**错误码:**
3499
3500以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3501
3502| 错误码ID | 错误信息 |
3503| ------- | ------------------------------ |
3504| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3505| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3506| 1300002 | This window state is abnormal.                |
3507| 1300003 | This window manager service works abnormally. |
3508
3509**示例:**
3510
3511```ts
3512try {
3513  windowClass.on('windowVisibilityChange', (boolean) => {
3514    console.info('Window visibility changed, isVisible=' + boolean);
3515  });
3516} catch (exception) {
3517  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
3518}
3519```
3520
3521### off('windowVisibilityChange')<sup>11+</sup>
3522
3523off(type: 'windowVisibilityChange', callback?: Callback&lt;boolean&gt;): void
3524
3525关闭本窗口可见状态变化事件的监听。
3526
3527**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3528
3529**系统能力:** SystemCapability.Window.SessionManager
3530
3531**参数:**
3532
3533| 参数名   | 类型                        | 必填 | 说明                                   |
3534| -------- |----------------------------| ---- |--------------------------------------|
3535| type     | string                     | 是   | 监听事件,固定为'windowVisibilityChange',即本窗口可见状态变化的事件。 |
3536| callback | Callback&lt;boolean&gt;    | 否   | 回调函数。当本窗口可见状态发生变化时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口可见状态变化事件的回调。            |
3537
3538**错误码:**
3539
3540以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3541
3542| 错误码ID | 错误信息 |
3543| ------- | ------------------------------ |
3544| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3545| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3546| 1300002 | This window state is abnormal.                |
3547| 1300003 | This window manager service works abnormally. |
3548
3549**示例:**
3550
3551```ts
3552const callback = (bool: boolean) => {
3553  // ...
3554}
3555try {
3556  // 通过on接口开启监听
3557  windowClass.on('windowVisibilityChange', callback);
3558  // 关闭指定callback的监听
3559  windowClass.off('windowVisibilityChange', callback);
3560  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3561  windowClass.off('windowVisibilityChange');
3562} catch (exception) {
3563  console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3564}
3565```
3566
3567### on('noInteractionDetected')<sup>12+</sup>
3568
3569on(type: 'noInteractionDetected', timeout: number, callback: Callback&lt;void&gt;): void
3570
3571开启本窗口在指定超时时间内无交互事件的监听,交互事件支持物理键盘输入事件和屏幕触控点击事件,不支持软键盘输入事件。
3572
3573**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3574
3575**系统能力:** SystemCapability.Window.SessionManager
3576
3577**参数:**
3578
3579| 参数名   | 类型                       | 必填 | 说明                                                         |
3580| -------- | --------------------------| ---- | ------------------------------------------------------------ |
3581| type     | string                    | 是   | 监听事件,固定为'noInteractionDetected',即本窗口在指定超时时间内无交互的事件。 |
3582| timeout     | number                    | 是   | 指定本窗口在多长时间内无交互即回调,单位为秒(s)。该参数仅支持整数输入,负数和小数为非法参数。 |
3583| callback | Callback&lt;void&gt;      | 是   | 回调函数。当本窗口在指定超时时间内无交互事件时的回调。  |
3584
3585**错误码:**
3586
3587以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3588
3589| 错误码ID | 错误信息 |
3590| ------- | ------------------------------ |
3591| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3592| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3593| 1300002 | This window state is abnormal.                |
3594| 1300003 | This window manager service works abnormally. |
3595
3596**示例:**
3597
3598```ts
3599try {
3600  windowClass.on('noInteractionDetected', 60, () => {
3601    console.info('no interaction in 60s');
3602  });
3603} catch (exception) {
3604  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
3605}
3606```
3607
3608### off('noInteractionDetected')<sup>12+</sup>
3609
3610off(type: 'noInteractionDetected', callback?: Callback&lt;void&gt;): void
3611
3612关闭本窗口在指定超时时间内无交互事件的监听,交互事件支持物理键盘输入事件和屏幕触控点击事件,不支持软键盘输入事件。
3613
3614**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3615
3616**系统能力:** SystemCapability.Window.SessionManager
3617
3618**参数:**
3619
3620| 参数名   | 类型                        | 必填 | 说明                                   |
3621| -------- |----------------------------| ---- |--------------------------------------|
3622| type     | string                     | 是   | 监听事件,固定为'noInteractionDetected',即本窗口在指定超时时间内无交互的事件。 |
3623| callback | Callback&lt;void&gt;    | 否   | 回调函数,当本窗口在指定超时时间内无交互事件时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口在指定超时时间内无交互事件的监听。 |
3624
3625**错误码:**
3626
3627以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3628
3629| 错误码ID | 错误信息 |
3630| ------- | ------------------------------ |
3631| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3632| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3633| 1300002 | This window state is abnormal.                |
3634| 1300003 | This window manager service works abnormally. |
3635
3636**示例:**
3637
3638```ts
3639const callback = () => {
3640  // ...
3641}
3642try {
3643  windowClass.on('noInteractionDetected', 60, callback);
3644  windowClass.off('noInteractionDetected', callback);
3645  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3646  windowClass.off('noInteractionDetected');
3647} catch (exception) {
3648  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3649}
3650```
3651
3652### on('windowStatusChange')<sup>11+</sup>
3653
3654on(type:  'windowStatusChange', callback: Callback&lt;WindowStatusType&gt;): void
3655
3656开启窗口模式变化的监听,当窗口windowStatus发生变化时进行通知(此时窗口属性可能还没有更新)。
3657
3658**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3659
3660**系统能力:** SystemCapability.Window.SessionManager
3661
3662**参数:**
3663
3664| 参数名   | 类型                           | 必填 | 说明                                                     |
3665| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
3666| type     | string                         | 是   | 监听事件,固定为'windowStatusChange',即窗口模式变化事件。 |
3667| callback | Callback&lt;[WindowStatusType](#windowstatustype11)&gt; | 是   | 回调函数。返回当前的窗口模式。                           |
3668
3669**错误码:**
3670
3671以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3672
3673| 错误码ID | 错误信息 |
3674| ------- | ------------------------------ |
3675| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3676| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3677
3678**示例:**
3679
3680```ts
3681try {
3682    windowClass.on('windowStatusChange', (WindowStatusType) => {
3683        console.info('Succeeded in enabling the listener for window status changes. Data: ' + JSON.stringify(WindowStatusType));
3684    });
3685} catch (exception) {
3686    console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3687}
3688```
3689
3690### off('windowStatusChange')<sup>11+</sup>
3691
3692off(type: 'windowStatusChange', callback?: Callback&lt;WindowStatusType&gt;): void
3693
3694关闭窗口模式变化的监听。
3695
3696**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3697
3698**系统能力:** SystemCapability.Window.SessionManager
3699
3700**参数:**
3701
3702| 参数名   | 类型                          | 必填 | 说明                                                     |
3703| -------- | ----------------------------- | ---- | -------------------------------------------------------- |
3704| type     | string                        | 是   | 监听事件,固定为'windowStatusChange',即窗口模式变化事件。 |
3705| callback | Callback&lt;[WindowStatusType](#windowstatustype11)&gt; | 否   | 回调函数。返回当前的窗口模式。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有窗口模式变化的监听。                           |
3706
3707**错误码:**
3708
3709以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3710
3711| 错误码ID | 错误信息 |
3712| ------- | ------------------------------ |
3713| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3714| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3715
3716**示例:**
3717
3718```ts
3719const callback = (windowStatusType: window.WindowStatusType) => {
3720    // ...
3721}
3722try {
3723    windowClass.on('windowStatusChange', callback);
3724    windowClass.off('windowStatusChange', callback);
3725    // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3726    windowClass.off('windowStatusChange');
3727} catch (exception) {
3728    console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3729}
3730```
3731
3732### setWindowGrayScale<sup>12+</sup>
3733
3734setWindowGrayScale(grayScale: number): Promise&lt;void&gt;
3735
3736设置窗口灰阶,使用Promise异步回调。该接口需要在调用[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)使窗口加载页面内容后调用。
3737
3738**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3739
3740**系统能力:** SystemCapability.Window.SessionManager
3741
3742**参数:**
3743
3744| 参数名 | 类型 | 必填 | 说明                                     |
3745| --------- | ------ | -- | ---------------------------------------- |
3746| grayScale | number | 是 | 窗口灰阶。该参数为浮点数,取值范围为[0.0, 1.0]。0.0表示窗口图像无变化,1.0表示窗口图像完全转为灰度图像,0.0至1.0之间时效果呈线性变化。 |
3747
3748**返回值:**
3749
3750| 类型 | 说明 |
3751| ------------------- | ------------------------ |
3752| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
3753
3754**错误码:**
3755
3756以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3757
3758| 错误码ID | 错误信息 |
3759| ------- | --------------------------------------------- |
3760| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3761| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3762| 1300002 | This window state is abnormal.                |
3763| 1300003 | This window manager service works abnormally. |
3764
3765**示例:**
3766
3767```ts
3768import { BusinessError } from '@kit.BasicServicesKit';
3769
3770windowClass?.setUIContent('pages/Index', (error: BusinessError) => {
3771  if (error.code) {
3772    console.error(`Failed to set the content. Cause code: ${error.code}`);
3773    return;
3774  }
3775  console.info('Succeeded in setting the content.');
3776  let grayScale: number = 0.5;
3777  try {
3778    if (canIUse("SystemCapability.Window.SessionManager")) {
3779      let promise = windowClass?.setWindowGrayScale(grayScale);
3780      promise?.then(() => {
3781        console.info('Succeeded in setting the grayScale.');
3782      }).catch((err: BusinessError) => {
3783        console.error(`Failed to set the grayScale. Cause code: ${err.code}, message: ${err.message}`);
3784      });
3785    }
3786  } catch (exception) {
3787    console.error(`Failed to set the grayScale. Cause code: ${exception.code}, message: ${exception.message}`);
3788  }
3789});
3790```
3791
3792### on('windowTitleButtonRectChange')<sup>11+</sup>
3793
3794on(type: 'windowTitleButtonRectChange', callback: Callback&lt;TitleButtonRect&gt;): void
3795
3796开启窗口标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
3797
3798**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3799
3800**系统能力:** SystemCapability.Window.SessionManager
3801
3802**参数:**
3803
3804| 参数名   | 类型                                                  | 必填 | 说明                                                         |
3805| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
3806| type     | string                                                | 是   | 监听事件,固定为'windowTitleButtonRectChange',即标题栏上的最小化、最大化、关闭按钮矩形区域变化事件。 |
3807| callback | Callback&lt;[TitleButtonRect](#titlebuttonrect11)&gt; | 是   | 回调函数。返回当前标题栏上的最小化、最大化、关闭按钮矩形区域。 |
3808
3809**错误码:**
3810
3811以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3812
3813| 错误码ID | 错误信息                       |
3814| -------- | ------------------------------ |
3815| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3816| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
3817| 1300002  | This window state is abnormal. |
3818
3819**示例:**
3820
3821```ts
3822windowClass.setUIContent('pages/WindowPage').then(() => {
3823  try {
3824    windowClass?.on('windowTitleButtonRectChange', (titleButtonRect) => {
3825      console.info('Succeeded in enabling the listener for window title buttons area changes. Data: ' + JSON.stringify(titleButtonRect));
3826    });
3827  } catch (exception) {
3828    console.error(`Failed to enable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`);
3829  }
3830})
3831```
3832
3833### off('windowTitleButtonRectChange')<sup>11+</sup>
3834
3835off(type: 'windowTitleButtonRectChange', callback?: Callback&lt;TitleButtonRect&gt;): void
3836
3837关闭窗口标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
3838
3839**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3840
3841**系统能力:** SystemCapability.Window.SessionManager
3842
3843**参数:**
3844
3845| 参数名   | 类型                                                  | 必填 | 说明                                                         |
3846| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
3847| type     | string                                                | 是   | 监听事件,固定为'windowTitleButtonRectChange',即标题栏上的最小化、最大化、关闭按钮矩形区域变化事件。 |
3848| callback | Callback&lt;[TitleButtonRect](#titlebuttonrect11)&gt; | 否   | 回调函数。返回当前标题栏上的最小化、最大化、关闭按钮矩形区域。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听。 |
3849
3850**错误码:**
3851
3852以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3853
3854| 错误码ID | 错误信息                       |
3855| -------- | ------------------------------ |
3856| 401      | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3857| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
3858| 1300002  | This window state is abnormal. |
3859
3860**示例:**
3861
3862```ts
3863windowClass.setUIContent('pages/WindowPage').then(() => {
3864	const callback = (titleButtonRect: window.TitleButtonRect) => {
3865		// ...
3866	}
3867  try {
3868    // 通过on接口开启监听
3869    windowClass?.on('windowTitleButtonRectChange', callback);
3870    // 关闭指定callback的监听
3871    windowClass?.off('windowTitleButtonRectChange', callback);
3872    // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3873    windowClass?.off('windowTitleButtonRectChange');
3874  } catch (exception) {
3875    console.error(`Failed to disable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`);
3876  }
3877})
3878```
3879
3880### on('windowRectChange')<sup>12+</sup>
3881
3882on(type:  'windowRectChange', callback: Callback&lt;RectChangeOptions&gt;): void
3883
3884开启窗口矩形(窗口位置及窗口大小)变化的监听。
3885
3886**系统能力:** SystemCapability.Window.SessionManager
3887
3888**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3889
3890**参数:**
3891
3892| 参数名   | 类型                           | 必填 | 说明                                                     |
3893| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
3894| type     | string                         | 是   | 监听事件,固定为'windowRectChange',即窗口矩形变化事件。 |
3895| callback | Callback&lt;[RectChangeOptions](#rectchangeoptions12)&gt; | 是   | 回调函数。返回当前窗口矩形变化值及变化原因。                           |
3896
3897**错误码:**
3898
3899以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3900
3901| 错误码ID | 错误信息 |
3902| ------- | -------------------------------------------- |
3903| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3904| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3905| 1300002 | This window state is abnormal. |
3906| 1300003 | This window manager service works abnormally. |
3907
3908**示例:**
3909
3910```ts
3911windowClass.on('windowRectChange', (data: window.RectChangeOptions) => {
3912    console.info('Succeeded window rect changes. Data: ' + JSON.stringify(data));
3913});
3914```
3915
3916### off('windowRectChange')<sup>12+</sup>
3917
3918off(type: 'windowRectChange', callback?: Callback&lt;RectChangeOptions&gt;): void
3919
3920关闭窗口矩形(窗口位置及窗口大小)变化的监听。
3921
3922**系统能力:** SystemCapability.Window.SessionManager
3923
3924**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3925
3926**参数:**
3927
3928| 参数名   | 类型                           | 必填 | 说明                                                         |
3929| -------- | ------------------------------ | ---- | ------------------------------------------------------------ |
3930| type     | string                         | 是   | 监听事件,固定为'windowRectChange',即窗口矩形变化事件。     |
3931| callback | Callback&lt;[RectChangeOptions](#rectchangeoptions12)&gt; | 否   | 回调函数。返回当前的窗口矩形及变化原因。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有窗口矩形变化的监听。 |
3932
3933**错误码:**
3934
3935以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3936
3937| 错误码ID | 错误信息 |
3938| ------- | -------------------------------------------- |
3939| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3940| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3941| 1300002 | This window state is abnormal. |
3942| 1300003 | This window manager service works abnormally. |
3943
3944**示例:**
3945
3946```ts
3947const callback = (rectChangeOptions: window.RectChangeOptions) => {
3948  // ...
3949}
3950windowClass.on('windowRectChange', callback);
3951windowClass.off('windowRectChange', callback);
3952// 如果通过on开启多个callback进行监听,同时关闭所有监听:
3953windowClass.off('windowRectChange');
3954```
3955
3956### on('subWindowClose')<sup>12+</sup>
3957
3958on(type:  'subWindowClose', callback: Callback&lt;void&gt;): void
3959
3960开启子窗口关闭事件的监听。此监听仅在点击系统提供的右上角关闭按钮关闭子窗时触发,其余关闭方式不触发回调。
3961
3962**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3963
3964**系统能力:** SystemCapability.Window.SessionManager
3965
3966**参数:**
3967
3968| 参数名   | 类型                           | 必填 | 说明                                                     |
3969| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
3970| type     | string                         | 是   | 监听事件,固定为'subWindowClose',即子窗口关闭事件。 |
3971| callback | Callback&lt;void&gt; | 是   | 回调函数。当点击子窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前子窗是否继续关闭,true表示不关闭子窗,false表示关闭子窗。   |
3972
3973**错误码:**
3974
3975以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3976
3977| 错误码ID | 错误信息 |
3978| ------- | -------------------------------------------- |
3979| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3980| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3981| 1300002 | This window state is abnormal. |
3982| 1300004 | Unauthorized operation. |
3983
3984**示例:**
3985
3986```ts
3987const callback = () => {
3988  // ...
3989  return true;
3990}
3991try {
3992  windowClass.on('subWindowClose', callback);
3993} catch (exception) {
3994  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
3995}
3996```
3997
3998### off('subWindowClose')<sup>12+</sup>
3999
4000off(type: 'subWindowClose', callback?: Callback&lt;void&gt;): void
4001
4002关闭子窗口关闭事件的监听。
4003
4004**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4005
4006**系统能力:** SystemCapability.Window.SessionManager
4007
4008**参数:**
4009
4010| 参数名   | 类型                           | 必填 | 说明                                                         |
4011| -------- | ------------------------------ | ---- | ------------------------------------------------------------ |
4012| type     | string                         | 是   | 监听事件,固定为'subWindowClose',即子窗口关闭事件。     |
4013| callback | Callback&lt;void&gt; | 否   | 回调函数。当点击子窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前子窗是否继续关闭,true表示不关闭子窗,false表示关闭子窗。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有子窗口关闭的监听。 |
4014
4015**错误码:**
4016
4017以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4018
4019| 错误码ID | 错误信息 |
4020| ------- | -------------------------------------------- |
4021| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
4022| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
4023| 1300002 | This window state is abnormal. |
4024| 1300004 | Unauthorized operation. |
4025
4026**示例:**
4027
4028```ts
4029const callback = () => {
4030  // ...
4031  return true;
4032}
4033try {
4034  windowClass.on('subWindowClose', callback);
4035  windowClass.off('subWindowClose', callback);
4036  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
4037  windowClass.off('subWindowClose');
4038} catch (exception) {
4039  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
4040}
4041```
4042
4043### isWindowSupportWideGamut<sup>9+</sup>
4044
4045isWindowSupportWideGamut(callback: AsyncCallback&lt;boolean&gt;): void
4046
4047判断当前窗口是否支持广色域模式,使用callback异步回调。
4048
4049**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4050
4051**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4052
4053**参数:**
4054
4055| 参数名 | 类型 | 必填 | 说明 |
4056| -------- | ---------------------------- | -- | -------------------------------------------------------------------------------- |
4057| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 |
4058
4059**错误码:**
4060
4061以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
4062
4063| 错误码ID | 错误信息 |
4064| ------- | ------------------------------ |
4065| 1300002 | This window state is abnormal. |
4066
4067**示例:**
4068
4069```ts
4070import { BusinessError } from '@kit.BasicServicesKit';
4071
4072windowClass.isWindowSupportWideGamut((err: BusinessError, data) => {
4073  const errCode: number = err.code;
4074  if (errCode) {
4075    console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`);
4076    return;
4077  }
4078  console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data));
4079});
4080```
4081
4082### isWindowSupportWideGamut<sup>9+</sup>
4083
4084isWindowSupportWideGamut(): Promise&lt;boolean&gt;
4085
4086判断当前窗口是否支持广色域模式,使用Promise异步回调。
4087
4088**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4089
4090**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4091
4092**返回值:**
4093
4094| 类型 | 说明 |
4095| ---------------------- | ------------------------------------------------------------------------------------ |
4096| Promise&lt;boolean&gt; | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 |
4097
4098**错误码:**
4099
4100以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
4101
4102| 错误码ID | 错误信息 |
4103| ------- | ------------------------------ |
4104| 1300002 | This window state is abnormal. |
4105
4106**示例:**
4107
4108```ts
4109import { BusinessError } from '@kit.BasicServicesKit';
4110
4111let promise = windowClass.isWindowSupportWideGamut();
4112promise.then((data) => {
4113  console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data));
4114}).catch((err: BusinessError) => {
4115  console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`);
4116});
4117```
4118
4119### setWindowColorSpace<sup>9+</sup>
4120
4121setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback&lt;void&gt;): void
4122
4123设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。
4124
4125**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4126
4127**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4128
4129**参数:**
4130
4131| 参数名 | 类型 | 必填 | 说明 |
4132| ---------- | ------------------------- | -- | ----------- |
4133| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 |
4134| callback   | AsyncCallback&lt;void&gt; | 是 | 回调函数。   |
4135
4136**错误码:**
4137
4138以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4139
4140| 错误码ID | 错误信息 |
4141| ------- | ------------------------------ |
4142| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
4143| 1300002 | This window state is abnormal. |
4144
4145**示例:**
4146
4147```ts
4148import { BusinessError } from '@kit.BasicServicesKit';
4149
4150try {
4151  windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => {
4152    const errCode: number = err.code;
4153    if (errCode) {
4154      console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`);
4155      return;
4156    }
4157    console.info('Succeeded in setting window colorspace.');
4158  });
4159} catch (exception) {
4160  console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`);
4161}
4162```
4163
4164### setWindowColorSpace<sup>9+</sup>
4165
4166setWindowColorSpace(colorSpace:ColorSpace): Promise&lt;void&gt;
4167
4168设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。
4169
4170**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4171
4172**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4173
4174**参数:**
4175
4176| 参数名 | 类型 | 必填 | 说明 |
4177| ---------- | ------------------------- | -- | ------------- |
4178| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 |
4179
4180**返回值:**
4181
4182| 类型 | 说明 |
4183| ------------------- | ------------------------ |
4184| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4185
4186**错误码:**
4187
4188以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4189
4190| 错误码ID | 错误信息 |
4191| ------- | ------------------------------ |
4192| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
4193| 1300002 | This window state is abnormal. |
4194
4195**示例:**
4196
4197```ts
4198import { BusinessError } from '@kit.BasicServicesKit';
4199
4200try {
4201  let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT);
4202  promise.then(() => {
4203    console.info('Succeeded in setting window colorspace.');
4204  }).catch((err: BusinessError) => {
4205    console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`);
4206  });
4207} catch (exception) {
4208  console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`);
4209}
4210```
4211
4212### getWindowColorSpace<sup>9+</sup>
4213
4214getWindowColorSpace(): ColorSpace
4215
4216获取当前窗口色域模式。
4217
4218**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4219
4220**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4221
4222**返回值:**
4223
4224| 类型 | 说明 |
4225| ------------------------- | ------------- |
4226| [ColorSpace](#colorspace8) | 当前色域模式。 |
4227
4228**错误码:**
4229
4230以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
4231
4232| 错误码ID | 错误信息 |
4233| ------- | ------------------------------ |
4234| 1300002 | This window state is abnormal. |
4235
4236**示例:**
4237
4238```ts
4239let colorSpace = windowClass.getWindowColorSpace();
4240```
4241
4242### setWindowBackgroundColor<sup>9+</sup>
4243
4244setWindowBackgroundColor(color: string): void
4245
4246设置窗口的背景色。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
4247
4248**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4249
4250**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4251
4252**参数:**
4253
4254| 参数名 | 类型 | 必填 | 说明 |
4255| ----- | ------ | -- | ----------------------------------------------------------------------- |
4256| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 |
4257
4258**错误码:**
4259
4260以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4261
4262| 错误码ID | 错误信息 |
4263| ------- | ------------------------------ |
4264| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4265| 1300002 | This window state is abnormal. |
4266
4267**示例:**
4268
4269```ts
4270import { BusinessError } from '@kit.BasicServicesKit';
4271
4272let storage: LocalStorage = new LocalStorage();
4273storage.setOrCreate('storageSimpleProp', 121);
4274windowClass.loadContent("pages/page2", storage, (err: BusinessError) => {
4275  let errCode: number = err.code;
4276  if (errCode) {
4277    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
4278    return;
4279  }
4280  console.info('Succeeded in loading the content.');
4281  let color: string = '#00ff33';
4282  try {
4283    windowClass?.setWindowBackgroundColor(color);
4284  } catch (exception) {
4285    console.error(`Failed to set the background color. Cause code: ${exception.code}, message: ${exception.message}`);
4286  };
4287});
4288```
4289
4290### setWindowBrightness<sup>9+</sup>
4291
4292setWindowBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void
4293
4294允许应用主窗口设置屏幕亮度值,使用callback异步回调。
4295
4296当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。
4297
4298**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4299
4300**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4301
4302**参数:**
4303
4304| 参数名 | 类型 | 必填 | 说明                                        |
4305| ---------- | ------------------------- | -- |-------------------------------------------|
4306| brightness | number                    | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 |
4307| callback   | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                     |
4308
4309**错误码:**
4310
4311以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4312
4313| 错误码ID | 错误信息 |
4314| ------- | -------------------------------------------- |
4315| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4316| 1300002 | This window state is abnormal.               |
4317| 1300003 | This window manager service works abnormally. |
4318
4319**示例:**
4320
4321```ts
4322// EntryAbility.ets
4323import { UIAbility } from '@kit.AbilityKit';
4324import { BusinessError } from '@kit.BasicServicesKit';
4325
4326export default class EntryAbility extends UIAbility {
4327  // ...
4328  onWindowStageCreate(windowStage: window.WindowStage): void {
4329    console.info('onWindowStageCreate');
4330    let windowClass: window.Window | undefined = undefined;
4331    windowStage.getMainWindow((err: BusinessError, data) => {
4332      const errCode: number = err.code;
4333      if (errCode) {
4334        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
4335        return;
4336      }
4337      windowClass = data;
4338      let brightness: number = 1;
4339      try {
4340        windowClass.setWindowBrightness(brightness, (err: BusinessError) => {
4341          const errCode: number = err.code;
4342          if (errCode) {
4343            console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`);
4344            return;
4345          }
4346          console.info('Succeeded in setting the brightness.');
4347        });
4348      } catch (exception) {
4349        console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`);
4350      }
4351    });
4352  }
4353}
4354```
4355
4356### setWindowBrightness<sup>9+</sup>
4357
4358setWindowBrightness(brightness: number): Promise&lt;void&gt;
4359
4360允许应用主窗口设置屏幕亮度值,使用Promise异步回调。
4361
4362当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。
4363
4364**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4365
4366**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4367
4368**参数:**
4369
4370| 参数名 | 类型 | 必填 | 说明                                     |
4371| ---------- | ------ | -- |----------------------------------------|
4372| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 |
4373
4374**返回值:**
4375
4376| 类型 | 说明 |
4377| ------------------- | ------------------------ |
4378| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4379
4380**错误码:**
4381
4382以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4383
4384| 错误码ID | 错误信息 |
4385| ------- | -------------------------------------------- |
4386| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4387| 1300002 | This window state is abnormal.               |
4388| 1300003 | This window manager service works abnormally. |
4389
4390**示例:**
4391
4392```ts
4393// EntryAbility.ets
4394import { UIAbility } from '@kit.AbilityKit';
4395import { BusinessError } from '@kit.BasicServicesKit';
4396
4397export default class EntryAbility extends UIAbility {
4398  // ...
4399  onWindowStageCreate(windowStage: window.WindowStage): void {
4400    console.info('onWindowStageCreate');
4401    let windowClass: window.Window | undefined = undefined;
4402    windowStage.getMainWindow((err: BusinessError, data) => {
4403      const errCode: number = err.code;
4404      if (errCode) {
4405        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
4406        return;
4407      }
4408      windowClass = data;
4409      let brightness: number = 1;
4410      try {
4411        let promise = windowClass.setWindowBrightness(brightness);
4412        promise.then(() => {
4413          console.info('Succeeded in setting the brightness.');
4414        }).catch((err: BusinessError) => {
4415          console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`);
4416        });
4417      } catch (exception) {
4418        console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`);
4419      }
4420    });
4421  }
4422}
4423```
4424
4425### setWindowFocusable<sup>9+</sup>
4426
4427setWindowFocusable(isFocusable: boolean, callback: AsyncCallback&lt;void&gt;): void
4428
4429设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用callback异步回调。
4430
4431**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4432
4433**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4434
4435**参数:**
4436
4437| 参数名 | 类型 | 必填 | 说明 |
4438| ----------- | ------------------------- | -- | ------------------------------------------------------- |
4439| isFocusable | boolean                   | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 |
4440| callback    | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                               |
4441
4442**错误码:**
4443
4444以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4445
4446| 错误码ID | 错误信息 |
4447| ------- | -------------------------------------------- |
4448| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4449| 1300002 | This window state is abnormal.               |
4450| 1300003 | This window manager service works abnormally. |
4451
4452**示例:**
4453
4454```ts
4455import { BusinessError } from '@kit.BasicServicesKit';
4456
4457let isFocusable: boolean = true;
4458try {
4459  windowClass.setWindowFocusable(isFocusable, (err: BusinessError) => {
4460    const errCode: number = err.code;
4461    if (errCode) {
4462      console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`);
4463      return;
4464    }
4465    console.info('Succeeded in setting the window to be focusable.');
4466  });
4467} catch (exception) {
4468  console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`);
4469}
4470```
4471
4472### setWindowFocusable<sup>9+</sup>
4473
4474setWindowFocusable(isFocusable: boolean): Promise&lt;void&gt;
4475
4476设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用Promise异步回调。
4477
4478**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4479
4480**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4481
4482**参数:**
4483
4484| 参数名 | 类型 | 必填 | 说明 |
4485| ----------- | ------- | -- | -------------------------------------------------------- |
4486| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。  |
4487
4488**返回值:**
4489
4490| 类型 | 说明 |
4491| ------------------- | ------------------------ |
4492| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4493
4494**错误码:**
4495
4496以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4497
4498| 错误码ID | 错误信息 |
4499| ------- | -------------------------------------------- |
4500| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4501| 1300002 | This window state is abnormal.               |
4502| 1300003 | This window manager service works abnormally. |
4503
4504**示例:**
4505
4506```ts
4507import { BusinessError } from '@kit.BasicServicesKit';
4508
4509let isFocusable: boolean = true;
4510try {
4511  let promise = windowClass.setWindowFocusable(isFocusable);
4512  promise.then(() => {
4513    console.info('Succeeded in setting the window to be focusable.');
4514  }).catch((err: BusinessError) => {
4515    console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`);
4516  });
4517} catch (exception) {
4518  console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`);
4519}
4520```
4521
4522### setWindowKeepScreenOn<sup>9+</sup>
4523
4524setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback&lt;void&gt;): void
4525
4526设置屏幕是否为常亮状态,使用callback异步回调。
4527
4528规范使用该接口:仅在必要场景(导航、视频播放、绘画、游戏等场景)下,设置该属性为true;退出上述场景后,应当重置该属性为false;其他场景(无屏幕互动、音频播放等)下,不使用该接口;系统检测到非规范使用该接口时,可能会恢复自动灭屏功能。
4529
4530**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4531
4532**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4533
4534**参数:**
4535
4536| 参数名 | 类型 | 必填 | 说明 |
4537| -------------- | ------------------------- | -- | ---------------------------------------------------- |
4538| isKeepScreenOn | boolean                   | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。  |
4539| callback       | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                            |
4540
4541**错误码:**
4542
4543以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4544
4545| 错误码ID | 错误信息 |
4546| ------- | -------------------------------------------- |
4547| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4548| 1300002 | This window state is abnormal.               |
4549| 1300003 | This window manager service works abnormally. |
4550
4551**示例:**
4552
4553```ts
4554import { BusinessError } from '@kit.BasicServicesKit';
4555
4556let isKeepScreenOn: boolean = true;
4557try {
4558  windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err: BusinessError) => {
4559    const errCode: number = err.code;
4560    if (errCode) {
4561      console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`);
4562      return;
4563    }
4564    console.info('Succeeded in setting the screen to be always on.');
4565  });
4566} catch (exception) {
4567  console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`);
4568}
4569```
4570
4571### setWindowKeepScreenOn<sup>9+</sup>
4572
4573setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise&lt;void&gt;
4574
4575设置屏幕是否为常亮状态,使用Promise异步回调。
4576
4577规范使用该接口:仅在必要场景(导航、视频播放、绘画、游戏等场景)下,设置该属性为true;退出上述场景后,应当重置该属性为false;其他场景(无屏幕互动、音频播放等)下,不使用该接口;系统检测到非规范使用该接口时,可能会恢复自动灭屏功能。
4578
4579**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4580
4581**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4582
4583**参数:**
4584
4585| 参数名 | 类型 | 必填 | 说明 |
4586| -------------- | ------- | -- | --------------------------------------------------- |
4587| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 |
4588
4589**返回值:**
4590
4591| 类型 | 说明 |
4592| ------------------- | ------------------------ |
4593| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4594
4595**错误码:**
4596
4597以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4598
4599| 错误码ID | 错误信息 |
4600| ------- | -------------------------------------------- |
4601| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4602| 1300002 | This window state is abnormal.               |
4603| 1300003 | This window manager service works abnormally. |
4604
4605**示例:**
4606
4607```ts
4608import { BusinessError } from '@kit.BasicServicesKit';
4609
4610let isKeepScreenOn: boolean = true;
4611try {
4612  let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn);
4613  promise.then(() => {
4614    console.info('Succeeded in setting the screen to be always on.');
4615  }).catch((err: BusinessError) => {
4616    console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`);
4617  });
4618} catch (exception) {
4619  console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`);
4620}
4621```
4622
4623### setWindowPrivacyMode<sup>9+</sup>
4624
4625setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback&lt;void&gt;): void
4626
4627设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。
4628
4629**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4630
4631**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4632
4633**需要权限:** ohos.permission.PRIVACY_WINDOW
4634
4635**参数:**
4636
4637| 参数名 | 类型 | 必填 | 说明 |
4638| ------------- | ------------------------- | -- | ------------------------------------------------------ |
4639| isPrivacyMode | boolean                   | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。  |
4640| callback      | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                              |
4641
4642**错误码:**
4643
4644以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4645
4646| 错误码ID | 错误信息 |
4647| ------- | ------------------------------ |
4648| 201     | Permission verification failed. The application does not have the permission required to call the API. |
4649| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4650| 1300002 | This window state is abnormal. |
4651
4652**示例:**
4653
4654```ts
4655import { BusinessError } from '@kit.BasicServicesKit';
4656
4657let isPrivacyMode: boolean = true;
4658try {
4659  windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => {
4660    const errCode: number = err.code;
4661    if (errCode) {
4662      console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`);
4663      return;
4664    }
4665    console.info('Succeeded in setting the window to privacy mode.');
4666  });
4667} catch (exception) {
4668  console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`);
4669}
4670```
4671
4672### setWindowPrivacyMode<sup>9+</sup>
4673
4674setWindowPrivacyMode(isPrivacyMode: boolean): Promise&lt;void&gt;
4675
4676设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。
4677
4678**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4679
4680**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4681
4682**需要权限:** ohos.permission.PRIVACY_WINDOW
4683
4684**参数:**
4685
4686| 参数名 | 类型 | 必填 | 说明 |
4687| ------------- | ------- | -- | ----------------------------------------------------- |
4688| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 |
4689
4690**返回值:**
4691
4692| 类型 | 说明 |
4693| ------------------- | ------------------------ |
4694| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4695
4696**错误码:**
4697
4698以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4699
4700| 错误码ID | 错误信息 |
4701| ------- | ------------------------------ |
4702| 201     | Permission verification failed. The application does not have the permission required to call the API. |
4703| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4704| 1300002 | This window state is abnormal. |
4705
4706**示例:**
4707
4708```ts
4709import { BusinessError } from '@kit.BasicServicesKit';
4710
4711let isPrivacyMode: boolean = true;
4712try {
4713  let promise = windowClass.setWindowPrivacyMode(isPrivacyMode);
4714  promise.then(() => {
4715    console.info('Succeeded in setting the window to privacy mode.');
4716  }).catch((err: BusinessError) => {
4717    console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`);
4718  });
4719} catch (exception) {
4720  console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`);
4721}
4722```
4723
4724### setWindowTouchable<sup>9+</sup>
4725
4726setWindowTouchable(isTouchable: boolean, callback: AsyncCallback&lt;void&gt;): void
4727
4728设置窗口是否为可触状态,使用callback异步回调。
4729
4730**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4731
4732**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4733
4734**参数:**
4735
4736| 参数名 | 类型 | 必填 | 说明 |
4737| ----------- | ------------------------- | -- | ----------------------------------------------- |
4738| isTouchable | boolean                   | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 |
4739| callback    | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                        |
4740
4741**错误码:**
4742
4743以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4744
4745| 错误码ID | 错误信息 |
4746| ------- | -------------------------------------------- |
4747| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4748| 1300002 | This window state is abnormal.               |
4749| 1300003 | This window manager service works abnormally. |
4750
4751**示例:**
4752
4753```ts
4754import { BusinessError } from '@kit.BasicServicesKit';
4755
4756let isTouchable = true;
4757try {
4758  windowClass.setWindowTouchable(isTouchable, (err: BusinessError) => {
4759    const errCode: number = err.code;
4760    if (errCode) {
4761      console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`);
4762      return;
4763    }
4764    console.info('Succeeded in setting the window to be touchable.');
4765  });
4766} catch (exception) {
4767  console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`);
4768}
4769```
4770
4771### setWindowTouchable<sup>9+</sup>
4772
4773setWindowTouchable(isTouchable: boolean): Promise&lt;void&gt;
4774
4775设置窗口是否为可触状态,使用Promise异步回调。
4776
4777**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4778
4779**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4780
4781**参数:**
4782
4783| 参数名 | 类型 | 必填 | 说明 |
4784| ----------- | ------- | -- | ----------------------------------------------- |
4785| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 |
4786
4787**返回值:**
4788
4789| 类型 | 说明 |
4790| ------------------- | ------------------------- |
4791| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4792
4793**错误码:**
4794
4795以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4796
4797| 错误码ID | 错误信息 |
4798| ------- | -------------------------------------------- |
4799| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4800| 1300002 | This window state is abnormal.               |
4801| 1300003 | This window manager service works abnormally. |
4802
4803**示例:**
4804
4805```ts
4806import { BusinessError } from '@kit.BasicServicesKit';
4807
4808let isTouchable: boolean = true;
4809try {
4810  let promise = windowClass.setWindowTouchable(isTouchable);
4811  promise.then(() => {
4812    console.info('Succeeded in setting the window to be touchable.');
4813  }).catch((err: BusinessError) => {
4814    console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`);
4815  });
4816} catch (exception) {
4817  console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`);
4818}
4819```
4820
4821### snapshot<sup>9+</sup>
4822
4823snapshot(callback: AsyncCallback&lt;image.PixelMap&gt;): void
4824
4825获取窗口截图,使用callback异步回调。
4826
4827**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4828
4829**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4830
4831**参数:**
4832
4833| 参数名      | 类型                      | 必填 | 说明                 |
4834| ----------- | ------------------------- | ---- | -------------------- |
4835| callback    | AsyncCallback&lt;[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)&gt; | 是   | 回调函数。  |
4836
4837**错误码:**
4838
4839以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
4840
4841| 错误码ID | 错误信息 |
4842| ------- | ------------------------------ |
4843| 1300002 | This window state is abnormal. |
4844
4845**示例:**
4846
4847```ts
4848import { BusinessError } from '@kit.BasicServicesKit';
4849import { image } from '@kit.ImageKit';
4850
4851windowClass.snapshot((err: BusinessError, pixelMap: image.PixelMap) => {
4852  const errCode: number = err.code;
4853  if (errCode) {
4854    console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`);
4855    return;
4856  }
4857  console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
4858  pixelMap.release(); // PixelMap使用完后及时释放内存
4859});
4860```
4861
4862### snapshot<sup>9+</sup>
4863
4864snapshot(): Promise&lt;image.PixelMap&gt;
4865
4866获取窗口截图,使用Promise异步回调。
4867
4868**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4869
4870**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4871
4872**返回值:**
4873
4874| 类型                | 说明                      |
4875| ------------------- | ------------------------- |
4876| Promise&lt;[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)&gt; | Promise对象。返回当前窗口截图。 |
4877
4878**错误码:**
4879
4880以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
4881
4882| 错误码ID | 错误信息 |
4883| ------- | ------------------------------ |
4884| 1300002 | This window state is abnormal. |
4885
4886**示例:**
4887
4888```ts
4889import { BusinessError } from '@kit.BasicServicesKit';
4890import { image } from '@kit.ImageKit';
4891
4892let promise = windowClass.snapshot();
4893promise.then((pixelMap: image.PixelMap) => {
4894  console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
4895  pixelMap.release(); // PixelMap使用完后及时释放内存
4896}).catch((err: BusinessError) => {
4897  console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`);
4898});
4899```
4900
4901### setAspectRatio<sup>10+</sup>
4902
4903setAspectRatio(ratio: number): Promise&lt;void&gt;
4904
4905设置窗口内容布局的比例,使用Promise异步回调。
4906
4907通过其他接口如[resize](#resize9)、[resizeAsync](#resizeasync12)设置窗口大小时,不受ratio约束。
4908
4909仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。
4910
4911**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4912
4913**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4914
4915**参数:**
4916
4917| 参数名             | 类型    | 必填 | 说明                                        |
4918| ------------------ | ------- | ---- |-------------------------------------------|
4919| ratio | number | 是   | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,受窗口最大最小尺寸限制,比例值下限为最小宽度/最大高度,上限为最大宽度/最小高度。窗口最大最小尺寸由[WindowLimits](#windowlimits11)和系统限制的交集决定,系统限制优先级高于[WindowLimits](#windowlimits11)。ratio的有效范围会随[WindowLimits](#windowlimits11)变化而变化。如果先设置了[WindowLimits](#windowlimits11),后设置的ratio与其冲突,会返回错误码;如果先设置了ratio,后设置的[WindowLimits](#windowlimits11)与其冲突,窗口的宽高比可能会不跟随设置的宽高比(ratio)。 |
4920
4921**返回值:**
4922
4923| 类型                | 说明                      |
4924| ------------------- | ------------------------- |
4925| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4926
4927**错误码:**
4928
4929以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4930
4931| 错误码ID | 错误信息 |
4932| ------- | -------------------------------------------- |
4933| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
4934| 1300002 | This window state is abnormal.               |
4935| 1300004 | Unauthorized operation.                      |
4936
4937**示例:**
4938<!--code_no_check-->
4939```ts
4940// EntryAbility.ets
4941import { UIAbility } from '@kit.AbilityKit';
4942import { BusinessError } from '@kit.BasicServicesKit';
4943
4944export default class EntryAbility extends UIAbility {
4945
4946  // ...
4947  onWindowStageCreate(windowStage: window.WindowStage) {
4948    console.info('onWindowStageCreate');
4949    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
4950    if (!windowClass) {
4951      console.info('windowClass is null');
4952    }
4953    try {
4954      let ratio = 1.0;
4955      let promise = windowClass.setAspectRatio(ratio);
4956      promise.then(() => {
4957        console.info('Succeeded in setting aspect ratio of window.');
4958      }).catch((err: BusinessError) => {
4959        console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`);
4960      });
4961    } catch (exception) {
4962      console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`);
4963    }
4964  }
4965}
4966```
4967
4968### setAspectRatio<sup>10+</sup>
4969
4970setAspectRatio(ratio: number, callback: AsyncCallback&lt;void&gt;): void
4971
4972设置窗口内容布局的比例,使用callback异步回调。
4973
4974通过其他接口如[resize](#resize9)、[resizeAsync](#resizeasync12)设置窗口大小时,不受ratio约束。
4975
4976仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。
4977
4978**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4979
4980**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4981
4982**参数:**
4983
4984| 参数名             | 类型    | 必填 | 说明                                         |
4985| ------------------ | ------- | ---- |--------------------------------------------|
4986| ratio | number | 是   | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,受窗口最大最小尺寸限制,比例值下限为最小宽度/最大高度,上限为最大宽度/最小高度。窗口最大最小尺寸由[WindowLimits](#windowlimits11)和系统限制的交集决定,系统限制优先级高于[WindowLimits](#windowlimits11)。ratio的有效范围会随[WindowLimits](#windowlimits11)变化而变化。如果先设置了[WindowLimits](#windowlimits11),后设置的ratio与其冲突,会返回错误码;如果先设置了ratio,后设置的[WindowLimits](#windowlimits11)与其冲突,窗口的宽高比可能会不跟随设置的宽高比(ratio)。 |
4987| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                      |
4988
4989**错误码:**
4990
4991以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4992
4993| 错误码ID | 错误信息 |
4994| ------- | -------------------------------------------- |
4995| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
4996| 1300002 | This window state is abnormal.               |
4997| 1300004 | Unauthorized operation.                      |
4998
4999**示例:**
5000<!--code_no_check-->
5001```ts
5002// EntryAbility.ets
5003import { UIAbility } from '@kit.AbilityKit';
5004import { BusinessError } from '@kit.BasicServicesKit';
5005
5006export default class EntryAbility extends UIAbility {
5007
5008  // ...
5009  onWindowStageCreate(windowStage: window.WindowStage) {
5010    console.info('onWindowStageCreate');
5011    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
5012    if (!windowClass) {
5013      console.info('Failed to load the content. Cause: windowClass is null');
5014    }
5015    try {
5016      let ratio = 1.0;
5017      windowClass.setAspectRatio(ratio, (err: BusinessError) => {
5018        const errCode: number = err.code;
5019        if (errCode) {
5020          console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`);
5021          return;
5022        }
5023        console.info('Succeeded in setting the aspect ratio of window.');
5024      });
5025    } catch (exception) {
5026      console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`);
5027    }
5028  }
5029}
5030
5031```
5032
5033### resetAspectRatio<sup>10+</sup>
5034
5035resetAspectRatio(): Promise&lt;void&gt;
5036
5037取消设置窗口内容布局的比例,使用Promise异步回调。
5038
5039仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,调用后将清除持久化储存的比例信息。
5040
5041**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5042
5043**系统能力:** SystemCapability.WindowManager.WindowManager.Core
5044
5045**返回值:**
5046
5047| 类型                | 说明                      |
5048| ------------------- | ------------------------- |
5049| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5050
5051**错误码:**
5052
5053以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
5054
5055| 错误码ID | 错误信息 |
5056| ------- | -------------------------------------------- |
5057| 1300002 | This window state is abnormal.               |
5058| 1300004 | Unauthorized operation.                      |
5059
5060**示例:**
5061<!--code_no_check-->
5062```ts
5063// EntryAbility.ets
5064import { UIAbility } from '@kit.AbilityKit';
5065import { BusinessError } from '@kit.BasicServicesKit';
5066
5067export default class EntryAbility extends UIAbility {
5068
5069  // ...
5070  onWindowStageCreate(windowStage: window.WindowStage) {
5071    console.info('onWindowStageCreate');
5072    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
5073    if (!windowClass) {
5074      console.info('Failed to load the content. Cause: windowClass is null');
5075    }
5076    try {
5077      let promise = windowClass.resetAspectRatio();
5078      promise.then(() => {
5079        console.info('Succeeded in resetting aspect ratio of window.');
5080      }).catch((err: BusinessError) => {
5081        console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`);
5082      });
5083    } catch (exception) {
5084      console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`);
5085    }
5086  }
5087}
5088```
5089
5090### resetAspectRatio<sup>10+</sup>
5091
5092resetAspectRatio(callback: AsyncCallback&lt;void&gt;): void
5093
5094取消设置窗口内容布局的比例,使用callback异步回调。
5095
5096仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,调用后将清除持久化储存的比例信息。
5097
5098**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5099
5100**系统能力:** SystemCapability.WindowManager.WindowManager.Core
5101
5102**参数:**
5103
5104| 参数名             | 类型    | 必填 | 说明                                                         |
5105| ------------------ | ------- | ---- | ------------------------------------------------------------ |
5106| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
5107
5108**错误码:**
5109
5110以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
5111
5112| 错误码ID | 错误信息 |
5113| ------- | -------------------------------------------- |
5114| 1300002 | This window state is abnormal.               |
5115| 1300004 | Unauthorized operation.                      |
5116
5117**示例:**
5118<!--code_no_check-->
5119```ts
5120// EntryAbility.ets
5121import { UIAbility } from '@kit.AbilityKit';
5122import { BusinessError } from '@kit.BasicServicesKit';
5123
5124export default class EntryAbility extends UIAbility {
5125
5126  // ...
5127  onWindowStageCreate(windowStage: window.WindowStage) {
5128    console.info('onWindowStageCreate');
5129    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
5130    if (!windowClass) {
5131      console.info('Failed to load the content. Cause: windowClass is null');
5132    }
5133    try {
5134      windowClass.resetAspectRatio((err: BusinessError) => {
5135        const errCode: number = err.code;
5136        if (errCode) {
5137          console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`);
5138          return;
5139        }
5140        console.info('Succeeded in resetting aspect ratio of window.');
5141      });
5142    } catch (exception) {
5143      console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`);
5144    }
5145  }
5146}
5147```
5148
5149### minimize<sup>11+</sup>
5150
5151minimize(callback: AsyncCallback&lt;void&gt;): void
5152
5153此接口根据调用对象不同,实现不同的两个功能:
5154
5155当调用对象为主窗口时,实现最小化功能,可在Dock栏中还原;
5156
5157当调用对象为子窗口时,实现隐藏功能,不可在Dock栏中还原。
5158
5159使用callback异步回调。
5160
5161**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5162
5163**系统能力:** SystemCapability.Window.SessionManager
5164
5165**参数:**
5166
5167| 参数名   | 类型                      | 必填 | 说明       |
5168| -------- | ------------------------- | ---- | ---------- |
5169| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。 |
5170
5171**错误码:**
5172
5173以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5174
5175| 错误码ID | 错误信息 |
5176| ------- | ------------------------------ |
5177| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5178| 1300002 | This window state is abnormal. |
5179| 1300003 | This window manager service works abnormally. |
5180
5181**示例:**
5182
5183```ts
5184import { BusinessError } from '@kit.BasicServicesKit';
5185
5186windowClass.minimize((err: BusinessError) => {
5187  const errCode: number = err.code;
5188  if (errCode) {
5189    console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`);
5190    return;
5191  }
5192  console.info('Succeeded in minimizing the window.');
5193});
5194```
5195
5196### minimize<sup>11+</sup>
5197
5198minimize(): Promise&lt;void&gt;
5199
5200此接口根据调用对象不同,实现不同的两个功能:
5201
5202当调用对象为主窗口时,实现最小化功能,可在Dock栏中还原;
5203
5204当调用对象为子窗口时,实现隐藏功能,不可在Dock栏中还原。
5205
5206使用Promise异步回调。
5207
5208**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5209
5210**系统能力:** SystemCapability.Window.SessionManager
5211
5212**返回值:**
5213
5214| 类型                | 说明                      |
5215| ------------------- | ------------------------- |
5216| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5217
5218**错误码:**
5219
5220以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5221
5222| 错误码ID | 错误信息 |
5223| ------- | ------------------------------ |
5224| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5225| 1300002 | This window state is abnormal. |
5226| 1300003 | This window manager service works abnormally. |
5227
5228**示例:**
5229
5230```ts
5231import { BusinessError } from '@kit.BasicServicesKit';
5232
5233let promise = windowClass.minimize();
5234promise.then(() => {
5235  console.info('Succeeded in minimizing the window.');
5236}).catch((err: BusinessError) => {
5237  console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`);
5238});
5239```
5240
5241### maximize<sup>12+</sup>
5242maximize(presentation?: MaximizePresentation): Promise&lt;void&gt;
5243
5244主窗口调用,实现最大化功能,使用Promise异步回调,仅2in1设备可用。
5245
5246**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5247
5248**系统能力:** SystemCapability.Window.SessionManager
5249
5250**参数:**
5251
5252| 参数名 | 类型  | 必填 | 说明 |
5253| ----- | ---------------------------- | -- | --------------------------------- |
5254| presentation  | [MaximizePresentation](#maximizepresentation12) | 否 | 主窗口最大化时候的布局枚举。默认值window.MaximizePresentation.ENTER_IMMERSIVE,即默认最大化时进入沉浸式布局。 |
5255
5256**返回值:**
5257
5258| 类型                | 说明                      |
5259| ------------------- | ------------------------- |
5260| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5261
5262**错误码:**
5263
5264以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5265
5266| 错误码ID | 错误信息 |
5267| ------- | ------------------------------ |
5268| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5269| 1300002 | This window state is abnormal.                |
5270| 1300003 | This window manager service works abnormally. |
5271| 1300004 | Unauthorized operation.                       |
5272| 1300005 | This window stage is abnormal. |
5273
5274**示例:**
5275
5276```ts
5277// EntryAbility.ets
5278import { UIAbility } from '@kit.AbilityKit';
5279import { BusinessError } from '@kit.BasicServicesKit';
5280export default class EntryAbility extends UIAbility {
5281  // ...
5282
5283  onWindowStageCreate(windowStage: window.WindowStage) {
5284    console.info('onWindowStageCreate');
5285    let windowClass: window.Window | undefined = undefined;
5286    windowStage.getMainWindow((err: BusinessError, data) => {
5287      const errCode: number = err.code;
5288      if (errCode) {
5289        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
5290        return;
5291      }
5292      windowClass = data;
5293      let promise = windowClass.maximize();
5294      // let promise = windowClass.maximize(window.MaximizePresentation.ENTER_IMMERSIVE);
5295      promise.then(() => {
5296        console.info('Succeeded in maximizing the window.');
5297      }).catch((err: BusinessError) => {
5298        console.error(`Failed to maximize the window. Cause code: ${err.code}, message: ${err.message}`);
5299      });
5300    });
5301  }
5302};
5303```
5304
5305### recover<sup>11+</sup>
5306
5307recover(): Promise&lt;void&gt;
5308
5309将主窗口从全屏、最大化、分屏模式下还原为浮动窗口,并恢复到进入该模式之前的大小和位置,已经是浮动窗口模式不可再还原。使用Promise异步回调。此接口仅在多窗层叠布局效果下生效,仅2in1设备可用。
5310
5311**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5312
5313**系统能力:** SystemCapability.Window.SessionManager
5314
5315**返回值:**
5316
5317| 类型                | 说明                      |
5318| ------------------- | ------------------------- |
5319| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5320
5321**错误码:**
5322
5323以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5324
5325| 错误码ID | 错误信息 |
5326| ------- | ------------------------------ |
5327| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5328| 1300001 | Repeated operation. |
5329| 1300002 | This window state is abnormal. |
5330
5331**示例:**
5332
5333```ts
5334// EntryAbility.ets
5335import { UIAbility } from '@kit.AbilityKit';
5336import { BusinessError } from '@kit.BasicServicesKit';
5337
5338export default class EntryAbility extends UIAbility {
5339  // ...
5340  onWindowStageCreate(windowStage: window.WindowStage): void {
5341    console.info('onWindowStageCreate');
5342    let windowClass: window.Window | undefined = undefined;
5343    windowStage.getMainWindow((err: BusinessError, data) => {
5344      const errCode: number = err.code;
5345      if (errCode) {
5346        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
5347        return;
5348      }
5349      windowClass = data;
5350      let promise = windowClass.recover();
5351      promise.then(() => {
5352        console.info('Succeeded in recovering the window.');
5353      }).catch((err: BusinessError) => {
5354        console.error(`Failed to recover the window. Cause code: ${err.code}, message: ${err.message}`);
5355      });
5356    });
5357  }
5358}
5359```
5360
5361### getWindowLimits<sup>11+</sup>
5362
5363getWindowLimits(): WindowLimits
5364
5365获取当前应用窗口的尺寸限制。
5366
5367**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5368
5369**系统能力:** SystemCapability.Window.SessionManager
5370
5371**返回值:**
5372
5373| 类型                          | 说明           |
5374| ----------------------------- | ------------------ |
5375| [WindowLimits](#windowlimits11) | 当前窗口尺寸限制。 |
5376
5377**错误码:**
5378
5379以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5380
5381| 错误码ID | 错误信息                       |
5382| :------- | :----------------------------- |
5383| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5384| 1300002  | This window state is abnormal. |
5385
5386**示例:**
5387
5388```ts
5389try {
5390  let windowLimits = windowClass.getWindowLimits();
5391} catch (exception) {
5392  console.error(`Failed to obtain the window limits of window. Cause code: ${exception.code}, message: ${exception.message}`);
5393}
5394```
5395
5396### setWindowLimits<sup>11+</sup>
5397
5398setWindowLimits(windowLimits: WindowLimits): Promise&lt;WindowLimits&gt;
5399
5400设置当前应用窗口的尺寸限制,使用Promise异步回调。
5401默认存在一个系统尺寸限制,系统尺寸限制由产品配置决定,不可修改。未调用setWindowLimits配置过WindowLimits时,使用[getWindowLimits](#getwindowlimits11)可获取系统限制。
5402
5403**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5404
5405**系统能力:** SystemCapability.Window.SessionManager
5406
5407**参数:**
5408
5409| 参数名       | 类型                          | 必填 | 说明                           |
5410| :----------- | :---------------------------- | :--- | :----------------------------- |
5411| windowLimits | [WindowLimits](#windowlimits11) | 是   | 目标窗口的尺寸限制,单位为px。 |
5412
5413**返回值:**
5414
5415| 类型                                         | 说明                                |
5416| :------------------------------------------- | :---------------------------------- |
5417| Promise&lt;[WindowLimits](#windowlimits11)&gt; | Promise对象。返回设置后的尺寸限制,为入参与系统尺寸限制的交集。 |
5418
5419**错误码:**
5420
5421以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5422
5423| 错误码ID | 错误信息                                      |
5424| :------- | :-------------------------------------------- |
5425| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5426| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5427| 1300002  | This window state is abnormal.                |
5428| 1300003  | This window manager service works abnormally. |
5429| 1300004 | Unauthorized operation.                |
5430
5431**示例:**
5432
5433```ts
5434import { BusinessError } from '@kit.BasicServicesKit';
5435try {
5436  let windowLimits: window.WindowLimits = {
5437    maxWidth: 1500,
5438    maxHeight: 1000,
5439    minWidth: 500,
5440    minHeight: 400
5441  };
5442  let promise = windowClass.setWindowLimits(windowLimits);
5443    promise.then((data) => {
5444    console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data));
5445  }).catch((err: BusinessError) => {
5446    console.error(`Failed to change the window limits. Cause code: ${err.code}, message: ${err.message}`);
5447  });
5448} catch (exception) {
5449  console.error(`Failed to change the window limits. Cause code: ${exception.code}, message: ${exception.message}`);
5450}
5451```
5452
5453### setWindowMask<sup>12+</sup>
5454
5455setWindowMask(windowMask: Array&lt;Array&lt;number&gt;&gt;): Promise&lt;void&gt;;
5456
5457设置异形窗口的掩码,使用Promise异步回调。异形窗口为非常规形状的窗口,掩码用于描述异形窗口的形状。此接口仅限子窗和全局悬浮窗可用,仅2in1设备可用。
5458当异形窗口大小发生变化时,实际的显示内容为掩码大小和窗口大小的交集部分。
5459
5460**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5461
5462**系统能力:** SystemCapability.Window.SessionManager
5463
5464**参数:**
5465
5466| 参数名       | 类型                          | 必填 | 说明                           |
5467| :----------- | :---------------------------- | :--- | :----------------------------- |
5468| windowMask | Array&lt;Array&lt;number&gt;&gt; | 是   | 异形窗口的掩码,该参数仅支持宽高为窗口宽高、取值为整数0和整数1的二维数组输入,整数0代表所在像素透明,整数1代表所在像素不透明,宽高不符合的二维数组或二维数组取值不为整数0和整数1的二维数组为非法参数。 |
5469
5470**返回值:**
5471
5472| 类型                                         | 说明                                |
5473| :------------------------------------------- | :---------------------------------- |
5474| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5475
5476**错误码:**
5477
5478以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5479
5480| 错误码ID | 错误信息                                      |
5481| :------- | :-------------------------------------------- |
5482| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5483| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5484| 1300002  | This window state is abnormal.                |
5485| 1300003  | This window manager service works abnormally. |
5486| 1300004  | Unauthorized operation.                       |
5487
5488**示例:**
5489
5490```ts
5491import { BusinessError } from '@kit.BasicServicesKit';
5492try {
5493  let windowMask: Array<Array<number>> = [
5494      [0, 0, 0, 1, 0, 0, 0],
5495      [0, 0, 1, 1, 1, 0, 0],
5496      [0, 1, 1, 0, 1, 1, 0],
5497      [1, 1, 0, 0, 0, 1, 1]
5498    ];
5499  let promise = windowClass.setWindowMask(windowMask);
5500    promise.then(() => {
5501    console.info('Succeeded in setting the window mask.');
5502  }).catch((err: BusinessError) => {
5503    console.error(`Failed to set the window mask. Cause code: ${err.code}, message: ${err.message}`);
5504  });
5505} catch (exception) {
5506  console.error(`Failed to set the window mask. Cause code: ${exception.code}, message: ${exception.message}`);
5507}
5508```
5509
5510### keepKeyboardOnFocus<sup>11+</sup>
5511
5512keepKeyboardOnFocus(keepKeyboardFlag: boolean): void
5513
5514窗口获焦时保留由其他窗口创建的软键盘,仅支持系统窗口与应用子窗口。
5515
5516**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5517
5518**系统能力:** SystemCapability.Window.SessionManager
5519
5520**参数:**
5521
5522| 参数名           | 类型    | 必填 | 说明                                                         |
5523| ---------------- | ------- | ---- | ------------------------------------------------------------ |
5524| keepKeyboardFlag | boolean | 是   | 是否保留其他窗口创建的软键盘。true表示保留;false表示不保留。|
5525
5526**错误码:**
5527
5528以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5529
5530| 错误码ID | 错误信息 |
5531| ------- | ---------------------------------------- |
5532| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5533| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5534| 1300002 | This window state is abnormal.           |
5535| 1300004 | Unauthorized operation.                  |
5536
5537**示例:**
5538
5539```ts
5540try {
5541  windowClass.keepKeyboardOnFocus(true);
5542} catch (exception) {
5543  console.error(`Failed to keep keyboard onFocus. Cause code: ${exception.code}, message: ${exception.message}`);
5544}
5545```
5546
5547### setWindowDecorVisible<sup>11+</sup>
5548
5549setWindowDecorVisible(isVisible: boolean): void
5550
5551设置窗口标题栏是否可见,对存在标题栏和三键区的窗口形态生效。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
5552
5553**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5554
5555**系统能力:** SystemCapability.Window.SessionManager
5556
5557**参数:**
5558
5559| 参数名    | 类型    | 必填 | 说明                                          |
5560| --------- | ------- | ---- | --------------------------------------------- |
5561| isVisible | boolean | 是   | 设置标题栏是否可见,true为可见,false为隐藏。 |
5562
5563**错误码:**
5564
5565以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5566
5567| 错误码ID | 错误信息                       |
5568| -------- | ------------------------------ |
5569| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5570| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5571| 1300002  | This window state is abnormal. |
5572| 1300004  | Unauthorized operation.        |
5573
5574**示例:**
5575
5576```ts
5577import { BusinessError } from '@kit.BasicServicesKit';
5578let storage: LocalStorage = new LocalStorage();
5579storage.setOrCreate('storageSimpleProp', 121);
5580windowClass.loadContent("pages/page2", storage, (err: BusinessError) => {
5581  let errCode: number = err.code;
5582  if (errCode) {
5583    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
5584    return;
5585  }
5586  console.info('Succeeded in loading the content.');
5587  let isVisible = false;
5588  // 调用setWindowDecorVisible接口
5589  try {
5590      windowClass?.setWindowDecorVisible(isVisible);
5591  } catch (exception) {
5592      console.error(`Failed to set the visibility of window decor. Cause code: ${exception.code}, message: ${exception.message}`);
5593  }
5594});
5595```
5596
5597### setSubWindowModal<sup>12+</sup>
5598
5599setSubWindowModal(isModal: boolean): Promise&lt;void&gt;
5600
5601设置子窗的模态属性是否启用,使用Promise异步回调。
5602
5603子窗口调用该接口时,设置子窗口模态属性是否启用。启用子窗口模态属性后,其父级窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态属性被禁用。
5604
5605子窗口之外的窗口调用该接口时,会报错。
5606
5607**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5608
5609**系统能力:** SystemCapability.Window.SessionManager
5610
5611**参数:**
5612
5613| 参数名    | 类型    | 必填 | 说明                                          |
5614| --------- | ------- | ---- | --------------------------------------------- |
5615| isModal | boolean | 是   | 设置子窗口模态属性是否启用,true为启用,false为不启用。 |
5616
5617
5618**返回值:**
5619
5620| 类型 | 说明 |
5621| ------------------- | ------------------------ |
5622| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5623
5624**错误码:**
5625
5626以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5627
5628| 错误码ID | 错误信息                       |
5629| -------- | ------------------------------ |
5630| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5631| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5632| 1300002  | This window state is abnormal. |
5633| 1300004  | Unauthorized operation.        |
5634
5635**示例:**
5636
5637```ts
5638// EntryAbility.ets
5639import { UIAbility } from '@kit.AbilityKit';
5640import { BusinessError } from '@kit.BasicServicesKit';
5641
5642export default class EntryAbility extends UIAbility {
5643  // ...
5644  onWindowStageCreate(windowStage: window.WindowStage): void {
5645    console.info('onWindowStageCreate');
5646    let windowClass: window.Window | undefined = undefined;
5647    // 创建子窗
5648    try {
5649      let subWindow = windowStage.createSubWindow("testSubWindow");
5650      subWindow.then((data) => {
5651        if (data == null) {
5652          console.error("Failed to create the subWindow. Cause: The data is empty");
5653          return;
5654        }
5655        windowClass = data;
5656        let promise = windowClass.setSubWindowModal(true);
5657        promise.then(() => {
5658          console.info('Succeeded in setting subwindow modal');
5659        }).catch((err: BusinessError) => {
5660          console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`);
5661        });
5662      });
5663    } catch (exception) {
5664      console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`);
5665    }
5666  }
5667}
5668```
5669
5670### setWindowDecorHeight<sup>11+</sup>
5671
5672setWindowDecorHeight(height: number): void
5673
5674<!--RP1-->
5675设置窗口的标题栏高度,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
5676<!--RP1End-->
5677
5678**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5679
5680**系统能力:** SystemCapability.Window.SessionManager
5681
5682**参数:**
5683
5684| 参数名 | 类型   | 必填 | 说明                                                         |
5685| ------ | ------ | ---- | ------------------------------------------------------------ |
5686| height | number | 是   |设置的窗口标题栏高度,仅支持具有窗口标题栏的窗口。该参数为整数,浮点数输入将向下取整,取值范围为[37,112],范围外为非法参数,单位为vp。 |
5687
5688**错误码:**
5689
5690以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5691
5692| 错误码ID | 错误信息                       |
5693| -------- | ------------------------------ |
5694| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5695| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5696| 1300002  | This window state is abnormal. |
5697
5698**示例:**
5699
5700```ts
5701windowClass.setUIContent('pages/WindowPage').then(() => {
5702  let height: number = 50;
5703  try {
5704    windowClass?.setWindowDecorHeight(height);
5705    console.info(`Succeeded in setting the height of window decor: ${height}`);
5706  } catch (exception) {
5707    console.error(`Failed to set the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`);
5708  }
5709})
5710```
5711
5712### getWindowDecorHeight<sup>11+</sup>
5713
5714getWindowDecorHeight(): number
5715
5716<!--RP2-->
5717获取窗口的标题栏高度,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
5718<!--RP2End-->
5719
5720**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5721
5722**系统能力:** SystemCapability.Window.SessionManager
5723
5724**返回值:**
5725
5726| 类型   | 说明                                                         |
5727| ------ | ------------------------------------------------------------ |
5728| number | 返回的窗口标题栏高度。该参数为整数,取值范围为[37,112],单位为vp。 |
5729
5730**错误码:**
5731
5732以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5733
5734| 错误码ID | 错误信息                       |
5735| -------- | ------------------------------ |
5736| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5737| 1300002  | This window state is abnormal. |
5738
5739**示例:**
5740
5741```ts
5742windowClass.setUIContent('pages/WindowPage').then(() => {
5743  try {
5744    let height = windowClass?.getWindowDecorHeight();
5745    console.info(`Succeeded in getting the height of window decor: ${height}`);
5746  } catch (exception) {
5747    console.error(`Failed to get the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`);
5748  }
5749})
5750```
5751
5752### getTitleButtonRect<sup>11+</sup>
5753
5754getTitleButtonRect(): TitleButtonRect
5755
5756获取主窗口或启用装饰的子窗口的标题栏上的最小化、最大化、关闭按钮矩形区域。
5757
5758**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5759
5760**系统能力:** SystemCapability.Window.SessionManager
5761
5762**返回值:**
5763
5764| 类型                                  | 说明                                                         |
5765| ------------------------------------- | ------------------------------------------------------------ |
5766| [TitleButtonRect](#titlebuttonrect11) | 标题栏上的最小化、最大化、关闭按钮矩形区域,该区域位置坐标相对窗口右上角。 |
5767
5768**错误码:**
5769
5770以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5771
5772| 错误码ID | 错误信息                       |
5773| -------- | ------------------------------ |
5774| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5775| 1300002  | This window state is abnormal. |
5776
5777**示例:**
5778
5779```ts
5780// EntryAbility.ets
5781import { UIAbility } from '@kit.AbilityKit';
5782import { BusinessError } from '@kit.BasicServicesKit';
5783
5784export default class EntryAbility extends UIAbility {
5785  // ...
5786  onWindowStageCreate(windowStage: window.WindowStage): void {
5787    console.info('onWindowStageCreate');
5788    let windowClass: window.Window | undefined = undefined;
5789    windowStage.getMainWindow((err: BusinessError, data) => {
5790      const errCode: number = err.code;
5791      if (errCode) {
5792        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
5793        return;
5794      }
5795      windowClass = data;
5796      try {
5797        let titleButtonArea = windowClass.getTitleButtonRect();
5798        console.info('Succeeded in obtaining the area of title buttons. Data: ' + JSON.stringify(titleButtonArea));
5799      } catch (exception) {
5800        console.error(`Failed to get the area of title buttons. Cause code: ${exception.code}, message: ${exception.message}`);
5801      }
5802    });
5803  }
5804}
5805```
5806
5807### getWindowStatus<sup>12+</sup>
5808
5809getWindowStatus(): WindowStatusType
5810
5811获取当前应用窗口的模式。
5812
5813**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5814
5815**系统能力:** SystemCapability.Window.SessionManager
5816
5817**返回值:**
5818
5819| 类型                           | 说明                                   |
5820| ------------------------------ | ----------------------------------------|
5821| [WindowStatusType](#windowstatustype11) | 当前窗口模式。                              |
5822
5823**错误码:**
5824
5825以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5826
5827| 错误码ID | 错误信息 |
5828| ------- | ------------------------------ |
5829| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5830| 1300002  | This window state is abnormal. |
5831
5832**示例:**
5833
5834```ts
5835try {
5836  let windowStatusType = windowClass.getWindowStatus();
5837} catch (exception) {
5838  console.error(`Failed to obtain the window status of window. Cause code: ${exception.code}, message: ${exception.message}`);
5839}
5840```
5841
5842### isFocused<sup>12+</sup>
5843
5844isFocused(): boolean
5845
5846判断当前窗口是否已获焦。
5847
5848**系统能力:** SystemCapability.WindowManager.WindowManager.Core
5849
5850**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5851
5852**返回值:**
5853
5854| 类型 | 说明 |
5855| ------- | ------------------------------------------------------------------ |
5856| boolean | 当前窗口是否已获焦。true表示当前窗口已获焦,false则表示当前窗口未获焦。 |
5857
5858**错误码:**
5859
5860以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
5861
5862| 错误码ID | 错误信息 |
5863| ------- | ------------------------------ |
5864| 1300002 | This window state is abnormal. |
5865
5866**示例:**
5867
5868```ts
5869try {
5870  let focus = windowClass.isFocused();
5871  console.info('Succeeded in checking whether the window is focused. Data: ' + JSON.stringify(focus));
5872} catch (exception) {
5873  console.error(`Failed to check whether the window is focused. Cause code: ${exception.code}, message: ${exception.message}`);
5874}
5875```
5876
5877### createSubWindowWithOptions<sup>12+</sup>
5878
5879createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise&lt;Window&gt;
5880
5881创建主窗口或子窗口下的子窗口,使用Promise异步回调,该接口仅在2in1设备上调用生效。
5882
5883**模型约束:** 此接口仅可在Stage模型下使用。
5884
5885**系统能力:** SystemCapability.Window.SessionManager
5886
5887**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5888
5889**参数:**
5890
5891| 参数名 | 类型   | 必填 | 说明           |
5892| ------ | ------ | ---- | -------------- |
5893| name   | string | 是   | 子窗口的名字。 |
5894| options  | [SubWindowOptions](#subwindowoptions11) | 是   | 子窗口参数。  |
5895
5896**返回值:**
5897
5898| 类型                             | 说明                                             |
5899| -------------------------------- | ------------------------------------------------ |
5900| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前Window下创建的子窗口对象。 |
5901
5902**错误码:**
5903
5904以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5905
5906| 错误码ID | 错误信息 |
5907| ------- | ------------------------------ |
5908| 401     | Parameter error. Possible cause: Incorrect parameter types. |
5909| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5910| 1300002 | This window state is abnormal. |
5911| 1300003 | This window manager service works abnormally. |
5912| 1300004 | Unauthorized operation. |
5913
5914**示例:**
5915
5916```ts
5917import { BusinessError } from '@kit.BasicServicesKit';
5918
5919try {
5920  let options : window.SubWindowOptions = {
5921    title: 'title',
5922    decorEnabled: true,
5923    isModal: true
5924  };
5925  let promise = windowClass.createSubWindowWithOptions('mySubWindow', options);
5926  promise.then((data) => {
5927    console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
5928  }).catch((err: BusinessError) => {
5929    console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`);
5930  });
5931} catch (exception) {
5932  console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`);
5933}
5934```
5935
5936### enableLandscapeMultiWindow<sup>12+</sup>
5937
5938enableLandscapeMultiWindow(): Promise&lt;void&gt;
5939
5940应用部分界面支持横向布局时,在进入该界面时使能,使能后可支持进入横向多窗。不建议竖向布局界面使用。
5941
5942此接口只对应用主窗口生效,且需要在module.json5配置文件中[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中配置preferMultiWindowOrientation属性为"landscape_auto"。
5943
5944**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5945
5946**系统能力:** SystemCapability.Window.SessionManager
5947
5948**返回值:**
5949
5950| 类型                | 说明                      |
5951| ------------------- | ------------------------- |
5952| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5953
5954**错误码:**
5955
5956以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
5957
5958| 错误码ID | 错误信息 |
5959| ------- | -------------------------------------------- |
5960| 1300002 | This window state is abnormal.               |
5961| 1300003 | This window manager service works abnormally. |
5962
5963**示例:**
5964
5965```ts
5966// EntryAbility.ets
5967import { UIAbility } from '@kit.AbilityKit';
5968import { BusinessError } from '@kit.BasicServicesKit';
5969import { window } from '@kit.ArkUI';
5970
5971export default class EntryAbility extends UIAbility {
5972  // ...
5973  onWindowStageCreate(windowStage: window.WindowStage): void {
5974    console.info('onWindowStageCreate');
5975    let windowClass: window.Window | undefined = undefined;
5976    windowStage.getMainWindow((err: BusinessError, data) => {
5977      const errCode: number = err.code;
5978      if (errCode) {
5979        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
5980        return;
5981      }
5982      windowClass = data;
5983      let promise = windowClass.enableLandscapeMultiWindow();
5984      promise.then(() => {
5985        console.info('Succeeded in making multi-window become landscape.');
5986      }).catch((err: BusinessError) => {
5987        console.error(`Failed to make multi-window become landscape. Cause code: ${err.code}, message: ${err.message}`);
5988      });
5989    });
5990  }
5991}
5992```
5993
5994### disableLandscapeMultiWindow<sup>12+</sup>
5995
5996disableLandscapeMultiWindow(): Promise&lt;void&gt;
5997
5998应用部分界面支持横向布局时,在退出该界面时去使能,去使能后不支持进入横向多窗。
5999
6000此接口只对应用主窗口生效,且需要在module.json5配置文件中[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中配置preferMultiWindowOrientation属性为"landscape_auto"。
6001
6002**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6003
6004**系统能力:** SystemCapability.Window.SessionManager
6005
6006**返回值:**
6007
6008| 类型                | 说明                      |
6009| ------------------- | ------------------------- |
6010| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6011
6012**错误码:**
6013
6014以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
6015
6016| 错误码ID | 错误信息 |
6017| ------- | -------------------------------------------- |
6018| 1300002 | This window state is abnormal.               |
6019| 1300003 | This window manager service works abnormally. |
6020
6021**示例:**
6022
6023```ts
6024// EntryAbility.ets
6025import { UIAbility } from '@kit.AbilityKit';
6026import { BusinessError } from '@kit.BasicServicesKit';
6027import { window } from '@kit.ArkUI';
6028
6029export default class EntryAbility extends UIAbility {
6030  // ...
6031  onWindowStageCreate(windowStage: window.WindowStage): void {
6032    console.info('onWindowStageCreate');
6033    let windowClass: window.Window | undefined = undefined;
6034    windowStage.getMainWindow((err: BusinessError, data) => {
6035      const errCode: number = err.code;
6036      if (errCode) {
6037        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6038        return;
6039      }
6040      windowClass = data;
6041      let promise = windowClass.disableLandscapeMultiWindow();
6042      promise.then(() => {
6043        console.info('Succeeded in making multi-window become not landscape.');
6044      }).catch((err: BusinessError) => {
6045        console.error(`Failed to make multi-window become not landscape. Cause code: ${err.code}, message: ${err.message}`);
6046      });
6047    });
6048  }
6049}
6050```
6051
6052### setDialogBackGestureEnabled<sup>12+</sup>
6053
6054setDialogBackGestureEnabled(enabled: boolean): Promise&lt;void&gt;
6055
6056设置模态窗口是否响应手势返回事件,非模态窗口调用返回错误码。
6057
6058**系统能力**:SystemCapability.Window.SessionManager
6059
6060**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6061
6062**参数:**
6063
6064| 参数名      | 类型    | 必填 | 说明                                                         |
6065| ---------- | ------- | ---- | ------------------------------------------------------------ |
6066| enabled    | boolean | 是   | 是否响应手势返回事件。<br>true表示响应手势返回事件,触发onBackPress回调;false表示不响应手势返回事件,不触发onBackPress回调。</br> |
6067
6068**返回值:**
6069
6070| 类型                | 说明                      |
6071| ------------------- | ------------------------- |
6072| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6073
6074**错误码:**
6075
6076以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6077
6078| 错误码ID | 错误信息 |
6079| ------- | -------------------------------------------- |
6080| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6081| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
6082| 1300002 | This window state is abnormal. |
6083| 1300003  | This window manager service works abnormally. |
6084| 1300004 | Unauthorized operation. |
6085
6086**示例:**
6087
6088```ts
6089// EntryAbility.ets
6090import { UIAbility } from '@kit.AbilityKit';
6091import { BusinessError } from '@kit.BasicServicesKit';
6092
6093export default class EntryAbility extends UIAbility {
6094  onWindowStageCreate(windowStage: window.WindowStage): void {
6095    console.info('onWindowStageCreate');
6096    let windowClass: window.Window | undefined = undefined;
6097    let config: window.Configuration = {
6098      name: "test",
6099      windowType: window.WindowType.TYPE_DIALOG,
6100      ctx: this.context
6101    };
6102    try {
6103      window.createWindow(config, (err: BusinessError, data) => {
6104        const errCode: number = err.code;
6105        if (errCode) {
6106          console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`);
6107          return;
6108        }
6109        windowClass = data;
6110        windowClass.setUIContent("pages/Index");
6111        let enabled = true;
6112        let promise = windowClass.setDialogBackGestureEnabled(enabled);
6113        promise.then(() => {
6114          console.info('Succeeded in setting dialog window to respond back gesture.');
6115        }).catch((err: BusinessError) => {
6116          console.error(`Failed to set dialog window to respond back gesture. Cause code: ${err.code}, message: ${err.message}`);
6117        });
6118      });
6119    } catch (exception) {
6120      console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`);
6121    }
6122  }
6123}
6124```
6125
6126```ts
6127// ets/pages/Index.ets
6128@Entry
6129@Component
6130struct Index {
6131  @State message: string = 'Hello World'
6132  build() {
6133    RelativeContainer() {
6134      Text(this.message)
6135        .id('HelloWorld')
6136        .fontSize(50)
6137        .fontWeight(FontWeight.Bold)
6138    }
6139    .height('100%')
6140    .width('100%')
6141  }
6142
6143  onBackPress(): boolean | void {
6144    console.info('Succeeded in setting dialog window to respond back gesture.');
6145    return true;
6146  }
6147}
6148```
6149
6150### setGestureBackEnabled<sup>13+<sup>
6151
6152setGestureBackEnabled(enabled: boolean): Promise&lt;void&gt;
6153
6154设置当前窗口是否禁用返回手势功能,仅主窗全屏模式下生效,2in1设备下不生效。
6155禁用返回手势功能后,当前应用会禁用手势热区,侧滑返回功能失效;切换到其他应用或者回到桌面后,手势热区恢复,侧滑返回功能正常。
6156开启返回手势功能后,当前应用会恢复手势热区,侧滑返回功能正常。
6157
6158**系统能力:** SystemCapability.Window.SessionManager
6159
6160**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
6161
6162**参数:**
6163
6164| 参数名     | 类型       | 必填     | 说明                                           |
6165| ---------- | --------- | -------- | --------------------------------------------- |
6166| enabled    | boolean   | 是       | true时开启返回手势功能,false时禁用返回手势功能。 |
6167
6168**返回值:**
6169
6170| 类型                | 说明                      |
6171| ------------------- | ------------------------- |
6172| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6173
6174**错误码:**
6175
6176以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6177
6178| 错误码ID | 错误信息                                                                                                     |
6179| -------- | ------------------------------------------------------------------------------------------------------------ |
6180| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6181| 801      | Capability not supported. Failed to call the API due to limited device capabilities.                         |
6182| 1300002  | This window state is abnormal.                                                                               |
6183| 1300003  | This window manager service works abnormally.                                                                |
6184| 1300004  | Unauthorized operation.                                                                                |
6185
6186**示例:**
6187
6188```ts
6189// EntryAbility.ets
6190import { UIAbility } from '@kit.AbilityKit';
6191import { BusinessError } from '@kit.BasicServicesKit';
6192import { window } from '@kit.ArkUI';
6193
6194export default class EntryAbility extends UIAbility {
6195  // ...
6196  onWindowStageCreate(windowStage: window.WindowStage): void {
6197    console.info('onWindowStageCreate');
6198    let windowClass: window.Window | undefined = undefined;
6199    windowStage.getMainWindow((err: BusinessError, data) => {
6200      const errCode: number = err.code;
6201      if (errCode) {
6202        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6203        return;
6204      }
6205      windowClass = data;
6206
6207      // 设置当前窗口禁用返回手势功能
6208      try {
6209        let gestureBackEnabled: boolean = false;
6210        let promise = windowClass.setGestureBackEnabled(gestureBackEnabled);
6211        promise.then(() => {
6212          console.info(`Succeeded in setting gesture back disabled`);
6213        }).catch((err: BusinessError) => {
6214          console.error(`Failed to set gesture back disabled, Cause code: ${err.code}, message: ${err.message}`);
6215        });
6216      } catch(exception) {
6217        console.error(`Failed to set gesture back disabled, Cause code: ${exception.code}, message: ${exception.message}`);
6218      }
6219    });
6220  }
6221}
6222```
6223
6224### isGestureBackEnabled<sup>13+<sup>
6225
6226isGestureBackEnabled(): boolean
6227
6228获取当前窗口是否禁用返回手势功能,仅主窗全屏模式下生效,2in1设备不生效。
6229
6230**系统能力:** SystemCapability.Window.SessionManager
6231
6232**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
6233
6234**返回值:**
6235
6236| 类型                | 说明                                           |
6237| ------------------- | --------------------------------------------- |
6238| boolean             | 是否已经禁用返回手势。true表示未禁用返回手势功能,false表示已禁用返回手势功能。 |
6239
6240**错误码:**
6241
6242以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6243
6244| 错误码ID | 错误信息                                                                                                     |
6245| -------- | ------------------------------------------------------------------------------------------------------------ |
6246| 801      | Capability not supported. Failed to call the API due to limited device capabilities.                         |
6247| 1300002  | This window state is abnormal.                                                                               |
6248| 1300003  | This window manager service works abnormally.                                                                |
6249| 1300004  | Unauthorized operation.                                                                                |
6250
6251**示例:**
6252
6253```ts
6254// EntryAbility.ets
6255import { UIAbility } from '@kit.AbilityKit';
6256import { BusinessError } from '@kit.BasicServicesKit';
6257import { window } from '@kit.ArkUI';
6258
6259export default class EntryAbility extends UIAbility {
6260  // ...
6261  onWindowStageCreate(windowStage: window.WindowStage): void {
6262    console.info('onWindowStageCreate');
6263    let windowClass: window.Window | undefined = undefined;
6264    windowStage.getMainWindow((err: BusinessError, data) => {
6265      const errCode: number = err.code;
6266      if (errCode) {
6267        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6268        return;
6269      }
6270      windowClass = data;
6271
6272      // 获取当前窗口是否禁用返回手势功能
6273      try {
6274        let gestureBackEnabled: boolean = windowClass.isGestureBackEnabled();
6275        console.info(`Succeeded in obtaining gesture back enabled status: ${gestureBackEnabled}`);
6276      } catch (exception) {
6277        console.error(`Failed to get gesture back enabled status. Cause code: ${exception.code}, message: ${exception.message}`);
6278      }
6279    });
6280  }
6281}
6282```
6283
6284### setWindowSystemBarProperties<sup>(deprecated)</sup>
6285
6286setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback&lt;void&gt;): void
6287
6288设置主窗口三键导航栏、状态栏的属性,使用callback异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
6289
6290子窗口调用后不生效。
6291
6292> **说明:**
6293>
6294> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowSystemBarProperties](#setwindowsystembarproperties9)。
6295
6296**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6297
6298**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6299
6300**参数:**
6301
6302| 参数名              | 类型                                        | 必填 | 说明                   |
6303| ------------------- | ------------------------------------------- | ---- | ---------------------- |
6304| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是   | 三键导航栏、状态栏的属性。 |
6305| callback            | AsyncCallback&lt;void&gt;                   | 是   | 回调函数。             |
6306
6307**错误码:**
6308
6309以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6310
6311| 错误码ID | 错误信息                                                                                                     |
6312| -------- | ------------------------------------------------------------------------------------------------------------ |
6313| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6314| 801      | Capability not supported. Failed to call the API due to limited device capabilities.                         |
6315| 1300002  | This window state is abnormal.                                                                               |
6316| 1300003  | This window manager service works abnormally.                                                                |
6317
6318**示例:**
6319
6320```ts
6321// EntryAbility.ets
6322import { UIAbility } from '@kit.AbilityKit';
6323import { BusinessError } from '@kit.BasicServicesKit';
6324
6325export default class EntryAbility extends UIAbility {
6326  // ...
6327  onWindowStageCreate(windowStage: window.WindowStage): void {
6328    console.info('onWindowStageCreate');
6329    let windowClass: window.Window | undefined = undefined;
6330    windowStage.getMainWindow((err: BusinessError, data) => {
6331      const errCode: number = err.code;
6332      if (errCode) {
6333        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6334        return;
6335      }
6336      windowClass = data;
6337      let SystemBarProperties: window.SystemBarProperties = {
6338        statusBarColor: '#ff00ff',
6339        navigationBarColor: '#00ff00',
6340        //以下两个属性从API Version8开始支持
6341        statusBarContentColor: '#ffffff',
6342        navigationBarContentColor: '#00ffff'
6343      };
6344      try {
6345        windowClass.setWindowSystemBarProperties(SystemBarProperties, (err: BusinessError) => {
6346          const errCode: number = err.code;
6347          if (errCode) {
6348            console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
6349            return;
6350          }
6351          console.info('Succeeded in setting the system bar properties.');
6352        });
6353      } catch (exception) {
6354        console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`);
6355      }
6356    });
6357  }
6358}
6359```
6360
6361### setWindowSystemBarEnable<sup>(deprecated)</sup>
6362
6363setWindowSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback&lt;void&gt;): void
6364
6365设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用callback异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
6366
6367子窗口调用后不生效。
6368
6369> **说明:**
6370>
6371> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowSystemBarEnable](#setwindowsystembarenable9)。
6372
6373**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6374
6375**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6376
6377**参数:**
6378
6379| 参数名   | 类型                          | 必填 | 说明                                                                                                                                          |
6380| -------- | ----------------------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------- |
6381| names    | Array<'status'\|'navigation'> | 是   | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];不设置,则默认不显示。 |
6382| callback | AsyncCallback&lt;void&gt;     | 是   | 回调函数。                                                                                                                                    |
6383
6384**错误码:**
6385
6386以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6387
6388| 错误码ID | 错误信息                                                                                                     |
6389| -------- | ------------------------------------------------------------------------------------------------------------ |
6390| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6391| 1300002  | This window state is abnormal.                                                                               |
6392| 1300003  | This window manager service works abnormally.                                                                |
6393
6394**示例:**
6395
6396```ts
6397// 此处以不显示三键导航栏、状态栏、底部导航条为例
6398// EntryAbility.ets
6399import { UIAbility } from '@kit.AbilityKit';
6400import { BusinessError } from '@kit.BasicServicesKit';
6401
6402export default class EntryAbility extends UIAbility {
6403  // ...
6404  onWindowStageCreate(windowStage: window.WindowStage): void {
6405    console.info('onWindowStageCreate');
6406    let windowClass: window.Window | undefined = undefined;
6407    windowStage.getMainWindow((err: BusinessError, data) => {
6408      const errCode: number = err.code;
6409      if (errCode) {
6410        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6411        return;
6412      }
6413      windowClass = data;
6414      let names: Array<'status' | 'navigation'> = [];
6415      try {
6416        windowClass.setWindowSystemBarEnable(names, (err: BusinessError) => {
6417          const errCode: number = err.code;
6418          if (errCode) {
6419            console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
6420            return;
6421          }
6422          console.info('Succeeded in setting the system bar to be invisible.');
6423        });
6424      } catch (exception) {
6425        console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`);
6426      }
6427    });
6428  }
6429}
6430```
6431
6432### setWindowLayoutFullScreen<sup>(deprecated)</sup>
6433
6434setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void
6435
6436设置主窗口或子窗口的布局是否为沉浸式布局,使用callback异步回调。
6437沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
6438非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。
6439
6440> **说明:**
6441>
6442> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowLayoutFullScreen](#setwindowlayoutfullscreen9)。
6443
6444**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6445
6446**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6447
6448**参数:**
6449
6450| 参数名             | 类型                      | 必填 | 说明                                                                                                          |
6451| ------------------ | ------------------------- | ---- | ------------------------------------------------------------------------------------------------------------- |
6452| isLayoutFullScreen | boolean                   | 是   | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 |
6453| callback           | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                                                                                    |
6454
6455**错误码:**
6456
6457以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6458
6459| 错误码ID | 错误信息                                                                                                     |
6460| -------- | ------------------------------------------------------------------------------------------------------------ |
6461| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6462| 1300002  | This window state is abnormal.                                                                               |
6463| 1300003  | This window manager service works abnormally.                                                                |
6464
6465**示例:**
6466
6467```ts
6468// EntryAbility.ets
6469import { UIAbility } from '@kit.AbilityKit';
6470import { BusinessError } from '@kit.BasicServicesKit';
6471
6472export default class EntryAbility extends UIAbility {
6473  // ...
6474  onWindowStageCreate(windowStage: window.WindowStage): void {
6475    console.info('onWindowStageCreate');
6476    let windowClass: window.Window | undefined = undefined;
6477    windowStage.getMainWindow((err: BusinessError, data) => {
6478      const errCode: number = err.code;
6479      if (errCode) {
6480        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6481        return;
6482      }
6483      windowClass = data;
6484      let isLayoutFullScreen = true;
6485      try {
6486        windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => {
6487          const errCode: number = err.code;
6488          if (errCode) {
6489            console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
6490            return;
6491          }
6492          console.info('Succeeded in setting the window layout to full-screen mode.');
6493        });
6494      } catch (exception) {
6495        console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`);
6496      }
6497    });
6498  }
6499}
6500```
6501
6502### show<sup>(deprecated)</sup>
6503
6504show(callback: AsyncCallback&lt;void&gt;): void
6505
6506显示当前窗口,使用callback异步回调。
6507
6508> **说明:**
6509>
6510> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9)。
6511
6512**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6513
6514**参数:**
6515
6516| 参数名   | 类型                      | 必填 | 说明       |
6517| -------- | ------------------------- | ---- | ---------- |
6518| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。 |
6519
6520**示例:**
6521
6522```ts
6523import { BusinessError } from '@kit.BasicServicesKit';
6524
6525windowClass.show((err: BusinessError) => {
6526  const errCode: number = err.code;
6527  if (errCode) {
6528    console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`);
6529    return;
6530  }
6531  console.info('Succeeded in showing the window.');
6532});
6533```
6534
6535### show<sup>(deprecated)</sup>
6536
6537show(): Promise&lt;void&gt;
6538
6539显示当前窗口,使用Promise异步回调。
6540
6541> **说明:**
6542>
6543> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9-1)。
6544
6545**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6546
6547**返回值:**
6548
6549| 类型                | 说明                      |
6550| ------------------- | ------------------------- |
6551| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6552
6553**示例:**
6554
6555```ts
6556import { BusinessError } from '@kit.BasicServicesKit';
6557
6558let promise = windowClass.show();
6559promise.then(() => {
6560  console.info('Succeeded in showing the window.');
6561}).catch((err: BusinessError) => {
6562  console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`);
6563});
6564```
6565
6566### destroy<sup>(deprecated)</sup>
6567
6568destroy(callback: AsyncCallback&lt;void&gt;): void
6569
6570销毁当前窗口,使用callback异步回调。
6571
6572> **说明:**
6573>
6574> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9)。
6575
6576**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6577
6578**参数:**
6579
6580| 参数名   | 类型                      | 必填 | 说明       |
6581| -------- | ------------------------- | ---- | ---------- |
6582| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。 |
6583
6584**示例:**
6585
6586```ts
6587import { BusinessError } from '@kit.BasicServicesKit';
6588
6589windowClass.destroy((err: BusinessError) => {
6590  const errCode: number = err.code;
6591  if (err.code) {
6592    console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`);
6593    return;
6594  }
6595  console.info('Succeeded in destroying the window.');
6596});
6597```
6598
6599### destroy<sup>(deprecated)</sup>
6600
6601destroy(): Promise&lt;void&gt;
6602
6603销毁当前窗口,使用Promise异步回调。
6604
6605> **说明:**
6606>
6607> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9-1)。
6608
6609**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6610
6611**返回值:**
6612
6613| 类型                | 说明                      |
6614| ------------------- | ------------------------- |
6615| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6616
6617**示例:**
6618
6619```ts
6620import { BusinessError } from '@kit.BasicServicesKit';
6621
6622let promise = windowClass.destroy();
6623promise.then(() => {
6624  console.info('Succeeded in destroying the window.');
6625}).catch((err: BusinessError) => {
6626  console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`);
6627});
6628```
6629
6630### moveTo<sup>(deprecated)</sup>
6631
6632moveTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void
6633
6634移动窗口位置,使用callback异步回调。
6635
6636全屏模式窗口不支持该操作。
6637
6638> **说明:**
6639>
6640> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9)。
6641
6642**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6643
6644**参数:**
6645
6646| 参数名   | 类型                      | 必填 | 说明                                              |
6647| -------- | ------------------------- | ---- | ------------------------------------------------- |
6648| x        | number                    | 是   | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
6649| y        | number                    | 是   | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
6650| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                        |
6651
6652**示例:**
6653
6654```ts
6655import { BusinessError } from '@kit.BasicServicesKit';
6656
6657windowClass.moveTo(300, 300, (err: BusinessError) => {
6658  const errCode: number = err.code;
6659  if (errCode) {
6660    console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
6661    return;
6662  }
6663  console.info('Succeeded in moving the window.');
6664});
6665```
6666
6667### moveTo<sup>(deprecated)</sup>
6668
6669moveTo(x: number, y: number): Promise&lt;void&gt;
6670
6671移动窗口位置,使用Promise异步回调。
6672
6673全屏模式窗口不支持该操作。
6674
6675> **说明:**
6676>
6677> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9-1)。
6678
6679**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6680
6681**参数:**
6682
6683| 参数名 | 类型   | 必填 | 说明                                              |
6684| ------ | ------ | ---- | ------------------------------------------------- |
6685| x      | number | 是   | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
6686| y      | number | 是   | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
6687
6688**返回值:**
6689
6690| 类型                | 说明                      |
6691| ------------------- | ------------------------- |
6692| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6693
6694**示例:**
6695
6696```ts
6697import { BusinessError } from '@kit.BasicServicesKit';
6698
6699let promise = windowClass.moveTo(300, 300);
6700promise.then(() => {
6701  console.info('Succeeded in moving the window.');
6702}).catch((err: BusinessError) => {
6703  console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
6704});
6705```
6706
6707### resetSize<sup>(deprecated)</sup>
6708
6709resetSize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void
6710
6711改变当前窗口大小,使用callback异步回调。
6712
6713应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为px。
6714应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
6715
6716系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为px。
6717
6718设置的宽度与高度受到此约束限制,规则:
6719若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
6720若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
6721
6722全屏模式窗口不支持该操作。
6723
6724> **说明:**
6725>
6726> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9)。
6727
6728**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6729
6730**参数:**
6731
6732| 参数名   | 类型                      | 必填 | 说明                       |
6733| -------- | ------------------------- | ---- | -------------------------- |
6734| width    | number                    | 是   | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
6735| height   | number                    | 是   | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
6736| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。                 |
6737
6738**示例:**
6739
6740```ts
6741import { BusinessError } from '@kit.BasicServicesKit';
6742
6743windowClass.resetSize(500, 1000, (err: BusinessError) => {
6744  const errCode: number = err.code;
6745  if (errCode) {
6746    console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
6747    return;
6748  }
6749  console.info('Succeeded in changing the window size.');
6750});
6751```
6752
6753### resetSize<sup>(deprecated)</sup>
6754
6755resetSize(width: number, height: number): Promise&lt;void&gt;
6756
6757改变当前窗口大小,使用Promise异步回调。
6758
6759应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为px。
6760应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
6761
6762系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为px。
6763
6764设置的宽度与高度受到此约束限制,规则:
6765若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
6766若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
6767
6768全屏模式窗口不支持该操作。
6769
6770> **说明:**
6771>
6772> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9-1)。
6773
6774**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6775
6776**参数:**
6777
6778| 参数名 | 类型   | 必填 | 说明                       |
6779| ------ | ------ | ---- | -------------------------- |
6780| width  | number | 是   | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
6781| height | number | 是   | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
6782
6783**返回值:**
6784
6785| 类型                | 说明                      |
6786| ------------------- | ------------------------- |
6787| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6788
6789**示例:**
6790
6791```ts
6792import { BusinessError } from '@kit.BasicServicesKit';
6793
6794let promise = windowClass.resetSize(500, 1000);
6795promise.then(() => {
6796  console.info('Succeeded in changing the window size.');
6797}).catch((err: BusinessError) => {
6798  console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
6799});
6800```
6801
6802### getProperties<sup>(deprecated)</sup>
6803
6804getProperties(callback: AsyncCallback&lt;WindowProperties&gt;): void
6805
6806获取当前窗口的属性,使用callback异步回调,返回WindowProperties。
6807
6808> **说明:**
6809>
6810> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。
6811
6812**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6813
6814**参数:**
6815
6816| 参数名   | 类型                                                       | 必填 | 说明                         |
6817| -------- | ---------------------------------------------------------- | ---- | ---------------------------- |
6818| callback | AsyncCallback&lt;[WindowProperties](#windowproperties)&gt; | 是   | 回调函数。返回当前窗口属性。 |
6819
6820**示例:**
6821
6822```ts
6823import { BusinessError } from '@kit.BasicServicesKit';
6824
6825windowClass.getProperties((err: BusinessError, data) => {
6826  const errCode: number = err.code;
6827  if (errCode) {
6828    console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`);
6829    return;
6830  }
6831  console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data));
6832});
6833```
6834
6835### getProperties<sup>(deprecated)</sup>
6836
6837getProperties(): Promise&lt;WindowProperties&gt;
6838
6839获取当前窗口的属性,使用Promise异步回调,返回WindowProperties。
6840
6841> **说明:**
6842>
6843> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。
6844
6845**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6846
6847**返回值:**
6848
6849| 类型                                                 | 说明                            |
6850| ---------------------------------------------------- | ------------------------------- |
6851| Promise&lt;[WindowProperties](#windowproperties)&gt; | Promise对象。返回当前窗口属性。 |
6852
6853**示例:**
6854
6855```ts
6856import { BusinessError } from '@kit.BasicServicesKit';
6857
6858let promise = windowClass.getProperties();
6859promise.then((data) => {
6860  console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data));
6861}).catch((err: BusinessError) => {
6862  console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`);
6863});
6864```
6865
6866### getAvoidArea<sup>(deprecated)</sup>
6867
6868getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback&lt;[AvoidArea](#avoidarea7)&gt;): void
6869
6870获取当前窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。
6871
6872> **说明:**
6873>
6874> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。
6875
6876**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6877
6878**参数:**
6879
6880| 参数名   | 类型                                            | 必填 | 说明                                                         |
6881| -------- |-----------------------------------------------| ---- | ------------------------------------------------------------ |
6882| type     | [AvoidAreaType](#avoidareatype7)              | 是   | 表示规避区类型。|
6883| callback | AsyncCallback&lt;[AvoidArea](#avoidarea7)&gt; | 是   | 回调函数。返回窗口内容规避区域。                             |
6884
6885**示例:**
6886
6887```ts
6888import { BusinessError } from '@kit.BasicServicesKit';
6889
6890let type = window.AvoidAreaType.TYPE_SYSTEM;
6891windowClass.getAvoidArea(type, (err: BusinessError, data) => {
6892  const errCode: number = err.code;
6893  if (errCode) {
6894    console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`);
6895    return;
6896  }
6897  console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
6898});
6899```
6900
6901### getAvoidArea<sup>(deprecated)</sup>
6902
6903getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise&lt;[AvoidArea](#avoidarea7)&gt;
6904
6905获取当前窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。
6906
6907> **说明:**
6908>
6909> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。
6910
6911**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6912
6913**参数:**
6914
6915| 参数名 | 类型                               | 必填 | 说明                                                         |
6916| ------ |----------------------------------| ---- | ------------------------------------------------------------ |
6917| type   | [AvoidAreaType](#avoidareatype7) | 是   | 表示规避区类型。 |
6918
6919**返回值:**
6920
6921| 类型                                      | 说明                                |
6922|-----------------------------------------| ----------------------------------- |
6923| Promise&lt;[AvoidArea](#avoidarea7)&gt; | Promise对象。返回窗口内容规避区域。 |
6924
6925**示例:**
6926
6927```ts
6928import { BusinessError } from '@kit.BasicServicesKit';
6929
6930let type = window.AvoidAreaType.TYPE_SYSTEM;
6931let promise = windowClass.getAvoidArea(type);
6932promise.then((data) => {
6933  console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
6934}).catch((err: BusinessError) => {
6935  console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`);
6936});
6937```
6938
6939### setFullScreen<sup>(deprecated)</sup>
6940
6941setFullScreen(isFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void
6942
6943设置主窗口或子窗口的布局是否为全屏布局,使用callback异步回调。
6944全屏布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
6945非全屏布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。
6946
6947> **说明:**
6948>
6949> 从 API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)实现全屏。
6950
6951**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6952
6953**参数:**
6954
6955| 参数名       | 类型                      | 必填 | 说明                                           |
6956| ------------ | ------------------------- | ---- | ---------------------------------------------- |
6957| isFullScreen | boolean                   | 是   | 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。 |
6958| callback     | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                     |
6959
6960**示例:**
6961
6962```ts
6963// EntryAbility.ets
6964import { UIAbility } from '@kit.AbilityKit';
6965import { BusinessError } from '@kit.BasicServicesKit';
6966
6967export default class EntryAbility extends UIAbility {
6968  // ...
6969  onWindowStageCreate(windowStage: window.WindowStage): void {
6970    console.info('onWindowStageCreate');
6971    let windowClass: window.Window | undefined = undefined;
6972    windowStage.getMainWindow((err: BusinessError, data) => {
6973      const errCode: number = err.code;
6974      if (errCode) {
6975        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6976        return;
6977      }
6978      windowClass = data;
6979      let isFullScreen: boolean = true;
6980      windowClass.setFullScreen(isFullScreen, (err: BusinessError) => {
6981        const errCode: number = err.code;
6982        if (errCode) {
6983          console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
6984          return;
6985        }
6986        console.info('Succeeded in enabling the full-screen mode.');
6987      });
6988    });
6989  }
6990}
6991```
6992
6993### setFullScreen<sup>(deprecated)</sup>
6994
6995setFullScreen(isFullScreen: boolean): Promise&lt;void&gt;
6996
6997设置主窗口或子窗口的布局是否为全屏布局,使用Promise异步回调。
6998全屏布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
6999非全屏布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。
7000
7001> **说明:**
7002>
7003> 从 API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)实现全屏。
7004
7005**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7006
7007**参数:**
7008
7009| 参数名       | 类型    | 必填 | 说明                                           |
7010| ------------ | ------- | ---- | ---------------------------------------------- |
7011| isFullScreen | boolean | 是   | 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。 |
7012
7013**返回值:**
7014
7015| 类型                | 说明                      |
7016| ------------------- | ------------------------- |
7017| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7018
7019**示例:**
7020
7021```ts
7022// EntryAbility.ets
7023import { UIAbility } from '@kit.AbilityKit';
7024import { BusinessError } from '@kit.BasicServicesKit';
7025
7026export default class EntryAbility extends UIAbility {
7027  // ...
7028  onWindowStageCreate(windowStage: window.WindowStage): void {
7029    console.info('onWindowStageCreate');
7030    let windowClass: window.Window | undefined = undefined;
7031    windowStage.getMainWindow((err: BusinessError, data) => {
7032      const errCode: number = err.code;
7033      if (errCode) {
7034        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7035        return;
7036      }
7037      windowClass = data;
7038      let isFullScreen: boolean = true;
7039      let promise = windowClass.setFullScreen(isFullScreen);
7040      promise.then(() => {
7041        console.info('Succeeded in enabling the full-screen mode.');
7042      }).catch((err: BusinessError) => {
7043        console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
7044      });
7045    });
7046  }
7047}
7048```
7049
7050### setLayoutFullScreen<sup>(deprecated)</sup>
7051
7052setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void
7053
7054设置主窗口或子窗口的布局是否为沉浸式布局,使用callback异步回调。
7055沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
7056非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。
7057
7058> **说明:**
7059>
7060> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)。
7061
7062**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7063
7064**参数:**
7065
7066| 参数名             | 类型                      | 必填 | 说明                                                         |
7067| ------------------ | ------------------------- | ---- | ------------------------------------------------------------ |
7068| isLayoutFullScreen | boolean                   | 是   | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。 |
7069| callback           | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                                   |
7070
7071**示例:**
7072
7073```ts
7074// EntryAbility.ets
7075import { UIAbility } from '@kit.AbilityKit';
7076import { BusinessError } from '@kit.BasicServicesKit';
7077
7078export default class EntryAbility extends UIAbility {
7079  // ...
7080  onWindowStageCreate(windowStage: window.WindowStage): void {
7081    console.info('onWindowStageCreate');
7082    let windowClass: window.Window | undefined = undefined;
7083    windowStage.getMainWindow((err: BusinessError, data) => {
7084      const errCode: number = err.code;
7085      if (errCode) {
7086        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7087        return;
7088      }
7089      windowClass = data;
7090      let isLayoutFullScreen: boolean = true;
7091      windowClass.setLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => {
7092        const errCode: number = err.code;
7093        if (errCode) {
7094          console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
7095          return;
7096        }
7097        console.info('Succeeded in setting the window layout to full-screen mode.');
7098      });
7099    });
7100  }
7101}
7102```
7103
7104### setLayoutFullScreen<sup>(deprecated)</sup>
7105
7106setLayoutFullScreen(isLayoutFullScreen: boolean): Promise&lt;void&gt;
7107
7108设置主窗口或子窗口的布局是否为沉浸式布局,使用Promise异步回调。
7109沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
7110非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。
7111
7112> **说明:**
7113>
7114> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)。
7115
7116**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7117
7118**参数:**
7119
7120| 参数名             | 类型    | 必填 | 说明                                                         |
7121| ------------------ | ------- | ---- | ------------------------------------------------------------ |
7122| isLayoutFullScreen | boolean | 是   | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。 |
7123
7124**返回值:**
7125
7126| 类型                | 说明                      |
7127| ------------------- | ------------------------- |
7128| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7129
7130**示例:**
7131
7132```ts
7133// EntryAbility.ets
7134import { UIAbility } from '@kit.AbilityKit';
7135import { BusinessError } from '@kit.BasicServicesKit';
7136
7137export default class EntryAbility extends UIAbility {
7138  // ...
7139  onWindowStageCreate(windowStage: window.WindowStage): void {
7140    console.info('onWindowStageCreate');
7141    let windowClass: window.Window | undefined = undefined;
7142    windowStage.getMainWindow((err: BusinessError, data) => {
7143      const errCode: number = err.code;
7144      if (errCode) {
7145        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7146        return;
7147      }
7148      windowClass = data;
7149      let isLayoutFullScreen: boolean = true;
7150      let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen);
7151      promise.then(() => {
7152        console.info('Succeeded in setting the window layout to full-screen mode.');
7153      }).catch((err: BusinessError) => {
7154        console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
7155      });
7156    });
7157  }
7158}
7159```
7160
7161### setSystemBarEnable<sup>(deprecated)</sup>
7162
7163setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback&lt;void&gt;): void
7164
7165设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用callback异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
7166
7167子窗口调用后不生效。
7168
7169> **说明:**
7170>
7171> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)。
7172
7173**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7174
7175**参数:**
7176
7177| 参数名   | 类型                      | 必填 | 说明                                                         |
7178| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
7179| names    | Array<'status'\|'navigation'> | 是   | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];不设置,则默认不显示。 |
7180| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                                   |
7181
7182
7183**示例:**
7184
7185```ts
7186// 此处以不显示三键导航栏、状态栏、底部导航条为例
7187// EntryAbility.ets
7188import { UIAbility } from '@kit.AbilityKit';
7189import { BusinessError } from '@kit.BasicServicesKit';
7190
7191export default class EntryAbility extends UIAbility {
7192  // ...
7193  onWindowStageCreate(windowStage: window.WindowStage): void {
7194    console.info('onWindowStageCreate');
7195    let windowClass: window.Window | undefined = undefined;
7196    windowStage.getMainWindow((err: BusinessError, data) => {
7197      const errCode: number = err.code;
7198      if (errCode) {
7199        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7200        return;
7201      }
7202      windowClass = data;
7203      let names: Array<'status' | 'navigation'> = [];
7204      windowClass.setSystemBarEnable(names, (err: BusinessError) => {
7205        const errCode: number = err.code;
7206        if (errCode) {
7207          console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
7208          return;
7209        }
7210        console.info('Succeeded in setting the system bar to be invisible.');
7211      });
7212    });
7213  }
7214}
7215```
7216
7217### setSystemBarEnable<sup>(deprecated)</sup>
7218
7219setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise&lt;void&gt;
7220
7221设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
7222
7223子窗口调用后不生效。
7224
7225> **说明:**
7226>
7227> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)。
7228
7229**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7230
7231**参数:**
7232
7233| 参数名 | 类型  | 必填 | 说明                                                         |
7234| ------ | ---------------------------- | ---- | ------------------------ |
7235| names  | Array<'status'\|'navigation'> | 是   | 设置窗口全屏模式时状态栏、三键导航栏、底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];不设置,则默认不显示。 |
7236
7237**返回值:**
7238
7239| 类型                | 说明                      |
7240| ------------------- | ------------------------- |
7241| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7242
7243
7244**示例:**
7245
7246```ts
7247// 此处以不显示三键导航栏、状态栏、底部导航条为例
7248// EntryAbility.ets
7249import { UIAbility } from '@kit.AbilityKit';
7250import { BusinessError } from '@kit.BasicServicesKit';
7251
7252export default class EntryAbility extends UIAbility {
7253  // ...
7254  onWindowStageCreate(windowStage: window.WindowStage): void {
7255    console.info('onWindowStageCreate');
7256    let windowClass: window.Window | undefined = undefined;
7257    windowStage.getMainWindow((err: BusinessError, data) => {
7258      const errCode: number = err.code;
7259      if (errCode) {
7260        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7261        return;
7262      }
7263      windowClass = data;
7264      let names: Array<'status' | 'navigation'> = [];
7265      let promise = windowClass.setSystemBarEnable(names);
7266      promise.then(() => {
7267        console.info('Succeeded in setting the system bar to be invisible.');
7268      }).catch((err: BusinessError) => {
7269        console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
7270      });
7271    });
7272  }
7273}
7274```
7275
7276### setSystemBarProperties<sup>(deprecated)</sup>
7277
7278setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback&lt;void&gt;): void
7279
7280设置主窗口三键导航栏、状态栏的属性,使用callback异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
7281
7282子窗口调用后不生效。
7283
7284> **说明:**
7285>
7286> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9)。
7287
7288**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7289
7290**参数:**
7291
7292| 参数名              | 类型                                        | 必填 | 说明                   |
7293| ------------------- | ------------------------------------------- | ---- | ---------------------- |
7294| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是   | 三键导航栏、状态栏的属性。 |
7295| callback            | AsyncCallback&lt;void&gt;                   | 是   | 回调函数。             |
7296
7297**示例:**
7298
7299```ts
7300// EntryAbility.ets
7301import { UIAbility } from '@kit.AbilityKit';
7302import { BusinessError } from '@kit.BasicServicesKit';
7303
7304export default class EntryAbility extends UIAbility {
7305  // ...
7306  onWindowStageCreate(windowStage: window.WindowStage): void {
7307    console.info('onWindowStageCreate');
7308    let windowClass: window.Window | undefined = undefined;
7309    windowStage.getMainWindow((err: BusinessError, data) => {
7310      const errCode: number = err.code;
7311      if (errCode) {
7312        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7313        return;
7314      }
7315      windowClass = data;
7316      let SystemBarProperties: window.SystemBarProperties = {
7317        statusBarColor: '#ff00ff',
7318        navigationBarColor: '#00ff00',
7319        //以下两个属性从API Version8开始支持
7320        statusBarContentColor: '#ffffff',
7321        navigationBarContentColor: '#00ffff'
7322      };
7323      windowClass.setSystemBarProperties(SystemBarProperties, (err) => {
7324        const errCode: number = err.code;
7325        if (errCode) {
7326          console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
7327          return;
7328        }
7329        console.info('Succeeded in setting the system bar properties.');
7330      });
7331    });
7332  }
7333}
7334```
7335
7336### setSystemBarProperties<sup>(deprecated)</sup>
7337
7338setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise&lt;void&gt;
7339
7340设置主窗口三键导航栏、状态栏的属性,使用Promise异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
7341
7342子窗口调用后不生效。
7343
7344> **说明:**
7345>
7346> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9-1)。
7347
7348**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7349
7350**参数:**
7351
7352| 参数名              | 类型                                        | 必填 | 说明                   |
7353| ------------------- | ------------------------------------------- | ---- | ---------------------- |
7354| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是   | 三键导航栏、状态栏的属性。 |
7355
7356**返回值:**
7357
7358| 类型                | 说明                      |
7359| ------------------- | ------------------------- |
7360| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7361
7362**示例:**
7363
7364```ts
7365// EntryAbility.ets
7366import { UIAbility } from '@kit.AbilityKit';
7367import { BusinessError } from '@kit.BasicServicesKit';
7368
7369export default class EntryAbility extends UIAbility {
7370  // ...
7371  onWindowStageCreate(windowStage: window.WindowStage): void {
7372    console.info('onWindowStageCreate');
7373    let windowClass: window.Window | undefined = undefined;
7374    windowStage.getMainWindow((err: BusinessError, data) => {
7375      const errCode: number = err.code;
7376      if (errCode) {
7377        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7378        return;
7379      }
7380      windowClass = data;
7381      let SystemBarProperties: window.SystemBarProperties = {
7382        statusBarColor: '#ff00ff',
7383        navigationBarColor: '#00ff00',
7384        //以下两个属性从API Version8开始支持
7385        statusBarContentColor: '#ffffff',
7386        navigationBarContentColor: '#00ffff'
7387      };
7388      let promise = windowClass.setSystemBarProperties(SystemBarProperties);
7389      promise.then(() => {
7390        console.info('Succeeded in setting the system bar properties.');
7391      }).catch((err: BusinessError) => {
7392        console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
7393      });
7394    });
7395  }
7396}
7397```
7398
7399### loadContent<sup>(deprecated)</sup>
7400
7401loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void
7402
7403为当前窗口加载具体页面内容,使用callback异步回调。
7404
7405> **说明:**
7406>
7407> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9)。
7408
7409**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7410
7411**参数:**
7412
7413| 参数名   | 类型                      | 必填 | 说明                 |
7414| -------- | ------------------------- | ---- | -------------------- |
7415| path     | string                    | 是   | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 |
7416| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
7417
7418**示例:**
7419
7420```ts
7421import { BusinessError } from '@kit.BasicServicesKit';
7422
7423windowClass.loadContent('pages/page2/page3', (err: BusinessError) => {
7424  const errCode: number = err.code;
7425  if (errCode) {
7426    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
7427    return;
7428  }
7429  console.info('Succeeded in loading the content.');
7430});
7431```
7432
7433### loadContent<sup>(deprecated)</sup>
7434
7435loadContent(path: string): Promise&lt;void&gt;
7436
7437为当前窗口加载具体页面内容,使用Promise异步回调。
7438
7439> **说明:**
7440>
7441> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9-1)。
7442
7443**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7444
7445**参数:**
7446
7447| 参数名 | 类型   | 必填 | 说明                 |
7448| ------ | ------ | ---- | -------------------- |
7449| path   | string | 是   | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 |
7450
7451**返回值:**
7452
7453| 类型                | 说明                      |
7454| ------------------- | ------------------------- |
7455| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7456
7457**示例:**
7458
7459```ts
7460import { BusinessError } from '@kit.BasicServicesKit';
7461
7462let promise = windowClass.loadContent('pages/page2/page3');
7463promise.then(() => {
7464  console.info('Succeeded in loading the content.');
7465}).catch((err: BusinessError) => {
7466  console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
7467});
7468```
7469
7470### isShowing<sup>(deprecated)</sup>
7471
7472isShowing(callback: AsyncCallback&lt;boolean&gt;): void
7473
7474判断当前窗口是否已显示,使用callback异步回调。
7475
7476> **说明:**
7477>
7478> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。
7479
7480**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7481
7482**参数:**
7483
7484| 参数名   | 类型                         | 必填 | 说明                                                         |
7485| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
7486| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 |
7487
7488**示例:**
7489
7490```ts
7491import { BusinessError } from '@kit.BasicServicesKit';
7492
7493windowClass.isShowing((err: BusinessError, data) => {
7494  const errCode: number = err.code;
7495  if (errCode) {
7496    console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`);
7497    return;
7498  }
7499  console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
7500});
7501```
7502
7503### isShowing<sup>(deprecated)</sup>
7504
7505isShowing(): Promise&lt;boolean&gt;
7506
7507判断当前窗口是否已显示,使用Promise异步回调。
7508
7509> **说明:**
7510>
7511> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。
7512
7513**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7514
7515**返回值:**
7516
7517| 类型                   | 说明                                                         |
7518| ---------------------- | ------------------------------------------------------------ |
7519| Promise&lt;boolean&gt; | Promise对象。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 |
7520
7521**示例:**
7522
7523```ts
7524import { BusinessError } from '@kit.BasicServicesKit';
7525
7526let promise = windowClass.isShowing();
7527promise.then((data) => {
7528  console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
7529}).catch((err: BusinessError) => {
7530  console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`);
7531});
7532```
7533
7534### on('systemAvoidAreaChange')<sup>(deprecated)</sup>
7535
7536on(type: 'systemAvoidAreaChange', callback: Callback&lt;AvoidArea&gt;): void
7537
7538开启当前窗口系统规避区变化的监听。
7539
7540> **说明:**
7541>
7542> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[on('avoidAreaChange')](#onavoidareachange9)。
7543
7544**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7545
7546**参数:**
7547
7548| 参数名   | 类型                                       | 必填 | 说明                                                    |
7549| -------- |------------------------------------------| ---- | ------------------------------------------------------- |
7550| type     | string                                   | 是   | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 |
7551| callback | Callback&lt;[AvoidArea](#avoidarea7)&gt; | 是   | 回调函数。返回当前规避区。                             |
7552
7553
7554**示例:**
7555
7556```ts
7557windowClass.on('systemAvoidAreaChange', (data) => {
7558  console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data));
7559});
7560```
7561
7562### off('systemAvoidAreaChange')<sup>(deprecated)</sup>
7563
7564off(type: 'systemAvoidAreaChange', callback?: Callback&lt;AvoidArea&gt;): void
7565
7566关闭当前窗口系统规避区变化的监听。
7567
7568> **说明:**
7569>
7570> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[off('avoidAreaChange')](#offavoidareachange9)。
7571
7572**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7573
7574**参数:**
7575
7576| 参数名   | 类型                                       | 必填 | 说明                                                    |
7577| -------- |------------------------------------------| ---- | ------------------------------------------------------- |
7578| type     | string                                   | 是   | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 |
7579| callback | Callback&lt;[AvoidArea](#avoidarea7)&gt; | 否   | 回调函数。返回当前规避区。若传入参数,则关闭该监听。若未传入参数,则关闭所有系统规避区变化的监听。           |
7580
7581**示例:**
7582
7583```ts
7584const callback = (avoidArea: window.AvoidArea) => {
7585  // ...
7586}
7587windowClass.on('systemAvoidAreaChange', callback);
7588windowClass.off('systemAvoidAreaChange', callback);
7589// 如果通过on开启多个callback进行监听,同时关闭所有监听:
7590windowClass.off('systemAvoidAreaChange');
7591```
7592
7593### isSupportWideGamut<sup>(deprecated)</sup>
7594
7595isSupportWideGamut(callback: AsyncCallback&lt;boolean&gt;): void
7596
7597判断当前窗口是否支持广色域模式,使用callback异步回调。
7598
7599> **说明:**
7600>
7601> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9)。
7602
7603**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7604
7605**参数:**
7606
7607| 参数名   | 类型                         | 必填 | 说明                                                         |
7608| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
7609| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 |
7610
7611**示例:**
7612
7613```ts
7614import { BusinessError } from '@kit.BasicServicesKit';
7615
7616windowClass.isSupportWideGamut((err: BusinessError, data) => {
7617  const errCode: number = err.code;
7618  if (errCode) {
7619    console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`);
7620    return;
7621  }
7622  console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data));
7623});
7624```
7625
7626### isSupportWideGamut<sup>(deprecated)</sup>
7627
7628isSupportWideGamut(): Promise&lt;boolean&gt;
7629
7630判断当前窗口是否支持广色域模式,使用Promise异步回调。
7631
7632> **说明:**
7633>
7634> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9-1)。
7635
7636**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7637
7638**返回值:**
7639
7640| 类型                   | 说明                                                         |
7641| ---------------------- | ------------------------------------------------------------ |
7642| Promise&lt;boolean&gt; | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 |
7643
7644**示例:**
7645
7646```ts
7647import { BusinessError } from '@kit.BasicServicesKit';
7648
7649let promise = windowClass.isSupportWideGamut();
7650promise.then((data) => {
7651  console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data));
7652}).catch((err: BusinessError) => {
7653  console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`);
7654});
7655```
7656
7657### setColorSpace<sup>(deprecated)</sup>
7658
7659setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback&lt;void&gt;): void
7660
7661设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。
7662
7663> **说明:**
7664>
7665> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9)。
7666
7667**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7668
7669**参数:**
7670
7671| 参数名     | 类型                      | 必填 | 说明         |
7672| ---------- | ------------------------- | ---- | ------------ |
7673| colorSpace | [ColorSpace](#colorspace8) | 是   | 设置色域模式。 |
7674| callback   | AsyncCallback&lt;void&gt; | 是   | 回调函数。   |
7675
7676
7677**示例:**
7678
7679```ts
7680import { BusinessError } from '@kit.BasicServicesKit';
7681
7682windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => {
7683  const errCode: number = err.code;
7684  if (errCode) {
7685    console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`);
7686    return;
7687  }
7688  console.info('Succeeded in setting window colorspace.');
7689});
7690```
7691
7692### setColorSpace<sup>(deprecated)</sup>
7693
7694setColorSpace(colorSpace:ColorSpace): Promise&lt;void&gt;
7695
7696设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。
7697
7698> **说明:**
7699>
7700> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9-1)。
7701
7702**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7703
7704**参数:**
7705
7706| 参数名     | 类型                      | 必填 | 说明           |
7707| ---------- | ------------------------- | ---- | -------------- |
7708| colorSpace | [ColorSpace](#colorspace8) | 是   | 设置色域模式。 |
7709
7710**返回值:**
7711
7712| 类型                | 说明                      |
7713| ------------------- | ------------------------- |
7714| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7715
7716
7717**示例:**
7718
7719```ts
7720import { BusinessError } from '@kit.BasicServicesKit';
7721
7722let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT);
7723promise.then(() => {
7724  console.info('Succeeded in setting window colorspace.');
7725}).catch((err: BusinessError) => {
7726  console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`);
7727});
7728```
7729
7730### getColorSpace<sup>(deprecated)</sup>
7731
7732getColorSpace(callback: AsyncCallback&lt;ColorSpace&gt;): void
7733
7734获取当前窗口色域模式,使用callback异步回调。
7735
7736> **说明:**
7737>
7738> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。
7739
7740**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7741
7742**参数:**
7743
7744| 参数名   | 类型                                           | 必填 | 说明                                                       |
7745| -------- | ---------------------------------------------- | ---- | ---------------------------------------------------------- |
7746| callback | AsyncCallback&lt;[ColorSpace](#colorspace8)&gt; | 是   | 回调函数。当获取成功,err为undefined,data为当前色域模式。 |
7747
7748**示例:**
7749
7750```ts
7751import { BusinessError } from '@kit.BasicServicesKit';
7752
7753windowClass.getColorSpace((err: BusinessError, data) => {
7754  const errCode: number = err.code;
7755  if (errCode) {
7756    console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`);
7757    return;
7758  }
7759  console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data));
7760});
7761```
7762
7763### getColorSpace<sup>(deprecated)</sup>
7764
7765getColorSpace(): Promise&lt;ColorSpace&gt;
7766
7767获取当前窗口色域模式,使用Promise异步回调。
7768
7769> **说明:**
7770>
7771> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。
7772
7773**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7774
7775**返回值:**
7776
7777| 类型                                     | 说明                            |
7778| ---------------------------------------- | ------------------------------- |
7779| Promise&lt;[ColorSpace](#colorspace8)&gt; | Promise对象。返回当前色域模式。 |
7780
7781**示例:**
7782
7783```ts
7784import { BusinessError } from '@kit.BasicServicesKit';
7785
7786let promise = windowClass.getColorSpace();
7787promise.then((data) => {
7788  console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data));
7789}).catch((err: BusinessError) => {
7790  console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`);
7791});
7792```
7793
7794### setBackgroundColor<sup>(deprecated)</sup>
7795
7796setBackgroundColor(color: string, callback: AsyncCallback&lt;void&gt;): void
7797
7798设置窗口的背景色,使用callback异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
7799
7800> **说明:**
7801>
7802> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。
7803
7804**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7805
7806**参数:**
7807
7808| 参数名   | 类型                      | 必填 | 说明                                                         |
7809| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
7810| color    | string                    | 是   | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 |
7811| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                                   |
7812
7813
7814**示例:**
7815
7816```ts
7817import { BusinessError } from '@kit.BasicServicesKit';
7818
7819let color: string = '#00ff33';
7820windowClass.setBackgroundColor(color, (err: BusinessError) => {
7821  const errCode: number = err.code;
7822  if (errCode) {
7823    console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`);
7824    return;
7825  }
7826  console.info('Succeeded in setting the background color.');
7827});
7828```
7829
7830### setBackgroundColor<sup>(deprecated)</sup>
7831
7832setBackgroundColor(color: string): Promise&lt;void&gt;
7833
7834设置窗口的背景色,使用Promise异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
7835
7836> **说明:**
7837>
7838> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。
7839
7840**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7841
7842**参数:**
7843
7844| 参数名 | 类型   | 必填 | 说明                                                         |
7845| ------ | ------ | ---- | ------------------------------------------------------------ |
7846| color  | string | 是   | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 |
7847
7848**返回值:**
7849
7850| 类型                | 说明                      |
7851| ------------------- | ------------------------- |
7852| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7853
7854
7855**示例:**
7856
7857```ts
7858import { BusinessError } from '@kit.BasicServicesKit';
7859
7860let color: string = '#00ff33';
7861let promise = windowClass.setBackgroundColor(color);
7862promise.then(() => {
7863  console.info('Succeeded in setting the background color.');
7864}).catch((err: BusinessError) => {
7865  console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`);
7866});
7867```
7868
7869### setBrightness<sup>(deprecated)</sup>
7870
7871setBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void
7872
7873允许应用窗口设置屏幕亮度值,使用callback异步回调。
7874
7875当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。
7876
7877> **说明:**
7878>
7879> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9)。
7880
7881**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7882
7883**参数:**
7884
7885| 参数名     | 类型                      | 必填 | 说明                                    |
7886| ---------- | ------------------------- | ---- |---------------------------------------|
7887| brightness | number                    | 是   | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 |
7888| callback   | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                 |
7889
7890
7891**示例:**
7892
7893```ts
7894import { BusinessError } from '@kit.BasicServicesKit';
7895
7896let brightness: number = 1;
7897windowClass.setBrightness(brightness, (err: BusinessError) => {
7898  const errCode: number = err.code;
7899  if (errCode) {
7900    console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`);
7901    return;
7902  }
7903  console.info('Succeeded in setting the brightness.');
7904});
7905```
7906
7907### setBrightness<sup>(deprecated)</sup>
7908
7909setBrightness(brightness: number): Promise&lt;void&gt;
7910
7911允许应用窗口设置屏幕亮度值,使用Promise异步回调。
7912
7913当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。
7914
7915> **说明:**
7916>
7917> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9-1)。
7918
7919**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7920
7921**参数:**
7922
7923| 参数名     | 类型   | 必填 | 说明                                       |
7924| ---------- | ------ | ---- |------------------------------------------|
7925| brightness | number | 是   | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 |
7926
7927**返回值:**
7928
7929| 类型                | 说明                      |
7930| ------------------- | ------------------------- |
7931| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7932
7933
7934**示例:**
7935
7936```ts
7937import { BusinessError } from '@kit.BasicServicesKit';
7938
7939let brightness: number = 1;
7940let promise = windowClass.setBrightness(brightness);
7941promise.then(() => {
7942  console.info('Succeeded in setting the brightness.');
7943}).catch((err: BusinessError) => {
7944  console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`);
7945});
7946```
7947
7948### setDimBehind<sup>(deprecated)</sup>
7949
7950setDimBehind(dimBehindValue: number, callback: AsyncCallback&lt;void&gt;): void
7951
7952窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用callback异步回调。
7953
7954> **说明:**
7955>
7956> 该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。
7957
7958**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7959
7960**参数:**
7961
7962| 参数名         | 类型                      | 必填 | 说明                                     |
7963| -------------- | ------------------------- | ---- |----------------------------------------|
7964| dimBehindValue | number                    | 是   | 表示靠后的窗口的暗度值,取值范围为[0.0, 1.0],取1.0时表示最暗。 |
7965| callback       | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                  |
7966
7967**示例:**
7968
7969```ts
7970import { BusinessError } from '@kit.BasicServicesKit';
7971
7972windowClass.setDimBehind(0.5, (err: BusinessError) => {
7973  const errCode: number = err.code;
7974  if (errCode) {
7975    console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`);
7976    return;
7977  }
7978  console.info('Succeeded in setting the dimness.');
7979});
7980```
7981
7982### setDimBehind<sup>(deprecated)</sup>
7983
7984setDimBehind(dimBehindValue: number): Promise&lt;void&gt;
7985
7986窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用Promise异步回调。
7987
7988> **说明:**
7989>
7990> 该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。
7991
7992**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7993
7994**参数:**
7995
7996| 参数名         | 类型   | 必填 | 说明                                               |
7997| -------------- | ------ | ---- | -------------------------------------------------- |
7998| dimBehindValue | number | 是   | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 |
7999
8000**返回值:**
8001
8002| 类型                | 说明                      |
8003| ------------------- | ------------------------- |
8004| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8005
8006**示例:**
8007
8008```ts
8009import { BusinessError } from '@kit.BasicServicesKit';
8010
8011let promise = windowClass.setDimBehind(0.5);
8012promise.then(() => {
8013  console.info('Succeeded in setting the dimness.');
8014}).catch((err: BusinessError) => {
8015  console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`);
8016});
8017```
8018
8019### setFocusable<sup>(deprecated)</sup>
8020
8021setFocusable(isFocusable: boolean, callback: AsyncCallback&lt;void&gt;): void
8022
8023设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从操作前的获焦窗口切换到该窗口,使用callback异步回调。
8024
8025> **说明:**
8026>
8027> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9)。
8028
8029**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8030
8031**参数:**
8032
8033| 参数名      | 类型                      | 必填 | 说明                         |
8034| ----------- | ------------------------- | ---- | ---------------------------- |
8035| isFocusable | boolean                   | 是   | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 |
8036| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数。                   |
8037
8038
8039**示例:**
8040
8041```ts
8042import { BusinessError } from '@kit.BasicServicesKit';
8043
8044let isFocusable: boolean = true;
8045windowClass.setFocusable(isFocusable, (err: BusinessError) => {
8046  const errCode: number = err.code;
8047  if (errCode) {
8048    console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`);
8049    return;
8050  }
8051  console.info('Succeeded in setting the window to be focusable.');
8052});
8053```
8054
8055### setFocusable<sup>(deprecated)</sup>
8056
8057setFocusable(isFocusable: boolean): Promise&lt;void&gt;
8058
8059设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用Promise异步回调。
8060
8061> **说明:**
8062>
8063> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9-1)。
8064
8065**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8066
8067**参数:**
8068
8069| 参数名      | 类型    | 必填 | 说明                         |
8070| ----------- | ------- | ---- | ---------------------------- |
8071| isFocusable | boolean | 是   | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 |
8072
8073**返回值:**
8074
8075| 类型                | 说明                      |
8076| ------------------- | ------------------------- |
8077| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8078
8079
8080**示例:**
8081
8082```ts
8083import { BusinessError } from '@kit.BasicServicesKit';
8084
8085let isFocusable: boolean = true;
8086let promise = windowClass.setFocusable(isFocusable);
8087promise.then(() => {
8088  console.info('Succeeded in setting the window to be focusable.');
8089}).catch((err: BusinessError) => {
8090  console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`);
8091});
8092```
8093
8094### setKeepScreenOn<sup>(deprecated)</sup>
8095
8096setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback&lt;void&gt;): void
8097
8098设置屏幕是否为常亮状态,使用callback异步回调。
8099
8100> **说明:**
8101>
8102> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9)。
8103
8104**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8105
8106**参数:**
8107
8108| 参数名         | 类型                      | 必填 | 说明                     |
8109| -------------- | ------------------------- | ---- | ------------------------ |
8110| isKeepScreenOn | boolean                   | 是   | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 |
8111| callback       | AsyncCallback&lt;void&gt; | 是   | 回调函数。               |
8112
8113
8114**示例:**
8115
8116```ts
8117import { BusinessError } from '@kit.BasicServicesKit';
8118
8119let isKeepScreenOn: boolean = true;
8120windowClass.setKeepScreenOn(isKeepScreenOn, (err: BusinessError) => {
8121  const errCode: number = err.code;
8122  if (errCode) {
8123    console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`);
8124    return;
8125  }
8126  console.info('Succeeded in setting the screen to be always on.');
8127});
8128```
8129
8130### setKeepScreenOn<sup>(deprecated)</sup>
8131
8132setKeepScreenOn(isKeepScreenOn: boolean): Promise&lt;void&gt;
8133
8134设置屏幕是否为常亮状态,使用Promise异步回调。
8135
8136> **说明:**
8137>
8138> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9-1)。
8139
8140**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8141
8142**参数:**
8143
8144| 参数名         | 类型    | 必填 | 说明                     |
8145| -------------- | ------- | ---- | ------------------------ |
8146| isKeepScreenOn | boolean | 是   | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 |
8147
8148**返回值:**
8149
8150| 类型                | 说明                      |
8151| ------------------- | ------------------------- |
8152| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8153
8154**示例:**
8155
8156```ts
8157import { BusinessError } from '@kit.BasicServicesKit';
8158
8159let isKeepScreenOn: boolean = true;
8160let promise = windowClass.setKeepScreenOn(isKeepScreenOn);
8161promise.then(() => {
8162  console.info('Succeeded in setting the screen to be always on.');
8163}).catch((err: BusinessError) => {
8164  console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`);
8165});
8166```
8167
8168### setOutsideTouchable<sup>(deprecated)</sup>
8169
8170setOutsideTouchable(touchable: boolean, callback: AsyncCallback&lt;void&gt;): void
8171
8172设置是否允许可点击子窗口之外的区域,使用callback异步回调。
8173
8174> **说明:**
8175>
8176> 从 API version 7开始支持,从API version 9开始废弃。
8177>
8178> 从 API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。
8179
8180**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8181
8182**参数:**
8183
8184| 参数名    | 类型                      | 必填 | 说明             |
8185| --------- | ------------------------- | ---- | ---------------- |
8186| touchable | boolean                   | 是   | 设置是否可点击。true表示可点击;false表示不可点击。 |
8187| callback  | AsyncCallback&lt;void&gt; | 是   | 回调函数。       |
8188
8189**示例:**
8190
8191```ts
8192import { BusinessError } from '@kit.BasicServicesKit';
8193
8194windowClass.setOutsideTouchable(true, (err: BusinessError) => {
8195  const errCode: number = err.code;
8196  if (errCode) {
8197    console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`);
8198    return;
8199  }
8200  console.info('Succeeded in setting the area to be touchable.');
8201});
8202```
8203
8204### setOutsideTouchable<sup>(deprecated)</sup>
8205
8206setOutsideTouchable(touchable: boolean): Promise&lt;void&gt;
8207
8208设置是否允许可点击子窗口之外的区域,使用Promise异步回调。
8209
8210> **说明:**
8211>
8212> 从 API version 7开始支持,从API version 9开始废弃。
8213>
8214> 从 API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。
8215
8216**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8217
8218**参数:**
8219
8220| 参数名    | 类型    | 必填 | 说明             |
8221| --------- | ------- | ---- | ---------------- |
8222| touchable | boolean | 是   | 设置是否可点击。true表示可点击;false表示不可点击。 |
8223
8224**返回值:**
8225
8226| 类型                | 说明                      |
8227| ------------------- | ------------------------- |
8228| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8229
8230**示例:**
8231
8232```ts
8233import { BusinessError } from '@kit.BasicServicesKit';
8234
8235let promise = windowClass.setOutsideTouchable(true);
8236promise.then(() => {
8237  console.info('Succeeded in setting the area to be touchable.');
8238}).catch((err: BusinessError) => {
8239  console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`);
8240});
8241```
8242
8243### setPrivacyMode<sup>(deprecated)</sup>
8244
8245setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback&lt;void&gt;): void
8246
8247设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。
8248
8249> **说明:**
8250>
8251> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9)。
8252
8253**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8254
8255**参数:**
8256
8257| 参数名        | 类型                      | 必填 | 说明                 |
8258| ------------- | ------------------------- | ---- | -------------------- |
8259| isPrivacyMode | boolean                   | 是   | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 |
8260| callback      | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
8261
8262**示例:**
8263
8264```ts
8265import { BusinessError } from '@kit.BasicServicesKit';
8266
8267let isPrivacyMode: boolean = true;
8268windowClass.setPrivacyMode(isPrivacyMode, (err: BusinessError) => {
8269  const errCode: number = err.code;
8270  if (errCode) {
8271    console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`);
8272    return;
8273  }
8274  console.info('Succeeded in setting the window to privacy mode.');
8275});
8276```
8277
8278### setPrivacyMode<sup>(deprecated)</sup>
8279
8280setPrivacyMode(isPrivacyMode: boolean): Promise&lt;void&gt;
8281
8282设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。
8283
8284> **说明:**
8285>
8286> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9-1)。
8287
8288**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8289
8290**参数:**
8291
8292| 参数名        | 类型    | 必填 | 说明                 |
8293| ------------- | ------- | ---- | -------------------- |
8294| isPrivacyMode | boolean | 是   | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 |
8295
8296**返回值:**
8297
8298| 类型                | 说明                      |
8299| ------------------- | ------------------------- |
8300| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8301
8302**示例:**
8303
8304```ts
8305import { BusinessError } from '@kit.BasicServicesKit';
8306
8307let isPrivacyMode: boolean = true;
8308let promise = windowClass.setPrivacyMode(isPrivacyMode);
8309promise.then(() => {
8310  console.info('Succeeded in setting the window to privacy mode.');
8311}).catch((err: BusinessError) => {
8312  console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`);
8313});
8314```
8315
8316### setTouchable<sup>(deprecated)</sup>
8317
8318setTouchable(isTouchable: boolean, callback: AsyncCallback&lt;void&gt;): void
8319
8320设置窗口是否为可触状态,使用callback异步回调。
8321
8322> **说明:**
8323>
8324> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9)。
8325
8326**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8327
8328**参数:**
8329
8330| 参数名      | 类型                      | 必填 | 说明                 |
8331| ----------- | ------------------------- | ---- | -------------------- |
8332| isTouchable | boolean                   | 是   | 窗口是否为可触状态。true表示可触;false表示不可触。 |
8333| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
8334
8335
8336**示例:**
8337
8338```ts
8339import { BusinessError } from '@kit.BasicServicesKit';
8340
8341let isTouchable = true;
8342windowClass.setTouchable(isTouchable, (err: BusinessError) => {
8343  const errCode: number = err.code;
8344  if (errCode) {
8345    console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`);
8346    return;
8347  }
8348  console.info('Succeeded in setting the window to be touchable.');
8349});
8350```
8351
8352### setTouchable<sup>(deprecated)</sup>
8353
8354setTouchable(isTouchable: boolean): Promise&lt;void&gt;
8355
8356设置窗口是否为可触状态,使用Promise异步回调。
8357
8358> **说明:**
8359>
8360> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9-1)。
8361
8362**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8363
8364**参数:**
8365
8366| 参数名      | 类型    | 必填 | 说明                 |
8367| ----------- | ------- | ---- | -------------------- |
8368| isTouchable | boolean | 是   | 窗口是否为可触状态。true表示可触;false表示不可触。 |
8369
8370**返回值:**
8371
8372| 类型                | 说明                      |
8373| ------------------- | ------------------------- |
8374| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8375
8376
8377**示例:**
8378
8379```ts
8380import { BusinessError } from '@kit.BasicServicesKit';
8381
8382let isTouchable = true;
8383let promise = windowClass.setTouchable(isTouchable);
8384promise.then(() => {
8385  console.info('Succeeded in setting the window to be touchable.');
8386}).catch((err: BusinessError) => {
8387  console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`);
8388});
8389```
8390
8391## WindowStageEventType<sup>9+</sup>
8392
8393WindowStage生命周期。
8394
8395**模型约束:** 此接口仅可在Stage模型下使用。
8396
8397**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8398
8399**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8400
8401| 名称       | 值 | 说明       |
8402| ---------- | ------ | ---------- |
8403| SHOWN      | 1      | 切到前台,例如点击应用图标启动,无论是首次启动还是从后台启动均会触发。 |
8404| ACTIVE     | 2      | 获焦状态,例如应用窗口处理点击事件后的状态、应用启动后的状态。 |
8405| INACTIVE   | 3      | 失焦状态,例如打开新应用或点击其他窗口后,原获焦窗口的状态。 |
8406| HIDDEN     | 4      | 切到后台,例如应用上滑退出、应用窗口关闭。 |
8407| RESUMED<sup>11+</sup> | 5      | 前台可交互状态,例如应用打开后,可以与用户交互的状态。 |
8408| PAUSED<sup>11+</sup>  | 6      | 前台不可交互状态,例如从屏幕底部上划,应用进入到多任务界面后的状态。 |
8409
8410## SubWindowOptions<sup>11+</sup>
8411
8412子窗口创建参数。
8413
8414**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8415
8416**系统能力:** SystemCapability.Window.SessionManager
8417
8418| 名称      | 类型  | 只读 | 可选 | 说明         |
8419| ---------- | ---- | ---- | ---- | ----------- |
8420| title    | string | 否 | 否 | 子窗口标题。       |
8421| decorEnabled | boolean | 否 | 否 | 子窗口是否显示装饰。true表示子窗口显示装饰,false表示子窗口不显示装饰。       |
8422| isModal<sup>12+</sup>    | boolean | 否 | 是 | 子窗口是否启用模态属性。true表示子窗口启用模态属性,其父级窗口不能响应用户操作,false表示子窗口禁用模态属性,其父级窗口能响应用户操作。不设置,则默认为false。       |
8423
8424## WindowStage<sup>9+</sup>
8425
8426窗口管理器。管理各个基本窗口单元,即[Window](#window)实例。
8427
8428下列API示例中都需在[onWindowStageCreate()](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate)函数中使用WindowStage的实例调用对应方法。
8429
8430### getMainWindow<sup>9+</sup>
8431
8432getMainWindow(callback: AsyncCallback&lt;Window&gt;): void
8433
8434获取该WindowStage实例下的主窗口,使用callback异步回调。
8435
8436**模型约束:** 此接口仅可在Stage模型下使用。
8437
8438**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8439
8440**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8441
8442**参数:**
8443
8444| 参数名   | 类型                                   | 必填 | 说明                                          |
8445| -------- | -------------------------------------- | ---- | --------------------------------------------- |
8446| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前WindowStage下的主窗口对象。 |
8447
8448**错误码:**
8449
8450以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
8451
8452| 错误码ID | 错误信息 |
8453| ------- | ------------------------------ |
8454| 1300002 | This window state is abnormal. |
8455| 1300005 | This window stage is abnormal. |
8456
8457**示例:**
8458
8459```ts
8460// EntryAbility.ets
8461import { UIAbility } from '@kit.AbilityKit';
8462import { BusinessError } from '@kit.BasicServicesKit';
8463
8464export default class EntryAbility extends UIAbility {
8465  // ...
8466
8467  onWindowStageCreate(windowStage: window.WindowStage) {
8468    console.log('onWindowStageCreate');
8469    let windowClass: window.Window | undefined = undefined;
8470    windowStage.getMainWindow((err: BusinessError, data) => {
8471      const errCode: number = err.code;
8472      if (errCode) {
8473        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
8474        return;
8475      }
8476      windowClass = data;
8477      console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
8478    });
8479  }
8480};
8481```
8482
8483### getMainWindow<sup>9+</sup>
8484
8485getMainWindow(): Promise&lt;Window&gt;
8486
8487获取该WindowStage实例下的主窗口,使用Promise异步回调。
8488
8489**模型约束:** 此接口仅可在Stage模型下使用。
8490
8491**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8492
8493**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8494
8495**返回值:**
8496
8497| 类型                             | 说明                                             |
8498| -------------------------------- | ------------------------------------------------ |
8499| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前WindowStage下的主窗口对象。 |
8500
8501**错误码:**
8502
8503以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
8504
8505| 错误码ID | 错误信息 |
8506| ------- | ------------------------------ |
8507| 1300002 | This window state is abnormal. |
8508| 1300005 | This window stage is abnormal. |
8509
8510**示例:**
8511
8512```ts
8513// EntryAbility.ets
8514import { UIAbility } from '@kit.AbilityKit';
8515import { BusinessError } from '@kit.BasicServicesKit';
8516
8517export default class EntryAbility extends UIAbility {
8518  // ...
8519
8520  onWindowStageCreate(windowStage: window.WindowStage) {
8521    console.log('onWindowStageCreate');
8522    let windowClass: window.Window | undefined = undefined;
8523    let promise = windowStage.getMainWindow();
8524    promise.then((data) => {
8525      windowClass = data;
8526      console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
8527    }).catch((err: BusinessError) => {
8528      console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
8529    });
8530  }
8531};
8532```
8533
8534### getMainWindowSync<sup>9+</sup>
8535
8536getMainWindowSync(): Window
8537
8538获取该WindowStage实例下的主窗口。
8539
8540**模型约束:** 此接口仅可在Stage模型下使用。
8541
8542**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8543
8544**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8545
8546**返回值:**
8547
8548| 类型 | 说明 |
8549| ----------------- | --------------------------------- |
8550| [Window](#window) | 返回当前WindowStage下的主窗口对象。 |
8551
8552**错误码:**
8553
8554以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
8555
8556| 错误码ID | 错误信息 |
8557| ------- | ------------------------------ |
8558| 1300002 | This window state is abnormal. |
8559| 1300005 | This window stage is abnormal. |
8560
8561**示例:**
8562<!--code_no_check-->
8563```ts
8564// EntryAbility.ets
8565import { UIAbility } from '@kit.AbilityKit';
8566
8567export default class EntryAbility extends UIAbility {
8568  // ...
8569
8570  onWindowStageCreate(windowStage: window.WindowStage) {
8571    console.log('onWindowStageCreate');
8572    try {
8573      let windowClass = windowStage.getMainWindowSync();
8574    } catch (exception) {
8575      console.error(`Failed to obtain the main window. Cause code: ${exception.code}, message: ${exception.message}`);
8576    }
8577  }
8578};
8579```
8580
8581### createSubWindow<sup>9+</sup>
8582
8583createSubWindow(name: string, callback: AsyncCallback&lt;Window&gt;): void
8584
8585创建该WindowStage实例下的子窗口,使用callback异步回调。
8586
8587**模型约束:** 此接口仅可在Stage模型下使用。
8588
8589**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8590
8591**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8592
8593**参数:**
8594
8595| 参数名   | 类型                                   | 必填 | 说明                                          |
8596| -------- | -------------------------------------- | ---- | --------------------------------------------- |
8597| name     | string                                 | 是   | 子窗口的名字。                                |
8598| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前WindowStage下的子窗口对象。 |
8599
8600**错误码:**
8601
8602以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8603
8604| 错误码ID | 错误信息 |
8605| ------- | ------------------------------ |
8606| 401     | Parameter error. Possible cause: Incorrect parameter types. |
8607| 1300002 | This window state is abnormal. |
8608| 1300005 | This window stage is abnormal. |
8609
8610**示例:**
8611
8612```ts
8613// EntryAbility.ets
8614import { UIAbility } from '@kit.AbilityKit';
8615import { BusinessError } from '@kit.BasicServicesKit';
8616
8617export default class EntryAbility extends UIAbility {
8618  // ...
8619
8620  onWindowStageCreate(windowStage: window.WindowStage) {
8621    console.log('onWindowStageCreate');
8622    let windowClass: window.Window | undefined = undefined;
8623    try {
8624      windowStage.createSubWindow('mySubWindow', (err: BusinessError, data) => {
8625        const errCode: number = err.code;
8626        if (errCode) {
8627          console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`);
8628          return;
8629        }
8630        windowClass = data;
8631        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
8632        if (!windowClass) {
8633          console.info('Failed to load the content. Cause: windowClass is null');
8634        }
8635        else {
8636          (windowClass as window.Window).resize(500, 1000);
8637        }
8638      });
8639    } catch (exception) {
8640      console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`);
8641    }
8642  }
8643};
8644```
8645
8646### createSubWindow<sup>9+</sup>
8647
8648createSubWindow(name: string): Promise&lt;Window&gt;
8649
8650创建该WindowStage实例下的子窗口,使用Promise异步回调。
8651
8652**模型约束:** 此接口仅可在Stage模型下使用。
8653
8654**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8655
8656**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8657
8658**参数:**
8659
8660| 参数名 | 类型   | 必填 | 说明           |
8661| ------ | ------ | ---- | -------------- |
8662| name   | string | 是   | 子窗口的名字。 |
8663
8664**返回值:**
8665
8666| 类型                             | 说明                                             |
8667| -------------------------------- | ------------------------------------------------ |
8668| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前WindowStage下的子窗口对象。 |
8669
8670**错误码:**
8671
8672以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8673
8674| 错误码ID | 错误信息 |
8675| ------- | ------------------------------ |
8676| 401     | Parameter error. Possible cause: Incorrect parameter types. |
8677| 1300002 | This window state is abnormal. |
8678| 1300005 | This window stage is abnormal. |
8679
8680**示例:**
8681
8682```ts
8683// EntryAbility.ets
8684import { UIAbility } from '@kit.AbilityKit';
8685import { BusinessError } from '@kit.BasicServicesKit';
8686
8687export default class EntryAbility extends UIAbility {
8688  // ...
8689
8690  onWindowStageCreate(windowStage: window.WindowStage) {
8691    console.log('onWindowStageCreate');
8692    let windowClass: window.Window | undefined = undefined;
8693    try {
8694      let promise = windowStage.createSubWindow('mySubWindow');
8695      promise.then((data) => {
8696        windowClass = data;
8697        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
8698      }).catch((err: BusinessError) => {
8699        console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`);
8700      });
8701    } catch (exception) {
8702      console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`);
8703    }
8704  }
8705};
8706```
8707
8708### createSubWindowWithOptions<sup>11+</sup>
8709
8710createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise&lt;Window&gt;
8711
8712创建该WindowStage实例下的子窗口,使用Promise异步回调。
8713
8714**模型约束:** 此接口仅可在Stage模型下使用。
8715
8716**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8717
8718**系统能力:** SystemCapability.Window.SessionManager
8719
8720**参数:**
8721
8722| 参数名 | 类型   | 必填 | 说明           |
8723| ------ | ------ | ---- | -------------- |
8724| name   | string | 是   | 子窗口的名字。 |
8725| options  | [SubWindowOptions](#subwindowoptions11) | 是   | 子窗口参数。  |
8726
8727**返回值:**
8728
8729| 类型                             | 说明                                             |
8730| -------------------------------- | ------------------------------------------------ |
8731| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前WindowStage下创建的子窗口对象。 |
8732
8733**错误码:**
8734
8735以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8736
8737| 错误码ID | 错误信息 |
8738| ------- | ------------------------------ |
8739| 401     | Parameter error. Possible cause: Incorrect parameter types. |
8740| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
8741| 1300002 | This window state is abnormal. |
8742| 1300005 | This window stage is abnormal. |
8743
8744**示例:**
8745
8746```ts
8747// EntryAbility.ets
8748import { UIAbility } from '@kit.AbilityKit';
8749import { BusinessError } from '@kit.BasicServicesKit';
8750
8751export default class EntryAbility extends UIAbility {
8752  // ...
8753
8754  onWindowStageCreate(windowStage: window.WindowStage) {
8755    console.info('onWindowStageCreate');
8756    let windowClass: window.Window | undefined = undefined;
8757    try {
8758      let options : window.SubWindowOptions = {
8759        title: 'title',
8760        decorEnabled: true
8761      };
8762      let promise = windowStage.createSubWindowWithOptions('mySubWindow', options);
8763      promise.then((data) => {
8764        windowClass = data;
8765        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
8766      }).catch((err: BusinessError) => {
8767        console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`);
8768      });
8769    } catch (exception) {
8770      console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`);
8771    }
8772  }
8773};
8774```
8775
8776### getSubWindow<sup>9+</sup>
8777
8778getSubWindow(callback: AsyncCallback&lt;Array&lt;Window&gt;&gt;): void
8779
8780获取该WindowStage实例下的所有子窗口,使用callback异步回调。
8781
8782**模型约束:** 此接口仅可在Stage模型下使用。
8783
8784**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8785
8786**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8787
8788**参数:**
8789
8790| 参数名   | 类型                                                | 必填 | 说明                                              |
8791| -------- | --------------------------------------------------- | ---- | ------------------------------------------------- |
8792| callback | AsyncCallback&lt;Array&lt;[Window](#window)&gt;&gt; | 是   | 回调函数。返回当前WindowStage下的所有子窗口对象。 |
8793
8794**错误码:**
8795
8796以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
8797
8798| 错误码ID | 错误信息 |
8799| ------- | ------------------------------ |
8800| 1300005 | This window stage is abnormal. |
8801
8802**示例:**
8803<!--code_no_check-->
8804```ts
8805// EntryAbility.ets
8806import { UIAbility } from '@kit.AbilityKit';
8807import { BusinessError } from '@kit.BasicServicesKit';
8808
8809export default class EntryAbility extends UIAbility {
8810  // ...
8811
8812  onWindowStageCreate(windowStage: window.WindowStage) {
8813    console.log('onWindowStageCreate');
8814    let windowClass: window.Window[] = [];
8815    windowStage.getSubWindow((err: BusinessError, data) => {
8816      const errCode: number = err.code;
8817      if (errCode) {
8818        console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`);
8819        return;
8820      }
8821      windowClass = data;
8822      console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data));
8823    });
8824  }
8825};
8826```
8827
8828### getSubWindow<sup>9+</sup>
8829
8830getSubWindow(): Promise&lt;Array&lt;Window&gt;&gt;
8831
8832获取该WindowStage实例下的所有子窗口,使用Promise异步回调。
8833
8834**模型约束:** 此接口仅可在Stage模型下使用。
8835
8836**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8837
8838**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8839
8840**返回值:**
8841
8842| 类型                                          | 说明                                                 |
8843| --------------------------------------------- | ---------------------------------------------------- |
8844| Promise&lt;Array&lt;[Window](#window)&gt;&gt; | Promise对象。返回当前WindowStage下的所有子窗口对象。 |
8845
8846**错误码:**
8847
8848以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
8849
8850| 错误码ID | 错误信息 |
8851| ------- | ------------------------------ |
8852| 1300005 | This window stage is abnormal. |
8853
8854**示例:**
8855<!--code_no_check-->
8856```ts
8857// EntryAbility.ets
8858import { UIAbility } from '@kit.AbilityKit';
8859import { BusinessError } from '@kit.BasicServicesKit';
8860
8861export default class EntryAbility extends UIAbility {
8862  // ...
8863
8864  onWindowStageCreate(windowStage: window.WindowStage) {
8865    console.log('onWindowStageCreate');
8866    let windowClass: window.Window[] = [];
8867    let promise = windowStage.getSubWindow();
8868    promise.then((data) => {
8869      windowClass = data;
8870      console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data));
8871    }).catch((err: BusinessError) => {
8872      console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`);
8873    });
8874  }
8875};
8876```
8877
8878### loadContent<sup>9+</sup>
8879
8880loadContent(path: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
8881
8882为当前WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。
8883
8884**模型约束:** 此接口仅可在Stage模型下使用。
8885
8886**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8887
8888**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8889
8890**参数:**
8891
8892| 参数名   | 类型                                            | 必填 | 说明                                                         |
8893| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
8894| path     | string                                          | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。  |
8895| storage  | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
8896| callback | AsyncCallback&lt;void&gt;                       | 是   | 回调函数。                                                   |
8897
8898**错误码:**
8899
8900以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8901
8902| 错误码ID | 错误信息 |
8903| ------- | ------------------------------ |
8904| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8905| 1300002 | This window state is abnormal. |
8906| 1300005 | This window stage is abnormal. |
8907
8908**示例:**
8909
8910```ts
8911// EntryAbility.ets
8912import { UIAbility } from '@kit.AbilityKit';
8913import { BusinessError } from '@kit.BasicServicesKit';
8914
8915export default class EntryAbility extends UIAbility {
8916  // ...
8917
8918  storage: LocalStorage = new LocalStorage();
8919
8920  onWindowStageCreate(windowStage: window.WindowStage) {
8921    this.storage.setOrCreate('storageSimpleProp', 121);
8922    console.log('onWindowStageCreate');
8923    try {
8924      windowStage.loadContent('pages/page2', this.storage, (err: BusinessError) => {
8925        const errCode: number = err.code;
8926        if (errCode) {
8927          console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
8928          return;
8929        }
8930        console.info('Succeeded in loading the content.');
8931      });
8932    } catch (exception) {
8933      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
8934    }
8935  }
8936};
8937```
8938
8939### loadContent<sup>9+</sup>
8940
8941loadContent(path: string, storage?: LocalStorage): Promise&lt;void&gt;
8942
8943为当前WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。
8944
8945**模型约束:** 此接口仅可在Stage模型下使用。
8946
8947**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8948
8949**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8950
8951**参数:**
8952
8953| 参数名  | 类型                                            | 必填 | 说明                                                         |
8954| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
8955| path    | string                                          | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 |
8956| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 否   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
8957
8958**返回值:**
8959
8960| 类型                | 说明                      |
8961| ------------------- | ------------------------- |
8962| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8963
8964**错误码:**
8965
8966以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8967
8968| 错误码ID | 错误信息 |
8969| ------- | ------------------------------ |
8970| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8971| 1300002 | This window state is abnormal. |
8972| 1300005 | This window stage is abnormal. |
8973
8974**示例:**
8975
8976```ts
8977// EntryAbility.ets
8978import { UIAbility } from '@kit.AbilityKit';
8979import { BusinessError } from '@kit.BasicServicesKit';
8980
8981export default class EntryAbility extends UIAbility {
8982  // ...
8983
8984  storage: LocalStorage = new LocalStorage();
8985
8986  onWindowStageCreate(windowStage: window.WindowStage) {
8987    this.storage.setOrCreate('storageSimpleProp', 121);
8988    console.log('onWindowStageCreate');
8989    try {
8990      let promise = windowStage.loadContent('pages/page2', this.storage);
8991      promise.then(() => {
8992        console.info('Succeeded in loading the content.');
8993      }).catch((err: BusinessError) => {
8994        console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
8995      });
8996    } catch (exception) {
8997      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
8998    }
8999    ;
9000  }
9001};
9002```
9003
9004### loadContent<sup>9+</sup>
9005
9006loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void
9007
9008为当前WindowStage的主窗口加载具体页面内容,使用callback异步回调。
9009
9010**模型约束:** 此接口仅可在Stage模型下使用。
9011
9012**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9013
9014**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9015
9016**参数:**
9017
9018| 参数名   | 类型                      | 必填 | 说明                 |
9019| -------- | ------------------------- | ---- | -------------------- |
9020| path     | string                    | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 |
9021| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
9022
9023**错误码:**
9024
9025以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9026
9027| 错误码ID | 错误信息 |
9028| ------- | ------------------------------ |
9029| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9030| 1300002 | This window state is abnormal. |
9031| 1300005 | This window stage is abnormal. |
9032
9033**示例:**
9034
9035```ts
9036// EntryAbility.ets
9037import { UIAbility } from '@kit.AbilityKit';
9038import { BusinessError } from '@kit.BasicServicesKit';
9039
9040export default class EntryAbility extends UIAbility {
9041  // ...
9042
9043  onWindowStageCreate(windowStage: window.WindowStage) {
9044    console.log('onWindowStageCreate');
9045    try {
9046      windowStage.loadContent('pages/page2', (err: BusinessError) => {
9047        const errCode: number = err.code;
9048        if (errCode) {
9049          console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
9050          return;
9051        }
9052        console.info('Succeeded in loading the content.');
9053      });
9054    } catch (exception) {
9055      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
9056    }
9057  }
9058};
9059```
9060
9061### loadContentByName<sup>11+</sup>
9062
9063loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
9064
9065为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。
9066
9067**模型约束:** 此接口仅可在Stage模型下使用。
9068
9069**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9070
9071**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9072
9073**参数:**
9074
9075| 参数名   | 类型                                                    | 必填 | 说明                                                         |
9076| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
9077| name     | string                                                  | 是   | 命名路由页面的名称。                                             |
9078| storage  | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
9079| callback | AsyncCallback&lt;void&gt;                               | 是   | 回调函数。                                                   |
9080
9081**错误码:**
9082
9083以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9084
9085| 错误码ID | 错误信息                                      |
9086| -------- | --------------------------------------------- |
9087| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9088| 1300002  | This window state is abnormal.                |
9089| 1300003  | This window manager service works abnormally. |
9090
9091**示例:**
9092
9093<!--code_no_check-->
9094```ts
9095// EntryAbility.ets
9096import { UIAbility } from '@kit.AbilityKit';
9097import { BusinessError } from '@kit.BasicServicesKit';
9098import * as Index from '../pages/Index'; // 导入命名路由页面
9099
9100export default class EntryAbility extends UIAbility {
9101  // ...
9102
9103  storage: LocalStorage = new LocalStorage();
9104
9105  onWindowStageCreate(windowStage: window.WindowStage) {
9106    console.log('onWindowStageCreate');
9107    this.storage.setOrCreate('storageSimpleProp', 121);
9108    try {
9109      windowStage.loadContentByName(Index.entryName, this.storage, (err: BusinessError) => {
9110        const errCode: number = err.code;
9111        if (errCode) {
9112          console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
9113          return;
9114        }
9115        console.info('Succeeded in loading the content.');
9116      });
9117    } catch (exception) {
9118      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
9119    }
9120  }
9121};
9122```
9123<!--code_no_check-->
9124```ts
9125// ets/pages/Index.ets
9126export const entryName : string = 'Index';
9127@Entry({routeName: entryName, storage : LocalStorage.getShared()})
9128@Component
9129export struct Index {
9130  @State message: string = 'Hello World'
9131  build() {
9132    Row() {
9133      Column() {
9134        Text(this.message)
9135          .fontSize(50)
9136          .fontWeight(FontWeight.Bold)
9137      }
9138      .width('100%')
9139    }
9140    .height('100%')
9141  }
9142}
9143```
9144
9145### loadContentByName<sup>11+</sup>
9146
9147loadContentByName(name: string, callback: AsyncCallback&lt;void&gt;): void
9148
9149为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,使用callback异步回调。
9150
9151**模型约束:** 此接口仅可在Stage模型下使用。
9152
9153**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9154
9155**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9156
9157**参数:**
9158
9159| 参数名   | 类型                      | 必填 | 说明             |
9160| -------- | ------------------------- | ---- | ---------------- |
9161| name     | string                    | 是   | 命名路由页面的名称。 |
9162| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。       |
9163
9164**错误码:**
9165
9166以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9167
9168| 错误码ID | 错误信息                                      |
9169| -------- | --------------------------------------------- |
9170| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9171| 1300002  | This window state is abnormal.                |
9172| 1300003  | This window manager service works abnormally. |
9173
9174**示例:**
9175
9176<!--code_no_check-->
9177```ts
9178// EntryAbility.ets
9179import { UIAbility } from '@kit.AbilityKit';
9180import { BusinessError } from '@kit.BasicServicesKit';
9181import * as Index from '../pages/Index'; // 导入命名路由页面
9182
9183export default class EntryAbility extends UIAbility {
9184  // ...
9185
9186  onWindowStageCreate(windowStage: window.WindowStage) {
9187    console.log('onWindowStageCreate');
9188    try {
9189      windowStage.loadContentByName(Index.entryName, (err: BusinessError) => {
9190        const errCode: number = err.code;
9191        if (errCode) {
9192          console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
9193          return;
9194        }
9195        console.info('Succeeded in loading the content.');
9196      });
9197    } catch (exception) {
9198      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
9199    }
9200  }
9201};
9202```
9203<!--code_no_check-->
9204```ts
9205// ets/pages/Index.ets
9206export const entryName : string = 'Index';
9207@Entry({routeName: entryName})
9208@Component
9209export struct Index {
9210  @State message: string = 'Hello World'
9211  build() {
9212    Row() {
9213      Column() {
9214        Text(this.message)
9215          .fontSize(50)
9216          .fontWeight(FontWeight.Bold)
9217      }
9218      .width('100%')
9219    }
9220    .height('100%')
9221  }
9222}
9223```
9224
9225### loadContentByName<sup>11+</sup>
9226
9227loadContentByName(name: string, storage?: LocalStorage): Promise&lt;void&gt;;
9228
9229为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用promise异步回调。
9230
9231**模型约束:** 此接口仅可在Stage模型下使用。
9232
9233**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9234
9235**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9236
9237**参数:**
9238
9239| 参数名  | 类型         | 必填 | 说明                                                         |
9240| ------- | ------------ | ---- | ------------------------------------------------------------ |
9241| name    | string       | 是   | 命名路由页面的名称。                                             |
9242| storage | LocalStorage | 否   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
9243
9244**错误码:**
9245
9246以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9247
9248| 错误码ID | 错误信息                                      |
9249| -------- | --------------------------------------------- |
9250| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9251| 1300002  | This window state is abnormal.                |
9252| 1300003  | This window manager service works abnormally. |
9253
9254**示例:**
9255
9256<!--code_no_check-->
9257```ts
9258// EntryAbility.ets
9259import { UIAbility } from '@kit.AbilityKit';
9260import { BusinessError } from '@kit.BasicServicesKit';
9261import * as Index from '../pages/Index'; // 导入命名路由页面
9262
9263export default class EntryAbility extends UIAbility {
9264  // ...
9265
9266  storage: LocalStorage = new LocalStorage();
9267
9268  onWindowStageCreate(windowStage: window.WindowStage) {
9269    console.log('onWindowStageCreate');
9270    this.storage.setOrCreate('storageSimpleProp', 121);
9271    try {
9272      let promise = windowStage.loadContentByName(Index.entryName, this.storage);
9273      promise.then(() => {
9274        console.info('Succeeded in loading the content.');
9275      }).catch((err: BusinessError) => {
9276        console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
9277      });
9278    } catch (exception) {
9279      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
9280    }
9281  }
9282};
9283```
9284<!--code_no_check-->
9285```ts
9286// ets/pages/Index.ets
9287export const entryName : string = 'Index';
9288@Entry({routeName: entryName, storage : LocalStorage.getShared()})
9289@Component
9290export struct Index {
9291  @State message: string = 'Hello World'
9292  build() {
9293    Row() {
9294      Column() {
9295        Text(this.message)
9296          .fontSize(50)
9297          .fontWeight(FontWeight.Bold)
9298      }
9299      .width('100%')
9300    }
9301    .height('100%')
9302  }
9303}
9304```
9305
9306### on('windowStageEvent')<sup>9+</sup>
9307
9308on(eventType: 'windowStageEvent', callback: Callback&lt;WindowStageEventType&gt;): void
9309
9310开启WindowStage生命周期变化的监听。
9311
9312**模型约束:** 此接口仅可在Stage模型下使用。
9313
9314**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9315
9316**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9317
9318**参数:**
9319
9320| 参数名   | 类型                                                         | 必填 | 说明                                                         |
9321| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
9322| eventType  | string                                                       | 是   | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 |
9323| callback | Callback&lt;[WindowStageEventType](#windowstageeventtype9)&gt; | 是   | 回调函数。返回当前的WindowStage生命周期状态。                |
9324
9325**错误码:**
9326
9327以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9328
9329| 错误码ID | 错误信息 |
9330| ------- | ------------------------------ |
9331| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
9332| 1300002 | This window state is abnormal. |
9333| 1300005 | This window stage is abnormal. |
9334
9335**示例:**
9336
9337```ts
9338// EntryAbility.ets
9339import { UIAbility } from '@kit.AbilityKit';
9340
9341export default class EntryAbility extends UIAbility {
9342  // ...
9343
9344  onWindowStageCreate(windowStage: window.WindowStage) {
9345    console.log('onWindowStageCreate');
9346    try {
9347      windowStage.on('windowStageEvent', (data) => {
9348        console.info('Succeeded in enabling the listener for window stage event changes. Data: ' +
9349        JSON.stringify(data));
9350      });
9351    } catch (exception) {
9352      console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`);
9353    }
9354  }
9355};
9356```
9357
9358### off('windowStageEvent')<sup>9+</sup>
9359
9360off(eventType: 'windowStageEvent', callback?: Callback&lt;WindowStageEventType&gt;): void
9361
9362关闭WindowStage生命周期变化的监听。
9363
9364**模型约束:** 此接口仅可在Stage模型下使用。
9365
9366**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9367
9368**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9369
9370**参数:**
9371
9372| 参数名   | 类型                                                         | 必填 | 说明                                                         |
9373| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
9374| eventType  | string                                                       | 是   | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 |
9375| callback | Callback&lt;[WindowStageEventType](#windowstageeventtype9)&gt; | 否   | 回调函数。返回当前的WindowStage生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有WindowStage生命周期变化的监听。                |
9376
9377**错误码:**
9378
9379以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9380
9381| 错误码ID | 错误信息 |
9382| ------- | ------------------------------ |
9383| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
9384| 1300002 | This window state is abnormal. |
9385| 1300005 | This window stage is abnormal. |
9386
9387**示例:**
9388
9389```ts
9390// EntryAbility.ets
9391import { UIAbility } from '@kit.AbilityKit';
9392
9393export default class EntryAbility extends UIAbility {
9394  // ...
9395
9396  onWindowStageCreate(windowStage: window.WindowStage) {
9397    console.log('onWindowStageCreate');
9398    const callback = (windowStageEventType: window.WindowStageEventType) => {
9399      // ...
9400    }
9401    try {
9402      windowStage.on('windowStageEvent', callback);
9403    } catch (exception) {
9404      console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`);
9405    }
9406    try {
9407      windowStage.off('windowStageEvent', callback);
9408      // 如果通过on开启多个callback进行监听,同时关闭所有监听:
9409      windowStage.off('windowStageEvent');
9410    } catch (exception) {
9411      console.error(`Failed to disable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`);
9412    }
9413  }
9414};
9415```
9416
9417### setDefaultDensityEnabled<sup>12+</sup>
9418
9419setDefaultDensityEnabled(enabled: boolean): void
9420
9421设置应用是否使用系统默认Density。
9422
9423不调用此接口进行设置,则表示不使用系统默认Density,即窗口会跟随系统显示大小变化重新布局。
9424
9425**模型约束:** 此接口仅可在Stage模型下使用。
9426
9427**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
9428
9429**系统能力:** SystemCapability.Window.SessionManager
9430
9431**参数:**
9432
9433| 参数名           | 类型    | 必填 | 说明                         |
9434| ---------------- | ------- | ---- | ---------------------------- |
9435| enabled | boolean | 是   | 是否设置应用使用系统默认Density。true表示使用系统默认Density,窗口不跟随系统显示大小变化重新布局;false表示不使用系统默认Density,窗口跟随系统显示大小变化重新布局。 |
9436
9437**错误码:**
9438
9439以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9440
9441| 错误码ID | 错误信息 |
9442| ------- | ------------------------------ |
9443| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9444| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
9445| 1300002 | This window state is abnormal. |
9446| 1300005 | This window stage is abnormal. |
9447
9448**示例:**
9449
9450```ts
9451// EntryAbility.ets
9452import { UIAbility } from '@kit.AbilityKit';
9453
9454export default class EntryAbility extends UIAbility {
9455  // ...
9456
9457  onWindowStageCreate(windowStage: window.WindowStage) {
9458    console.log('onWindowStageCreate');
9459    try {
9460      windowStage.setDefaultDensityEnabled(true);
9461    } catch (exception) {
9462      console.error(`Failed to set default density enabled. Cause code: ${exception.code}, message: ${exception.message}`);
9463    }
9464  }
9465};
9466```
9467