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**系统能力:**  SystemCapability.Window.SessionManager
321
322| 名称       | 值   | 说明                          |
323| ---------- | ---- | ----------------------------- |
324| FOLLOW_APP_IMMERSIVE_SETTING  | 0    | 最大化时,跟随应用app当前设置的沉浸式布局。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。       |
325| EXIT_IMMERSIVE | 1    | 最大化时,如果当前窗口设置了沉浸式布局会退出沉浸式布局。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。             |
326| ENTER_IMMERSIVE    | 2    | 最大化时,进入沉浸式布局,鼠标Hover在热区上显示窗口标题栏和dock栏。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。   |
327| ENTER_IMMERSIVE_DISABLE_TITLE_AND_DOCK_HOVER<sup>14+</sup>    | 3    | 最大化时,进入沉浸式布局,鼠标Hover在热区上不显示窗口标题栏和dock栏。<br/>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。   |
328
329## window.createWindow<sup>9+</sup>
330
331createWindow(config: Configuration, callback: AsyncCallback&lt;Window&gt;): void
332
333创建子窗口或者系统窗口,使用callback异步回调。
334
335**需要权限:** 当创建窗口类型为window.WindowType.TYPE_FLOAT时,需要ohos.permission.SYSTEM_FLOAT_WINDOW权限
336
337**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
338
339**系统能力:** SystemCapability.WindowManager.WindowManager.Core
340
341**参数:**
342
343| 参数名 | 类型 | 必填 | 说明 |
344| -------- | -------------------------------------- | -- | --------------------------------- |
345| config   | [Configuration](#configuration9)       | 是 | 创建窗口时的参数。   |
346| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调函数。返回当前创建的窗口对象。 |
347
348**错误码:**
349
350以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
351
352| 错误码ID | 错误信息 |
353| ------- | -------------------------------- |
354| 201     | Permission verification failed. The application does not have the permission required to call the API. |
355| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
356| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
357| 1300001 | Repeated operation. |
358| 1300002 | This window state is abnormal. |
359| 1300004 | Unauthorized operation. |
360| 1300006 | This window context is abnormal. |
361| 1300008 | The display device is abnormal. |
362| 1300009 | The parent window is invalid. |
363
364**示例:**
365
366```ts
367import { BusinessError } from '@kit.BasicServicesKit';
368
369let windowClass: window.Window | undefined = undefined;
370let config: window.Configuration = {
371  name: "test",
372  windowType: window.WindowType.TYPE_DIALOG,
373  ctx: this.context
374};
375try {
376  window.createWindow(config, (err: BusinessError, data) => {
377    const errCode: number = err.code;
378    if (errCode) {
379      console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`);
380      return;
381    }
382    windowClass = data;
383    console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data));
384    windowClass.resize(500, 1000);
385  });
386} catch (exception) {
387  console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`);
388}
389```
390
391## window.createWindow<sup>9+</sup>
392
393createWindow(config: Configuration): Promise&lt;Window&gt;
394
395创建子窗口或者系统窗口,使用Promise异步回调。
396
397**需要权限:** 当创建窗口类型为window.WindowType.TYPE_FLOAT时,需要ohos.permission.SYSTEM_FLOAT_WINDOW权限
398
399**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
400
401**系统能力:** SystemCapability.WindowManager.WindowManager.Core
402
403**参数:**
404
405| 参数名 | 类型 | 必填 | 说明 |
406| ------ | -------------------------------- | -- | ------------------ |
407| config | [Configuration](#configuration9) | 是 | 创建窗口时的参数。 |
408
409**返回值:**
410
411| 类型 | 说明 |
412| -------------------------------- | ------------------------------------ |
413| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前创建的窗口对象。 |
414
415**错误码:**
416
417以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
418
419| 错误码ID | 错误信息 |
420| ------- | -------------------------------- |
421| 201     | Permission verification failed. The application does not have the permission required to call the API. |
422| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
423| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
424| 1300001 | Repeated operation. |
425| 1300002 | This window state is abnormal. |
426| 1300004 | Unauthorized operation. |
427| 1300006 | This window context is abnormal. |
428| 1300008 | The display device is abnormal. |
429| 1300009 | The parent window is invalid. |
430
431**示例:**
432
433```ts
434import { BusinessError } from '@kit.BasicServicesKit';
435
436let windowClass: window.Window | undefined = undefined;
437let config: window.Configuration = {
438  name: "test",
439  windowType: window.WindowType.TYPE_DIALOG,
440  ctx: this.context
441};
442try {
443  let promise = window.createWindow(config);
444  promise.then((data) => {
445    windowClass = data;
446    console.info('Succeeded in creating the window. Data:' + JSON.stringify(data));
447  }).catch((err: BusinessError) => {
448    console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`);
449  });
450} catch (exception) {
451  console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`);
452}
453```
454
455## window.findWindow<sup>9+</sup>
456
457findWindow(name: string): Window
458
459查找name所对应的窗口。
460
461**系统能力:** SystemCapability.WindowManager.WindowManager.Core
462
463**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
464
465**参数:**
466
467| 参数名 | 类型   | 必填 | 说明     |
468| ------ | ------ | ---- | -------- |
469| name   | string | 是   | 窗口名字,即[Configuration](#configuration9)中的name。 |
470
471**返回值:**
472
473| 类型 | 说明 |
474| ----------------- | ------------------- |
475| [Window](#window) | 当前查找的窗口对象。 |
476
477**错误码:**
478
479以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
480
481| 错误码ID | 错误信息 |
482| ------- | -------------------------------- |
483| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
484| 1300002 | This window state is abnormal. |
485
486**示例:**
487
488```ts
489let windowClass: window.Window | undefined = undefined;
490try {
491  windowClass = window.findWindow('test');
492} catch (exception) {
493  console.error(`Failed to find the Window. Cause code: ${exception.code}, message: ${exception.message}`);
494}
495```
496
497## window.getLastWindow<sup>9+</sup>
498
499getLastWindow(ctx: BaseContext, callback: AsyncCallback&lt;Window&gt;): void
500
501获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口,使用callback异步回调。
502
503**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
504
505**系统能力:** SystemCapability.WindowManager.WindowManager.Core
506
507**参数:**
508
509| 参数名 | 类型 | 必填 | 说明 |
510| -------- | -------------------------------------- | -- | ---------------------------------------- |
511| ctx      | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 |
512| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 |
513
514**错误码:**
515
516以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
517
518| 错误码ID | 错误信息 |
519| ------- | -------------------------------- |
520| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
521| 1300002 | This window state is abnormal.   |
522| 1300006 | This window context is abnormal. |
523
524**示例:**
525
526```ts
527// EntryAbility.ets
528import { UIAbility } from '@kit.AbilityKit';
529import { BusinessError } from '@kit.BasicServicesKit';
530
531export default class EntryAbility extends UIAbility {
532  // ...
533  onWindowStageCreate(windowStage: window.WindowStage) {
534    console.info('onWindowStageCreate');
535    let windowClass: window.Window | undefined = undefined;
536    try {
537      window.getLastWindow(this.context, (err: BusinessError, data) => {
538        const errCode: number = err.code;
539        if (errCode) {
540          console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
541          return;
542        }
543        windowClass = data;
544        console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
545      });
546    } catch (exception) {
547      console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`);
548    }
549  }
550}
551```
552
553## window.getLastWindow<sup>9+</sup>
554
555getLastWindow(ctx: BaseContext): Promise&lt;Window&gt;
556
557获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口,使用Promise异步回调。
558
559**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
560
561**系统能力:** SystemCapability.WindowManager.WindowManager.Core
562
563**参数:**
564
565| 参数名 | 类型 | 必填 | 说明 |
566| ------ | ----------- | ---- | ------------------------------------------------------------ |
567| ctx    | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用上下文信息。 |
568
569**返回值:**
570
571| 类型 | 说明 |
572| -------------------------------- | ------------------------------------------- |
573| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前应用内最后显示的窗口对象。 |
574
575**错误码:**
576
577以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
578
579| 错误码ID | 错误信息 |
580| ------- | -------------------------------- |
581| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
582| 1300002 | This window state is abnormal.   |
583| 1300006 | This window context is abnormal. |
584
585**示例:**
586
587```ts
588// EntryAbility.ets
589import { UIAbility } from '@kit.AbilityKit';
590import { BusinessError } from '@kit.BasicServicesKit';
591
592export default class EntryAbility extends UIAbility {
593  // ...
594  onWindowStageCreate(windowStage: window.WindowStage) {
595    console.info('onWindowStageCreate');
596    let windowClass: window.Window | undefined = undefined;
597    try {
598      let promise = window.getLastWindow(this.context);
599      promise.then((data) => {
600        windowClass = data;
601        console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
602      }).catch((err: BusinessError) => {
603        console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
604      });
605    } catch (exception) {
606      console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`);
607    }
608  }
609}
610```
611
612## window.shiftAppWindowFocus<sup>11+</sup>
613shiftAppWindowFocus(sourceWindowId: number, targetWindowId: number): Promise&lt;void&gt;
614
615在同应用内将窗口焦点从源窗口转移到目标窗口,仅支持应用主窗和子窗的焦点转移。
616
617**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
618
619**系统能力:** SystemCapability.Window.SessionManager
620
621**参数:**
622
623| 参数名          | 类型   | 必填  | 说明                    |
624| -------------- | ------ | ----- | ----------------------- |
625| sourceWindowId | number | 是    | 源窗口id,必须是获焦状态。|
626| targetWindowId | number | 是    | 目标窗口id。             |
627
628**返回值:**
629
630| 类型                | 说明                      |
631| ------------------- | ------------------------- |
632| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
633
634**错误码:**
635
636以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
637
638| 错误码ID | 错误信息                                      |
639| ------- | --------------------------------------------- |
640| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
641| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
642| 1300002 | This window state is abnormal.                |
643| 1300003 | This window manager service works abnormally. |
644| 1300004 | Unauthorized operation.                       |
645
646**示例:**
647
648```ts
649// EntryAbility.ets
650import { UIAbility } from '@kit.AbilityKit';
651import { BusinessError } from '@kit.BasicServicesKit';
652
653export default class EntryAbility extends UIAbility {
654  onWindowStageCreate(windowStage: window.WindowStage) {
655    // ...
656    console.info('onWindowStageCreate');
657    let windowClass: window.Window | undefined = undefined;
658    let subWindowClass: window.Window | undefined = undefined;
659    let windowClassId: number = -1;
660    let subWindowClassId: number = -1;
661
662    try {
663      // 获取应用主窗及ID
664      let promise = windowStage.getMainWindow();
665      promise.then((data) => {
666        if (data == null) {
667          console.error("Failed to obtaining the window. Cause: The data is empty");
668          return;
669        }
670        windowClass = data;
671        windowClass.setUIContent("pages/Index");
672        windowClassId = windowClass.getWindowProperties().id;
673        console.info('Succeeded in obtaining the window')
674      }).catch((err: BusinessError) => {
675        console.error(`Failed to obtaining the window. Cause code: ${err.code}, message: ${err.message}`);
676      });
677
678      // 创建或获取子窗及ID,此时子窗口获焦
679      let promiseSub = windowStage.createSubWindow("testSubWindow");
680      promiseSub.then((data) => {
681        if (data == null) {
682          console.error("Failed to obtaining the window. Cause: The data is empty");
683          return;
684        }
685        subWindowClass = data;
686        subWindowClassId = subWindowClass.getWindowProperties().id;
687        subWindowClass.resize(500, 500);
688        subWindowClass.setUIContent("pages/Index2");
689        subWindowClass.showWindow();
690
691        // 监听Window状态,确保已经就绪
692        subWindowClass.on("windowEvent", (windowEvent) => {
693          if (windowEvent == window.WindowEventType.WINDOW_ACTIVE) {
694            // 切换焦点
695            let promise = window.shiftAppWindowFocus(subWindowClassId, windowClassId);
696            promise.then(() => {
697              console.info('Succeeded in shifting app window focus');
698            }).catch((err: BusinessError) => {
699              console.error(`Failed to shift app window focus. Cause code: ${err.code}, message: ${err.message}`);
700            });
701          }
702        });
703      });
704    } catch (exception) {
705      console.error(`Failed to shift app focus. Cause code: ${exception.code}, message: ${exception.message}`);
706    }
707  }
708}
709```
710
711## window.getWindowsByCoordinate<sup>14+</sup>
712
713getWindowsByCoordinate(displayId: number, windowNumber?: number, x?: number, y?: number): Promise&lt;Array&lt;Window&gt;&gt;
714
715查询本应用指定坐标下的可见窗口,使用Promise异步回调。
716
717**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
718
719**系统能力:** SystemCapability.Window.SessionManager
720
721**参数:**
722
723| 参数名 | 类型   | 必填 | 说明                                                                        |
724| ------ | ---------- |----|---------------------------------------------------------------------------|
725| displayId   | number| 是  | 查询窗口所在的displayId,该参数应为整数,可以在窗口属性[WindowProperties](#windowproperties)中获取。 |
726| windowNumber    | number| 否  | 查询的窗口数量,该参数应为大于0整数,未设置或小于等于0返回所有满足条件的窗口。                                  |
727| x    | number | 否  | 查询的x坐标,该参数应为非负整数,未设置或小于0返回所有可见窗口。                                         |
728| y    | number| 否  | 查询的y坐标,该参数应为非负整数,未设置或小于0返回所有可见窗口。                                         |
729
730**返回值:**
731
732| 类型                             | 说明                      |
733| -------------------------------- |-------------------------|
734| Promise&lt;Array&lt;[Window](#window)&gt;&gt; | Promise对象。返回获取到的窗口对象数组。 |
735
736**错误码:**
737
738以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
739
740| 错误码ID    | 错误信息 |
741|----------| ------------------------------ |
742| 401      | Parameter error. Possible cause: Incorrect parameter types. |
743| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
744| 1300003 | This window manager service works abnormally. |
745
746```ts
747import { window } from '@kit.ArkUI';
748import { BusinessError } from '@kit.BasicServicesKit';
749
750try {
751    let properties = windowClass.getWindowProperties();
752    window.getWindowsByCoordinate(properties.displayId).then((data) => {
753        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
754        for (let window of data) {
755            // do something with window
756        }
757    }).catch((err: BusinessError) => {
758        console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`);
759    });
760
761    window.getWindowsByCoordinate(properties.displayId, 2, 500, 500).then((data) => {
762        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
763        for (let window of data) {
764            // do something with window
765        }
766    }).catch((err: BusinessError) => {
767        console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`);
768    });
769} catch (exception) {
770    console.error(`Failed to get window from point. Cause code: ${exception.code}, message: ${exception.message}`);
771}
772```
773
774## window.create<sup>(deprecated)</sup>
775
776create(id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void
777
778创建子窗口,使用callback异步回调。
779
780> **说明:**
781>
782> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。
783
784**模型约束:** 此接口仅可在FA模型下使用。
785
786**系统能力:** SystemCapability.WindowManager.WindowManager.Core
787
788**参数:**
789
790| 参数名   | 类型                                   | 必填 | 说明                                 |
791| -------- | -------------------------------------- | ---- | ------------------------------------ |
792| id       | string                                 | 是   | 窗口名字,即[Configuration](#configuration9)中的name。|
793| type     | [WindowType](#windowtype7)              | 是   | 窗口类型。                           |
794| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前创建的子窗口对象。 |
795
796
797**示例:**
798
799```ts
800import { BusinessError } from '@kit.BasicServicesKit';
801
802let windowClass: window.Window | undefined = undefined;
803window.create('test', window.WindowType.TYPE_APP, (err: BusinessError, data) => {
804  const errCode: number = err.code;
805  if (errCode) {
806    console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`);
807    return;
808  }
809  windowClass = data;
810  console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data));
811});
812```
813
814## window.create<sup>(deprecated)</sup>
815
816create(id: string, type: WindowType): Promise&lt;Window&gt;
817
818创建子窗口,使用Promise异步回调。
819
820> **说明:**
821>
822> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。
823
824**模型约束:** 此接口仅可在FA模型下使用。
825
826**系统能力:** SystemCapability.WindowManager.WindowManager.Core
827
828**参数:**
829
830| 参数名 | 类型                      | 必填 | 说明       |
831| ------ | ------------------------- | ---- | ---------- |
832| id     | string                    | 是   | 窗口名字,即[Configuration](#configuration9)中的name。   |
833| type   | [WindowType](#windowtype7) | 是   | 窗口类型。 |
834
835**返回值:**
836
837| 类型                             | 说明                                    |
838| -------------------------------- | --------------------------------------- |
839| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前创建的子窗口对象。 |
840
841
842**示例:**
843
844```ts
845import { BusinessError } from '@kit.BasicServicesKit';
846
847let windowClass: window.Window | undefined = undefined;
848let promise = window.create('test', window.WindowType.TYPE_APP);
849promise.then((data) => {
850  windowClass = data;
851  console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data));
852}).catch((err: BusinessError) => {
853  console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`);
854});
855```
856
857## window.create<sup>(deprecated)</sup>
858
859create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void
860
861创建系统窗口,使用callback异步回调。
862
863> **说明:**
864>
865> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。
866
867**系统能力:** SystemCapability.WindowManager.WindowManager.Core
868
869**参数:**
870
871| 参数名   | 类型                                                    | 必填 | 说明                                 |
872| -------- | ------------------------------------------------------- | ---- | ------------------------------------ |
873| ctx      | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用上下文信息。                 |
874| id       | string                                                  | 是   | 窗口名字,即[Configuration](#configuration9)中的name。   |
875| type     | [WindowType](#windowtype7)                              | 是   | 窗口类型。                           |
876| callback | AsyncCallback&lt;[Window](#window)&gt;                  | 是   | 回调函数。返回当前创建的子窗口对象。 |
877
878
879**示例:**
880
881```ts
882import { BusinessError } from '@kit.BasicServicesKit';
883
884let windowClass: window.Window | undefined = undefined;
885window.create('test', window.WindowType.TYPE_SYSTEM_ALERT, (err: BusinessError, data) => {
886  const errCode: number = err.code;
887  if (errCode) {
888    console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`);
889    return;
890  }
891  windowClass = data;
892  console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data));
893  windowClass.resetSize(500, 1000);
894});
895```
896
897## window.create<sup>(deprecated)</sup>
898
899create(ctx: BaseContext, id: string, type: WindowType): Promise&lt;Window&gt;
900
901创建系统窗口,使用Promise异步回调。
902
903> **说明:**
904>
905> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。
906
907**系统能力:** SystemCapability.WindowManager.WindowManager.Core
908
909**参数:**
910
911| 参数名 | 类型                      | 必填 | 说明                                                         |
912| ------ | ------------------------- | ---- | ------------------------------------------------------------ |
913| ctx    | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用上下文信息。 |
914| id     | string                    | 是   | 窗口名字,即[Configuration](#configuration9)中的name。 |
915| type   | [WindowType](#windowtype7) | 是   | 窗口类型。                                                   |
916
917**返回值:**
918
919| 类型                             | 说明                                    |
920| -------------------------------- | --------------------------------------- |
921| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前创建的子窗口对象。 |
922
923
924**示例:**
925
926```ts
927import { BusinessError } from '@kit.BasicServicesKit';
928
929let windowClass: window.Window | undefined = undefined;
930let promise = window.create('test', window.WindowType.TYPE_SYSTEM_ALERT);
931promise.then((data) => {
932  windowClass = data;
933  console.info('Succeeded in creating the window. Data:' + JSON.stringify(data));
934}).catch((err: BusinessError) => {
935  console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`);
936});
937```
938
939## window.find<sup>(deprecated)</sup>
940
941find(id: string, callback: AsyncCallback&lt;Window&gt;): void
942
943查找id所对应的窗口,使用callback异步回调。
944
945> **说明:**
946>
947> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。
948
949**系统能力:** SystemCapability.WindowManager.WindowManager.Core
950
951**参数:**
952
953| 参数名   | 类型                                   | 必填 | 说明                                 |
954| -------- | -------------------------------------- | ---- | ------------------------------------ |
955| id       | string                                 | 是   | 窗口名字,即[Configuration](#configuration9)中的name。 |
956| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前查找到的窗口对象。 |
957
958**示例:**
959
960```ts
961import { BusinessError } from '@kit.BasicServicesKit';
962
963let windowClass: window.Window | undefined = undefined;
964window.find('test', (err: BusinessError, data) => {
965  const errCode: number = err.code;
966  if (errCode) {
967    console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`);
968    return;
969  }
970  windowClass = data;
971  console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data));
972});
973```
974
975## window.find<sup>(deprecated)</sup>
976
977find(id: string): Promise&lt;Window&gt;
978
979查找id所对应的窗口,使用Promise异步回调。
980
981> **说明:**
982>
983> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。
984
985**系统能力:** SystemCapability.WindowManager.WindowManager.Core
986
987**参数:**
988
989| 参数名 | 类型   | 必填 | 说明     |
990| ------ | ------ | ---- | -------- |
991| id     | string | 是   | 窗口名字,即[Configuration](#configuration9)中的name。 |
992
993**返回值:**
994
995| 类型                             | 说明                                  |
996| -------------------------------- | ------------------------------------- |
997| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前查找的窗口对象。 |
998
999**示例:**
1000
1001```ts
1002import { BusinessError } from '@kit.BasicServicesKit';
1003
1004let windowClass: window.Window | undefined = undefined;
1005let promise = window.find('test');
1006promise.then((data) => {
1007  windowClass = data;
1008  console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data));
1009}).catch((err: BusinessError) => {
1010  console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`);
1011});
1012```
1013
1014## window.getTopWindow<sup>(deprecated)</sup>
1015
1016getTopWindow(callback: AsyncCallback&lt;Window&gt;): void
1017
1018获取当前应用内最后显示的窗口,使用callback异步回调。
1019
1020> **说明:**
1021>
1022> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。
1023
1024**模型约束:** 此接口仅可在FA模型下使用。
1025
1026**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1027
1028**参数:**
1029
1030| 参数名   | 类型                                   | 必填 | 说明                                         |
1031| -------- | -------------------------------------- | ---- | -------------------------------------------- |
1032| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前应用内最后显示的窗口对象。 |
1033
1034**示例:**
1035
1036```ts
1037import { BusinessError } from '@kit.BasicServicesKit';
1038
1039let windowClass: window.Window | undefined = undefined;
1040window.getTopWindow((err: BusinessError, data) => {
1041  const errCode: number = err.code;
1042  if (errCode) {
1043    console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
1044    return;
1045  }
1046  windowClass = data;
1047  console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1048});
1049```
1050
1051## window.getTopWindow<sup>(deprecated)</sup>
1052
1053getTopWindow(): Promise&lt;Window&gt;
1054
1055获取当前应用内最后显示的窗口,使用Promise异步回调。
1056
1057> **说明:**
1058>
1059> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。
1060
1061**模型约束:** 此接口仅可在FA模型下使用。
1062
1063**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1064
1065**返回值:**
1066
1067| 类型                             | 说明                                            |
1068| -------------------------------- | ----------------------------------------------- |
1069| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前应用内最后显示的窗口对象。 |
1070
1071**示例:**
1072
1073```ts
1074import { BusinessError } from '@kit.BasicServicesKit';
1075
1076let windowClass: window.Window | undefined = undefined;
1077let promise = window.getTopWindow();
1078promise.then((data)=> {
1079    windowClass = data;
1080    console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1081}).catch((err: BusinessError)=>{
1082    console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
1083});
1084```
1085
1086## window.getTopWindow<sup>(deprecated)</sup>
1087
1088getTopWindow(ctx: BaseContext, callback: AsyncCallback&lt;Window&gt;): void
1089
1090获取当前应用内最后显示的窗口,使用callback异步回调。
1091
1092> **说明:**
1093>
1094> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。
1095
1096**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1097
1098**参数:**
1099
1100| 参数名   | 类型                                   | 必填 | 说明                                                         |
1101| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
1102| ctx      | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md)                            | 是   | 当前应用上下文信息。 |
1103| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前应用内最后显示的窗口对象。                 |
1104
1105**示例:**
1106
1107```ts
1108// EntryAbility.ets
1109import { UIAbility } from '@kit.AbilityKit';
1110import { BusinessError } from '@kit.BasicServicesKit';
1111
1112export default class EntryAbility extends UIAbility {
1113  onWindowStageCreate(windowStage:window.WindowStage){
1114    console.info('onWindowStageCreate');
1115    let windowClass: window.Window | undefined = undefined;
1116    try {
1117      window.getTopWindow(this.context, (err: BusinessError, data) => {
1118        const errCode: number = err.code;
1119        if(errCode){
1120          console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
1121          return ;
1122        }
1123        windowClass = data;
1124        console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1125      });
1126    } catch(error){
1127      console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`);
1128    }
1129  }
1130}
1131```
1132
1133## window.getTopWindow<sup>(deprecated)</sup>
1134
1135getTopWindow(ctx: BaseContext): Promise&lt;Window&gt;
1136
1137获取当前应用内最后显示的窗口,使用Promise异步回调。
1138
1139> **说明:**
1140>
1141> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。
1142
1143**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1144
1145**参数:**
1146
1147| 参数名 | 类型    | 必填 | 说明                                                         |
1148| ------ | ----------- | ---- | ------------------------------------------------------------ |
1149| ctx    | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用上下文信息。 |
1150
1151**返回值:**
1152
1153| 类型                             | 说明                                            |
1154| -------------------------------- | ----------------------------------------------- |
1155| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前应用内最后显示的窗口对象。 |
1156
1157**示例:**
1158
1159```ts
1160// EntryAbility.ets
1161import { UIAbility } from '@kit.AbilityKit';
1162import { BusinessError } from '@kit.BasicServicesKit';
1163
1164export default class EntryAbility extends UIAbility {
1165  onWindowStageCreate(windowStage:window.WindowStage) {
1166    console.info('onWindowStageCreate');
1167    let windowClass: window.Window | undefined = undefined;
1168    let promise = window.getTopWindow(this.context);
1169    promise.then((data) => {
1170      windowClass = data;
1171      console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1172    }).catch((error: BusinessError) => {
1173      console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`);
1174    });
1175  }
1176}
1177```
1178
1179## SpecificSystemBar<sup>11+</sup>
1180
1181type SpecificSystemBar = 'status' \| 'navigation' \| 'navigationIndicator'
1182
1183当前支持显示或隐藏的系统栏类型。
1184
1185**系统能力:** SystemCapability.Window.SessionManager
1186
1187**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1188
1189| 类型       | 说明     |
1190|------------|--------|
1191| 'status'   | 状态栏。   |
1192| 'navigation'   | 三键导航栏。   |
1193| 'navigationIndicator'   | 底部导航条。 |
1194
1195## Window
1196
1197当前窗口实例,窗口管理器管理的基本单元。
1198
1199下列API示例中都需先使用[getLastWindow()](#windowgetlastwindow9)、[createWindow()](#windowcreatewindow9)、[findWindow()](#windowfindwindow9)中的任一方法获取到Window实例(windowClass),再通过此实例调用对应方法。
1200
1201### showWindow<sup>9+</sup>
1202
1203showWindow(callback: AsyncCallback&lt;void&gt;): void
1204
1205显示当前窗口,使用callback异步回调,仅支持系统窗口及应用子窗口,或将已显示的应用主窗口的层级提升至顶部。
1206
1207**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1208
1209**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1210
1211**参数:**
1212
1213| 参数名 | 类型 | 必填 | 说明 |
1214| -------- | ------------------------- | -- | --------- |
1215| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
1216
1217**错误码:**
1218
1219以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
1220
1221| 错误码ID | 错误信息 |
1222| ------- | ------------------------------ |
1223| 1300002 | This window state is abnormal. |
1224
1225**示例:**
1226
1227```ts
1228import { BusinessError } from '@kit.BasicServicesKit';
1229
1230windowClass.showWindow((err: BusinessError) => {
1231  const errCode: number = err.code;
1232  if (errCode) {
1233    console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`);
1234    return;
1235  }
1236  console.info('Succeeded in showing the window.');
1237});
1238```
1239
1240### showWindow<sup>9+</sup>
1241
1242showWindow(): Promise&lt;void&gt;
1243
1244显示当前窗口,使用Promise异步回调,仅支持系统窗口及应用子窗口,或将已显示的应用主窗口的层级提升至顶部。
1245
1246**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1247
1248**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1249
1250**返回值:**
1251
1252| 类型 | 说明 |
1253| ------------------- | ----------------------- |
1254| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1255
1256**错误码:**
1257
1258以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
1259
1260| 错误码ID | 错误信息 |
1261| ------- | ------------------------------ |
1262| 1300002 | This window state is abnormal. |
1263
1264**示例:**
1265
1266```ts
1267import { BusinessError } from '@kit.BasicServicesKit';
1268
1269let promise = windowClass.showWindow();
1270promise.then(() => {
1271  console.info('Succeeded in showing the window.');
1272}).catch((err: BusinessError) => {
1273  console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`);
1274});
1275```
1276
1277### destroyWindow<sup>9+</sup>
1278
1279destroyWindow(callback: AsyncCallback&lt;void&gt;): void
1280
1281销毁当前窗口,使用callback异步回调,仅支持系统窗口及应用子窗口。
1282
1283**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1284
1285**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1286
1287**参数:**
1288
1289| 参数名 | 类型 | 必填 | 说明 |
1290| -------- | ------------------------- | -- | --------- |
1291| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
1292
1293**错误码:**
1294
1295以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
1296
1297| 错误码ID | 错误信息 |
1298| ------- | -------------------------------------------- |
1299| 1300002 | This window state is abnormal.               |
1300| 1300003 | This window manager service works abnormally. |
1301
1302**示例:**
1303
1304```ts
1305import { BusinessError } from '@kit.BasicServicesKit';
1306
1307windowClass.destroyWindow((err) => {
1308  const errCode: number = err.code;
1309  if (errCode) {
1310    console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`);
1311    return;
1312  }
1313  console.info('Succeeded in destroying the window.');
1314});
1315```
1316
1317### destroyWindow<sup>9+</sup>
1318
1319destroyWindow(): Promise&lt;void&gt;
1320
1321销毁当前窗口,使用Promise异步回调,仅支持系统窗口及应用子窗口。
1322
1323**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1324
1325**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1326
1327**返回值:**
1328
1329| 类型 | 说明 |
1330| ------------------- | ------------------------ |
1331| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1332
1333**错误码:**
1334
1335以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
1336
1337| 错误码ID | 错误信息 |
1338| ------- | -------------------------------------------- |
1339| 1300002 | This window state is abnormal.               |
1340| 1300003 | This window manager service works abnormally. |
1341
1342**示例:**
1343
1344```ts
1345import { BusinessError } from '@kit.BasicServicesKit';
1346
1347let promise = windowClass.destroyWindow();
1348promise.then(() => {
1349  console.info('Succeeded in destroying the window.');
1350}).catch((err: BusinessError) => {
1351  console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`);
1352});
1353```
1354
1355### moveWindowTo<sup>9+</sup>
1356
1357moveWindowTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void
1358
1359移动窗口位置,使用callback异步回调。
1360
1361<!--RP4-->
1362全屏模式下,本接口仅在2in1设备上生效。<!--RP4End-->
1363在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。
1364
1365**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1366
1367**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1368
1369**参数:**
1370
1371| 参数名 | 类型 | 必填 | 说明 |
1372| -------- | ------------------------- | -- | --------------------------------------------- |
1373| x        | number                    | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
1374| y        | number                    | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
1375| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                     |
1376
1377**错误码:**
1378
1379以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1380
1381| 错误码ID | 错误信息 |
1382| ------- | -------------------------------------------- |
1383| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1384| 1300002 | This window state is abnormal.               |
1385| 1300003 | This window manager service works abnormally. |
1386
1387**示例:**
1388
1389```ts
1390import { BusinessError } from '@kit.BasicServicesKit';
1391
1392try {
1393  windowClass.moveWindowTo(300, 300, (err: BusinessError) => {
1394    const errCode: number = err.code;
1395    if (errCode) {
1396      console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
1397      return;
1398    }
1399    console.info('Succeeded in moving the window.');
1400  });
1401} catch (exception) {
1402  console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`);
1403}
1404```
1405
1406### moveWindowTo<sup>9+</sup>
1407
1408moveWindowTo(x: number, y: number): Promise&lt;void&gt;
1409
1410移动窗口位置,使用Promise异步回调。调用成功即返回,该接口返回后无法立即获取最终生效结果,如需立即获取,建议使用接口[moveWindowToAsync()](#movewindowtoasync12)。
1411
1412<!--RP4-->
1413全屏模式下,本接口仅在2in1设备上生效。<!--RP4End-->
1414在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。
1415
1416**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1417
1418**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1419
1420**参数:**
1421
1422| 参数名 | 类型 | 必填 | 说明 |
1423| -- | ----- | -- | --------------------------------------------- |
1424| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
1425| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
1426
1427**返回值:**
1428
1429| 类型 | 说明 |
1430| ------------------- | ------------------------ |
1431| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1432
1433**错误码:**
1434
1435以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1436
1437| 错误码ID | 错误信息 |
1438| ------- | -------------------------------------------- |
1439| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1440| 1300002 | This window state is abnormal.               |
1441| 1300003 | This window manager service works abnormally. |
1442
1443**示例:**
1444
1445```ts
1446import { BusinessError } from '@kit.BasicServicesKit';
1447
1448try {
1449  let promise = windowClass.moveWindowTo(300, 300);
1450  promise.then(() => {
1451    console.info('Succeeded in moving the window.');
1452  }).catch((err: BusinessError) => {
1453    console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
1454  });
1455} catch (exception) {
1456  console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`);
1457}
1458```
1459
1460### moveWindowToAsync<sup>12+</sup>
1461
1462moveWindowToAsync(x: number, y: number): Promise&lt;void&gt;
1463
1464移动窗口位置,使用Promise异步回调。调用生效后返回,回调中可使用getWindowProperties(见示例)立即获取最终生效结果。
1465
1466全屏模式窗口不支持该操作。
1467在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。
1468
1469**系统能力:** SystemCapability.Window.SessionManager
1470
1471**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1472
1473**参数:**
1474
1475| 参数名 | 类型 | 必填 | 说明 |
1476| -- | ----- | -- | --------------------------------------------- |
1477| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
1478| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
1479
1480**返回值:**
1481
1482| 类型 | 说明 |
1483| ------------------- | ------------------------ |
1484| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1485
1486**错误码:**
1487
1488以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1489
1490| 错误码ID | 错误信息 |
1491| ------- | -------------------------------------------- |
1492| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1493| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
1494| 1300002 | This window state is abnormal.               |
1495| 1300003 | This window manager service works abnormally. |
1496| 1300010 | The operation is not supported in full-screen mode. |
1497
1498**示例:**
1499
1500```ts
1501import { BusinessError } from '@kit.BasicServicesKit';
1502
1503try {
1504  let promise = windowClass.moveWindowToAsync(300, 300);
1505  promise.then(() => {
1506    console.info('Succeeded in moving the window.');
1507    let rect = windowClass.getWindowProperties().windowRect;
1508    console.info(`Get window rect: ` + JSON.stringify(rect));
1509  }).catch((err: BusinessError) => {
1510    console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
1511  });
1512} catch (exception) {
1513  console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`);
1514}
1515```
1516
1517### resize<sup>9+</sup>
1518
1519resize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void
1520
1521改变当前窗口大小,使用callback异步回调。
1522
1523应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。
1524应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
1525
1526系统窗口存在大小限制,宽度范围:[0, 1920],高度范围:[0, 1920],单位为vp。
1527
1528设置的宽度与高度受到此约束限制,规则:
1529若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
1530若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
1531
1532全屏模式窗口不支持该操作。
1533
1534**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1535
1536**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1537
1538**参数:**
1539
1540| 参数名 | 类型 | 必填 | 说明 |
1541| -------- | ------------------------- | -- | ------------------------ |
1542| width    | number                    | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
1543| height   | number                    | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
1544| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。                |
1545
1546**错误码:**
1547
1548以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1549
1550| 错误码ID | 错误信息 |
1551| ------- | -------------------------------------------- |
1552| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1553| 1300002 | This window state is abnormal.               |
1554| 1300003 | This window manager service works abnormally. |
1555
1556**示例:**
1557
1558```ts
1559import { BusinessError } from '@kit.BasicServicesKit';
1560
1561try {
1562  windowClass.resize(500, 1000, (err: BusinessError) => {
1563    const errCode: number = err.code;
1564    if (errCode) {
1565      console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
1566      return;
1567    }
1568    console.info('Succeeded in changing the window size.');
1569  });
1570} catch (exception) {
1571  console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`);
1572}
1573```
1574
1575### resize<sup>9+</sup>
1576
1577resize(width: number, height: number): Promise&lt;void&gt;
1578
1579改变当前窗口大小,使用Promise异步回调。调用成功即返回,该接口返回后无法立即获取最终生效结果,如需立即获取,建议使用接口[resizeAsync()](#resizeasync12)。
1580
1581应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。
1582应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
1583
1584系统窗口存在大小限制,宽度范围:[0, 1920],高度范围:[0, 1920],单位为vp。
1585
1586设置的宽度与高度受到此约束限制,规则:
1587若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
1588若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
1589
1590全屏模式窗口不支持该操作。
1591
1592**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1593
1594**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1595
1596**参数:**
1597
1598| 参数名 | 类型 | 必填 | 说明 |
1599| ------ | ------ | -- | ------------------------ |
1600| width  | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
1601| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
1602
1603**返回值:**
1604
1605| 类型 | 说明 |
1606| ------------------- | ------------------------ |
1607| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1608
1609**错误码:**
1610
1611以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1612
1613| 错误码ID | 错误信息 |
1614| ------- | -------------------------------------------- |
1615| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1616| 1300002 | This window state is abnormal.               |
1617| 1300003 | This window manager service works abnormally. |
1618
1619**示例:**
1620
1621```ts
1622import { BusinessError } from '@kit.BasicServicesKit';
1623
1624try {
1625  let promise = windowClass.resize(500, 1000);
1626  promise.then(() => {
1627    console.info('Succeeded in changing the window size.');
1628  }).catch((err: BusinessError) => {
1629    console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
1630  });
1631} catch (exception) {
1632  console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`);
1633}
1634```
1635
1636### resizeAsync<sup>12+</sup>
1637
1638resizeAsync(width: number, height: number): Promise&lt;void&gt;
1639
1640改变当前窗口大小,使用Promise异步回调。调用生效后返回,回调中可使用getWindowProperties(见示例)立即获取最终生效结果。
1641
1642应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。
1643应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
1644
1645系统窗口存在大小限制,宽度范围:[0, 1920],高度范围:[0, 1920],单位为vp。
1646
1647设置的宽度与高度受到此约束限制,规则:
1648若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
1649若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
1650
1651全屏模式窗口不支持该操作。
1652
1653**系统能力:** SystemCapability.Window.SessionManager
1654
1655**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1656
1657**参数:**
1658
1659| 参数名 | 类型 | 必填 | 说明 |
1660| ------ | ------ | -- | ------------------------ |
1661| width  | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
1662| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
1663
1664**返回值:**
1665
1666| 类型 | 说明 |
1667| ------------------- | ------------------------ |
1668| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1669
1670**错误码:**
1671
1672以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1673
1674| 错误码ID | 错误信息 |
1675| ------- | -------------------------------------------- |
1676| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1677| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
1678| 1300002 | This window state is abnormal.               |
1679| 1300003 | This window manager service works abnormally. |
1680| 1300010 | The operation is not supported in full-screen mode. |
1681
1682**示例:**
1683
1684```ts
1685import { BusinessError } from '@kit.BasicServicesKit';
1686
1687try {
1688  let promise = windowClass.resizeAsync(500, 1000);
1689  promise.then(() => {
1690    console.info('Succeeded in changing the window size.');
1691    let rect = windowClass.getWindowProperties().windowRect;
1692    console.info(`Get window rect: ` + JSON.stringify(rect));
1693  }).catch((err: BusinessError) => {
1694    console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
1695  });
1696} catch (exception) {
1697  console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`);
1698}
1699```
1700
1701### getWindowProperties<sup>9+</sup>
1702
1703getWindowProperties(): WindowProperties
1704
1705获取当前窗口的属性,返回WindowProperties。
1706
1707**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1708
1709**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1710
1711**返回值:**
1712
1713| 类型 | 说明 |
1714| ------------------------------------- | ------------- |
1715| [WindowProperties](#windowproperties) | 当前窗口属性。 |
1716
1717**错误码:**
1718
1719以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
1720
1721| 错误码ID | 错误信息 |
1722| ------- | ------------------------------ |
1723| 1300002 | This window state is abnormal. |
1724
1725**示例:**
1726
1727```ts
1728try {
1729  let properties = windowClass.getWindowProperties();
1730} catch (exception) {
1731  console.error(`Failed to obtain the window properties. Cause code: ${exception.code}, message: ${exception.message}`);
1732}
1733```
1734
1735### getWindowAvoidArea<sup>9+</sup>
1736
1737getWindowAvoidArea(type: AvoidAreaType): AvoidArea
1738
1739获取当前窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。
1740
1741该接口一般适用于两种场景:1、在onWindowStageCreate方法中,获取应用启动时的初始布局避让区域时可调用该接口;2、当应用内子窗需要临时显示,对显示内容做布局避让时可调用该接口。
1742
1743**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1744
1745**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1746
1747**参数:**
1748
1749| 参数名 | 类型 | 必填 | 说明 |
1750| ---- |----------------------------------| -- | ------------------------------------------------------------ |
1751| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。 |
1752
1753**返回值:**
1754
1755| 类型 | 说明 |
1756|--------------------------| ----------------- |
1757| [AvoidArea](#avoidarea7) | 窗口内容规避区域。 |
1758
1759**错误码:**
1760
1761以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1762
1763| 错误码ID | 错误信息 |
1764| ------- | ------------------------------ |
1765| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1766| 1300002 | This window state is abnormal. |
1767
1768**示例:**
1769
1770```ts
1771let type = window.AvoidAreaType.TYPE_SYSTEM;
1772try {
1773  let avoidArea = windowClass.getWindowAvoidArea(type);
1774} catch (exception) {
1775  console.error(`Failed to obtain the area. Cause code: ${exception.code}, message: ${exception.message}`);
1776}
1777```
1778
1779### setTitleAndDockHoverShown<sup>14+</sup>
1780
1781setTitleAndDockHoverShown(isTitleHoverShown?: boolean, isDockHoverShown?: boolean): Promise&lt;void&gt;
1782
1783设置主窗口进入全屏沉浸式时鼠标Hover到热区上是否显示窗口标题栏和dock栏,使用Promise异步回调,仅2in1设备可用。
1784
1785**系统能力**:SystemCapability.Window.SessionManager
1786
1787**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
1788
1789**参数:**
1790
1791| 参数名      | 类型    | 必填 | 说明                                                         |
1792| ---------- | ------- | ---- | ------------------------------------------------------------ |
1793| isTitleHoverShown    | boolean | 否   | 是否显示窗口标题栏。<br>true表示显示窗口标题栏;false表示不显示窗口标题栏。默认值是true。</br> |
1794| isDockHoverShown    | boolean | 否   | 是否显示dock栏。<br>true表示显示dock栏;false表示不显示dock栏。默认值是true。</br> |
1795
1796**错误码:**
1797
1798以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1799
1800| 错误码ID | 错误信息 |
1801| ------- | -------------------------------------------- |
1802| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1803| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
1804| 1300002 | This window state is abnormal. |
1805| 1300004 | Unauthorized operation. |
1806
1807**示例:**
1808
1809```ts
1810// EntryAbility.ets
1811import { UIAbility } from '@kit.AbilityKit';
1812import { BusinessError } from '@kit.BasicServicesKit';
1813import { window } from '@kit.ArkUI';
1814
1815export default class EntryAbility extends UIAbility {
1816  // ...
1817  onWindowStageCreate(windowStage: window.WindowStage): void {
1818    // 加载主窗口对应的页面。
1819    windowStage.loadContent('pages/Index', (err) => {
1820      let mainWindow: window.Window | undefined = undefined;
1821      // 获取应用主窗口。
1822      windowStage.getMainWindow().then(
1823        data => {
1824          mainWindow = data;
1825          console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
1826          // 调用maximize接口,设置窗口进入全屏沉浸式。
1827          mainWindow.maximize(window.MaximizePresentation.ENTER_IMMERSIVE);
1828          // 调用setTitleAndDockHoverShown接口,隐藏标题栏和dock栏。
1829          mainWindow.setTitleAndDockHoverShown(false, false);
1830        }
1831      ).catch((err: BusinessError) => {
1832          if(err.code){
1833            console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
1834          }
1835      });
1836    });
1837  }
1838}
1839```
1840
1841### setWindowLayoutFullScreen<sup>9+</sup>
1842
1843setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise&lt;void&gt;
1844
1845设置主窗口或子窗口的布局是否为沉浸式布局,使用Promise异步回调。
1846沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
1847非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。
1848
1849**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1850
1851**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1852
1853**参数:**
1854
1855| 参数名 | 类型 | 必填 | 说明 |
1856| ------------------ | ------- | -- | ------------------------------------------------------------------------------------------------ |
1857| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 |
1858
1859**返回值:**
1860
1861| 类型 | 说明 |
1862| ------------------- | ------------------------ |
1863| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1864
1865**错误码:**
1866
1867以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1868
1869| 错误码ID | 错误信息 |
1870| ------- | -------------------------------------------- |
1871| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1872| 1300002 | This window state is abnormal.               |
1873| 1300003 | This window manager service works abnormally. |
1874
1875**示例:**
1876
1877```ts
1878// EntryAbility.ets
1879import { UIAbility } from '@kit.AbilityKit';
1880import { BusinessError } from '@kit.BasicServicesKit';
1881
1882export default class EntryAbility extends UIAbility {
1883  // ...
1884  onWindowStageCreate(windowStage: window.WindowStage): void {
1885    console.info('onWindowStageCreate');
1886    let windowClass: window.Window | undefined = undefined;
1887    windowStage.getMainWindow((err: BusinessError, data) => {
1888      const errCode: number = err.code;
1889      if (errCode) {
1890        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
1891        return;
1892      }
1893      windowClass = data;
1894      let isLayoutFullScreen = true;
1895      try {
1896        let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen);
1897        promise.then(() => {
1898          console.info('Succeeded in setting the window layout to full-screen mode.');
1899        }).catch((err: BusinessError) => {
1900          console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
1901        });
1902      } catch (exception) {
1903        console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`);
1904      }
1905    });
1906  }
1907}
1908```
1909
1910### setImmersiveModeEnabledState<sup>12+</sup>
1911
1912setImmersiveModeEnabledState(enabled: boolean): void
1913
1914设置当前窗口是否开启沉浸式布局,该调用不会改变窗口模式和窗口大小。
1915
1916**系统能力**:SystemCapability.WindowManager.WindowManager.Core
1917
1918**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1919
1920**参数:**
1921
1922| 参数名      | 类型    | 必填 | 说明                                                         |
1923| ---------- | ------- | ---- | ------------------------------------------------------------ |
1924| enabled    | boolean | 是   | 是否开启沉浸式布局。<br>true表示开启,false表示关闭。</br> |
1925
1926**错误码:**
1927
1928以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1929
1930| 错误码ID | 错误信息 |
1931| ------- | -------------------------------------------- |
1932| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1933| 1300002 | This window state is abnormal.               |
1934| 1300003 | This window manager service works abnormally. |
1935| 1300004 | Unauthorized operation.                |
1936
1937**示例:**
1938
1939```ts
1940try {
1941  let enabled = false;
1942  windowClass.setImmersiveModeEnabledState(enabled);
1943} catch (exception) {
1944  console.error(`Failed to set the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`);
1945}
1946```
1947
1948### getImmersiveModeEnabledState<sup>12+</sup>
1949
1950getImmersiveModeEnabledState(): boolean
1951
1952查询当前窗口是否已经开启沉浸式布局。
1953
1954**系统能力**:SystemCapability.WindowManager.WindowManager.Core
1955
1956**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1957
1958**返回值:**
1959| 类型     | 说明                                                                                 |
1960| ------- | ------------------------------------------------------------------------------------ |
1961| boolean | 是否已经开启沉浸式布局。<br>true表示开启,false表示关闭。</br> |
1962
1963**错误码:**
1964
1965以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1966
1967| 错误码ID | 错误信息 |
1968| -------- | -------------------------------------------- |
1969| 1300002  | This window state is abnormal.               |
1970| 1300003  | This window manager service works abnormally. |
1971| 1300004  | Unauthorized operation.               |
1972
1973**示例:**
1974
1975```ts
1976try {
1977  let isEnabled = windowClass.getImmersiveModeEnabledState();
1978} catch (exception) {
1979  console.error(`Failed to get the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`);
1980}
1981```
1982
1983### setWindowSystemBarEnable<sup>9+</sup>
1984
1985setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise&lt;void&gt;
1986
1987设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
1988
1989子窗口调用后不生效。
1990
1991**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1992
1993**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1994
1995**参数:**
1996
1997| 参数名 | 类型  | 必填 | 说明 |
1998| ----- | ---------------------------- | -- | --------------------------------- |
1999| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];不设置,则默认不显示。 |
2000
2001**返回值:**
2002
2003| 类型 | 说明 |
2004| ------------------- | ------------------------ |
2005| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2006
2007**错误码:**
2008
2009以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2010
2011| 错误码ID | 错误信息 |
2012| ------- | -------------------------------------------- |
2013| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2014| 1300002 | This window state is abnormal.               |
2015| 1300003 | This window manager service works abnormally. |
2016
2017**示例:**
2018
2019```ts
2020// 此处以不显示三键导航栏、状态栏、底部导航条为例
2021// EntryAbility.ets
2022import { UIAbility } from '@kit.AbilityKit';
2023import { BusinessError } from '@kit.BasicServicesKit';
2024
2025export default class EntryAbility extends UIAbility {
2026  // ...
2027  onWindowStageCreate(windowStage: window.WindowStage): void {
2028    console.info('onWindowStageCreate');
2029    let windowClass: window.Window | undefined = undefined;
2030    windowStage.getMainWindow((err: BusinessError, data) => {
2031      const errCode: number = err.code;
2032      if (errCode) {
2033        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2034        return;
2035      }
2036      windowClass = data;
2037      let names: Array<'status' | 'navigation'> = [];
2038      try {
2039        let promise = windowClass.setWindowSystemBarEnable(names);
2040        promise.then(() => {
2041          console.info('Succeeded in setting the system bar to be invisible.');
2042        }).catch((err: BusinessError) => {
2043          console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
2044        });
2045      } catch (exception) {
2046        console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`);
2047      }
2048    });
2049  }
2050}
2051```
2052
2053### setSpecificSystemBarEnabled<sup>11+</sup>
2054
2055setSpecificSystemBarEnabled(name: SpecificSystemBar, enable: boolean, enableAnimation?: boolean): Promise&lt;void&gt;
2056
2057设置主窗口三键导航栏、状态栏、底部导航条的显示和隐藏,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
2058
2059子窗口调用后不生效。
2060
2061**系统能力:** SystemCapability.Window.SessionManager
2062
2063**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2064
2065**参数:**
2066
2067| 参数名 | 类型  | 必填 | 说明 |
2068| ----- | ---------------------------- | -- | --------------------------------- |
2069| name  | [SpecificSystemBar](#specificsystembar11) | 是 | 设置窗口全屏模式时,显示或隐藏的系统栏类型。 |
2070| enable  | boolean | 是 | 设置窗口全屏模式时状态栏、三键导航栏或底部导航条是否显示,true表示显示, false表示隐藏。|
2071| enableAnimation<sup>12+</sup>  | boolean | 否 | 设置状态栏、三键导航栏或底部导航条显示状态变化时是否使用动画,true表示使用, false表示不使用,默认值为false。|
2072
2073**返回值:**
2074
2075| 类型 | 说明 |
2076| ------------------- | ------------------------ |
2077| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2078
2079**错误码:**
2080
2081以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2082
2083| 错误码ID | 错误信息 |
2084| ------- | -------------------------------------------- |
2085| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2086| 1300002 | This window state is abnormal.               |
2087| 1300003 | This window manager service works abnormally. |
2088
2089**示例:**
2090
2091```ts
2092// 此处以隐藏底部导航条为例
2093// EntryAbility.ets
2094import { UIAbility } from '@kit.AbilityKit';
2095import { BusinessError } from '@kit.BasicServicesKit';
2096
2097export default class EntryAbility extends UIAbility {
2098  // ...
2099  onWindowStageCreate(windowStage: window.WindowStage): void {
2100    console.info('onWindowStageCreate');
2101    let windowClass: window.Window | undefined = undefined;
2102    windowStage.getMainWindow((err: BusinessError, data) => {
2103      const errCode: number = err.code;
2104      if (errCode) {
2105        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2106        return;
2107      }
2108      windowClass = data;
2109      try {
2110        let promise = windowClass.setSpecificSystemBarEnabled('navigationIndicator', false);
2111        promise.then(() => {
2112          console.info('Succeeded in setting the system bar to be invisible.');
2113        }).catch((err: BusinessError) => {
2114          console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
2115        });
2116      } catch (exception) {
2117        console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`);
2118      }
2119    });
2120  }
2121}
2122```
2123
2124### setWindowSystemBarProperties<sup>9+</sup>
2125
2126setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise&lt;void&gt;
2127
2128设置主窗口三键导航栏、状态栏的属性,使用Promise异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
2129
2130子窗口调用后不生效。
2131
2132**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2133
2134**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2135
2136**参数:**
2137
2138| 参数名              | 类型                                        | 必填 | 说明                   |
2139| ------------------- | ------------------------------------------- | ---- | ---------------------- |
2140| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是   | 三键导航栏、状态栏的属性。 |
2141
2142**返回值:**
2143
2144| 类型                | 说明                      |
2145| ------------------- | ------------------------- |
2146| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2147
2148**错误码:**
2149
2150以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2151
2152| 错误码ID | 错误信息 |
2153| ------- | -------------------------------------------- |
2154| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2155| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
2156| 1300002 | This window state is abnormal.               |
2157| 1300003 | This window manager service works abnormally. |
2158
2159**示例:**
2160
2161```ts
2162// EntryAbility.ets
2163import { UIAbility } from '@kit.AbilityKit';
2164import { BusinessError } from '@kit.BasicServicesKit';
2165
2166export default class EntryAbility extends UIAbility {
2167  // ...
2168  onWindowStageCreate(windowStage: window.WindowStage): void {
2169    console.info('onWindowStageCreate');
2170    let windowClass: window.Window | undefined = undefined;
2171    windowStage.getMainWindow((err: BusinessError, data) => {
2172      const errCode: number = err.code;
2173      if (errCode) {
2174        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2175        return;
2176      }
2177      windowClass = data;
2178      let SystemBarProperties: window.SystemBarProperties = {
2179        statusBarColor: '#ff00ff',
2180        navigationBarColor: '#00ff00',
2181        //以下两个属性从API Version8开始支持
2182        statusBarContentColor: '#ffffff',
2183        navigationBarContentColor: '#00ffff'
2184      };
2185      try {
2186        let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties);
2187        promise.then(() => {
2188          console.info('Succeeded in setting the system bar properties.');
2189        }).catch((err: BusinessError) => {
2190          console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
2191        });
2192      } catch (exception) {
2193        console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`);
2194      }
2195    });
2196  }
2197}
2198```
2199
2200### getWindowSystemBarProperties<sup>12+</sup>
2201
2202getWindowSystemBarProperties(): SystemBarProperties
2203
2204主窗口获取三键导航栏、状态栏的属性。
2205
2206**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2207
2208**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2209
2210**返回值:**
2211
2212| 类型 | 说明 |
2213| ------------------------------------- | ------------- |
2214| [SystemBarProperties](#systembarproperties) | 当前三键导航栏、状态栏属性。 |
2215
2216**错误码:**
2217
2218以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
2219
2220| 错误码ID | 错误信息 |
2221| ------- | ------------------------------ |
2222| 1300002 | This window state is abnormal. |
2223| 1300003 | This window manager service works abnormally. |
2224| 1300004 | Unauthorized operation.                       |
2225
2226
2227**示例:**
2228
2229```ts
2230// EntryAbility.ets
2231import { UIAbility } from '@kit.AbilityKit';
2232import { BusinessError } from '@kit.BasicServicesKit';
2233
2234export default class EntryAbility extends UIAbility {
2235  // ...
2236
2237  onWindowStageCreate(windowStage: window.WindowStage) {
2238    let windowClass: window.Window | undefined = undefined;
2239    windowStage.getMainWindow((err: BusinessError, data) => {
2240      const errCode: number = err.code;
2241      if (errCode) {
2242        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2243        return;
2244      }
2245      windowClass = data;
2246      try {
2247        let systemBarProperty = windowClass.getWindowSystemBarProperties();
2248        console.info('Success in obtaining system bar properties. Property: ' + JSON.stringify(systemBarProperty));
2249      } catch (err) {
2250        console.error(`Failed to get system bar properties. Code: ${err.code}, message: ${err.message}`);
2251      }
2252    });
2253  }
2254};
2255```
2256
2257### setPreferredOrientation<sup>9+</sup>
2258
2259setPreferredOrientation(orientation: Orientation, callback: AsyncCallback&lt;void&gt;): void
2260
2261设置主窗口的显示方向属性,使用callback异步回调。仅在支持跟随sensor旋转的设备上生效,子窗口调用后不生效。
2262
2263**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2264
2265**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2266
2267**参数:**
2268
2269| 参数名              | 类型                                        | 必填 | 说明                   |
2270| ------------------- | ------------------------------------------- | ---- | ---------------------- |
2271| orientation         | [Orientation](#orientation9)                | 是   | 窗口显示方向的属性。         |
2272| callback            | AsyncCallback&lt;void&gt;                   | 是   | 回调函数。该回调函数返回调用结果是否成功,非应用旋转动效结束。 |
2273
2274**错误码:**
2275
2276以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2277
2278| 错误码ID | 错误信息 |
2279| ------- | ------------------------------ |
2280| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2281| 1300002 | This window state is abnormal. |
2282
2283**示例:**
2284
2285```ts
2286// EntryAbility.ets
2287import { UIAbility } from '@kit.AbilityKit';
2288import { BusinessError } from '@kit.BasicServicesKit';
2289
2290export default class EntryAbility extends UIAbility {
2291  // ...
2292  onWindowStageCreate(windowStage: window.WindowStage): void {
2293    console.info('onWindowStageCreate');
2294    let windowClass: window.Window | undefined = undefined;
2295    windowStage.getMainWindow((err: BusinessError, data) => {
2296      const errCode: number = err.code;
2297      if (errCode) {
2298        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2299        return;
2300      }
2301      windowClass = data;
2302      let orientation = window.Orientation.AUTO_ROTATION;
2303      try {
2304        windowClass.setPreferredOrientation(orientation, (err: BusinessError) => {
2305          const errCode: number = err.code;
2306          if (errCode) {
2307            console.error(`Failed to set window orientation. Cause code: ${err.code}, message: ${err.message}`);
2308            return;
2309          }
2310          console.info('Succeeded in setting window orientation.');
2311        });
2312      } catch (exception) {
2313        console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`);
2314      }
2315    });
2316  }
2317}
2318```
2319
2320### setPreferredOrientation<sup>9+</sup>
2321
2322setPreferredOrientation(orientation: Orientation): Promise&lt;void&gt;
2323
2324设置主窗口的显示方向属性,使用Promise异步回调。仅在支持跟随sensor旋转的设备上生效,子窗口调用后不生效。
2325
2326**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2327
2328**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2329
2330**参数:**
2331
2332| 参数名              | 类型                                        | 必填 | 说明                   |
2333| ------------------- | ------------------------------------------- | ---- | ---------------------- |
2334| orientation         | [Orientation](#orientation9)                | 是   | 窗口显示方向的属性。       |
2335
2336**返回值:**
2337
2338| 类型                | 说明                      |
2339| ------------------- | ------------------------- |
2340| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2341
2342**错误码:**
2343
2344以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2345
2346| 错误码ID | 错误信息 |
2347| ------- | ------------------------------ |
2348| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2349| 1300002 | This window state is abnormal. |
2350
2351**示例:**
2352
2353```ts
2354// EntryAbility.ets
2355import { UIAbility } from '@kit.AbilityKit';
2356import { BusinessError } from '@kit.BasicServicesKit';
2357
2358export default class EntryAbility extends UIAbility {
2359  // ...
2360  onWindowStageCreate(windowStage: window.WindowStage): void {
2361    console.info('onWindowStageCreate');
2362    let windowClass: window.Window | undefined = undefined;
2363    windowStage.getMainWindow((err: BusinessError, data) => {
2364      const errCode: number = err.code;
2365      if (errCode) {
2366        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2367        return;
2368      }
2369      windowClass = data;
2370      let orientation = window.Orientation.AUTO_ROTATION;
2371      try {
2372        let promise = windowClass.setPreferredOrientation(orientation);
2373        promise.then(() => {
2374          console.info('Succeeded in setting the window orientation.');
2375        }).catch((err: BusinessError) => {
2376          console.error(`Failed to set the window orientation. Cause code: ${err.code}, message: ${err.message}`);
2377        });
2378      } catch (exception) {
2379        console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`);
2380      }
2381    });
2382  }
2383}
2384```
2385
2386### getPreferredOrientation<sup>12+</sup>
2387
2388getPreferredOrientation(): Orientation
2389
2390主窗口调用,获取窗口的显示方向属性。
2391
2392**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2393
2394**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2395
2396**返回值:**
2397
2398| 类型 | 说明 |
2399|------------------------------| ------------------ |
2400| [Orientation](#orientation9) | 窗口显示方向的属性。 |
2401
2402**错误码:**
2403
2404以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
2405
2406| 错误码ID | 错误信息 |
2407| ------- | ------------------------------ |
2408| 1300002 | This window state is abnormal. |
2409
2410**示例:**
2411
2412```ts
2413// EntryAbility.ets
2414import { UIAbility } from '@kit.AbilityKit';
2415import { BusinessError } from '@kit.BasicServicesKit';
2416export default class EntryAbility extends UIAbility {
2417  // ...
2418
2419  onWindowStageCreate(windowStage: window.WindowStage) {
2420    console.info('onWindowStageCreate');
2421    let windowClass: window.Window | undefined = undefined;
2422    windowStage.getMainWindow((err: BusinessError, data) => {
2423      const errCode: number = err.code;
2424      if (errCode) {
2425        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2426        return;
2427      }
2428      windowClass = data;
2429      try {
2430        let orientation = windowClass.getPreferredOrientation();
2431      } catch (exception) {
2432        console.error(`Failed to get window orientation. Cause code: ${exception.code}, message: ${exception.message}`);
2433      }
2434    });
2435  }
2436};
2437```
2438
2439### getUIContext<sup>10+</sup>
2440
2441getUIContext(): UIContext
2442
2443获取UIContext实例。
2444
2445**模型约束:** 此接口仅可在Stage模型下使用。
2446
2447**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2448
2449**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2450
2451**返回值:**
2452
2453| 类型       | 说明                   |
2454| ---------- | ---------------------- |
2455| [UIContext](js-apis-arkui-UIContext.md#uicontext) | 返回UIContext实例对象。 |
2456
2457**错误码:**
2458
2459以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
2460
2461| 错误码ID | 错误信息 |
2462| ------- | ------------------------------ |
2463| 1300002 | This window state is abnormal. |
2464
2465**示例:**
2466
2467```ts
2468// EntryAbility.ets
2469import { UIAbility } from '@kit.AbilityKit';
2470import { window, UIContext } from '@kit.ArkUI';
2471import { BusinessError } from '@kit.BasicServicesKit';
2472
2473export default class EntryAbility extends UIAbility {
2474  onWindowStageCreate(windowStage: window.WindowStage) {
2475    // 为主窗口加载对应的目标页面。
2476    windowStage.loadContent("pages/page2", (err: BusinessError) => {
2477      let errCode: number = err.code;
2478      if (errCode) {
2479        console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2480        return;
2481      }
2482      console.info('Succeeded in loading the content.');
2483      // 获取应用主窗口。
2484      let windowClass: window.Window | undefined = undefined;
2485      windowStage.getMainWindow((err: BusinessError, data) => {
2486        let errCode: number = err.code;
2487        if (errCode) {
2488          console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2489          return;
2490        }
2491        windowClass = data;
2492        console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
2493        // 获取UIContext实例。
2494        let uiContext: UIContext | null = null;
2495        uiContext = windowClass.getUIContext();
2496      });
2497    });
2498  }
2499};
2500```
2501
2502### setUIContent<sup>9+</sup>
2503
2504setUIContent(path: string, callback: AsyncCallback&lt;void&gt;): void
2505
2506根据当前工程中某个页面的路径为窗口加载具体页面内容,使用callback异步回调。
2507
2508**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2509
2510**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2511
2512**参数:**
2513
2514| 参数名 | 类型 | 必填 | 说明 |
2515| -------- | ------------------------- | -- | -------------------- |
2516| path     | string                    | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 |
2517| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。          |
2518
2519**错误码:**
2520
2521以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2522
2523| 错误码ID | 错误信息 |
2524| ------- | -------------------------------------------- |
2525| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2526| 1300002 | This window state is abnormal.               |
2527| 1300003 | This window manager service works abnormally. |
2528
2529**示例:**
2530
2531```ts
2532import { BusinessError } from '@kit.BasicServicesKit';
2533
2534try {
2535  windowClass.setUIContent('pages/page2/page3', (err: BusinessError) => {
2536    const errCode: number = err.code;
2537    if (errCode) {
2538      console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2539      return;
2540    }
2541    console.info('Succeeded in loading the content.');
2542  });
2543} catch (exception) {
2544  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
2545}
2546```
2547
2548### setUIContent<sup>9+</sup>
2549
2550setUIContent(path: string): Promise&lt;void&gt;
2551
2552根据当前工程中某个页面的路径为窗口加载具体页面内容,使用Promise异步回调。
2553
2554**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2555
2556**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2557
2558**参数:**
2559
2560| 参数名 | 类型 | 必填 | 说明 |
2561| ---- | ------ | -- | ------------------ |
2562| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 |
2563
2564**返回值:**
2565
2566| 类型 | 说明 |
2567| ------------------- | ------------------------ |
2568| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2569
2570**错误码:**
2571
2572以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2573
2574| 错误码ID | 错误信息 |
2575| ------- | -------------------------------------------- |
2576| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2577| 1300002 | This window state is abnormal.               |
2578| 1300003 | This window manager service works abnormally. |
2579
2580**示例:**
2581
2582```ts
2583import { BusinessError } from '@kit.BasicServicesKit';
2584
2585try {
2586  let promise = windowClass.setUIContent('pages/page2/page3');
2587  promise.then(() => {
2588    console.info('Succeeded in loading the content.');
2589  }).catch((err: BusinessError) => {
2590    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2591  });
2592} catch (exception) {
2593  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
2594}
2595```
2596
2597### loadContent<sup>9+</sup>
2598
2599loadContent(path: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
2600
2601根据当前工程中某个页面的路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。
2602
2603**模型约束:** 此接口仅可在Stage模型下使用。
2604
2605**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2606
2607**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2608
2609**参数:**
2610
2611| 参数名   | 类型                                            | 必填 | 说明                                                         |
2612| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
2613| path     | string                                          | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 |
2614| storage  | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
2615| callback | AsyncCallback&lt;void&gt;                       | 是   | 回调函数。                                                   |
2616
2617**错误码:**
2618
2619以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2620
2621| 错误码ID | 错误信息 |
2622| ------- | -------------------------------------------- |
2623| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2624| 1300002 | This window state is abnormal.               |
2625| 1300003 | This window manager service works abnormally. |
2626
2627**示例:**
2628
2629```ts
2630import { BusinessError } from '@kit.BasicServicesKit';
2631
2632let storage: LocalStorage = new LocalStorage();
2633storage.setOrCreate('storageSimpleProp', 121);
2634windowClass.loadContent('pages/page2', storage, (err: BusinessError) => {
2635  const errCode: number = err.code;
2636  if (errCode) {
2637    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2638    return;
2639  }
2640  console.info('Succeeded in loading the content.');
2641});
2642```
2643
2644### loadContent<sup>9+</sup>
2645
2646loadContent(path: string, storage: LocalStorage): Promise&lt;void&gt;
2647
2648根据当前工程中某个页面的路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。
2649
2650**模型约束:** 此接口仅可在Stage模型下使用。
2651
2652**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2653
2654**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2655
2656**参数:**
2657
2658| 参数名  | 类型                                            | 必填 | 说明                                                         |
2659| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
2660| path    | string                                          | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 |
2661| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
2662
2663**返回值:**
2664
2665| 类型                | 说明                      |
2666| ------------------- | ------------------------- |
2667| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2668
2669**错误码:**
2670
2671以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2672
2673| 错误码ID | 错误信息 |
2674| ------- | -------------------------------------------- |
2675| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2676| 1300002 | This window state is abnormal.               |
2677| 1300003 | This window manager service works abnormally. |
2678
2679**示例:**
2680
2681```ts
2682import { BusinessError } from '@kit.BasicServicesKit';
2683
2684let storage: LocalStorage = new LocalStorage();
2685storage.setOrCreate('storageSimpleProp', 121);
2686let promise = windowClass.loadContent('pages/page2', storage);
2687promise.then(() => {
2688  console.info('Succeeded in loading the content.');
2689}).catch((err: BusinessError) => {
2690  console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2691});
2692```
2693
2694### loadContentByName<sup>11+</sup>
2695
2696loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
2697
2698为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。
2699
2700**模型约束:** 此接口仅可在Stage模型下使用。
2701
2702**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2703
2704**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2705
2706**参数:**
2707
2708| 参数名   | 类型                                                    | 必填 | 说明                                                         |
2709| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2710| name     | string                                                  | 是   | 命名路由页面的名称。                                             |
2711| storage  | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
2712| callback | AsyncCallback&lt;void&gt;                               | 是   | 回调函数。                                                   |
2713
2714**错误码:**
2715
2716以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2717
2718| 错误码ID | 错误信息                                      |
2719| -------- | --------------------------------------------- |
2720| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2721| 1300002  | This window state is abnormal.                |
2722| 1300003  | This window manager service works abnormally. |
2723
2724**示例:**
2725<!--code_no_check-->
2726```ts
2727import { BusinessError } from '@kit.BasicServicesKit';
2728import * as Index from '../pages/Index'; // 导入命名路由页面
2729
2730console.info('onWindowStageCreate');
2731let storage: LocalStorage = new LocalStorage();
2732storage.setOrCreate('storageSimpleProp', 121);
2733try {
2734  (windowClass as window.Window).loadContentByName(Index.entryName, storage, (err: BusinessError) => {
2735    const errCode: number = err.code;
2736    if (errCode) {
2737      console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2738      return;
2739    }
2740    console.info('Succeeded in loading the content.');
2741  });
2742} catch (exception) {
2743  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
2744}
2745```
2746<!--code_no_check-->
2747```ts
2748// ets/pages/Index.ets
2749export const entryName : string = 'Index';
2750@Entry({routeName: entryName, storage : LocalStorage.getShared()})
2751@Component
2752export struct Index {
2753  @State message: string = 'Hello World'
2754  build() {
2755    Row() {
2756      Column() {
2757        Text(this.message)
2758          .fontSize(50)
2759          .fontWeight(FontWeight.Bold)
2760      }
2761      .width('100%')
2762    }
2763    .height('100%')
2764  }
2765}
2766```
2767
2768### loadContentByName<sup>11+</sup>
2769
2770loadContentByName(name: string, callback: AsyncCallback&lt;void&gt;): void
2771
2772为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面内容,使用callback异步回调。
2773
2774**模型约束:** 此接口仅可在Stage模型下使用。
2775
2776**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2777
2778**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2779
2780**参数:**
2781
2782| 参数名   | 类型                      | 必填 | 说明             |
2783| -------- | ------------------------- | ---- | ---------------- |
2784| name     | string                    | 是   | 命名路由页面的名称。 |
2785| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。       |
2786
2787**错误码:**
2788
2789以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2790
2791| 错误码ID | 错误信息                                      |
2792| -------- | --------------------------------------------- |
2793| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2794| 1300002  | This window state is abnormal.                |
2795| 1300003  | This window manager service works abnormally. |
2796
2797**示例:**
2798<!--code_no_check-->
2799```ts
2800import { BusinessError } from '@kit.BasicServicesKit';
2801import * as Index from '../pages/Index'; // 导入命名路由页面
2802
2803try {
2804  (windowClass as window.Window).loadContentByName(Index.entryName, (err: BusinessError) => {
2805    const errCode: number = err.code;
2806    if (errCode) {
2807      console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2808      return;
2809    }
2810    console.info('Succeeded in loading the content.');
2811  });
2812} catch (exception) {
2813  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
2814}
2815```
2816<!--code_no_check-->
2817```ts
2818// ets/pages/Index.ets
2819export const entryName : string = 'Index';
2820@Entry({routeName: entryName})
2821@Component
2822export struct Index {
2823  @State message: string = 'Hello World'
2824  build() {
2825    Row() {
2826      Column() {
2827        Text(this.message)
2828          .fontSize(50)
2829          .fontWeight(FontWeight.Bold)
2830      }
2831      .width('100%')
2832    }
2833    .height('100%')
2834  }
2835}
2836```
2837
2838### loadContentByName<sup>11+</sup>
2839
2840loadContentByName(name: string, storage?: LocalStorage): Promise&lt;void&gt;
2841
2842为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。
2843
2844**模型约束:** 此接口仅可在Stage模型下使用。
2845
2846**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2847
2848**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2849
2850**参数:**
2851
2852| 参数名  | 类型                                                    | 必填 | 说明                                                         |
2853| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2854| name    | string                                                  | 是   | 命名路由页面的名称。                                             |
2855| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 否   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
2856
2857**返回值:**
2858
2859| 类型                | 说明                      |
2860| ------------------- | ------------------------- |
2861| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2862
2863**错误码:**
2864
2865以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2866
2867| 错误码ID | 错误信息                                      |
2868| -------- | --------------------------------------------- |
2869| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2870| 1300002  | This window state is abnormal.                |
2871| 1300003  | This window manager service works abnormally. |
2872
2873**示例:**
2874<!--code_no_check-->
2875```ts
2876import { BusinessError } from '@kit.BasicServicesKit';
2877import * as Index from '../pages/Index'; // 导入命名路由页面
2878
2879let storage: LocalStorage = new LocalStorage();
2880storage.setOrCreate('storageSimpleProp', 121);
2881try {
2882  let promise = (windowClass as window.Window).loadContentByName(Index.entryName, storage);
2883  promise.then(() => {
2884    console.info('Succeeded in loading the content.');
2885  }).catch((err: BusinessError) => {
2886    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
2887  });
2888} catch (exception) {
2889  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
2890}
2891```
2892<!--code_no_check-->
2893```ts
2894// ets/pages/Index.ets
2895export const entryName : string = 'Index';
2896@Entry({routeName: entryName, storage : LocalStorage.getShared()})
2897@Component
2898export struct Index {
2899  @State message: string = 'Hello World'
2900  build() {
2901    Row() {
2902      Column() {
2903        Text(this.message)
2904          .fontSize(50)
2905          .fontWeight(FontWeight.Bold)
2906      }
2907      .width('100%')
2908    }
2909    .height('100%')
2910  }
2911}
2912```
2913
2914### isWindowShowing<sup>9+</sup>
2915
2916isWindowShowing(): boolean
2917
2918判断当前窗口是否已显示。
2919
2920**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2921
2922**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2923
2924**返回值:**
2925
2926| 类型 | 说明 |
2927| ------- | ------------------------------------------------------------------ |
2928| boolean | 当前窗口是否已显示。true表示当前窗口已显示,false则表示当前窗口未显示。 |
2929
2930**错误码:**
2931
2932以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
2933
2934| 错误码ID | 错误信息 |
2935| ------- | ------------------------------ |
2936| 1300002 | This window state is abnormal. |
2937
2938**示例:**
2939
2940```ts
2941try {
2942  let data = windowClass.isWindowShowing();
2943  console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
2944} catch (exception) {
2945  console.error(`Failed to check whether the window is showing. Cause code: ${exception.code}, message: ${exception.message}`);
2946}
2947```
2948
2949### on('windowSizeChange')<sup>7+</sup>
2950
2951on(type:  'windowSizeChange', callback: Callback&lt;Size&gt;): void
2952
2953开启窗口尺寸变化的监听。
2954
2955**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2956
2957**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2958
2959**参数:**
2960
2961| 参数名   | 类型                           | 必填 | 说明                                                     |
2962| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
2963| type     | string                         | 是   | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 |
2964| callback | Callback&lt;[Size](#size7)&gt; | 是   | 回调函数。返回当前的窗口尺寸。                           |
2965
2966**错误码:**
2967
2968以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2969
2970| 错误码ID | 错误信息 |
2971| ------- | -------------------------------------------- |
2972| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2973
2974**示例:**
2975
2976```ts
2977try {
2978  windowClass.on('windowSizeChange', (data) => {
2979    console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data));
2980  });
2981} catch (exception) {
2982  console.error(`Failed to enable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`);
2983}
2984```
2985
2986### off('windowSizeChange')<sup>7+</sup>
2987
2988off(type: 'windowSizeChange', callback?: Callback&lt;Size&gt;): void
2989
2990关闭窗口尺寸变化的监听。
2991
2992**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2993
2994**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2995
2996**参数:**
2997
2998| 参数名   | 类型                          | 必填 | 说明                                                     |
2999| -------- | ----------------------------- | ---- | -------------------------------------------------------- |
3000| type     | string                        | 是   | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 |
3001| callback | Callback&lt;[Size](#size7)&gt; | 否   | 回调函数。返回当前的窗口尺寸。如果传入参数,则关闭该监听。如果未传入参数,则关闭窗口尺寸变化的监听。                           |
3002
3003**错误码:**
3004
3005以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3006
3007| 错误码ID | 错误信息 |
3008| ------- | -------------------------------------------- |
3009| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3010
3011**示例:**
3012
3013```ts
3014const callback = (size: window.Size) => {
3015  // ...
3016}
3017try {
3018  // 通过on接口开启监听
3019  windowClass.on('windowSizeChange', callback);
3020  // 关闭指定callback的监听
3021  windowClass.off('windowSizeChange', callback);
3022  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3023  windowClass.off('windowSizeChange');
3024} catch (exception) {
3025  console.error(`Failed to disable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`);
3026}
3027```
3028
3029### on('avoidAreaChange')<sup>9+</sup>
3030
3031on(type: 'avoidAreaChange', callback: Callback&lt;AvoidAreaOptions&gt;): void
3032
3033开启当前窗口系统规避区变化的监听。
3034
3035**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3036
3037**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3038
3039**参数:**
3040
3041| 参数名   | 类型                              | 必填 | 说明                                  |
3042| -------- |----------------------------------| ---- |--------------------------------------|
3043| type     | string                           | 是   | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 |
3044| callback | Callback&lt;[AvoidAreaOptions](#avoidareaoptions12)&gt; | 是   | 回调函数。返回当前规避区以及规避区类型。|
3045
3046**错误码:**
3047
3048以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3049
3050| 错误码ID | 错误信息 |
3051| ------- | -------------------------------------------- |
3052| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3053
3054**示例:**
3055
3056```ts
3057try {
3058  windowClass.on('avoidAreaChange', (data) => {
3059    console.info('Succeeded in enabling the listener for system avoid area changes. type:' +
3060    JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area));
3061  });
3062} catch (exception) {
3063  console.error(`Failed to enable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`);
3064}
3065```
3066
3067### off('avoidAreaChange')<sup>9+</sup>
3068
3069off(type: 'avoidAreaChange', callback?: Callback&lt;AvoidAreaOptions&gt;): void
3070
3071关闭当前窗口系统规避区变化的监听。
3072
3073**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3074
3075**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3076
3077**参数:**
3078
3079| 参数名   | 类型                              | 必填 | 说明                                |
3080| -------- |----------------------------------|------|------------------------------------|
3081| type     | string                           | 是   | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 |
3082| callback | Callback&lt;[AvoidAreaOptions](#avoidareaoptions12)&gt; | 否   | 回调函数。返回当前规避区以及规避区类型。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有系统规避区变化的监听。|
3083
3084**错误码:**
3085
3086以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3087
3088| 错误码ID | 错误信息 |
3089| ------- | -------------------------------------------- |
3090| 401     | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed. |
3091
3092**示例:**
3093
3094```ts
3095interface Param {
3096  type: window.AvoidAreaType,
3097  area: window.AvoidArea
3098}
3099const callback = (data: Param) => {
3100  // ...
3101}
3102try {
3103  windowClass.on('avoidAreaChange', callback);
3104
3105  windowClass.off('avoidAreaChange', callback);
3106  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3107  windowClass.off('avoidAreaChange');
3108} catch (exception) {
3109  console.error(`Failed to enable or disable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`);
3110}
3111```
3112
3113### on('keyboardHeightChange')<sup>7+</sup>
3114
3115on(type: 'keyboardHeightChange', callback: Callback&lt;number&gt;): void
3116
3117开启固定态软键盘高度变化的监听,当软键盘由本窗口唤出并存在重叠区域时通知键盘高度变化。从API version 10开始,改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
3118
3119**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3120
3121**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3122
3123**参数:**
3124
3125| 参数名   | 类型                | 必填 | 说明                                        |
3126| -------- | ------------------- | ---- |-------------------------------------------|
3127| type     | string              | 是   | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 |
3128| callback | Callback&lt;number&gt; | 是   | 回调函数。返回当前的键盘高度,返回值为整数,单位为px。     |
3129
3130**错误码:**
3131
3132以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3133
3134| 错误码ID | 错误信息 |
3135| ------- | -------------------------------------------- |
3136| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3137
3138**示例:**
3139
3140```ts
3141import { BusinessError } from '@kit.BasicServicesKit';
3142
3143try {
3144  windowClass.on('keyboardHeightChange', (data) => {
3145    console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data));
3146  });
3147} catch (exception) {
3148  console.error(`Failed to enable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`);
3149}
3150```
3151
3152### off('keyboardHeightChange')<sup>7+</sup>
3153
3154off(type: 'keyboardHeightChange', callback?: Callback&lt;number&gt;): void
3155
3156关闭固定态软键盘高度变化的监听。从API version 10开始,改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
3157
3158**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3159
3160**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3161
3162**参数:**
3163
3164| 参数名   | 类型                   | 必填 | 说明                                                         |
3165| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
3166| type     | string                 | 是   | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 |
3167| callback | Callback&lt;number&gt; | 否   | 回调函数。返回当前的键盘高度,返回值为整数,单位为px。若传入参数,则关闭该监听。如果未传入参数,则关闭所有固定态软键盘高度变化的监听。                               |
3168
3169**错误码:**
3170
3171以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3172
3173| 错误码ID | 错误信息 |
3174| ------- | -------------------------------------------- |
3175| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3176
3177**示例:**
3178
3179```ts
3180import { BusinessError } from '@kit.BasicServicesKit';
3181
3182const callback = (height: number) => {
3183  // ...
3184}
3185try {
3186  windowClass.on('keyboardHeightChange', callback);
3187
3188  windowClass.off('keyboardHeightChange', callback);
3189  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3190  windowClass.off('keyboardHeightChange');
3191} catch (exception) {
3192  console.error(`Failed to disable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`);
3193}
3194```
3195
3196### on('touchOutside')<sup>11+</sup>
3197
3198on(type: 'touchOutside', callback: Callback&lt;void&gt;): void
3199
3200开启本窗口区域范围外的点击事件的监听。
3201
3202**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3203
3204**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3205
3206**参数:**
3207
3208| 参数名   | 类型                | 必填 | 说明                                                         |
3209| -------- | ------------------- | ---- | ------------------------------------------------------------ |
3210| type     | string              | 是   | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 |
3211| callback | Callback&lt;void&gt; | 是   | 回调函数。当点击事件发生在本窗口范围之外的回调。                               |
3212
3213**错误码:**
3214
3215以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3216
3217| 错误码ID | 错误信息 |
3218| ------- | -------------------------------------------- |
3219| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3220
3221**示例:**
3222
3223```ts
3224try {
3225  windowClass.on('touchOutside', () => {
3226    console.info('touch outside');
3227  });
3228} catch (exception) {
3229  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
3230}
3231```
3232
3233### off('touchOutside')<sup>11+</sup>
3234
3235off(type: 'touchOutside', callback?: Callback&lt;void&gt;): void
3236
3237关闭本窗口区域范围外的点击事件的监听。
3238
3239**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3240
3241**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3242
3243**参数:**
3244
3245| 参数名   | 类型                   | 必填 | 说明                                   |
3246| -------- |----------------------| ---- |--------------------------------------|
3247| type     | string               | 是   | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 |
3248| callback | Callback&lt;void&gt; | 否   | 回调函数。当点击事件发生在本窗口范围之外的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口区域范围外的点击事件的监听。            |
3249
3250**错误码:**
3251
3252以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3253
3254| 错误码ID | 错误信息 |
3255| ------- | -------------------------------------------- |
3256| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3257
3258**示例:**
3259
3260```ts
3261const callback = () => {
3262  // ...
3263}
3264try {
3265  windowClass.on('touchOutside', callback);
3266  windowClass.off('touchOutside', callback);
3267  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3268  windowClass.off('touchOutside');
3269} catch (exception) {
3270  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3271}
3272```
3273
3274### on('screenshot')<sup>9+</sup>
3275
3276on(type: 'screenshot', callback: Callback&lt;void&gt;): void
3277
3278开启截屏事件的监听。
3279
3280**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3281
3282**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3283
3284**参数:**
3285
3286| 参数名   | 类型                | 必填 | 说明                                                         |
3287| -------- | ------------------- | ---- | ------------------------------------------------------------ |
3288| type     | string              | 是   | 监听事件,固定为'screenshot',即截屏事件,对控制中心截屏、hdc命令截屏、整屏截屏接口生效。 |
3289| callback | Callback&lt;void&gt; | 是   | 回调函数。发生截屏事件时的回调。                               |
3290
3291**错误码:**
3292
3293以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3294
3295| 错误码ID | 错误信息 |
3296| ------- | -------------------------------------------- |
3297| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3298
3299**示例:**
3300
3301```ts
3302try {
3303  windowClass.on('screenshot', () => {
3304    console.info('screenshot happened');
3305  });
3306} catch (exception) {
3307  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
3308}
3309```
3310
3311### off('screenshot')<sup>9+</sup>
3312
3313off(type: 'screenshot', callback?: Callback&lt;void&gt;): void
3314
3315关闭截屏事件的监听。
3316
3317**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3318
3319**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3320
3321**参数:**
3322
3323| 参数名   | 类型                   | 必填 | 说明                                                         |
3324| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
3325| type     | string                 | 是   | 监听事件,固定为'screenshot',即截屏事件。 |
3326| callback | Callback&lt;void&gt; | 否   | 回调函数。发生截屏事件时的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有截屏事件的监听。 |
3327
3328**错误码:**
3329
3330以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3331
3332| 错误码ID | 错误信息 |
3333| ------- | -------------------------------------------- |
3334| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3335
3336**示例:**
3337
3338```ts
3339let callback = () => {
3340  console.info('screenshot happened');
3341};
3342try {
3343  windowClass.on('screenshot', callback);
3344  windowClass.off('screenshot', callback);
3345  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3346  windowClass.off('screenshot');
3347} catch (exception) {
3348  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3349}
3350```
3351
3352### on('dialogTargetTouch')<sup>10+</sup>
3353
3354on(type: 'dialogTargetTouch', callback: Callback&lt;void&gt;): void
3355
3356开启模态窗口所遮盖窗口的点击或触摸事件的监听,除模态窗口以外其他窗口调用此接口不生效。
3357
3358**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3359
3360**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3361
3362**参数:**
3363
3364| 参数名   | 类型                 | 必填 | 说明                                                          |
3365| -------- | ------------------- | ---- | ------------------------------------------------------------ |
3366| type     | string              | 是   | 监听事件,固定为'dialogTargetTouch',即模态窗口所遮盖窗口的点击或触摸事件。 |
3367| callback | Callback&lt;void&gt;| 是   | 回调函数。当点击或触摸事件发生在模态窗口所遮盖窗口的回调。 |
3368
3369**错误码:**
3370
3371以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3372
3373| 错误码ID | 错误信息 |
3374| ------- | -------------------------------------------- |
3375| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3376
3377**示例:**
3378
3379```ts
3380try {
3381  windowClass.on('dialogTargetTouch', () => {
3382    console.info('touch dialog target');
3383  });
3384} catch (exception) {
3385  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
3386}
3387```
3388
3389### off('dialogTargetTouch')<sup>10+</sup>
3390
3391off(type: 'dialogTargetTouch', callback?: Callback&lt;void&gt;): void
3392
3393关闭模态窗口目标窗口的点击事件的监听。
3394
3395**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3396
3397**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3398
3399**参数:**
3400
3401| 参数名   | 类型                    | 必填 | 说明                                                          |
3402| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
3403| type     | string                 | 是   | 监听事件,固定为'dialogTargetTouch',即模态窗口目标窗口的点击事件。 |
3404| callback | Callback&lt;void&gt;      | 否   | 回调函数。当点击事件发生在模态窗口目标窗口的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有模态窗口目标窗口的点击事件的监听。 |
3405
3406**错误码:**
3407
3408以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3409
3410| 错误码ID | 错误信息 |
3411| ------- | -------------------------------------------- |
3412| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3413
3414**示例:**
3415
3416```ts
3417const callback = () => {
3418  // ...
3419}
3420try {
3421  windowClass.on('dialogTargetTouch', callback);
3422  windowClass.off('dialogTargetTouch', callback);
3423  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3424  windowClass.off('dialogTargetTouch');
3425} catch (exception) {
3426  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3427}
3428```
3429
3430### on('windowEvent')<sup>10+</sup>
3431
3432on(type: 'windowEvent', callback: Callback&lt;WindowEventType&gt;): void
3433
3434开启窗口生命周期变化的监听。
3435
3436**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3437
3438**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3439
3440**参数:**
3441
3442| 参数名   | 类型                                                       | 必填 | 说明                                                         |
3443| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
3444| type     | string                                                     | 是   | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 |
3445| callback | Callback&lt;[WindowEventType](#windoweventtype10)&gt; | 是   | 回调函数。返回当前的窗口生命周期状态。                 |
3446
3447**错误码:**
3448
3449以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3450
3451| 错误码ID | 错误信息 |
3452| ------- | -------------------------------------------- |
3453| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3454
3455**示例:**
3456
3457```ts
3458try {
3459  windowClass.on('windowEvent', (data) => {
3460    console.info('Window event happened. Event:' + JSON.stringify(data));
3461  });
3462} catch (exception) {
3463  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
3464}
3465```
3466
3467### off('windowEvent')<sup>10+</sup>
3468
3469off(type: 'windowEvent', callback?: Callback&lt;WindowEventType&gt;): void
3470
3471关闭窗口生命周期变化的监听。
3472
3473**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3474
3475**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3476
3477**参数:**
3478
3479| 参数名   | 类型                                                       | 必填 | 说明                                                         |
3480| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
3481| type     | string                                                     | 是   | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 |
3482| callback | Callback&lt;[WindowEventType](#windoweventtype10)&gt; | 否   | 回调函数。返回当前的窗口生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有窗口生命周期变化的监听。                 |
3483
3484**错误码:**
3485
3486以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3487
3488| 错误码ID | 错误信息 |
3489| ------- | -------------------------------------------- |
3490| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3491
3492**示例:**
3493
3494```ts
3495const callback = (windowEventType: window.WindowEventType) => {
3496  // ...
3497}
3498try {
3499  // 通过on接口开启监听
3500  windowClass.on('windowEvent', callback);
3501  // 关闭指定callback的监听
3502  windowClass.off('windowEvent', callback);
3503  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3504  windowClass.off('windowEvent');
3505} catch (exception) {
3506  console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3507}
3508```
3509
3510### on('windowVisibilityChange')<sup>11+</sup>
3511
3512on(type: 'windowVisibilityChange', callback: Callback&lt;boolean&gt;): void
3513
3514开启本窗口可见状态变化事件的监听。
3515
3516**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3517
3518**系统能力:** SystemCapability.Window.SessionManager
3519
3520**参数:**
3521
3522| 参数名   | 类型                       | 必填 | 说明                                                         |
3523| -------- | --------------------------| ---- | ------------------------------------------------------------ |
3524| type     | string                    | 是   | 监听事件,固定为'windowVisibilityChange',即本窗口可见状态变化的事件。 |
3525| callback | Callback&lt;boolean&gt;   | 是   | 回调函数。当本窗口可见状态发生变化后的回调。回调函数返回boolean类型参数,当返回参数为true时表示窗口可见,否则表示窗口不可见。                               |
3526
3527**错误码:**
3528
3529以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3530
3531| 错误码ID | 错误信息 |
3532| ------- | ------------------------------ |
3533| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3534| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3535| 1300002 | This window state is abnormal.                |
3536| 1300003 | This window manager service works abnormally. |
3537
3538**示例:**
3539
3540```ts
3541try {
3542  windowClass.on('windowVisibilityChange', (boolean) => {
3543    console.info('Window visibility changed, isVisible=' + boolean);
3544  });
3545} catch (exception) {
3546  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
3547}
3548```
3549
3550### off('windowVisibilityChange')<sup>11+</sup>
3551
3552off(type: 'windowVisibilityChange', callback?: Callback&lt;boolean&gt;): void
3553
3554关闭本窗口可见状态变化事件的监听。
3555
3556**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3557
3558**系统能力:** SystemCapability.Window.SessionManager
3559
3560**参数:**
3561
3562| 参数名   | 类型                        | 必填 | 说明                                   |
3563| -------- |----------------------------| ---- |--------------------------------------|
3564| type     | string                     | 是   | 监听事件,固定为'windowVisibilityChange',即本窗口可见状态变化的事件。 |
3565| callback | Callback&lt;boolean&gt;    | 否   | 回调函数。当本窗口可见状态发生变化时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口可见状态变化事件的回调。            |
3566
3567**错误码:**
3568
3569以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3570
3571| 错误码ID | 错误信息 |
3572| ------- | ------------------------------ |
3573| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3574| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3575| 1300002 | This window state is abnormal.                |
3576| 1300003 | This window manager service works abnormally. |
3577
3578**示例:**
3579
3580```ts
3581const callback = (bool: boolean) => {
3582  // ...
3583}
3584try {
3585  // 通过on接口开启监听
3586  windowClass.on('windowVisibilityChange', callback);
3587  // 关闭指定callback的监听
3588  windowClass.off('windowVisibilityChange', callback);
3589  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3590  windowClass.off('windowVisibilityChange');
3591} catch (exception) {
3592  console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3593}
3594```
3595
3596### on('noInteractionDetected')<sup>12+</sup>
3597
3598on(type: 'noInteractionDetected', timeout: number, callback: Callback&lt;void&gt;): void
3599
3600开启本窗口在指定超时时间内无交互事件的监听,交互事件支持物理键盘输入事件和屏幕触控点击事件,不支持软键盘输入事件。
3601
3602**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3603
3604**系统能力:** SystemCapability.Window.SessionManager
3605
3606**参数:**
3607
3608| 参数名   | 类型                       | 必填 | 说明                                                         |
3609| -------- | --------------------------| ---- | ------------------------------------------------------------ |
3610| type     | string                    | 是   | 监听事件,固定为'noInteractionDetected',即本窗口在指定超时时间内无交互的事件。 |
3611| timeout     | number                    | 是   | 指定本窗口在多长时间内无交互即回调,单位为秒(s)。该参数仅支持整数输入,负数和小数为非法参数。 |
3612| callback | Callback&lt;void&gt;      | 是   | 回调函数。当本窗口在指定超时时间内无交互事件时的回调。  |
3613
3614**错误码:**
3615
3616以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3617
3618| 错误码ID | 错误信息 |
3619| ------- | ------------------------------ |
3620| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3621| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3622| 1300002 | This window state is abnormal.                |
3623| 1300003 | This window manager service works abnormally. |
3624
3625**示例:**
3626
3627```ts
3628try {
3629  windowClass.on('noInteractionDetected', 60, () => {
3630    console.info('no interaction in 60s');
3631  });
3632} catch (exception) {
3633  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
3634}
3635```
3636
3637### off('noInteractionDetected')<sup>12+</sup>
3638
3639off(type: 'noInteractionDetected', callback?: Callback&lt;void&gt;): void
3640
3641关闭本窗口在指定超时时间内无交互事件的监听,交互事件支持物理键盘输入事件和屏幕触控点击事件,不支持软键盘输入事件。
3642
3643**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3644
3645**系统能力:** SystemCapability.Window.SessionManager
3646
3647**参数:**
3648
3649| 参数名   | 类型                        | 必填 | 说明                                   |
3650| -------- |----------------------------| ---- |--------------------------------------|
3651| type     | string                     | 是   | 监听事件,固定为'noInteractionDetected',即本窗口在指定超时时间内无交互的事件。 |
3652| callback | Callback&lt;void&gt;    | 否   | 回调函数,当本窗口在指定超时时间内无交互事件时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口在指定超时时间内无交互事件的监听。 |
3653
3654**错误码:**
3655
3656以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3657
3658| 错误码ID | 错误信息 |
3659| ------- | ------------------------------ |
3660| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3661| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3662| 1300002 | This window state is abnormal.                |
3663| 1300003 | This window manager service works abnormally. |
3664
3665**示例:**
3666
3667```ts
3668const callback = () => {
3669  // ...
3670}
3671try {
3672  windowClass.on('noInteractionDetected', 60, callback);
3673  windowClass.off('noInteractionDetected', callback);
3674  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3675  windowClass.off('noInteractionDetected');
3676} catch (exception) {
3677  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3678}
3679```
3680
3681### on('windowStatusChange')<sup>11+</sup>
3682
3683on(type:  'windowStatusChange', callback: Callback&lt;WindowStatusType&gt;): void
3684
3685开启窗口模式变化的监听。
3686
3687**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3688
3689**系统能力:** SystemCapability.Window.SessionManager
3690
3691**参数:**
3692
3693| 参数名   | 类型                           | 必填 | 说明                                                     |
3694| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
3695| type     | string                         | 是   | 监听事件,固定为'windowStatusChange',即窗口模式变化事件。 |
3696| callback | Callback&lt;[WindowStatusType](#windowstatustype11)&gt; | 是   | 回调函数。返回当前的窗口模式。                           |
3697
3698**错误码:**
3699
3700以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3701
3702| 错误码ID | 错误信息 |
3703| ------- | ------------------------------ |
3704| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3705| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3706
3707**示例:**
3708
3709```ts
3710try {
3711    windowClass.on('windowStatusChange', (WindowStatusType) => {
3712        console.info('Succeeded in enabling the listener for window status changes. Data: ' + JSON.stringify(WindowStatusType));
3713    });
3714} catch (exception) {
3715    console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3716}
3717```
3718
3719### off('windowStatusChange')<sup>11+</sup>
3720
3721off(type: 'windowStatusChange', callback?: Callback&lt;WindowStatusType&gt;): void
3722
3723关闭窗口模式变化的监听。
3724
3725**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3726
3727**系统能力:** SystemCapability.Window.SessionManager
3728
3729**参数:**
3730
3731| 参数名   | 类型                          | 必填 | 说明                                                     |
3732| -------- | ----------------------------- | ---- | -------------------------------------------------------- |
3733| type     | string                        | 是   | 监听事件,固定为'windowStatusChange',即窗口模式变化事件。 |
3734| callback | Callback&lt;[WindowStatusType](#windowstatustype11)&gt; | 否   | 回调函数。返回当前的窗口模式。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有窗口模式变化的监听。                           |
3735
3736**错误码:**
3737
3738以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3739
3740| 错误码ID | 错误信息 |
3741| ------- | ------------------------------ |
3742| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3743| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3744
3745**示例:**
3746
3747```ts
3748const callback = (windowStatusType: window.WindowStatusType) => {
3749    // ...
3750}
3751try {
3752    windowClass.on('windowStatusChange', callback);
3753    windowClass.off('windowStatusChange', callback);
3754    // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3755    windowClass.off('windowStatusChange');
3756} catch (exception) {
3757    console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
3758}
3759```
3760
3761### setWindowGrayScale<sup>12+</sup>
3762
3763setWindowGrayScale(grayScale: number): Promise&lt;void&gt;
3764
3765设置窗口灰阶,使用Promise异步回调。该接口需要在调用[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)使窗口加载页面内容后调用。
3766
3767**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3768
3769**系统能力:** SystemCapability.Window.SessionManager
3770
3771**参数:**
3772
3773| 参数名 | 类型 | 必填 | 说明                                     |
3774| --------- | ------ | -- | ---------------------------------------- |
3775| grayScale | number | 是 | 窗口灰阶。该参数为浮点数,取值范围为[0.0, 1.0]。0.0表示窗口图像无变化,1.0表示窗口图像完全转为灰度图像,0.0至1.0之间时效果呈线性变化。 |
3776
3777**返回值:**
3778
3779| 类型 | 说明 |
3780| ------------------- | ------------------------ |
3781| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
3782
3783**错误码:**
3784
3785以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3786
3787| 错误码ID | 错误信息 |
3788| ------- | --------------------------------------------- |
3789| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3790| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3791| 1300002 | This window state is abnormal.                |
3792| 1300003 | This window manager service works abnormally. |
3793
3794**示例:**
3795
3796```ts
3797import { BusinessError } from '@kit.BasicServicesKit';
3798
3799windowClass?.setUIContent('pages/Index', (error: BusinessError) => {
3800  if (error.code) {
3801    console.error(`Failed to set the content. Cause code: ${error.code}`);
3802    return;
3803  }
3804  console.info('Succeeded in setting the content.');
3805  let grayScale: number = 0.5;
3806  try {
3807    if (canIUse("SystemCapability.Window.SessionManager")) {
3808      let promise = windowClass?.setWindowGrayScale(grayScale);
3809      promise?.then(() => {
3810        console.info('Succeeded in setting the grayScale.');
3811      }).catch((err: BusinessError) => {
3812        console.error(`Failed to set the grayScale. Cause code: ${err.code}, message: ${err.message}`);
3813      });
3814    }
3815  } catch (exception) {
3816    console.error(`Failed to set the grayScale. Cause code: ${exception.code}, message: ${exception.message}`);
3817  }
3818});
3819```
3820
3821### on('windowTitleButtonRectChange')<sup>11+</sup>
3822
3823on(type: 'windowTitleButtonRectChange', callback: Callback&lt;TitleButtonRect&gt;): void
3824
3825开启窗口标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
3826
3827**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3828
3829**系统能力:** SystemCapability.Window.SessionManager
3830
3831**参数:**
3832
3833| 参数名   | 类型                                                  | 必填 | 说明                                                         |
3834| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
3835| type     | string                                                | 是   | 监听事件,固定为'windowTitleButtonRectChange',即标题栏上的最小化、最大化、关闭按钮矩形区域变化事件。 |
3836| callback | Callback&lt;[TitleButtonRect](#titlebuttonrect11)&gt; | 是   | 回调函数。返回当前标题栏上的最小化、最大化、关闭按钮矩形区域。 |
3837
3838**错误码:**
3839
3840以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3841
3842| 错误码ID | 错误信息                       |
3843| -------- | ------------------------------ |
3844| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3845| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
3846| 1300002  | This window state is abnormal. |
3847
3848**示例:**
3849
3850```ts
3851windowClass.setUIContent('pages/WindowPage').then(() => {
3852  try {
3853    windowClass?.on('windowTitleButtonRectChange', (titleButtonRect) => {
3854      console.info('Succeeded in enabling the listener for window title buttons area changes. Data: ' + JSON.stringify(titleButtonRect));
3855    });
3856  } catch (exception) {
3857    console.error(`Failed to enable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`);
3858  }
3859})
3860```
3861
3862### off('windowTitleButtonRectChange')<sup>11+</sup>
3863
3864off(type: 'windowTitleButtonRectChange', callback?: Callback&lt;TitleButtonRect&gt;): void
3865
3866关闭窗口标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
3867
3868**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3869
3870**系统能力:** SystemCapability.Window.SessionManager
3871
3872**参数:**
3873
3874| 参数名   | 类型                                                  | 必填 | 说明                                                         |
3875| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
3876| type     | string                                                | 是   | 监听事件,固定为'windowTitleButtonRectChange',即标题栏上的最小化、最大化、关闭按钮矩形区域变化事件。 |
3877| callback | Callback&lt;[TitleButtonRect](#titlebuttonrect11)&gt; | 否   | 回调函数。返回当前标题栏上的最小化、最大化、关闭按钮矩形区域。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听。 |
3878
3879**错误码:**
3880
3881以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3882
3883| 错误码ID | 错误信息                       |
3884| -------- | ------------------------------ |
3885| 401      | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3886| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
3887| 1300002  | This window state is abnormal. |
3888
3889**示例:**
3890
3891```ts
3892windowClass.setUIContent('pages/WindowPage').then(() => {
3893	const callback = (titleButtonRect: window.TitleButtonRect) => {
3894		// ...
3895	}
3896  try {
3897    // 通过on接口开启监听
3898    windowClass?.on('windowTitleButtonRectChange', callback);
3899    // 关闭指定callback的监听
3900    windowClass?.off('windowTitleButtonRectChange', callback);
3901    // 如果通过on开启多个callback进行监听,同时关闭所有监听:
3902    windowClass?.off('windowTitleButtonRectChange');
3903  } catch (exception) {
3904    console.error(`Failed to disable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`);
3905  }
3906})
3907```
3908
3909### on('windowRectChange')<sup>12+</sup>
3910
3911on(type:  'windowRectChange', callback: Callback&lt;RectChangeOptions&gt;): void
3912
3913开启窗口矩形(窗口位置及窗口大小)变化的监听。
3914
3915**系统能力:** SystemCapability.Window.SessionManager
3916
3917**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3918
3919**参数:**
3920
3921| 参数名   | 类型                           | 必填 | 说明                                                     |
3922| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
3923| type     | string                         | 是   | 监听事件,固定为'windowRectChange',即窗口矩形变化事件。 |
3924| callback | Callback&lt;[RectChangeOptions](#rectchangeoptions12)&gt; | 是   | 回调函数。返回当前窗口矩形变化值及变化原因。                           |
3925
3926**错误码:**
3927
3928以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3929
3930| 错误码ID | 错误信息 |
3931| ------- | -------------------------------------------- |
3932| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3933| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3934| 1300002 | This window state is abnormal. |
3935| 1300003 | This window manager service works abnormally. |
3936
3937**示例:**
3938
3939```ts
3940windowClass.on('windowRectChange', (data: window.RectChangeOptions) => {
3941    console.info('Succeeded window rect changes. Data: ' + JSON.stringify(data));
3942});
3943```
3944
3945### off('windowRectChange')<sup>12+</sup>
3946
3947off(type: 'windowRectChange', callback?: Callback&lt;RectChangeOptions&gt;): void
3948
3949关闭窗口矩形(窗口位置及窗口大小)变化的监听。
3950
3951**系统能力:** SystemCapability.Window.SessionManager
3952
3953**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3954
3955**参数:**
3956
3957| 参数名   | 类型                           | 必填 | 说明                                                         |
3958| -------- | ------------------------------ | ---- | ------------------------------------------------------------ |
3959| type     | string                         | 是   | 监听事件,固定为'windowRectChange',即窗口矩形变化事件。     |
3960| callback | Callback&lt;[RectChangeOptions](#rectchangeoptions12)&gt; | 否   | 回调函数。返回当前的窗口矩形及变化原因。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有窗口矩形变化的监听。 |
3961
3962**错误码:**
3963
3964以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3965
3966| 错误码ID | 错误信息 |
3967| ------- | -------------------------------------------- |
3968| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
3969| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3970| 1300002 | This window state is abnormal. |
3971| 1300003 | This window manager service works abnormally. |
3972
3973**示例:**
3974
3975```ts
3976const callback = (rectChangeOptions: window.RectChangeOptions) => {
3977  // ...
3978}
3979windowClass.on('windowRectChange', callback);
3980windowClass.off('windowRectChange', callback);
3981// 如果通过on开启多个callback进行监听,同时关闭所有监听:
3982windowClass.off('windowRectChange');
3983```
3984
3985### on('subWindowClose')<sup>12+</sup>
3986
3987on(type:  'subWindowClose', callback: Callback&lt;void&gt;): void
3988
3989开启子窗口关闭事件的监听。此监听仅在点击系统提供的右上角关闭按钮关闭子窗时触发,其余关闭方式不触发回调。
3990
3991**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3992
3993**系统能力:** SystemCapability.Window.SessionManager
3994
3995**参数:**
3996
3997| 参数名   | 类型                           | 必填 | 说明                                                     |
3998| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
3999| type     | string                         | 是   | 监听事件,固定为'subWindowClose',即子窗口关闭事件。 |
4000| callback | Callback&lt;void&gt; | 是   | 回调函数。当点击子窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前子窗是否继续关闭,true表示不关闭子窗,false表示关闭子窗。   |
4001
4002**错误码:**
4003
4004以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4005
4006| 错误码ID | 错误信息 |
4007| ------- | -------------------------------------------- |
4008| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
4009| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
4010| 1300002 | This window state is abnormal. |
4011| 1300004 | Unauthorized operation. |
4012
4013**示例:**
4014
4015```ts
4016const callback = () => {
4017  // ...
4018  return true;
4019}
4020try {
4021  windowClass.on('subWindowClose', callback);
4022} catch (exception) {
4023  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
4024}
4025```
4026
4027### off('subWindowClose')<sup>12+</sup>
4028
4029off(type: 'subWindowClose', callback?: Callback&lt;void&gt;): void
4030
4031关闭子窗口关闭事件的监听。
4032
4033**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4034
4035**系统能力:** SystemCapability.Window.SessionManager
4036
4037**参数:**
4038
4039| 参数名   | 类型                           | 必填 | 说明                                                         |
4040| -------- | ------------------------------ | ---- | ------------------------------------------------------------ |
4041| type     | string                         | 是   | 监听事件,固定为'subWindowClose',即子窗口关闭事件。     |
4042| callback | Callback&lt;void&gt; | 否   | 回调函数。当点击子窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前子窗是否继续关闭,true表示不关闭子窗,false表示关闭子窗。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有子窗口关闭的监听。 |
4043
4044**错误码:**
4045
4046以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4047
4048| 错误码ID | 错误信息 |
4049| ------- | -------------------------------------------- |
4050| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
4051| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
4052| 1300002 | This window state is abnormal. |
4053| 1300004 | Unauthorized operation. |
4054
4055**示例:**
4056
4057```ts
4058const callback = () => {
4059  // ...
4060  return true;
4061}
4062try {
4063  windowClass.on('subWindowClose', callback);
4064  windowClass.off('subWindowClose', callback);
4065  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
4066  windowClass.off('subWindowClose');
4067} catch (exception) {
4068  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
4069}
4070```
4071
4072### isWindowSupportWideGamut<sup>9+</sup>
4073
4074isWindowSupportWideGamut(callback: AsyncCallback&lt;boolean&gt;): void
4075
4076判断当前窗口是否支持广色域模式,使用callback异步回调。
4077
4078**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4079
4080**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4081
4082**参数:**
4083
4084| 参数名 | 类型 | 必填 | 说明 |
4085| -------- | ---------------------------- | -- | -------------------------------------------------------------------------------- |
4086| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 |
4087
4088**错误码:**
4089
4090以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
4091
4092| 错误码ID | 错误信息 |
4093| ------- | ------------------------------ |
4094| 1300002 | This window state is abnormal. |
4095
4096**示例:**
4097
4098```ts
4099import { BusinessError } from '@kit.BasicServicesKit';
4100
4101windowClass.isWindowSupportWideGamut((err: BusinessError, data) => {
4102  const errCode: number = err.code;
4103  if (errCode) {
4104    console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`);
4105    return;
4106  }
4107  console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data));
4108});
4109```
4110
4111### isWindowSupportWideGamut<sup>9+</sup>
4112
4113isWindowSupportWideGamut(): Promise&lt;boolean&gt;
4114
4115判断当前窗口是否支持广色域模式,使用Promise异步回调。
4116
4117**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4118
4119**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4120
4121**返回值:**
4122
4123| 类型 | 说明 |
4124| ---------------------- | ------------------------------------------------------------------------------------ |
4125| Promise&lt;boolean&gt; | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 |
4126
4127**错误码:**
4128
4129以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
4130
4131| 错误码ID | 错误信息 |
4132| ------- | ------------------------------ |
4133| 1300002 | This window state is abnormal. |
4134
4135**示例:**
4136
4137```ts
4138import { BusinessError } from '@kit.BasicServicesKit';
4139
4140let promise = windowClass.isWindowSupportWideGamut();
4141promise.then((data) => {
4142  console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data));
4143}).catch((err: BusinessError) => {
4144  console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`);
4145});
4146```
4147
4148### setWindowColorSpace<sup>9+</sup>
4149
4150setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback&lt;void&gt;): void
4151
4152设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。
4153
4154**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4155
4156**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4157
4158**参数:**
4159
4160| 参数名 | 类型 | 必填 | 说明 |
4161| ---------- | ------------------------- | -- | ----------- |
4162| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 |
4163| callback   | AsyncCallback&lt;void&gt; | 是 | 回调函数。   |
4164
4165**错误码:**
4166
4167以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4168
4169| 错误码ID | 错误信息 |
4170| ------- | ------------------------------ |
4171| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
4172| 1300002 | This window state is abnormal. |
4173
4174**示例:**
4175
4176```ts
4177import { BusinessError } from '@kit.BasicServicesKit';
4178
4179try {
4180  windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => {
4181    const errCode: number = err.code;
4182    if (errCode) {
4183      console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`);
4184      return;
4185    }
4186    console.info('Succeeded in setting window colorspace.');
4187  });
4188} catch (exception) {
4189  console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`);
4190}
4191```
4192
4193### setWindowColorSpace<sup>9+</sup>
4194
4195setWindowColorSpace(colorSpace:ColorSpace): Promise&lt;void&gt;
4196
4197设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。
4198
4199**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4200
4201**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4202
4203**参数:**
4204
4205| 参数名 | 类型 | 必填 | 说明 |
4206| ---------- | ------------------------- | -- | ------------- |
4207| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 |
4208
4209**返回值:**
4210
4211| 类型 | 说明 |
4212| ------------------- | ------------------------ |
4213| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4214
4215**错误码:**
4216
4217以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4218
4219| 错误码ID | 错误信息 |
4220| ------- | ------------------------------ |
4221| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
4222| 1300002 | This window state is abnormal. |
4223
4224**示例:**
4225
4226```ts
4227import { BusinessError } from '@kit.BasicServicesKit';
4228
4229try {
4230  let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT);
4231  promise.then(() => {
4232    console.info('Succeeded in setting window colorspace.');
4233  }).catch((err: BusinessError) => {
4234    console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`);
4235  });
4236} catch (exception) {
4237  console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`);
4238}
4239```
4240
4241### getWindowColorSpace<sup>9+</sup>
4242
4243getWindowColorSpace(): ColorSpace
4244
4245获取当前窗口色域模式。
4246
4247**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4248
4249**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4250
4251**返回值:**
4252
4253| 类型 | 说明 |
4254| ------------------------- | ------------- |
4255| [ColorSpace](#colorspace8) | 当前色域模式。 |
4256
4257**错误码:**
4258
4259以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
4260
4261| 错误码ID | 错误信息 |
4262| ------- | ------------------------------ |
4263| 1300002 | This window state is abnormal. |
4264
4265**示例:**
4266
4267```ts
4268let colorSpace = windowClass.getWindowColorSpace();
4269```
4270
4271### setWindowBackgroundColor<sup>9+</sup>
4272
4273setWindowBackgroundColor(color: string): void
4274
4275设置窗口的背景色。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
4276
4277**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4278
4279**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4280
4281**参数:**
4282
4283| 参数名 | 类型 | 必填 | 说明 |
4284| ----- | ------ | -- | ----------------------------------------------------------------------- |
4285| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 |
4286
4287**错误码:**
4288
4289以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4290
4291| 错误码ID | 错误信息 |
4292| ------- | ------------------------------ |
4293| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4294| 1300002 | This window state is abnormal. |
4295
4296**示例:**
4297
4298```ts
4299import { BusinessError } from '@kit.BasicServicesKit';
4300
4301private SetUIContent(windowClass: window.Window) {
4302    windowClass.setUIContent("pages/ButtonWindow",(err: BusinessError) => {
4303      if (err.code) {
4304        console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
4305        return;
4306      }
4307      console.info('Succeeded in loading the content.');
4308      let color: string = '#00ff33';
4309      try {
4310        windowClass.setWindowBackgroundColor(color);
4311      } catch (exception) {
4312        console.error(`Failed to set the background color. Cause code: ${exception.code}, message: ${exception.message}`);
4313      };
4314    });
4315}
4316```
4317
4318### setWindowBrightness<sup>9+</sup>
4319
4320setWindowBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void
4321
4322允许应用主窗口设置屏幕亮度值,使用callback异步回调。
4323
4324当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。
4325
4326**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4327
4328**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4329
4330**参数:**
4331
4332| 参数名 | 类型 | 必填 | 说明                                        |
4333| ---------- | ------------------------- | -- |-------------------------------------------|
4334| brightness | number                    | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 |
4335| callback   | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                     |
4336
4337**错误码:**
4338
4339以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4340
4341| 错误码ID | 错误信息 |
4342| ------- | -------------------------------------------- |
4343| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4344| 1300002 | This window state is abnormal.               |
4345| 1300003 | This window manager service works abnormally. |
4346
4347**示例:**
4348
4349```ts
4350// EntryAbility.ets
4351import { UIAbility } from '@kit.AbilityKit';
4352import { BusinessError } from '@kit.BasicServicesKit';
4353
4354export default class EntryAbility extends UIAbility {
4355  // ...
4356  onWindowStageCreate(windowStage: window.WindowStage): void {
4357    console.info('onWindowStageCreate');
4358    let windowClass: window.Window | undefined = undefined;
4359    windowStage.getMainWindow((err: BusinessError, data) => {
4360      const errCode: number = err.code;
4361      if (errCode) {
4362        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
4363        return;
4364      }
4365      windowClass = data;
4366      let brightness: number = 1;
4367      try {
4368        windowClass.setWindowBrightness(brightness, (err: BusinessError) => {
4369          const errCode: number = err.code;
4370          if (errCode) {
4371            console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`);
4372            return;
4373          }
4374          console.info('Succeeded in setting the brightness.');
4375        });
4376      } catch (exception) {
4377        console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`);
4378      }
4379    });
4380  }
4381}
4382```
4383
4384### setWindowBrightness<sup>9+</sup>
4385
4386setWindowBrightness(brightness: number): Promise&lt;void&gt;
4387
4388允许应用主窗口设置屏幕亮度值,使用Promise异步回调。
4389
4390当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。
4391
4392**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4393
4394**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4395
4396**参数:**
4397
4398| 参数名 | 类型 | 必填 | 说明                                     |
4399| ---------- | ------ | -- |----------------------------------------|
4400| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 |
4401
4402**返回值:**
4403
4404| 类型 | 说明 |
4405| ------------------- | ------------------------ |
4406| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4407
4408**错误码:**
4409
4410以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4411
4412| 错误码ID | 错误信息 |
4413| ------- | -------------------------------------------- |
4414| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4415| 1300002 | This window state is abnormal.               |
4416| 1300003 | This window manager service works abnormally. |
4417
4418**示例:**
4419
4420```ts
4421// EntryAbility.ets
4422import { UIAbility } from '@kit.AbilityKit';
4423import { BusinessError } from '@kit.BasicServicesKit';
4424
4425export default class EntryAbility extends UIAbility {
4426  // ...
4427  onWindowStageCreate(windowStage: window.WindowStage): void {
4428    console.info('onWindowStageCreate');
4429    let windowClass: window.Window | undefined = undefined;
4430    windowStage.getMainWindow((err: BusinessError, data) => {
4431      const errCode: number = err.code;
4432      if (errCode) {
4433        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
4434        return;
4435      }
4436      windowClass = data;
4437      let brightness: number = 1;
4438      try {
4439        let promise = windowClass.setWindowBrightness(brightness);
4440        promise.then(() => {
4441          console.info('Succeeded in setting the brightness.');
4442        }).catch((err: BusinessError) => {
4443          console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`);
4444        });
4445      } catch (exception) {
4446        console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`);
4447      }
4448    });
4449  }
4450}
4451```
4452
4453### setWindowFocusable<sup>9+</sup>
4454
4455setWindowFocusable(isFocusable: boolean, callback: AsyncCallback&lt;void&gt;): void
4456
4457设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用callback异步回调。
4458
4459**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4460
4461**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4462
4463**参数:**
4464
4465| 参数名 | 类型 | 必填 | 说明 |
4466| ----------- | ------------------------- | -- | ------------------------------------------------------- |
4467| isFocusable | boolean                   | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 |
4468| callback    | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                               |
4469
4470**错误码:**
4471
4472以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4473
4474| 错误码ID | 错误信息 |
4475| ------- | -------------------------------------------- |
4476| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4477| 1300002 | This window state is abnormal.               |
4478| 1300003 | This window manager service works abnormally. |
4479
4480**示例:**
4481
4482```ts
4483import { BusinessError } from '@kit.BasicServicesKit';
4484
4485let isFocusable: boolean = true;
4486try {
4487  windowClass.setWindowFocusable(isFocusable, (err: BusinessError) => {
4488    const errCode: number = err.code;
4489    if (errCode) {
4490      console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`);
4491      return;
4492    }
4493    console.info('Succeeded in setting the window to be focusable.');
4494  });
4495} catch (exception) {
4496  console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`);
4497}
4498```
4499
4500### setWindowFocusable<sup>9+</sup>
4501
4502setWindowFocusable(isFocusable: boolean): Promise&lt;void&gt;
4503
4504设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用Promise异步回调。
4505
4506**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4507
4508**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4509
4510**参数:**
4511
4512| 参数名 | 类型 | 必填 | 说明 |
4513| ----------- | ------- | -- | -------------------------------------------------------- |
4514| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。  |
4515
4516**返回值:**
4517
4518| 类型 | 说明 |
4519| ------------------- | ------------------------ |
4520| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4521
4522**错误码:**
4523
4524以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4525
4526| 错误码ID | 错误信息 |
4527| ------- | -------------------------------------------- |
4528| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4529| 1300002 | This window state is abnormal.               |
4530| 1300003 | This window manager service works abnormally. |
4531
4532**示例:**
4533
4534```ts
4535import { BusinessError } from '@kit.BasicServicesKit';
4536
4537let isFocusable: boolean = true;
4538try {
4539  let promise = windowClass.setWindowFocusable(isFocusable);
4540  promise.then(() => {
4541    console.info('Succeeded in setting the window to be focusable.');
4542  }).catch((err: BusinessError) => {
4543    console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`);
4544  });
4545} catch (exception) {
4546  console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`);
4547}
4548```
4549
4550### setWindowKeepScreenOn<sup>9+</sup>
4551
4552setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback&lt;void&gt;): void
4553
4554设置屏幕是否为常亮状态,使用callback异步回调。
4555
4556规范使用该接口:仅在必要场景(导航、视频播放、绘画、游戏等场景)下,设置该属性为true;退出上述场景后,应当重置该属性为false;其他场景(无屏幕互动、音频播放等)下,不使用该接口;系统检测到非规范使用该接口时,可能会恢复自动灭屏功能。
4557
4558**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4559
4560**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4561
4562**参数:**
4563
4564| 参数名 | 类型 | 必填 | 说明 |
4565| -------------- | ------------------------- | -- | ---------------------------------------------------- |
4566| isKeepScreenOn | boolean                   | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。  |
4567| callback       | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                            |
4568
4569**错误码:**
4570
4571以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4572
4573| 错误码ID | 错误信息 |
4574| ------- | -------------------------------------------- |
4575| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4576| 1300002 | This window state is abnormal.               |
4577| 1300003 | This window manager service works abnormally. |
4578
4579**示例:**
4580
4581```ts
4582import { BusinessError } from '@kit.BasicServicesKit';
4583
4584let isKeepScreenOn: boolean = true;
4585try {
4586  windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err: BusinessError) => {
4587    const errCode: number = err.code;
4588    if (errCode) {
4589      console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`);
4590      return;
4591    }
4592    console.info('Succeeded in setting the screen to be always on.');
4593  });
4594} catch (exception) {
4595  console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`);
4596}
4597```
4598
4599### setWindowKeepScreenOn<sup>9+</sup>
4600
4601setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise&lt;void&gt;
4602
4603设置屏幕是否为常亮状态,使用Promise异步回调。
4604
4605规范使用该接口:仅在必要场景(导航、视频播放、绘画、游戏等场景)下,设置该属性为true;退出上述场景后,应当重置该属性为false;其他场景(无屏幕互动、音频播放等)下,不使用该接口;系统检测到非规范使用该接口时,可能会恢复自动灭屏功能。
4606
4607**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4608
4609**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4610
4611**参数:**
4612
4613| 参数名 | 类型 | 必填 | 说明 |
4614| -------------- | ------- | -- | --------------------------------------------------- |
4615| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 |
4616
4617**返回值:**
4618
4619| 类型 | 说明 |
4620| ------------------- | ------------------------ |
4621| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4622
4623**错误码:**
4624
4625以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4626
4627| 错误码ID | 错误信息 |
4628| ------- | -------------------------------------------- |
4629| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4630| 1300002 | This window state is abnormal.               |
4631| 1300003 | This window manager service works abnormally. |
4632
4633**示例:**
4634
4635```ts
4636import { BusinessError } from '@kit.BasicServicesKit';
4637
4638let isKeepScreenOn: boolean = true;
4639try {
4640  let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn);
4641  promise.then(() => {
4642    console.info('Succeeded in setting the screen to be always on.');
4643  }).catch((err: BusinessError) => {
4644    console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`);
4645  });
4646} catch (exception) {
4647  console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`);
4648}
4649```
4650
4651### setWindowPrivacyMode<sup>9+</sup>
4652
4653setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback&lt;void&gt;): void
4654
4655设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。
4656
4657**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4658
4659**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4660
4661**需要权限:** ohos.permission.PRIVACY_WINDOW
4662
4663**参数:**
4664
4665| 参数名 | 类型 | 必填 | 说明 |
4666| ------------- | ------------------------- | -- | ------------------------------------------------------ |
4667| isPrivacyMode | boolean                   | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。  |
4668| callback      | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                              |
4669
4670**错误码:**
4671
4672以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4673
4674| 错误码ID | 错误信息 |
4675| ------- | ------------------------------ |
4676| 201     | Permission verification failed. The application does not have the permission required to call the API. |
4677| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4678| 1300002 | This window state is abnormal. |
4679
4680**示例:**
4681
4682```ts
4683import { BusinessError } from '@kit.BasicServicesKit';
4684
4685let isPrivacyMode: boolean = true;
4686try {
4687  windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => {
4688    const errCode: number = err.code;
4689    if (errCode) {
4690      console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`);
4691      return;
4692    }
4693    console.info('Succeeded in setting the window to privacy mode.');
4694  });
4695} catch (exception) {
4696  console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`);
4697}
4698```
4699
4700### setWindowPrivacyMode<sup>9+</sup>
4701
4702setWindowPrivacyMode(isPrivacyMode: boolean): Promise&lt;void&gt;
4703
4704设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。
4705
4706**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4707
4708**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4709
4710**需要权限:** ohos.permission.PRIVACY_WINDOW
4711
4712**参数:**
4713
4714| 参数名 | 类型 | 必填 | 说明 |
4715| ------------- | ------- | -- | ----------------------------------------------------- |
4716| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 |
4717
4718**返回值:**
4719
4720| 类型 | 说明 |
4721| ------------------- | ------------------------ |
4722| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4723
4724**错误码:**
4725
4726以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4727
4728| 错误码ID | 错误信息 |
4729| ------- | ------------------------------ |
4730| 201     | Permission verification failed. The application does not have the permission required to call the API. |
4731| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4732| 1300002 | This window state is abnormal. |
4733
4734**示例:**
4735
4736```ts
4737import { BusinessError } from '@kit.BasicServicesKit';
4738
4739let isPrivacyMode: boolean = true;
4740try {
4741  let promise = windowClass.setWindowPrivacyMode(isPrivacyMode);
4742  promise.then(() => {
4743    console.info('Succeeded in setting the window to privacy mode.');
4744  }).catch((err: BusinessError) => {
4745    console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`);
4746  });
4747} catch (exception) {
4748  console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`);
4749}
4750```
4751
4752### setWindowTouchable<sup>9+</sup>
4753
4754setWindowTouchable(isTouchable: boolean, callback: AsyncCallback&lt;void&gt;): void
4755
4756设置窗口是否为可触状态,使用callback异步回调。
4757
4758**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4759
4760**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4761
4762**参数:**
4763
4764| 参数名 | 类型 | 必填 | 说明 |
4765| ----------- | ------------------------- | -- | ----------------------------------------------- |
4766| isTouchable | boolean                   | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 |
4767| callback    | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                        |
4768
4769**错误码:**
4770
4771以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4772
4773| 错误码ID | 错误信息 |
4774| ------- | -------------------------------------------- |
4775| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4776| 1300002 | This window state is abnormal.               |
4777| 1300003 | This window manager service works abnormally. |
4778
4779**示例:**
4780
4781```ts
4782import { BusinessError } from '@kit.BasicServicesKit';
4783
4784let isTouchable = true;
4785try {
4786  windowClass.setWindowTouchable(isTouchable, (err: BusinessError) => {
4787    const errCode: number = err.code;
4788    if (errCode) {
4789      console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`);
4790      return;
4791    }
4792    console.info('Succeeded in setting the window to be touchable.');
4793  });
4794} catch (exception) {
4795  console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`);
4796}
4797```
4798
4799### setWindowTouchable<sup>9+</sup>
4800
4801setWindowTouchable(isTouchable: boolean): Promise&lt;void&gt;
4802
4803设置窗口是否为可触状态,使用Promise异步回调。
4804
4805**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4806
4807**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4808
4809**参数:**
4810
4811| 参数名 | 类型 | 必填 | 说明 |
4812| ----------- | ------- | -- | ----------------------------------------------- |
4813| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 |
4814
4815**返回值:**
4816
4817| 类型 | 说明 |
4818| ------------------- | ------------------------- |
4819| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4820
4821**错误码:**
4822
4823以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4824
4825| 错误码ID | 错误信息 |
4826| ------- | -------------------------------------------- |
4827| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4828| 1300002 | This window state is abnormal.               |
4829| 1300003 | This window manager service works abnormally. |
4830
4831**示例:**
4832
4833```ts
4834import { BusinessError } from '@kit.BasicServicesKit';
4835
4836let isTouchable: boolean = true;
4837try {
4838  let promise = windowClass.setWindowTouchable(isTouchable);
4839  promise.then(() => {
4840    console.info('Succeeded in setting the window to be touchable.');
4841  }).catch((err: BusinessError) => {
4842    console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`);
4843  });
4844} catch (exception) {
4845  console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`);
4846}
4847```
4848
4849### snapshot<sup>9+</sup>
4850
4851snapshot(callback: AsyncCallback&lt;image.PixelMap&gt;): void
4852
4853获取窗口截图,使用callback异步回调。
4854
4855**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4856
4857**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4858
4859**参数:**
4860
4861| 参数名      | 类型                      | 必填 | 说明                 |
4862| ----------- | ------------------------- | ---- | -------------------- |
4863| callback    | AsyncCallback&lt;[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)&gt; | 是   | 回调函数。  |
4864
4865**错误码:**
4866
4867以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
4868
4869| 错误码ID | 错误信息 |
4870| ------- | ------------------------------ |
4871| 1300002 | This window state is abnormal. |
4872
4873**示例:**
4874
4875```ts
4876import { BusinessError } from '@kit.BasicServicesKit';
4877import { image } from '@kit.ImageKit';
4878
4879windowClass.snapshot((err: BusinessError, pixelMap: image.PixelMap) => {
4880  const errCode: number = err.code;
4881  if (errCode) {
4882    console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`);
4883    return;
4884  }
4885  console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
4886  pixelMap.release(); // PixelMap使用完后及时释放内存
4887});
4888```
4889
4890### snapshot<sup>9+</sup>
4891
4892snapshot(): Promise&lt;image.PixelMap&gt;
4893
4894获取窗口截图,使用Promise异步回调。
4895
4896**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4897
4898**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4899
4900**返回值:**
4901
4902| 类型                | 说明                      |
4903| ------------------- | ------------------------- |
4904| Promise&lt;[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)&gt; | Promise对象。返回当前窗口截图。 |
4905
4906**错误码:**
4907
4908以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
4909
4910| 错误码ID | 错误信息 |
4911| ------- | ------------------------------ |
4912| 1300002 | This window state is abnormal. |
4913
4914**示例:**
4915
4916```ts
4917import { BusinessError } from '@kit.BasicServicesKit';
4918import { image } from '@kit.ImageKit';
4919
4920let promise = windowClass.snapshot();
4921promise.then((pixelMap: image.PixelMap) => {
4922  console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
4923  pixelMap.release(); // PixelMap使用完后及时释放内存
4924}).catch((err: BusinessError) => {
4925  console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`);
4926});
4927```
4928
4929### setAspectRatio<sup>10+</sup>
4930
4931setAspectRatio(ratio: number): Promise&lt;void&gt;
4932
4933设置窗口内容布局的比例,使用Promise异步回调。
4934
4935仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。
4936
4937**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4938
4939**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4940
4941**参数:**
4942
4943| 参数名             | 类型    | 必填 | 说明                                        |
4944| ------------------ | ------- | ---- |-------------------------------------------|
4945| ratio | number | 是   | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,受窗口最大最小尺寸限制,比例值下限为最小宽度/最大高度,上限为最大宽度/最小高度。窗口最大最小尺寸由[WindowLimits](#windowlimits11)和系统限制的交集决定,系统限制优先级高于[WindowLimits](#windowlimits11)。 |
4946
4947**返回值:**
4948
4949| 类型                | 说明                      |
4950| ------------------- | ------------------------- |
4951| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4952
4953**错误码:**
4954
4955以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4956
4957| 错误码ID | 错误信息 |
4958| ------- | -------------------------------------------- |
4959| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
4960| 1300002 | This window state is abnormal.               |
4961| 1300004 | Unauthorized operation.                      |
4962
4963**示例:**
4964<!--code_no_check-->
4965```ts
4966// EntryAbility.ets
4967import { UIAbility } from '@kit.AbilityKit';
4968import { BusinessError } from '@kit.BasicServicesKit';
4969
4970export default class EntryAbility extends UIAbility {
4971
4972  // ...
4973  onWindowStageCreate(windowStage: window.WindowStage) {
4974    console.info('onWindowStageCreate');
4975    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
4976    if (!windowClass) {
4977      console.info('windowClass is null');
4978    }
4979    try {
4980      let ratio = 1.0;
4981      let promise = windowClass.setAspectRatio(ratio);
4982      promise.then(() => {
4983        console.info('Succeeded in setting aspect ratio of window.');
4984      }).catch((err: BusinessError) => {
4985        console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`);
4986      });
4987    } catch (exception) {
4988      console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`);
4989    }
4990  }
4991}
4992```
4993
4994### setAspectRatio<sup>10+</sup>
4995
4996setAspectRatio(ratio: number, callback: AsyncCallback&lt;void&gt;): void
4997
4998设置窗口内容布局的比例,使用callback异步回调。
4999
5000仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。
5001
5002**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5003
5004**系统能力:** SystemCapability.WindowManager.WindowManager.Core
5005
5006**参数:**
5007
5008| 参数名             | 类型    | 必填 | 说明                                         |
5009| ------------------ | ------- | ---- |--------------------------------------------|
5010| ratio | number | 是   | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,受窗口最大最小尺寸限制,比例值下限为最小宽度/最大高度,上限为最大宽度/最小高度。窗口最大最小尺寸由[WindowLimits](#windowlimits11)和系统限制的交集决定,系统限制优先级高于[WindowLimits](#windowlimits11)。 |
5011| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                      |
5012
5013**错误码:**
5014
5015以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5016
5017| 错误码ID | 错误信息 |
5018| ------- | -------------------------------------------- |
5019| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5020| 1300002 | This window state is abnormal.               |
5021| 1300004 | Unauthorized operation.                      |
5022
5023**示例:**
5024<!--code_no_check-->
5025```ts
5026// EntryAbility.ets
5027import { UIAbility } from '@kit.AbilityKit';
5028import { BusinessError } from '@kit.BasicServicesKit';
5029
5030export default class EntryAbility extends UIAbility {
5031
5032  // ...
5033  onWindowStageCreate(windowStage: window.WindowStage) {
5034    console.info('onWindowStageCreate');
5035    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
5036    if (!windowClass) {
5037      console.info('Failed to load the content. Cause: windowClass is null');
5038    }
5039    try {
5040      let ratio = 1.0;
5041      windowClass.setAspectRatio(ratio, (err: BusinessError) => {
5042        const errCode: number = err.code;
5043        if (errCode) {
5044          console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`);
5045          return;
5046        }
5047        console.info('Succeeded in setting the aspect ratio of window.');
5048      });
5049    } catch (exception) {
5050      console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`);
5051    }
5052  }
5053}
5054
5055```
5056
5057### resetAspectRatio<sup>10+</sup>
5058
5059resetAspectRatio(): Promise&lt;void&gt;
5060
5061取消设置窗口内容布局的比例,使用Promise异步回调。
5062
5063仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,调用后将清除持久化储存的比例信息。
5064
5065**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5066
5067**系统能力:** SystemCapability.WindowManager.WindowManager.Core
5068
5069**返回值:**
5070
5071| 类型                | 说明                      |
5072| ------------------- | ------------------------- |
5073| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5074
5075**错误码:**
5076
5077以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
5078
5079| 错误码ID | 错误信息 |
5080| ------- | -------------------------------------------- |
5081| 1300002 | This window state is abnormal.               |
5082| 1300004 | Unauthorized operation.                      |
5083
5084**示例:**
5085<!--code_no_check-->
5086```ts
5087// EntryAbility.ets
5088import { UIAbility } from '@kit.AbilityKit';
5089import { BusinessError } from '@kit.BasicServicesKit';
5090
5091export default class EntryAbility extends UIAbility {
5092
5093  // ...
5094  onWindowStageCreate(windowStage: window.WindowStage) {
5095    console.info('onWindowStageCreate');
5096    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
5097    if (!windowClass) {
5098      console.info('Failed to load the content. Cause: windowClass is null');
5099    }
5100    try {
5101      let promise = windowClass.resetAspectRatio();
5102      promise.then(() => {
5103        console.info('Succeeded in resetting aspect ratio of window.');
5104      }).catch((err: BusinessError) => {
5105        console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`);
5106      });
5107    } catch (exception) {
5108      console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`);
5109    }
5110  }
5111}
5112```
5113
5114### resetAspectRatio<sup>10+</sup>
5115
5116resetAspectRatio(callback: AsyncCallback&lt;void&gt;): void
5117
5118取消设置窗口内容布局的比例,使用callback异步回调。
5119
5120仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,调用后将清除持久化储存的比例信息。
5121
5122**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5123
5124**系统能力:** SystemCapability.WindowManager.WindowManager.Core
5125
5126**参数:**
5127
5128| 参数名             | 类型    | 必填 | 说明                                                         |
5129| ------------------ | ------- | ---- | ------------------------------------------------------------ |
5130| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
5131
5132**错误码:**
5133
5134以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
5135
5136| 错误码ID | 错误信息 |
5137| ------- | -------------------------------------------- |
5138| 1300002 | This window state is abnormal.               |
5139| 1300004 | Unauthorized operation.                      |
5140
5141**示例:**
5142<!--code_no_check-->
5143```ts
5144// EntryAbility.ets
5145import { UIAbility } from '@kit.AbilityKit';
5146import { BusinessError } from '@kit.BasicServicesKit';
5147
5148export default class EntryAbility extends UIAbility {
5149
5150  // ...
5151  onWindowStageCreate(windowStage: window.WindowStage) {
5152    console.info('onWindowStageCreate');
5153    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
5154    if (!windowClass) {
5155      console.info('Failed to load the content. Cause: windowClass is null');
5156    }
5157    try {
5158      windowClass.resetAspectRatio((err: BusinessError) => {
5159        const errCode: number = err.code;
5160        if (errCode) {
5161          console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`);
5162          return;
5163        }
5164        console.info('Succeeded in resetting aspect ratio of window.');
5165      });
5166    } catch (exception) {
5167      console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`);
5168    }
5169  }
5170}
5171```
5172
5173### minimize<sup>11+</sup>
5174
5175minimize(callback: AsyncCallback&lt;void&gt;): void
5176
5177此接口根据调用对象不同,实现不同的两个功能:
5178
5179当调用对象为主窗口时,实现最小化功能,可在Dock栏中还原;
5180
5181当调用对象为子窗口时,实现隐藏功能,不可在Dock栏中还原。
5182
5183使用callback异步回调。
5184
5185**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5186
5187**系统能力:** SystemCapability.Window.SessionManager
5188
5189**参数:**
5190
5191| 参数名   | 类型                      | 必填 | 说明       |
5192| -------- | ------------------------- | ---- | ---------- |
5193| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。 |
5194
5195**错误码:**
5196
5197以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5198
5199| 错误码ID | 错误信息 |
5200| ------- | ------------------------------ |
5201| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5202| 1300002 | This window state is abnormal. |
5203| 1300003 | This window manager service works abnormally. |
5204
5205**示例:**
5206
5207```ts
5208import { BusinessError } from '@kit.BasicServicesKit';
5209
5210windowClass.minimize((err: BusinessError) => {
5211  const errCode: number = err.code;
5212  if (errCode) {
5213    console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`);
5214    return;
5215  }
5216  console.info('Succeeded in minimizing the window.');
5217});
5218```
5219
5220### minimize<sup>11+</sup>
5221
5222minimize(): Promise&lt;void&gt;
5223
5224此接口根据调用对象不同,实现不同的两个功能:
5225
5226当调用对象为主窗口时,实现最小化功能,可在Dock栏中还原;
5227
5228当调用对象为子窗口时,实现隐藏功能,不可在Dock栏中还原。
5229
5230使用Promise异步回调。
5231
5232**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5233
5234**系统能力:** SystemCapability.Window.SessionManager
5235
5236**返回值:**
5237
5238| 类型                | 说明                      |
5239| ------------------- | ------------------------- |
5240| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5241
5242**错误码:**
5243
5244以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5245
5246| 错误码ID | 错误信息 |
5247| ------- | ------------------------------ |
5248| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5249| 1300002 | This window state is abnormal. |
5250| 1300003 | This window manager service works abnormally. |
5251
5252**示例:**
5253
5254```ts
5255import { BusinessError } from '@kit.BasicServicesKit';
5256
5257let promise = windowClass.minimize();
5258promise.then(() => {
5259  console.info('Succeeded in minimizing the window.');
5260}).catch((err: BusinessError) => {
5261  console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`);
5262});
5263```
5264
5265### maximize<sup>12+</sup>
5266maximize(presentation?: MaximizePresentation): Promise&lt;void&gt;
5267
5268主窗口调用,实现最大化功能,使用Promise异步回调,仅2in1设备可用。
5269
5270**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5271
5272**系统能力:** SystemCapability.Window.SessionManager
5273
5274**参数:**
5275
5276| 参数名 | 类型  | 必填 | 说明 |
5277| ----- | ---------------------------- | -- | --------------------------------- |
5278| presentation  | [MaximizePresentation](#maximizepresentation12) | 否 | 主窗口最大化时候的布局枚举。默认值window.MaximizePresentation.ENTER_IMMERSIVE,即默认最大化时进入沉浸式布局。 |
5279
5280**返回值:**
5281
5282| 类型                | 说明                      |
5283| ------------------- | ------------------------- |
5284| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5285
5286**错误码:**
5287
5288以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5289
5290| 错误码ID | 错误信息 |
5291| ------- | ------------------------------ |
5292| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5293| 1300002 | This window state is abnormal.                |
5294| 1300003 | This window manager service works abnormally. |
5295| 1300004 | Unauthorized operation.                       |
5296| 1300005 | This window stage is abnormal. |
5297
5298**示例:**
5299
5300```ts
5301// EntryAbility.ets
5302import { UIAbility } from '@kit.AbilityKit';
5303import { BusinessError } from '@kit.BasicServicesKit';
5304export default class EntryAbility extends UIAbility {
5305  // ...
5306
5307  onWindowStageCreate(windowStage: window.WindowStage) {
5308    console.info('onWindowStageCreate');
5309    let windowClass: window.Window | undefined = undefined;
5310    windowStage.getMainWindow((err: BusinessError, data) => {
5311      const errCode: number = err.code;
5312      if (errCode) {
5313        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
5314        return;
5315      }
5316      windowClass = data;
5317      let promise = windowClass.maximize();
5318      // let promise = windowClass.maximize(window.MaximizePresentation.ENTER_IMMERSIVE);
5319      promise.then(() => {
5320        console.info('Succeeded in maximizing the window.');
5321      }).catch((err: BusinessError) => {
5322        console.error(`Failed to maximize the window. Cause code: ${err.code}, message: ${err.message}`);
5323      });
5324    });
5325  }
5326};
5327```
5328
5329### recover<sup>11+</sup>
5330
5331recover(): Promise&lt;void&gt;
5332
5333将主窗口从全屏、最大化、分屏模式下还原为浮动窗口,并恢复到进入该模式之前的大小和位置,已经是浮动窗口模式不可再还原。使用Promise异步回调。此接口仅在多窗层叠布局效果下生效,仅2in1设备可用。
5334
5335**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5336
5337**系统能力:** SystemCapability.Window.SessionManager
5338
5339**返回值:**
5340
5341| 类型                | 说明                      |
5342| ------------------- | ------------------------- |
5343| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5344
5345**错误码:**
5346
5347以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5348
5349| 错误码ID | 错误信息 |
5350| ------- | ------------------------------ |
5351| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5352| 1300001 | Repeated operation. |
5353| 1300002 | This window state is abnormal. |
5354
5355**示例:**
5356
5357```ts
5358// EntryAbility.ets
5359import { UIAbility } from '@kit.AbilityKit';
5360import { BusinessError } from '@kit.BasicServicesKit';
5361
5362export default class EntryAbility extends UIAbility {
5363  // ...
5364  onWindowStageCreate(windowStage: window.WindowStage): void {
5365    console.info('onWindowStageCreate');
5366    let windowClass: window.Window | undefined = undefined;
5367    windowStage.getMainWindow((err: BusinessError, data) => {
5368      const errCode: number = err.code;
5369      if (errCode) {
5370        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
5371        return;
5372      }
5373      windowClass = data;
5374      let promise = windowClass.recover();
5375      promise.then(() => {
5376        console.info('Succeeded in recovering the window.');
5377      }).catch((err: BusinessError) => {
5378        console.error(`Failed to recover the window. Cause code: ${err.code}, message: ${err.message}`);
5379      });
5380    });
5381  }
5382}
5383```
5384
5385### restore<sup>14+</sup>
5386
5387restore(): Promise&lt;void&gt;
5388
5389将主窗口从最小化状态,恢复到前台显示,并恢复到进入该模式之前的大小和位置。使用Promise异步回调。  
5390此接口仅在多窗层叠布局效果下生效,仅在主窗口为最小化状态且UIAbility生命周期为onForeground时生效,仅2in1设备可用。
5391
5392**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
5393
5394**系统能力:** SystemCapability.Window.SessionManager
5395
5396**返回值:**
5397
5398| 类型                | 说明                      |
5399| ------------------- | ------------------------- |
5400| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5401
5402**错误码:**
5403
5404以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5405
5406| **错误码ID** | **错误信息**                                                 |
5407| ------------ | ------------------------------------------------------------ |
5408| 801          | Capability not supported. Failed to call the API due to limited device capabilities. |
5409| 1300002      | This window state is abnormal.                               |
5410| 1300003      | This window manager service works abnormally.                |
5411| 1300004      | Unauthorized operation.                                      |
5412
5413**示例**
5414
5415```ts
5416// EntryAbility.ets
5417import { UIAbility } from '@kit.AbilityKit';
5418import { BusinessError } from '@kit.BasicServicesKit';
5419import { window } from '@kit.ArkUI';
5420import { BusinessError } from '@kit.BasicServicesKit';
5421
5422export default class EntryAbility extends UIAbility {
5423  onWindowStageCreate(windowStage: window.WindowStage): void {
5424    // 加载主窗口对应的页面
5425    windowStage.loadContent('pages/Index', (err) => {
5426      let mainWindow: window.Window | undefined = undefined;
5427      // 获取应用主窗口。
5428      windowStage.getMainWindow().then(
5429        data => {
5430          mainWindow = data;
5431          console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
5432          // 调用minimize, 使主窗缩小。
5433          mainWindow.minimize();
5434          //设置延时函数延时5秒钟后对主窗进行恢复。
5435          setTimeout(()=>{
5436              //调用restore()函数对主窗进行恢复。
5437              let promise = mainWindow.restore();
5438              promise.then(() => {
5439                  console.info('Succeeded in restoring the window.');
5440              }).catch((err: BusinessError) => {
5441                  console.error(`Failed to restore the window. Cause code: ${err.code}, 
5442                  message: ${err.message}`);
5443              });
5444          },5000);
5445        }
5446      ).catch((err: BusinessError) => {
5447          if(err.code){
5448            console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
5449          }
5450      });
5451    });
5452  }
5453}
5454```
5455
5456### getWindowLimits<sup>11+</sup>
5457
5458getWindowLimits(): WindowLimits
5459
5460获取当前应用窗口的尺寸限制。
5461
5462**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5463
5464**系统能力:** SystemCapability.Window.SessionManager
5465
5466**返回值:**
5467
5468| 类型                          | 说明           |
5469| ----------------------------- | ------------------ |
5470| [WindowLimits](#windowlimits11) | 当前窗口尺寸限制。 |
5471
5472**错误码:**
5473
5474以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5475
5476| 错误码ID | 错误信息                       |
5477| :------- | :----------------------------- |
5478| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5479| 1300002  | This window state is abnormal. |
5480
5481**示例:**
5482
5483```ts
5484try {
5485  let windowLimits = windowClass.getWindowLimits();
5486} catch (exception) {
5487  console.error(`Failed to obtain the window limits of window. Cause code: ${exception.code}, message: ${exception.message}`);
5488}
5489```
5490
5491### setWindowLimits<sup>11+</sup>
5492
5493setWindowLimits(windowLimits: WindowLimits): Promise&lt;WindowLimits&gt;
5494
5495设置当前应用窗口的尺寸限制,使用Promise异步回调。
5496默认存在一个系统尺寸限制,系统尺寸限制由产品配置决定,不可修改。未调用setWindowLimits配置过WindowLimits时,使用[getWindowLimits](#getwindowlimits11)可获取系统限制。
5497
5498**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5499
5500**系统能力:** SystemCapability.Window.SessionManager
5501
5502**参数:**
5503
5504| 参数名       | 类型                          | 必填 | 说明                           |
5505| :----------- | :---------------------------- | :--- | :----------------------------- |
5506| windowLimits | [WindowLimits](#windowlimits11) | 是   | 目标窗口的尺寸限制,单位为px。 |
5507
5508**返回值:**
5509
5510| 类型                                         | 说明                                |
5511| :------------------------------------------- | :---------------------------------- |
5512| Promise&lt;[WindowLimits](#windowlimits11)&gt; | Promise对象。返回设置后的尺寸限制,为入参与系统尺寸限制的交集。 |
5513
5514**错误码:**
5515
5516以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5517
5518| 错误码ID | 错误信息                                      |
5519| :------- | :-------------------------------------------- |
5520| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5521| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5522| 1300002  | This window state is abnormal.                |
5523| 1300003  | This window manager service works abnormally. |
5524| 1300004 | Unauthorized operation.                |
5525
5526**示例:**
5527
5528```ts
5529import { BusinessError } from '@kit.BasicServicesKit';
5530try {
5531  let windowLimits: window.WindowLimits = {
5532    maxWidth: 1500,
5533    maxHeight: 1000,
5534    minWidth: 500,
5535    minHeight: 400
5536  };
5537  let promise = windowClass.setWindowLimits(windowLimits);
5538    promise.then((data) => {
5539    console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data));
5540  }).catch((err: BusinessError) => {
5541    console.error(`Failed to change the window limits. Cause code: ${err.code}, message: ${err.message}`);
5542  });
5543} catch (exception) {
5544  console.error(`Failed to change the window limits. Cause code: ${exception.code}, message: ${exception.message}`);
5545}
5546```
5547
5548### setWindowMask<sup>12+</sup>
5549
5550setWindowMask(windowMask: Array&lt;Array&lt;number&gt;&gt;): Promise&lt;void&gt;;
5551
5552设置异形窗口的掩码,使用Promise异步回调。异形窗口为非常规形状的窗口,掩码用于描述异形窗口的形状。此接口仅限子窗和全局悬浮窗可用,仅2in1设备可用。
5553
5554**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5555
5556**系统能力:** SystemCapability.Window.SessionManager
5557
5558**参数:**
5559
5560| 参数名       | 类型                          | 必填 | 说明                           |
5561| :----------- | :---------------------------- | :--- | :----------------------------- |
5562| windowMask | Array&lt;Array&lt;number&gt;&gt; | 是   | 异形窗口的掩码,该参数仅支持宽高为窗口宽高、取值为整数0和整数1的二维数组输入,整数0代表所在像素透明,整数1代表所在像素不透明,宽高不符合的二维数组或二维数组取值不为整数0和整数1的二维数组为非法参数。 |
5563
5564**返回值:**
5565
5566| 类型                                         | 说明                                |
5567| :------------------------------------------- | :---------------------------------- |
5568| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5569
5570**错误码:**
5571
5572以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5573
5574| 错误码ID | 错误信息                                      |
5575| :------- | :-------------------------------------------- |
5576| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5577| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5578| 1300002  | This window state is abnormal.                |
5579| 1300003  | This window manager service works abnormally. |
5580| 1300004  | Unauthorized operation.                       |
5581
5582**示例:**
5583
5584```ts
5585import { BusinessError } from '@kit.BasicServicesKit';
5586try {
5587  let windowMask: Array<Array<number>> = [
5588      [0, 0, 0, 1, 0, 0, 0],
5589      [0, 0, 1, 1, 1, 0, 0],
5590      [0, 1, 1, 0, 1, 1, 0],
5591      [1, 1, 0, 0, 0, 1, 1]
5592    ];
5593  let promise = windowClass.setWindowMask(windowMask);
5594    promise.then(() => {
5595    console.info('Succeeded in setting the window mask.');
5596  }).catch((err: BusinessError) => {
5597    console.error(`Failed to set the window mask. Cause code: ${err.code}, message: ${err.message}`);
5598  });
5599} catch (exception) {
5600  console.error(`Failed to set the window mask. Cause code: ${exception.code}, message: ${exception.message}`);
5601}
5602```
5603
5604### keepKeyboardOnFocus<sup>11+</sup>
5605
5606keepKeyboardOnFocus(keepKeyboardFlag: boolean): void
5607
5608窗口获焦时保留由其他窗口创建的软键盘,仅支持系统窗口与应用子窗口。
5609
5610**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5611
5612**系统能力:** SystemCapability.Window.SessionManager
5613
5614**参数:**
5615
5616| 参数名           | 类型    | 必填 | 说明                                                         |
5617| ---------------- | ------- | ---- | ------------------------------------------------------------ |
5618| keepKeyboardFlag | boolean | 是   | 是否保留其他窗口创建的软键盘。true表示保留;false表示不保留。|
5619
5620**错误码:**
5621
5622以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5623
5624| 错误码ID | 错误信息 |
5625| ------- | ---------------------------------------- |
5626| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5627| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5628| 1300002 | This window state is abnormal.           |
5629| 1300004 | Unauthorized operation.                  |
5630
5631**示例:**
5632
5633```ts
5634try {
5635  windowClass.keepKeyboardOnFocus(true);
5636} catch (exception) {
5637  console.error(`Failed to keep keyboard onFocus. Cause code: ${exception.code}, message: ${exception.message}`);
5638}
5639```
5640
5641### setWindowDecorVisible<sup>11+</sup>
5642
5643setWindowDecorVisible(isVisible: boolean): void
5644
5645设置窗口标题栏是否可见,对存在标题栏和三键区的窗口形态生效。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
5646
5647**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5648
5649**系统能力:** SystemCapability.Window.SessionManager
5650
5651**参数:**
5652
5653| 参数名    | 类型    | 必填 | 说明                                          |
5654| --------- | ------- | ---- | --------------------------------------------- |
5655| isVisible | boolean | 是   | 设置标题栏是否可见,true为可见,false为隐藏。 |
5656
5657**错误码:**
5658
5659以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5660
5661| 错误码ID | 错误信息                       |
5662| -------- | ------------------------------ |
5663| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5664| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5665| 1300002  | This window state is abnormal. |
5666| 1300004  | Unauthorized operation.        |
5667
5668**示例:**
5669
5670```ts
5671import { BusinessError } from '@kit.BasicServicesKit';
5672let storage: LocalStorage = new LocalStorage();
5673storage.setOrCreate('storageSimpleProp', 121);
5674windowClass.loadContent("pages/page2", storage, (err: BusinessError) => {
5675  let errCode: number = err.code;
5676  if (errCode) {
5677    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
5678    return;
5679  }
5680  console.info('Succeeded in loading the content.');
5681  let isVisible = false;
5682  // 调用setWindowDecorVisible接口
5683  try {
5684      windowClass?.setWindowDecorVisible(isVisible);
5685  } catch (exception) {
5686      console.error(`Failed to set the visibility of window decor. Cause code: ${exception.code}, message: ${exception.message}`);
5687  }
5688});
5689```
5690
5691### setSubWindowModal<sup>12+</sup>
5692
5693setSubWindowModal(isModal: boolean): Promise&lt;void&gt;
5694
5695设置子窗的模态属性是否启用,使用Promise异步回调。
5696
5697子窗口调用该接口时,设置子窗口模态属性是否启用。启用子窗口模态属性后,其父级窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态属性被禁用。
5698
5699子窗口之外的窗口调用该接口时,会报错。
5700
5701**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5702
5703**系统能力:** SystemCapability.Window.SessionManager
5704
5705**参数:**
5706
5707| 参数名    | 类型    | 必填 | 说明                                          |
5708| --------- | ------- | ---- | --------------------------------------------- |
5709| isModal | boolean | 是   | 设置子窗口模态属性是否启用,true为启用,false为不启用。 |
5710
5711
5712**返回值:**
5713
5714| 类型 | 说明 |
5715| ------------------- | ------------------------ |
5716| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5717
5718**错误码:**
5719
5720以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5721
5722| 错误码ID | 错误信息                       |
5723| -------- | ------------------------------ |
5724| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5725| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5726| 1300002  | This window state is abnormal. |
5727| 1300004  | Unauthorized operation.        |
5728
5729**示例:**
5730
5731```ts
5732// EntryAbility.ets
5733import { UIAbility } from '@kit.AbilityKit';
5734import { BusinessError } from '@kit.BasicServicesKit';
5735
5736export default class EntryAbility extends UIAbility {
5737  // ...
5738  onWindowStageCreate(windowStage: window.WindowStage): void {
5739    console.info('onWindowStageCreate');
5740    let windowClass: window.Window | undefined = undefined;
5741    // 创建子窗
5742    try {
5743      let subWindow = windowStage.createSubWindow("testSubWindow");
5744      subWindow.then((data) => {
5745        if (data == null) {
5746          console.error("Failed to create the subWindow. Cause: The data is empty");
5747          return;
5748        }
5749        windowClass = data;
5750        let promise = windowClass.setSubWindowModal(true);
5751        promise.then(() => {
5752          console.info('Succeeded in setting subwindow modal');
5753        }).catch((err: BusinessError) => {
5754          console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`);
5755        });
5756      });
5757    } catch (exception) {
5758      console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`);
5759    }
5760  }
5761}
5762```
5763
5764### setSubWindowModal<sup>14+</sup>
5765
5766setSubWindowModal(isModal: boolean, modalityType: ModalityType): Promise&lt;void&gt;
5767
5768设置子窗的模态类型,使用Promise异步回调。
5769
5770当子窗口模态类型为模窗口子窗时,其父级窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态类型被禁用。
5771
5772当子窗口模态类型为模应用子窗时,其父级窗口与该应用其他实例的窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态类型被禁用。
5773
5774此接口仅支持设置子窗口模态类型,当需要禁用子窗口模态属性时,建议使用[setSubWindowModal<sup>12+</sup>](#setsubwindowmodal12)。
5775
5776子窗口之外的窗口调用该接口时,会报错。
5777
5778**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
5779
5780**系统能力:** SystemCapability.Window.SessionManager
5781
5782**参数:**
5783
5784| 参数名    | 类型    | 必填 | 说明                                          |
5785| --------- | ------- | ---- | --------------------------------------------- |
5786| isModal | boolean | 是   | 设置子窗口模态属性是否启用,true为启用,false为不启用。当前仅支持设置为true。 |
5787| modalityType | [ModalityType](#modalitytype14) | 是   | 子窗口模态类型。 |
5788
5789**返回值:**
5790
5791| 类型 | 说明 |
5792| ------------------- | ------------------------ |
5793| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5794
5795**错误码:**
5796
5797以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5798
5799| 错误码ID | 错误信息                       |
5800| -------- | ------------------------------ |
5801| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5802| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5803| 1300002  | This window state is abnormal. |
5804| 1300004  | Unauthorized operation.        |
5805
5806**示例:**
5807
5808```ts
5809// EntryAbility.ets
5810import { UIAbility } from '@kit.AbilityKit';
5811import { BusinessError } from '@kit.BasicServicesKit';
5812import { window } from '@kit.ArkUI';
5813
5814export default class EntryAbility extends UIAbility {
5815  // ...
5816  onWindowStageCreate(windowStage: window.WindowStage): void {
5817    console.info('onWindowStageCreate');
5818    let windowClass: window.Window | undefined = undefined;
5819    // 创建子窗
5820    try {
5821      let subWindow = windowStage.createSubWindow("testSubWindow");
5822      subWindow.then((data) => {
5823        if (data == null) {
5824          console.error("Failed to create the subWindow. Cause: The data is empty");
5825          return;
5826        }
5827        windowClass = data;
5828        let promise = windowClass.setSubWindowModal(true, window.ModalityType.WINDOW_MODALITY);
5829        promise.then(() => {
5830          console.info('Succeeded in setting subwindow modal');
5831        }).catch((err: BusinessError) => {
5832          console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`);
5833        });
5834      });
5835    } catch (exception) {
5836      console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`);
5837    }
5838  }
5839}
5840```
5841
5842### setWindowDecorHeight<sup>11+</sup>
5843
5844setWindowDecorHeight(height: number): void
5845
5846<!--RP1-->
5847设置窗口的标题栏高度,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
5848<!--RP1End-->
5849
5850**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5851
5852**系统能力:** SystemCapability.Window.SessionManager
5853
5854**参数:**
5855
5856| 参数名 | 类型   | 必填 | 说明                                                         |
5857| ------ | ------ | ---- | ------------------------------------------------------------ |
5858| height | number | 是   |设置的窗口标题栏高度,仅支持具有窗口标题栏的窗口。该参数为整数,浮点数输入将向下取整,取值范围为[37,112],范围外为非法参数,单位为vp。 |
5859
5860**错误码:**
5861
5862以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5863
5864| 错误码ID | 错误信息                       |
5865| -------- | ------------------------------ |
5866| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5867| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5868| 1300002  | This window state is abnormal. |
5869
5870**示例:**
5871
5872```ts
5873windowClass.setUIContent('pages/WindowPage').then(() => {
5874  let height: number = 50;
5875  try {
5876    windowClass?.setWindowDecorHeight(height);
5877    console.info(`Succeeded in setting the height of window decor: ${height}`);
5878  } catch (exception) {
5879    console.error(`Failed to set the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`);
5880  }
5881})
5882```
5883
5884### getWindowDecorHeight<sup>11+</sup>
5885
5886getWindowDecorHeight(): number
5887
5888<!--RP2-->
5889获取窗口的标题栏高度,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
5890<!--RP2End-->
5891
5892**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5893
5894**系统能力:** SystemCapability.Window.SessionManager
5895
5896**返回值:**
5897
5898| 类型   | 说明                                                         |
5899| ------ | ------------------------------------------------------------ |
5900| number | 返回的窗口标题栏高度。该参数为整数,取值范围为[37,112],单位为vp。 |
5901
5902**错误码:**
5903
5904以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5905
5906| 错误码ID | 错误信息                       |
5907| -------- | ------------------------------ |
5908| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5909| 1300002  | This window state is abnormal. |
5910
5911**示例:**
5912
5913```ts
5914windowClass.setUIContent('pages/WindowPage').then(() => {
5915  try {
5916    let height = windowClass?.getWindowDecorHeight();
5917    console.info(`Succeeded in getting the height of window decor: ${height}`);
5918  } catch (exception) {
5919    console.error(`Failed to get the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`);
5920  }
5921})
5922```
5923
5924### getTitleButtonRect<sup>11+</sup>
5925
5926getTitleButtonRect(): TitleButtonRect
5927
5928<!--RP3-->获取主窗口或启用装饰的子窗口的标题栏上的最小化、最大化、关闭按钮矩形区域,此接口仅可在2in1设备上使用。<!--RP3End-->
5929
5930**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5931
5932**系统能力:** SystemCapability.Window.SessionManager
5933
5934**返回值:**
5935
5936| 类型                                  | 说明                                                         |
5937| ------------------------------------- | ------------------------------------------------------------ |
5938| [TitleButtonRect](#titlebuttonrect11) | 标题栏上的最小化、最大化、关闭按钮矩形区域,该区域位置坐标相对窗口右上角。 |
5939
5940**错误码:**
5941
5942以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5943
5944| 错误码ID | 错误信息                       |
5945| -------- | ------------------------------ |
5946| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5947| 1300002  | This window state is abnormal. |
5948
5949**示例:**
5950
5951```ts
5952// EntryAbility.ets
5953import { UIAbility } from '@kit.AbilityKit';
5954import { BusinessError } from '@kit.BasicServicesKit';
5955
5956export default class EntryAbility extends UIAbility {
5957  // ...
5958  onWindowStageCreate(windowStage: window.WindowStage): void {
5959    console.info('onWindowStageCreate');
5960    let windowClass: window.Window | undefined = undefined;
5961    windowStage.getMainWindow((err: BusinessError, data) => {
5962      const errCode: number = err.code;
5963      if (errCode) {
5964        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
5965        return;
5966      }
5967      windowClass = data;
5968      try {
5969        let titleButtonArea = windowClass.getTitleButtonRect();
5970        console.info('Succeeded in obtaining the area of title buttons. Data: ' + JSON.stringify(titleButtonArea));
5971      } catch (exception) {
5972        console.error(`Failed to get the area of title buttons. Cause code: ${exception.code}, message: ${exception.message}`);
5973      }
5974    });
5975  }
5976}
5977```
5978
5979### getWindowStatus<sup>12+</sup>
5980
5981getWindowStatus(): WindowStatusType
5982
5983获取当前应用窗口的模式。
5984
5985**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5986
5987**系统能力:** SystemCapability.Window.SessionManager
5988
5989**返回值:**
5990
5991| 类型                           | 说明                                   |
5992| ------------------------------ | ----------------------------------------|
5993| [WindowStatusType](#windowstatustype11) | 当前窗口模式。                              |
5994
5995**错误码:**
5996
5997以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5998
5999| 错误码ID | 错误信息 |
6000| ------- | ------------------------------ |
6001| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
6002| 1300002  | This window state is abnormal. |
6003
6004**示例:**
6005
6006```ts
6007try {
6008  let windowStatusType = windowClass.getWindowStatus();
6009} catch (exception) {
6010  console.error(`Failed to obtain the window status of window. Cause code: ${exception.code}, message: ${exception.message}`);
6011}
6012```
6013
6014### isFocused<sup>12+</sup>
6015
6016isFocused(): boolean
6017
6018判断当前窗口是否已获焦。
6019
6020**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6021
6022**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6023
6024**返回值:**
6025
6026| 类型 | 说明 |
6027| ------- | ------------------------------------------------------------------ |
6028| boolean | 当前窗口是否已获焦。true表示当前窗口已获焦,false则表示当前窗口未获焦。 |
6029
6030**错误码:**
6031
6032以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
6033
6034| 错误码ID | 错误信息 |
6035| ------- | ------------------------------ |
6036| 1300002 | This window state is abnormal. |
6037
6038**示例:**
6039
6040```ts
6041try {
6042  let focus = windowClass.isFocused();
6043  console.info('Succeeded in checking whether the window is focused. Data: ' + JSON.stringify(focus));
6044} catch (exception) {
6045  console.error(`Failed to check whether the window is focused. Cause code: ${exception.code}, message: ${exception.message}`);
6046}
6047```
6048
6049### createSubWindowWithOptions<sup>12+</sup>
6050
6051createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise&lt;Window&gt;
6052
6053创建主窗口或子窗口下的子窗口,使用Promise异步回调,该接口仅在2in1设备上调用生效。
6054
6055**模型约束:** 此接口仅可在Stage模型下使用。
6056
6057**系统能力:** SystemCapability.Window.SessionManager
6058
6059**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6060
6061**参数:**
6062
6063| 参数名 | 类型   | 必填 | 说明           |
6064| ------ | ------ | ---- | -------------- |
6065| name   | string | 是   | 子窗口的名字。 |
6066| options  | [SubWindowOptions](#subwindowoptions12) | 是   | 子窗口参数。  |
6067
6068**返回值:**
6069
6070| 类型                             | 说明                                             |
6071| -------------------------------- | ------------------------------------------------ |
6072| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前Window下创建的子窗口对象。 |
6073
6074**错误码:**
6075
6076以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6077
6078| 错误码ID | 错误信息 |
6079| ------- | ------------------------------ |
6080| 401     | Parameter error. Possible cause: 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
6089import { BusinessError } from '@kit.BasicServicesKit';
6090
6091try {
6092  let options : window.SubWindowOptions = {
6093    title: 'title',
6094    decorEnabled: true,
6095    isModal: true
6096  };
6097  let promise = windowClass.createSubWindowWithOptions('mySubWindow', options);
6098  promise.then((data) => {
6099    console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
6100  }).catch((err: BusinessError) => {
6101    console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`);
6102  });
6103} catch (exception) {
6104  console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`);
6105}
6106```
6107
6108### setWindowTitleButtonVisible<sup>14+</sup>
6109
6110setWindowTitleButtonVisible(isMaximizeVisible: boolean, isMinimizeVisible: boolean): void
6111
6112设置主窗标题栏上的最大化、最小化按钮是否可见。
6113
6114此接口仅支持2in1设备。
6115
6116**系统能力:** SystemCapability.Window.SessionManager
6117
6118**参数:**
6119
6120| 参数名    | 类型    | 必填 | 说明                                          |
6121| --------- | ------- | ---- | --------------------------------------------- |
6122| isMaximizeVisible | boolean | 是   | 设置最大化按钮是否可见,true为可见,false为隐藏。如果最大化按钮隐藏,那么在最大化场景下,也隐藏对应的还原按钮。 |
6123| isMinimizeVisible | boolean | 是   | 设置最小化按钮是否可见,true为可见,false为隐藏。 |
6124
6125**错误码:**
6126
6127以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6128
6129| 错误码ID | 错误信息                       |
6130| -------- | ------------------------------ |
6131| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6132| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
6133| 1300002  | This window state is abnormal. |
6134| 1300004  | Unauthorized operation. |
6135
6136**示例:**
6137
6138```ts
6139// EntryAbility.ets
6140import { UIAbility } from '@kit.AbilityKit';
6141import { BusinessError } from '@kit.BasicServicesKit';
6142import { window } from '@kit.ArkUI';
6143
6144export default class EntryAbility extends UIAbility {
6145  onWindowStageCreate(windowStage: window.WindowStage): void {
6146    // 加载主窗口对应的页面
6147    windowStage.loadContent('pages/Index', (err) => {
6148      let mainWindow: window.Window | undefined = undefined;
6149      // 获取应用主窗口。
6150      windowStage.getMainWindow().then(
6151        data => {
6152          mainWindow = data;
6153          console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
6154          // 调用setWindowTitleButtonVisible接口,隐藏主窗标题栏最大化、最小化按钮。
6155          mainWindow.setWindowTitleButtonVisible(false, false);
6156        }
6157      ).catch((err: BusinessError) => {
6158          if(err.code){
6159            console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6160          }
6161      });
6162    });
6163  }
6164}
6165```
6166
6167### setWindowTopmost<sup>14+</sup>
6168
6169setWindowTopmost(isWindowTopmost: boolean): Promise&lt;void&gt;
6170
6171应用主窗口调用,实现将窗口置于其他应用窗口之上不被遮挡,使用Promise异步回调。<br>
6172应用可通过自定义快捷键实现主窗口的置顶和取消置顶。<br>
6173此接口仅支持2in1设备。
6174
6175**系统能力:** SystemCapability.Window.SessionManager<br>
6176**需要权限:** ohos.permission.WINDOW_TOPMOST
6177
6178**参数:**
6179
6180| 参数名    | 类型    | 必填 | 说明                                          |
6181| --------- | ------- | ---- | --------------------------------------------- |
6182| isWindowTopmost | boolean | 是   | 设置主窗口置顶,true为置顶,false为取消置顶。 |
6183
6184
6185**错误码:**
6186
6187以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6188
6189| 错误码ID | 错误信息                       |
6190| -------- | ------------------------------ |
6191| 201      | Permission verification failed. The application does not have the permission required to call the API.  |
6192| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6193| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
6194| 1300002  | This window state is abnormal. |
6195| 1300004  | Unauthorized operation. |
6196
6197**示例:**
6198
6199```ts
6200// ets/pages/Index.ets
6201import { window } from '@kit.ArkUI';
6202import { common } from '@kit.AbilityKit';
6203import { BusinessError } from '@kit.BasicServicesKit';
6204
6205const context = (getContext(this) as common.UIAbilityContext);
6206let windowClass: window.Window | undefined;
6207let keyUpEventAry: string[] = [];
6208
6209@Entry
6210@Component
6211struct Index {
6212  build() {
6213    RelativeContainer() {
6214      Button("窗口置顶")
6215        .onClick(() => {
6216          try {
6217            let promiseCtx = window.getLastWindow(context);
6218            promiseCtx.then((data) => {
6219              windowClass = data;
6220              //  true:窗口置顶,false:取消窗口置顶
6221              let isWindowTopmost: boolean = true;
6222              let promiseTopmost = windowClass.setWindowTopmost(isWindowTopmost);
6223              promiseTopmost.then(() => {
6224                console.info('Succeeded in setting the main window to be topmost.');
6225              }).catch((err: BusinessError) => {
6226                console.error(`Failed to set the main window to be topmost. Cause code: ${err.code}, message: ${err.message}`);
6227              });
6228            })
6229          } catch (exception) {
6230            console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`)
6231          }
6232        })
6233    }
6234    .height('100%')
6235    .width('100%')
6236    .onKeyEvent((event) => {
6237      if(event) {
6238        if(event.type === KeyType.Down) {
6239          keyUpEventAry = [];
6240        }
6241        if(event.type === KeyType.Up) {
6242          keyUpEventAry.push(event.keyText);
6243          // 自定义快捷键 ctrl+T 执行主窗口置顶、取消置顶的操作
6244          if(windowClass && keyUpEventAry.includes('KEYCODE_CTRL_LEFT') && keyUpEventAry.includes('KEYCODE_T')) {
6245            let isWindowTopmost: boolean = false;
6246            windowClass.setWindowTopmost(isWindowTopmost);
6247          }
6248        }
6249      }
6250    })
6251  }
6252}
6253```
6254
6255### enableLandscapeMultiWindow<sup>12+</sup>
6256
6257enableLandscapeMultiWindow(): Promise&lt;void&gt;
6258
6259应用部分界面支持横向布局时,在进入该界面时使能,使能后可支持进入横向多窗。不建议竖向布局界面使用。
6260
6261此接口只对应用主窗口生效,且需要在module.json5配置文件中[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中配置preferMultiWindowOrientation属性为"landscape_auto"。
6262
6263**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6264
6265**系统能力:** SystemCapability.Window.SessionManager
6266
6267**返回值:**
6268
6269| 类型                | 说明                      |
6270| ------------------- | ------------------------- |
6271| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6272
6273**错误码:**
6274
6275以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
6276
6277| 错误码ID | 错误信息 |
6278| ------- | -------------------------------------------- |
6279| 1300002 | This window state is abnormal.               |
6280| 1300003 | This window manager service works abnormally. |
6281
6282**示例:**
6283
6284```ts
6285// EntryAbility.ets
6286import { UIAbility } from '@kit.AbilityKit';
6287import { BusinessError } from '@kit.BasicServicesKit';
6288import { window } from '@kit.ArkUI';
6289
6290export default class EntryAbility extends UIAbility {
6291  // ...
6292  onWindowStageCreate(windowStage: window.WindowStage): void {
6293    console.info('onWindowStageCreate');
6294    let windowClass: window.Window | undefined = undefined;
6295    windowStage.getMainWindow((err: BusinessError, data) => {
6296      const errCode: number = err.code;
6297      if (errCode) {
6298        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6299        return;
6300      }
6301      windowClass = data;
6302      let promise = windowClass.enableLandscapeMultiWindow();
6303      promise.then(() => {
6304        console.info('Succeeded in making multi-window become landscape.');
6305      }).catch((err: BusinessError) => {
6306        console.error(`Failed to make multi-window become landscape. Cause code: ${err.code}, message: ${err.message}`);
6307      });
6308    });
6309  }
6310}
6311```
6312
6313### disableLandscapeMultiWindow<sup>12+</sup>
6314
6315disableLandscapeMultiWindow(): Promise&lt;void&gt;
6316
6317应用部分界面支持横向布局时,在退出该界面时去使能,去使能后不支持进入横向多窗。
6318
6319此接口只对应用主窗口生效,且需要在module.json5配置文件中[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中配置preferMultiWindowOrientation属性为"landscape_auto"。
6320
6321**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6322
6323**系统能力:** SystemCapability.Window.SessionManager
6324
6325**返回值:**
6326
6327| 类型                | 说明                      |
6328| ------------------- | ------------------------- |
6329| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6330
6331**错误码:**
6332
6333以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
6334
6335| 错误码ID | 错误信息 |
6336| ------- | -------------------------------------------- |
6337| 1300002 | This window state is abnormal.               |
6338| 1300003 | This window manager service works abnormally. |
6339
6340**示例:**
6341
6342```ts
6343// EntryAbility.ets
6344import { UIAbility } from '@kit.AbilityKit';
6345import { BusinessError } from '@kit.BasicServicesKit';
6346import { window } from '@kit.ArkUI';
6347
6348export default class EntryAbility extends UIAbility {
6349  // ...
6350  onWindowStageCreate(windowStage: window.WindowStage): void {
6351    console.info('onWindowStageCreate');
6352    let windowClass: window.Window | undefined = undefined;
6353    windowStage.getMainWindow((err: BusinessError, data) => {
6354      const errCode: number = err.code;
6355      if (errCode) {
6356        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6357        return;
6358      }
6359      windowClass = data;
6360      let promise = windowClass.disableLandscapeMultiWindow();
6361      promise.then(() => {
6362        console.info('Succeeded in making multi-window become not landscape.');
6363      }).catch((err: BusinessError) => {
6364        console.error(`Failed to make multi-window become not landscape. Cause code: ${err.code}, message: ${err.message}`);
6365      });
6366    });
6367  }
6368}
6369```
6370
6371### setDialogBackGestureEnabled<sup>12+</sup>
6372
6373setDialogBackGestureEnabled(enabled: boolean): Promise&lt;void&gt;
6374
6375设置模态窗口是否响应手势返回事件,非模态窗口调用返回错误码。
6376
6377**系统能力**:SystemCapability.Window.SessionManager
6378
6379**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6380
6381**参数:**
6382
6383| 参数名      | 类型    | 必填 | 说明                                                         |
6384| ---------- | ------- | ---- | ------------------------------------------------------------ |
6385| enabled    | boolean | 是   | 是否响应手势返回事件。<br>true表示响应手势返回事件,触发onBackPress回调;false表示不响应手势返回事件,不触发onBackPress回调。</br> |
6386
6387**返回值:**
6388
6389| 类型                | 说明                      |
6390| ------------------- | ------------------------- |
6391| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6392
6393**错误码:**
6394
6395以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6396
6397| 错误码ID | 错误信息 |
6398| ------- | -------------------------------------------- |
6399| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6400| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
6401| 1300002 | This window state is abnormal. |
6402| 1300003  | This window manager service works abnormally. |
6403| 1300004 | Unauthorized operation. |
6404
6405**示例:**
6406
6407```ts
6408// EntryAbility.ets
6409import { UIAbility } from '@kit.AbilityKit';
6410import { BusinessError } from '@kit.BasicServicesKit';
6411
6412export default class EntryAbility extends UIAbility {
6413  onWindowStageCreate(windowStage: window.WindowStage): void {
6414    console.info('onWindowStageCreate');
6415    let windowClass: window.Window | undefined = undefined;
6416    let config: window.Configuration = {
6417      name: "test",
6418      windowType: window.WindowType.TYPE_DIALOG,
6419      ctx: this.context
6420    };
6421    try {
6422      window.createWindow(config, (err: BusinessError, data) => {
6423        const errCode: number = err.code;
6424        if (errCode) {
6425          console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`);
6426          return;
6427        }
6428        windowClass = data;
6429        windowClass.setUIContent("pages/Index");
6430        let enabled = true;
6431        let promise = windowClass.setDialogBackGestureEnabled(enabled);
6432        promise.then(() => {
6433          console.info('Succeeded in setting dialog window to respond back gesture.');
6434        }).catch((err: BusinessError) => {
6435          console.error(`Failed to set dialog window to respond back gesture. Cause code: ${err.code}, message: ${err.message}`);
6436        });
6437      });
6438    } catch (exception) {
6439      console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`);
6440    }
6441  }
6442}
6443```
6444
6445```ts
6446// ets/pages/Index.ets
6447@Entry
6448@Component
6449struct Index {
6450  @State message: string = 'Hello World'
6451  build() {
6452    RelativeContainer() {
6453      Text(this.message)
6454        .id('HelloWorld')
6455        .fontSize(50)
6456        .fontWeight(FontWeight.Bold)
6457    }
6458    .height('100%')
6459    .width('100%')
6460  }
6461
6462  onBackPress(): boolean | void {
6463    console.info('Succeeded in setting dialog window to respond back gesture.');
6464    return true;
6465  }
6466}
6467```
6468
6469### setWindowSystemBarProperties<sup>(deprecated)</sup>
6470
6471setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback&lt;void&gt;): void
6472
6473设置主窗口三键导航栏、状态栏的属性,使用callback异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
6474
6475子窗口调用后不生效。
6476
6477> **说明:**
6478>
6479> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowSystemBarProperties](#setwindowsystembarproperties9)。
6480
6481**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6482
6483**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6484
6485**参数:**
6486
6487| 参数名              | 类型                                        | 必填 | 说明                   |
6488| ------------------- | ------------------------------------------- | ---- | ---------------------- |
6489| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是   | 三键导航栏、状态栏的属性。 |
6490| callback            | AsyncCallback&lt;void&gt;                   | 是   | 回调函数。             |
6491
6492**错误码:**
6493
6494以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6495
6496| 错误码ID | 错误信息                                                                                                     |
6497| -------- | ------------------------------------------------------------------------------------------------------------ |
6498| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6499| 801      | Capability not supported. Failed to call the API due to limited device capabilities.                         |
6500| 1300002  | This window state is abnormal.                                                                               |
6501| 1300003  | This window manager service works abnormally.                                                                |
6502
6503**示例:**
6504
6505```ts
6506// EntryAbility.ets
6507import { UIAbility } from '@kit.AbilityKit';
6508import { BusinessError } from '@kit.BasicServicesKit';
6509
6510export default class EntryAbility extends UIAbility {
6511  // ...
6512  onWindowStageCreate(windowStage: window.WindowStage): void {
6513    console.info('onWindowStageCreate');
6514    let windowClass: window.Window | undefined = undefined;
6515    windowStage.getMainWindow((err: BusinessError, data) => {
6516      const errCode: number = err.code;
6517      if (errCode) {
6518        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6519        return;
6520      }
6521      windowClass = data;
6522      let SystemBarProperties: window.SystemBarProperties = {
6523        statusBarColor: '#ff00ff',
6524        navigationBarColor: '#00ff00',
6525        //以下两个属性从API Version8开始支持
6526        statusBarContentColor: '#ffffff',
6527        navigationBarContentColor: '#00ffff'
6528      };
6529      try {
6530        windowClass.setWindowSystemBarProperties(SystemBarProperties, (err: BusinessError) => {
6531          const errCode: number = err.code;
6532          if (errCode) {
6533            console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
6534            return;
6535          }
6536          console.info('Succeeded in setting the system bar properties.');
6537        });
6538      } catch (exception) {
6539        console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`);
6540      }
6541    });
6542  }
6543}
6544```
6545
6546### setWindowSystemBarEnable<sup>(deprecated)</sup>
6547
6548setWindowSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback&lt;void&gt;): void
6549
6550设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用callback异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
6551
6552子窗口调用后不生效。
6553
6554> **说明:**
6555>
6556> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowSystemBarEnable](#setwindowsystembarenable9)。
6557
6558**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6559
6560**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6561
6562**参数:**
6563
6564| 参数名   | 类型                          | 必填 | 说明                                                                                                                                          |
6565| -------- | ----------------------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------- |
6566| names    | Array<'status'\|'navigation'> | 是   | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];不设置,则默认不显示。 |
6567| callback | AsyncCallback&lt;void&gt;     | 是   | 回调函数。                                                                                                                                    |
6568
6569**错误码:**
6570
6571以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6572
6573| 错误码ID | 错误信息                                                                                                     |
6574| -------- | ------------------------------------------------------------------------------------------------------------ |
6575| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6576| 1300002  | This window state is abnormal.                                                                               |
6577| 1300003  | This window manager service works abnormally.                                                                |
6578
6579**示例:**
6580
6581```ts
6582// 此处以不显示三键导航栏、状态栏、底部导航条为例
6583// EntryAbility.ets
6584import { UIAbility } from '@kit.AbilityKit';
6585import { BusinessError } from '@kit.BasicServicesKit';
6586
6587export default class EntryAbility extends UIAbility {
6588  // ...
6589  onWindowStageCreate(windowStage: window.WindowStage): void {
6590    console.info('onWindowStageCreate');
6591    let windowClass: window.Window | undefined = undefined;
6592    windowStage.getMainWindow((err: BusinessError, data) => {
6593      const errCode: number = err.code;
6594      if (errCode) {
6595        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6596        return;
6597      }
6598      windowClass = data;
6599      let names: Array<'status' | 'navigation'> = [];
6600      try {
6601        windowClass.setWindowSystemBarEnable(names, (err: BusinessError) => {
6602          const errCode: number = err.code;
6603          if (errCode) {
6604            console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
6605            return;
6606          }
6607          console.info('Succeeded in setting the system bar to be invisible.');
6608        });
6609      } catch (exception) {
6610        console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`);
6611      }
6612    });
6613  }
6614}
6615```
6616
6617### setWindowLayoutFullScreen<sup>(deprecated)</sup>
6618
6619setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void
6620
6621设置主窗口或子窗口的布局是否为沉浸式布局,使用callback异步回调。
6622沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
6623非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。
6624
6625> **说明:**
6626>
6627> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowLayoutFullScreen](#setwindowlayoutfullscreen9)。
6628
6629**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6630
6631**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6632
6633**参数:**
6634
6635| 参数名             | 类型                      | 必填 | 说明                                                                                                          |
6636| ------------------ | ------------------------- | ---- | ------------------------------------------------------------------------------------------------------------- |
6637| isLayoutFullScreen | boolean                   | 是   | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 |
6638| callback           | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                                                                                    |
6639
6640**错误码:**
6641
6642以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6643
6644| 错误码ID | 错误信息                                                                                                     |
6645| -------- | ------------------------------------------------------------------------------------------------------------ |
6646| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6647| 1300002  | This window state is abnormal.                                                                               |
6648| 1300003  | This window manager service works abnormally.                                                                |
6649
6650**示例:**
6651
6652```ts
6653// EntryAbility.ets
6654import { UIAbility } from '@kit.AbilityKit';
6655import { BusinessError } from '@kit.BasicServicesKit';
6656
6657export default class EntryAbility extends UIAbility {
6658  // ...
6659  onWindowStageCreate(windowStage: window.WindowStage): void {
6660    console.info('onWindowStageCreate');
6661    let windowClass: window.Window | undefined = undefined;
6662    windowStage.getMainWindow((err: BusinessError, data) => {
6663      const errCode: number = err.code;
6664      if (errCode) {
6665        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6666        return;
6667      }
6668      windowClass = data;
6669      let isLayoutFullScreen = true;
6670      try {
6671        windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => {
6672          const errCode: number = err.code;
6673          if (errCode) {
6674            console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
6675            return;
6676          }
6677          console.info('Succeeded in setting the window layout to full-screen mode.');
6678        });
6679      } catch (exception) {
6680        console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`);
6681      }
6682    });
6683  }
6684}
6685```
6686
6687### show<sup>(deprecated)</sup>
6688
6689show(callback: AsyncCallback&lt;void&gt;): void
6690
6691显示当前窗口,使用callback异步回调。
6692
6693> **说明:**
6694>
6695> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9)。
6696
6697**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6698
6699**参数:**
6700
6701| 参数名   | 类型                      | 必填 | 说明       |
6702| -------- | ------------------------- | ---- | ---------- |
6703| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。 |
6704
6705**示例:**
6706
6707```ts
6708import { BusinessError } from '@kit.BasicServicesKit';
6709
6710windowClass.show((err: BusinessError) => {
6711  const errCode: number = err.code;
6712  if (errCode) {
6713    console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`);
6714    return;
6715  }
6716  console.info('Succeeded in showing the window.');
6717});
6718```
6719
6720### show<sup>(deprecated)</sup>
6721
6722show(): Promise&lt;void&gt;
6723
6724显示当前窗口,使用Promise异步回调。
6725
6726> **说明:**
6727>
6728> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9-1)。
6729
6730**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6731
6732**返回值:**
6733
6734| 类型                | 说明                      |
6735| ------------------- | ------------------------- |
6736| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6737
6738**示例:**
6739
6740```ts
6741import { BusinessError } from '@kit.BasicServicesKit';
6742
6743let promise = windowClass.show();
6744promise.then(() => {
6745  console.info('Succeeded in showing the window.');
6746}).catch((err: BusinessError) => {
6747  console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`);
6748});
6749```
6750
6751### destroy<sup>(deprecated)</sup>
6752
6753destroy(callback: AsyncCallback&lt;void&gt;): void
6754
6755销毁当前窗口,使用callback异步回调。
6756
6757> **说明:**
6758>
6759> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9)。
6760
6761**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6762
6763**参数:**
6764
6765| 参数名   | 类型                      | 必填 | 说明       |
6766| -------- | ------------------------- | ---- | ---------- |
6767| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。 |
6768
6769**示例:**
6770
6771```ts
6772import { BusinessError } from '@kit.BasicServicesKit';
6773
6774windowClass.destroy((err: BusinessError) => {
6775  const errCode: number = err.code;
6776  if (err.code) {
6777    console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`);
6778    return;
6779  }
6780  console.info('Succeeded in destroying the window.');
6781});
6782```
6783
6784### destroy<sup>(deprecated)</sup>
6785
6786destroy(): Promise&lt;void&gt;
6787
6788销毁当前窗口,使用Promise异步回调。
6789
6790> **说明:**
6791>
6792> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9-1)。
6793
6794**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6795
6796**返回值:**
6797
6798| 类型                | 说明                      |
6799| ------------------- | ------------------------- |
6800| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6801
6802**示例:**
6803
6804```ts
6805import { BusinessError } from '@kit.BasicServicesKit';
6806
6807let promise = windowClass.destroy();
6808promise.then(() => {
6809  console.info('Succeeded in destroying the window.');
6810}).catch((err: BusinessError) => {
6811  console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`);
6812});
6813```
6814
6815### moveTo<sup>(deprecated)</sup>
6816
6817moveTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void
6818
6819移动窗口位置,使用callback异步回调。
6820
6821全屏模式窗口不支持该操作。
6822
6823> **说明:**
6824>
6825> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9)。
6826
6827**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6828
6829**参数:**
6830
6831| 参数名   | 类型                      | 必填 | 说明                                              |
6832| -------- | ------------------------- | ---- | ------------------------------------------------- |
6833| x        | number                    | 是   | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
6834| y        | number                    | 是   | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
6835| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                        |
6836
6837**示例:**
6838
6839```ts
6840import { BusinessError } from '@kit.BasicServicesKit';
6841
6842windowClass.moveTo(300, 300, (err: BusinessError) => {
6843  const errCode: number = err.code;
6844  if (errCode) {
6845    console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
6846    return;
6847  }
6848  console.info('Succeeded in moving the window.');
6849});
6850```
6851
6852### moveTo<sup>(deprecated)</sup>
6853
6854moveTo(x: number, y: number): Promise&lt;void&gt;
6855
6856移动窗口位置,使用Promise异步回调。
6857
6858全屏模式窗口不支持该操作。
6859
6860> **说明:**
6861>
6862> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9-1)。
6863
6864**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6865
6866**参数:**
6867
6868| 参数名 | 类型   | 必填 | 说明                                              |
6869| ------ | ------ | ---- | ------------------------------------------------- |
6870| x      | number | 是   | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
6871| y      | number | 是   | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 |
6872
6873**返回值:**
6874
6875| 类型                | 说明                      |
6876| ------------------- | ------------------------- |
6877| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6878
6879**示例:**
6880
6881```ts
6882import { BusinessError } from '@kit.BasicServicesKit';
6883
6884let promise = windowClass.moveTo(300, 300);
6885promise.then(() => {
6886  console.info('Succeeded in moving the window.');
6887}).catch((err: BusinessError) => {
6888  console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
6889});
6890```
6891
6892### resetSize<sup>(deprecated)</sup>
6893
6894resetSize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void
6895
6896改变当前窗口大小,使用callback异步回调。
6897
6898应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。
6899应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
6900
6901系统窗口存在大小限制,宽度范围:[0, 1920],高度范围:[0, 1920],单位为vp。
6902
6903设置的宽度与高度受到此约束限制,规则:
6904若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
6905若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
6906
6907全屏模式窗口不支持该操作。
6908
6909> **说明:**
6910>
6911> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9)。
6912
6913**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6914
6915**参数:**
6916
6917| 参数名   | 类型                      | 必填 | 说明                       |
6918| -------- | ------------------------- | ---- | -------------------------- |
6919| width    | number                    | 是   | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
6920| height   | number                    | 是   | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
6921| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。                 |
6922
6923**示例:**
6924
6925```ts
6926import { BusinessError } from '@kit.BasicServicesKit';
6927
6928windowClass.resetSize(500, 1000, (err: BusinessError) => {
6929  const errCode: number = err.code;
6930  if (errCode) {
6931    console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
6932    return;
6933  }
6934  console.info('Succeeded in changing the window size.');
6935});
6936```
6937
6938### resetSize<sup>(deprecated)</sup>
6939
6940resetSize(width: number, height: number): Promise&lt;void&gt;
6941
6942改变当前窗口大小,使用Promise异步回调。
6943
6944应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。
6945应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
6946
6947系统窗口存在大小限制,宽度范围:[0, 1920],高度范围:[0, 1920],单位为vp。
6948
6949设置的宽度与高度受到此约束限制,规则:
6950若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
6951若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
6952
6953全屏模式窗口不支持该操作。
6954
6955> **说明:**
6956>
6957> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9-1)。
6958
6959**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6960
6961**参数:**
6962
6963| 参数名 | 类型   | 必填 | 说明                       |
6964| ------ | ------ | ---- | -------------------------- |
6965| width  | number | 是   | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
6966| height | number | 是   | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
6967
6968**返回值:**
6969
6970| 类型                | 说明                      |
6971| ------------------- | ------------------------- |
6972| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6973
6974**示例:**
6975
6976```ts
6977import { BusinessError } from '@kit.BasicServicesKit';
6978
6979let promise = windowClass.resetSize(500, 1000);
6980promise.then(() => {
6981  console.info('Succeeded in changing the window size.');
6982}).catch((err: BusinessError) => {
6983  console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
6984});
6985```
6986
6987### getProperties<sup>(deprecated)</sup>
6988
6989getProperties(callback: AsyncCallback&lt;WindowProperties&gt;): void
6990
6991获取当前窗口的属性,使用callback异步回调,返回WindowProperties。
6992
6993> **说明:**
6994>
6995> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。
6996
6997**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6998
6999**参数:**
7000
7001| 参数名   | 类型                                                       | 必填 | 说明                         |
7002| -------- | ---------------------------------------------------------- | ---- | ---------------------------- |
7003| callback | AsyncCallback&lt;[WindowProperties](#windowproperties)&gt; | 是   | 回调函数。返回当前窗口属性。 |
7004
7005**示例:**
7006
7007```ts
7008import { BusinessError } from '@kit.BasicServicesKit';
7009
7010windowClass.getProperties((err: BusinessError, data) => {
7011  const errCode: number = err.code;
7012  if (errCode) {
7013    console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`);
7014    return;
7015  }
7016  console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data));
7017});
7018```
7019
7020### getProperties<sup>(deprecated)</sup>
7021
7022getProperties(): Promise&lt;WindowProperties&gt;
7023
7024获取当前窗口的属性,使用Promise异步回调,返回WindowProperties。
7025
7026> **说明:**
7027>
7028> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。
7029
7030**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7031
7032**返回值:**
7033
7034| 类型                                                 | 说明                            |
7035| ---------------------------------------------------- | ------------------------------- |
7036| Promise&lt;[WindowProperties](#windowproperties)&gt; | Promise对象。返回当前窗口属性。 |
7037
7038**示例:**
7039
7040```ts
7041import { BusinessError } from '@kit.BasicServicesKit';
7042
7043let promise = windowClass.getProperties();
7044promise.then((data) => {
7045  console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data));
7046}).catch((err: BusinessError) => {
7047  console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`);
7048});
7049```
7050
7051### getAvoidArea<sup>(deprecated)</sup>
7052
7053getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback&lt;[AvoidArea](#avoidarea7)&gt;): void
7054
7055获取当前窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。
7056
7057> **说明:**
7058>
7059> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。
7060
7061**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7062
7063**参数:**
7064
7065| 参数名   | 类型                                            | 必填 | 说明                                                         |
7066| -------- |-----------------------------------------------| ---- | ------------------------------------------------------------ |
7067| type     | [AvoidAreaType](#avoidareatype7)              | 是   | 表示规避区类型。|
7068| callback | AsyncCallback&lt;[AvoidArea](#avoidarea7)&gt; | 是   | 回调函数。返回窗口内容规避区域。                             |
7069
7070**示例:**
7071
7072```ts
7073import { BusinessError } from '@kit.BasicServicesKit';
7074
7075let type = window.AvoidAreaType.TYPE_SYSTEM;
7076windowClass.getAvoidArea(type, (err: BusinessError, data) => {
7077  const errCode: number = err.code;
7078  if (errCode) {
7079    console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`);
7080    return;
7081  }
7082  console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
7083});
7084```
7085
7086### getAvoidArea<sup>(deprecated)</sup>
7087
7088getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise&lt;[AvoidArea](#avoidarea7)&gt;
7089
7090获取当前窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。
7091
7092> **说明:**
7093>
7094> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。
7095
7096**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7097
7098**参数:**
7099
7100| 参数名 | 类型                               | 必填 | 说明                                                         |
7101| ------ |----------------------------------| ---- | ------------------------------------------------------------ |
7102| type   | [AvoidAreaType](#avoidareatype7) | 是   | 表示规避区类型。 |
7103
7104**返回值:**
7105
7106| 类型                                      | 说明                                |
7107|-----------------------------------------| ----------------------------------- |
7108| Promise&lt;[AvoidArea](#avoidarea7)&gt; | Promise对象。返回窗口内容规避区域。 |
7109
7110**示例:**
7111
7112```ts
7113import { BusinessError } from '@kit.BasicServicesKit';
7114
7115let type = window.AvoidAreaType.TYPE_SYSTEM;
7116let promise = windowClass.getAvoidArea(type);
7117promise.then((data) => {
7118  console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
7119}).catch((err: BusinessError) => {
7120  console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`);
7121});
7122```
7123
7124### setFullScreen<sup>(deprecated)</sup>
7125
7126setFullScreen(isFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void
7127
7128设置主窗口或子窗口的布局是否为全屏布局,使用callback异步回调。
7129全屏布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
7130非全屏布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。
7131
7132> **说明:**
7133>
7134> 从 API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)实现全屏。
7135
7136**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7137
7138**参数:**
7139
7140| 参数名       | 类型                      | 必填 | 说明                                           |
7141| ------------ | ------------------------- | ---- | ---------------------------------------------- |
7142| isFullScreen | boolean                   | 是   | 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。 |
7143| callback     | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                     |
7144
7145**示例:**
7146
7147```ts
7148// EntryAbility.ets
7149import { UIAbility } from '@kit.AbilityKit';
7150import { BusinessError } from '@kit.BasicServicesKit';
7151
7152export default class EntryAbility extends UIAbility {
7153  // ...
7154  onWindowStageCreate(windowStage: window.WindowStage): void {
7155    console.info('onWindowStageCreate');
7156    let windowClass: window.Window | undefined = undefined;
7157    windowStage.getMainWindow((err: BusinessError, data) => {
7158      const errCode: number = err.code;
7159      if (errCode) {
7160        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7161        return;
7162      }
7163      windowClass = data;
7164      let isFullScreen: boolean = true;
7165      windowClass.setFullScreen(isFullScreen, (err: BusinessError) => {
7166        const errCode: number = err.code;
7167        if (errCode) {
7168          console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
7169          return;
7170        }
7171        console.info('Succeeded in enabling the full-screen mode.');
7172      });
7173    });
7174  }
7175}
7176```
7177
7178### setFullScreen<sup>(deprecated)</sup>
7179
7180setFullScreen(isFullScreen: boolean): Promise&lt;void&gt;
7181
7182设置主窗口或子窗口的布局是否为全屏布局,使用Promise异步回调。
7183全屏布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
7184非全屏布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。
7185
7186> **说明:**
7187>
7188> 从 API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)实现全屏。
7189
7190**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7191
7192**参数:**
7193
7194| 参数名       | 类型    | 必填 | 说明                                           |
7195| ------------ | ------- | ---- | ---------------------------------------------- |
7196| isFullScreen | boolean | 是   | 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。 |
7197
7198**返回值:**
7199
7200| 类型                | 说明                      |
7201| ------------------- | ------------------------- |
7202| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7203
7204**示例:**
7205
7206```ts
7207// EntryAbility.ets
7208import { UIAbility } from '@kit.AbilityKit';
7209import { BusinessError } from '@kit.BasicServicesKit';
7210
7211export default class EntryAbility extends UIAbility {
7212  // ...
7213  onWindowStageCreate(windowStage: window.WindowStage): void {
7214    console.info('onWindowStageCreate');
7215    let windowClass: window.Window | undefined = undefined;
7216    windowStage.getMainWindow((err: BusinessError, data) => {
7217      const errCode: number = err.code;
7218      if (errCode) {
7219        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7220        return;
7221      }
7222      windowClass = data;
7223      let isFullScreen: boolean = true;
7224      let promise = windowClass.setFullScreen(isFullScreen);
7225      promise.then(() => {
7226        console.info('Succeeded in enabling the full-screen mode.');
7227      }).catch((err: BusinessError) => {
7228        console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
7229      });
7230    });
7231  }
7232}
7233```
7234
7235### setLayoutFullScreen<sup>(deprecated)</sup>
7236
7237setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void
7238
7239设置主窗口或子窗口的布局是否为沉浸式布局,使用callback异步回调。
7240沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
7241非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。
7242
7243> **说明:**
7244>
7245> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)。
7246
7247**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7248
7249**参数:**
7250
7251| 参数名             | 类型                      | 必填 | 说明                                                         |
7252| ------------------ | ------------------------- | ---- | ------------------------------------------------------------ |
7253| isLayoutFullScreen | boolean                   | 是   | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。 |
7254| callback           | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                                   |
7255
7256**示例:**
7257
7258```ts
7259// EntryAbility.ets
7260import { UIAbility } from '@kit.AbilityKit';
7261import { BusinessError } from '@kit.BasicServicesKit';
7262
7263export default class EntryAbility extends UIAbility {
7264  // ...
7265  onWindowStageCreate(windowStage: window.WindowStage): void {
7266    console.info('onWindowStageCreate');
7267    let windowClass: window.Window | undefined = undefined;
7268    windowStage.getMainWindow((err: BusinessError, data) => {
7269      const errCode: number = err.code;
7270      if (errCode) {
7271        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7272        return;
7273      }
7274      windowClass = data;
7275      let isLayoutFullScreen: boolean = true;
7276      windowClass.setLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => {
7277        const errCode: number = err.code;
7278        if (errCode) {
7279          console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
7280          return;
7281        }
7282        console.info('Succeeded in setting the window layout to full-screen mode.');
7283      });
7284    });
7285  }
7286}
7287```
7288
7289### setLayoutFullScreen<sup>(deprecated)</sup>
7290
7291setLayoutFullScreen(isLayoutFullScreen: boolean): Promise&lt;void&gt;
7292
7293设置主窗口或子窗口的布局是否为沉浸式布局,使用Promise异步回调。
7294沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。
7295非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。
7296
7297> **说明:**
7298>
7299> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)。
7300
7301**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7302
7303**参数:**
7304
7305| 参数名             | 类型    | 必填 | 说明                                                         |
7306| ------------------ | ------- | ---- | ------------------------------------------------------------ |
7307| isLayoutFullScreen | boolean | 是   | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。 |
7308
7309**返回值:**
7310
7311| 类型                | 说明                      |
7312| ------------------- | ------------------------- |
7313| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7314
7315**示例:**
7316
7317```ts
7318// EntryAbility.ets
7319import { UIAbility } from '@kit.AbilityKit';
7320import { BusinessError } from '@kit.BasicServicesKit';
7321
7322export default class EntryAbility extends UIAbility {
7323  // ...
7324  onWindowStageCreate(windowStage: window.WindowStage): void {
7325    console.info('onWindowStageCreate');
7326    let windowClass: window.Window | undefined = undefined;
7327    windowStage.getMainWindow((err: BusinessError, data) => {
7328      const errCode: number = err.code;
7329      if (errCode) {
7330        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7331        return;
7332      }
7333      windowClass = data;
7334      let isLayoutFullScreen: boolean = true;
7335      let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen);
7336      promise.then(() => {
7337        console.info('Succeeded in setting the window layout to full-screen mode.');
7338      }).catch((err: BusinessError) => {
7339        console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
7340      });
7341    });
7342  }
7343}
7344```
7345
7346### setSystemBarEnable<sup>(deprecated)</sup>
7347
7348setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback&lt;void&gt;): void
7349
7350设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用callback异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
7351
7352子窗口调用后不生效。
7353
7354> **说明:**
7355>
7356> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)。
7357
7358**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7359
7360**参数:**
7361
7362| 参数名   | 类型                      | 必填 | 说明                                                         |
7363| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
7364| names    | Array<'status'\|'navigation'> | 是   | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];不设置,则默认不显示。 |
7365| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                                   |
7366
7367
7368**示例:**
7369
7370```ts
7371// 此处以不显示三键导航栏、状态栏、底部导航条为例
7372// EntryAbility.ets
7373import { UIAbility } from '@kit.AbilityKit';
7374import { BusinessError } from '@kit.BasicServicesKit';
7375
7376export default class EntryAbility extends UIAbility {
7377  // ...
7378  onWindowStageCreate(windowStage: window.WindowStage): void {
7379    console.info('onWindowStageCreate');
7380    let windowClass: window.Window | undefined = undefined;
7381    windowStage.getMainWindow((err: BusinessError, data) => {
7382      const errCode: number = err.code;
7383      if (errCode) {
7384        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7385        return;
7386      }
7387      windowClass = data;
7388      let names: Array<'status' | 'navigation'> = [];
7389      windowClass.setSystemBarEnable(names, (err: BusinessError) => {
7390        const errCode: number = err.code;
7391        if (errCode) {
7392          console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
7393          return;
7394        }
7395        console.info('Succeeded in setting the system bar to be invisible.');
7396      });
7397    });
7398  }
7399}
7400```
7401
7402### setSystemBarEnable<sup>(deprecated)</sup>
7403
7404setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise&lt;void&gt;
7405
7406设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
7407
7408子窗口调用后不生效。
7409
7410> **说明:**
7411>
7412> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)。
7413
7414**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7415
7416**参数:**
7417
7418| 参数名 | 类型  | 必填 | 说明                                                         |
7419| ------ | ---------------------------- | ---- | ------------------------ |
7420| names  | Array<'status'\|'navigation'> | 是   | 设置窗口全屏模式时状态栏、三键导航栏、底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];不设置,则默认不显示。 |
7421
7422**返回值:**
7423
7424| 类型                | 说明                      |
7425| ------------------- | ------------------------- |
7426| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7427
7428
7429**示例:**
7430
7431```ts
7432// 此处以不显示三键导航栏、状态栏、底部导航条为例
7433// EntryAbility.ets
7434import { UIAbility } from '@kit.AbilityKit';
7435import { BusinessError } from '@kit.BasicServicesKit';
7436
7437export default class EntryAbility extends UIAbility {
7438  // ...
7439  onWindowStageCreate(windowStage: window.WindowStage): void {
7440    console.info('onWindowStageCreate');
7441    let windowClass: window.Window | undefined = undefined;
7442    windowStage.getMainWindow((err: BusinessError, data) => {
7443      const errCode: number = err.code;
7444      if (errCode) {
7445        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7446        return;
7447      }
7448      windowClass = data;
7449      let names: Array<'status' | 'navigation'> = [];
7450      let promise = windowClass.setSystemBarEnable(names);
7451      promise.then(() => {
7452        console.info('Succeeded in setting the system bar to be invisible.');
7453      }).catch((err: BusinessError) => {
7454        console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
7455      });
7456    });
7457  }
7458}
7459```
7460
7461### setSystemBarProperties<sup>(deprecated)</sup>
7462
7463setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback&lt;void&gt;): void
7464
7465设置主窗口三键导航栏、状态栏的属性,使用callback异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
7466
7467子窗口调用后不生效。
7468
7469> **说明:**
7470>
7471> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9)。
7472
7473**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7474
7475**参数:**
7476
7477| 参数名              | 类型                                        | 必填 | 说明                   |
7478| ------------------- | ------------------------------------------- | ---- | ---------------------- |
7479| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是   | 三键导航栏、状态栏的属性。 |
7480| callback            | AsyncCallback&lt;void&gt;                   | 是   | 回调函数。             |
7481
7482**示例:**
7483
7484```ts
7485// EntryAbility.ets
7486import { UIAbility } from '@kit.AbilityKit';
7487import { BusinessError } from '@kit.BasicServicesKit';
7488
7489export default class EntryAbility extends UIAbility {
7490  // ...
7491  onWindowStageCreate(windowStage: window.WindowStage): void {
7492    console.info('onWindowStageCreate');
7493    let windowClass: window.Window | undefined = undefined;
7494    windowStage.getMainWindow((err: BusinessError, data) => {
7495      const errCode: number = err.code;
7496      if (errCode) {
7497        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7498        return;
7499      }
7500      windowClass = data;
7501      let SystemBarProperties: window.SystemBarProperties = {
7502        statusBarColor: '#ff00ff',
7503        navigationBarColor: '#00ff00',
7504        //以下两个属性从API Version8开始支持
7505        statusBarContentColor: '#ffffff',
7506        navigationBarContentColor: '#00ffff'
7507      };
7508      windowClass.setSystemBarProperties(SystemBarProperties, (err) => {
7509        const errCode: number = err.code;
7510        if (errCode) {
7511          console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
7512          return;
7513        }
7514        console.info('Succeeded in setting the system bar properties.');
7515      });
7516    });
7517  }
7518}
7519```
7520
7521### setSystemBarProperties<sup>(deprecated)</sup>
7522
7523setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise&lt;void&gt;
7524
7525设置主窗口三键导航栏、状态栏的属性,使用Promise异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
7526
7527子窗口调用后不生效。
7528
7529> **说明:**
7530>
7531> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9-1)。
7532
7533**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7534
7535**参数:**
7536
7537| 参数名              | 类型                                        | 必填 | 说明                   |
7538| ------------------- | ------------------------------------------- | ---- | ---------------------- |
7539| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是   | 三键导航栏、状态栏的属性。 |
7540
7541**返回值:**
7542
7543| 类型                | 说明                      |
7544| ------------------- | ------------------------- |
7545| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7546
7547**示例:**
7548
7549```ts
7550// EntryAbility.ets
7551import { UIAbility } from '@kit.AbilityKit';
7552import { BusinessError } from '@kit.BasicServicesKit';
7553
7554export default class EntryAbility extends UIAbility {
7555  // ...
7556  onWindowStageCreate(windowStage: window.WindowStage): void {
7557    console.info('onWindowStageCreate');
7558    let windowClass: window.Window | undefined = undefined;
7559    windowStage.getMainWindow((err: BusinessError, data) => {
7560      const errCode: number = err.code;
7561      if (errCode) {
7562        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7563        return;
7564      }
7565      windowClass = data;
7566      let SystemBarProperties: window.SystemBarProperties = {
7567        statusBarColor: '#ff00ff',
7568        navigationBarColor: '#00ff00',
7569        //以下两个属性从API Version8开始支持
7570        statusBarContentColor: '#ffffff',
7571        navigationBarContentColor: '#00ffff'
7572      };
7573      let promise = windowClass.setSystemBarProperties(SystemBarProperties);
7574      promise.then(() => {
7575        console.info('Succeeded in setting the system bar properties.');
7576      }).catch((err: BusinessError) => {
7577        console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
7578      });
7579    });
7580  }
7581}
7582```
7583
7584### loadContent<sup>(deprecated)</sup>
7585
7586loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void
7587
7588为当前窗口加载具体页面内容,使用callback异步回调。
7589
7590> **说明:**
7591>
7592> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9)。
7593
7594**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7595
7596**参数:**
7597
7598| 参数名   | 类型                      | 必填 | 说明                 |
7599| -------- | ------------------------- | ---- | -------------------- |
7600| path     | string                    | 是   | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 |
7601| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
7602
7603**示例:**
7604
7605```ts
7606import { BusinessError } from '@kit.BasicServicesKit';
7607
7608windowClass.loadContent('pages/page2/page3', (err: BusinessError) => {
7609  const errCode: number = err.code;
7610  if (errCode) {
7611    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
7612    return;
7613  }
7614  console.info('Succeeded in loading the content.');
7615});
7616```
7617
7618### loadContent<sup>(deprecated)</sup>
7619
7620loadContent(path: string): Promise&lt;void&gt;
7621
7622为当前窗口加载具体页面内容,使用Promise异步回调。
7623
7624> **说明:**
7625>
7626> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9-1)。
7627
7628**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7629
7630**参数:**
7631
7632| 参数名 | 类型   | 必填 | 说明                 |
7633| ------ | ------ | ---- | -------------------- |
7634| path   | string | 是   | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 |
7635
7636**返回值:**
7637
7638| 类型                | 说明                      |
7639| ------------------- | ------------------------- |
7640| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7641
7642**示例:**
7643
7644```ts
7645import { BusinessError } from '@kit.BasicServicesKit';
7646
7647let promise = windowClass.loadContent('pages/page2/page3');
7648promise.then(() => {
7649  console.info('Succeeded in loading the content.');
7650}).catch((err: BusinessError) => {
7651  console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
7652});
7653```
7654
7655### isShowing<sup>(deprecated)</sup>
7656
7657isShowing(callback: AsyncCallback&lt;boolean&gt;): void
7658
7659判断当前窗口是否已显示,使用callback异步回调。
7660
7661> **说明:**
7662>
7663> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。
7664
7665**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7666
7667**参数:**
7668
7669| 参数名   | 类型                         | 必填 | 说明                                                         |
7670| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
7671| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 |
7672
7673**示例:**
7674
7675```ts
7676import { BusinessError } from '@kit.BasicServicesKit';
7677
7678windowClass.isShowing((err: BusinessError, data) => {
7679  const errCode: number = err.code;
7680  if (errCode) {
7681    console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`);
7682    return;
7683  }
7684  console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
7685});
7686```
7687
7688### isShowing<sup>(deprecated)</sup>
7689
7690isShowing(): Promise&lt;boolean&gt;
7691
7692判断当前窗口是否已显示,使用Promise异步回调。
7693
7694> **说明:**
7695>
7696> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。
7697
7698**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7699
7700**返回值:**
7701
7702| 类型                   | 说明                                                         |
7703| ---------------------- | ------------------------------------------------------------ |
7704| Promise&lt;boolean&gt; | Promise对象。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 |
7705
7706**示例:**
7707
7708```ts
7709import { BusinessError } from '@kit.BasicServicesKit';
7710
7711let promise = windowClass.isShowing();
7712promise.then((data) => {
7713  console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
7714}).catch((err: BusinessError) => {
7715  console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`);
7716});
7717```
7718
7719### on('systemAvoidAreaChange')<sup>(deprecated)</sup>
7720
7721on(type: 'systemAvoidAreaChange', callback: Callback&lt;AvoidArea&gt;): void
7722
7723开启当前窗口系统规避区变化的监听。
7724
7725> **说明:**
7726>
7727> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[on('avoidAreaChange')](#onavoidareachange9)。
7728
7729**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7730
7731**参数:**
7732
7733| 参数名   | 类型                                       | 必填 | 说明                                                    |
7734| -------- |------------------------------------------| ---- | ------------------------------------------------------- |
7735| type     | string                                   | 是   | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 |
7736| callback | Callback&lt;[AvoidArea](#avoidarea7)&gt; | 是   | 回调函数。返回当前规避区。                             |
7737
7738
7739**示例:**
7740
7741```ts
7742windowClass.on('systemAvoidAreaChange', (data) => {
7743  console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data));
7744});
7745```
7746
7747### off('systemAvoidAreaChange')<sup>(deprecated)</sup>
7748
7749off(type: 'systemAvoidAreaChange', callback?: Callback&lt;AvoidArea&gt;): void
7750
7751关闭当前窗口系统规避区变化的监听。
7752
7753> **说明:**
7754>
7755> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[off('avoidAreaChange')](#offavoidareachange9)。
7756
7757**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7758
7759**参数:**
7760
7761| 参数名   | 类型                                       | 必填 | 说明                                                    |
7762| -------- |------------------------------------------| ---- | ------------------------------------------------------- |
7763| type     | string                                   | 是   | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 |
7764| callback | Callback&lt;[AvoidArea](#avoidarea7)&gt; | 否   | 回调函数。返回当前规避区。若传入参数,则关闭该监听。若未传入参数,则关闭所有系统规避区变化的监听。           |
7765
7766**示例:**
7767
7768```ts
7769const callback = (avoidArea: window.AvoidArea) => {
7770  // ...
7771}
7772windowClass.on('systemAvoidAreaChange', callback);
7773windowClass.off('systemAvoidAreaChange', callback);
7774// 如果通过on开启多个callback进行监听,同时关闭所有监听:
7775windowClass.off('systemAvoidAreaChange');
7776```
7777
7778### isSupportWideGamut<sup>(deprecated)</sup>
7779
7780isSupportWideGamut(callback: AsyncCallback&lt;boolean&gt;): void
7781
7782判断当前窗口是否支持广色域模式,使用callback异步回调。
7783
7784> **说明:**
7785>
7786> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9)。
7787
7788**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7789
7790**参数:**
7791
7792| 参数名   | 类型                         | 必填 | 说明                                                         |
7793| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
7794| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 |
7795
7796**示例:**
7797
7798```ts
7799import { BusinessError } from '@kit.BasicServicesKit';
7800
7801windowClass.isSupportWideGamut((err: BusinessError, data) => {
7802  const errCode: number = err.code;
7803  if (errCode) {
7804    console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`);
7805    return;
7806  }
7807  console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data));
7808});
7809```
7810
7811### isSupportWideGamut<sup>(deprecated)</sup>
7812
7813isSupportWideGamut(): Promise&lt;boolean&gt;
7814
7815判断当前窗口是否支持广色域模式,使用Promise异步回调。
7816
7817> **说明:**
7818>
7819> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9-1)。
7820
7821**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7822
7823**返回值:**
7824
7825| 类型                   | 说明                                                         |
7826| ---------------------- | ------------------------------------------------------------ |
7827| Promise&lt;boolean&gt; | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 |
7828
7829**示例:**
7830
7831```ts
7832import { BusinessError } from '@kit.BasicServicesKit';
7833
7834let promise = windowClass.isSupportWideGamut();
7835promise.then((data) => {
7836  console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data));
7837}).catch((err: BusinessError) => {
7838  console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`);
7839});
7840```
7841
7842### setColorSpace<sup>(deprecated)</sup>
7843
7844setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback&lt;void&gt;): void
7845
7846设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。
7847
7848> **说明:**
7849>
7850> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9)。
7851
7852**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7853
7854**参数:**
7855
7856| 参数名     | 类型                      | 必填 | 说明         |
7857| ---------- | ------------------------- | ---- | ------------ |
7858| colorSpace | [ColorSpace](#colorspace8) | 是   | 设置色域模式。 |
7859| callback   | AsyncCallback&lt;void&gt; | 是   | 回调函数。   |
7860
7861
7862**示例:**
7863
7864```ts
7865import { BusinessError } from '@kit.BasicServicesKit';
7866
7867windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => {
7868  const errCode: number = err.code;
7869  if (errCode) {
7870    console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`);
7871    return;
7872  }
7873  console.info('Succeeded in setting window colorspace.');
7874});
7875```
7876
7877### setColorSpace<sup>(deprecated)</sup>
7878
7879setColorSpace(colorSpace:ColorSpace): Promise&lt;void&gt;
7880
7881设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。
7882
7883> **说明:**
7884>
7885> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9-1)。
7886
7887**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7888
7889**参数:**
7890
7891| 参数名     | 类型                      | 必填 | 说明           |
7892| ---------- | ------------------------- | ---- | -------------- |
7893| colorSpace | [ColorSpace](#colorspace8) | 是   | 设置色域模式。 |
7894
7895**返回值:**
7896
7897| 类型                | 说明                      |
7898| ------------------- | ------------------------- |
7899| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7900
7901
7902**示例:**
7903
7904```ts
7905import { BusinessError } from '@kit.BasicServicesKit';
7906
7907let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT);
7908promise.then(() => {
7909  console.info('Succeeded in setting window colorspace.');
7910}).catch((err: BusinessError) => {
7911  console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`);
7912});
7913```
7914
7915### getColorSpace<sup>(deprecated)</sup>
7916
7917getColorSpace(callback: AsyncCallback&lt;ColorSpace&gt;): void
7918
7919获取当前窗口色域模式,使用callback异步回调。
7920
7921> **说明:**
7922>
7923> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。
7924
7925**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7926
7927**参数:**
7928
7929| 参数名   | 类型                                           | 必填 | 说明                                                       |
7930| -------- | ---------------------------------------------- | ---- | ---------------------------------------------------------- |
7931| callback | AsyncCallback&lt;[ColorSpace](#colorspace8)&gt; | 是   | 回调函数。当获取成功,err为undefined,data为当前色域模式。 |
7932
7933**示例:**
7934
7935```ts
7936import { BusinessError } from '@kit.BasicServicesKit';
7937
7938windowClass.getColorSpace((err: BusinessError, data) => {
7939  const errCode: number = err.code;
7940  if (errCode) {
7941    console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`);
7942    return;
7943  }
7944  console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data));
7945});
7946```
7947
7948### getColorSpace<sup>(deprecated)</sup>
7949
7950getColorSpace(): Promise&lt;ColorSpace&gt;
7951
7952获取当前窗口色域模式,使用Promise异步回调。
7953
7954> **说明:**
7955>
7956> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。
7957
7958**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7959
7960**返回值:**
7961
7962| 类型                                     | 说明                            |
7963| ---------------------------------------- | ------------------------------- |
7964| Promise&lt;[ColorSpace](#colorspace8)&gt; | Promise对象。返回当前色域模式。 |
7965
7966**示例:**
7967
7968```ts
7969import { BusinessError } from '@kit.BasicServicesKit';
7970
7971let promise = windowClass.getColorSpace();
7972promise.then((data) => {
7973  console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data));
7974}).catch((err: BusinessError) => {
7975  console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`);
7976});
7977```
7978
7979### setBackgroundColor<sup>(deprecated)</sup>
7980
7981setBackgroundColor(color: string, callback: AsyncCallback&lt;void&gt;): void
7982
7983设置窗口的背景色,使用callback异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
7984
7985> **说明:**
7986>
7987> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。
7988
7989**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7990
7991**参数:**
7992
7993| 参数名   | 类型                      | 必填 | 说明                                                         |
7994| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
7995| color    | string                    | 是   | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 |
7996| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                                   |
7997
7998
7999**示例:**
8000
8001```ts
8002import { BusinessError } from '@kit.BasicServicesKit';
8003
8004let color: string = '#00ff33';
8005windowClass.setBackgroundColor(color, (err: BusinessError) => {
8006  const errCode: number = err.code;
8007  if (errCode) {
8008    console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`);
8009    return;
8010  }
8011  console.info('Succeeded in setting the background color.');
8012});
8013```
8014
8015### setBackgroundColor<sup>(deprecated)</sup>
8016
8017setBackgroundColor(color: string): Promise&lt;void&gt;
8018
8019设置窗口的背景色,使用Promise异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
8020
8021> **说明:**
8022>
8023> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。
8024
8025**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8026
8027**参数:**
8028
8029| 参数名 | 类型   | 必填 | 说明                                                         |
8030| ------ | ------ | ---- | ------------------------------------------------------------ |
8031| color  | string | 是   | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 |
8032
8033**返回值:**
8034
8035| 类型                | 说明                      |
8036| ------------------- | ------------------------- |
8037| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8038
8039
8040**示例:**
8041
8042```ts
8043import { BusinessError } from '@kit.BasicServicesKit';
8044
8045let color: string = '#00ff33';
8046let promise = windowClass.setBackgroundColor(color);
8047promise.then(() => {
8048  console.info('Succeeded in setting the background color.');
8049}).catch((err: BusinessError) => {
8050  console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`);
8051});
8052```
8053
8054### setBrightness<sup>(deprecated)</sup>
8055
8056setBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void
8057
8058允许应用窗口设置屏幕亮度值,使用callback异步回调。
8059
8060当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。
8061
8062> **说明:**
8063>
8064> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9)。
8065
8066**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8067
8068**参数:**
8069
8070| 参数名     | 类型                      | 必填 | 说明                                    |
8071| ---------- | ------------------------- | ---- |---------------------------------------|
8072| brightness | number                    | 是   | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 |
8073| callback   | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                 |
8074
8075
8076**示例:**
8077
8078```ts
8079import { BusinessError } from '@kit.BasicServicesKit';
8080
8081let brightness: number = 1;
8082windowClass.setBrightness(brightness, (err: BusinessError) => {
8083  const errCode: number = err.code;
8084  if (errCode) {
8085    console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`);
8086    return;
8087  }
8088  console.info('Succeeded in setting the brightness.');
8089});
8090```
8091
8092### setBrightness<sup>(deprecated)</sup>
8093
8094setBrightness(brightness: number): Promise&lt;void&gt;
8095
8096允许应用窗口设置屏幕亮度值,使用Promise异步回调。
8097
8098当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。
8099
8100> **说明:**
8101>
8102> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9-1)。
8103
8104**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8105
8106**参数:**
8107
8108| 参数名     | 类型   | 必填 | 说明                                       |
8109| ---------- | ------ | ---- |------------------------------------------|
8110| brightness | number | 是   | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 |
8111
8112**返回值:**
8113
8114| 类型                | 说明                      |
8115| ------------------- | ------------------------- |
8116| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8117
8118
8119**示例:**
8120
8121```ts
8122import { BusinessError } from '@kit.BasicServicesKit';
8123
8124let brightness: number = 1;
8125let promise = windowClass.setBrightness(brightness);
8126promise.then(() => {
8127  console.info('Succeeded in setting the brightness.');
8128}).catch((err: BusinessError) => {
8129  console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`);
8130});
8131```
8132
8133### setDimBehind<sup>(deprecated)</sup>
8134
8135setDimBehind(dimBehindValue: number, callback: AsyncCallback&lt;void&gt;): void
8136
8137窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用callback异步回调。
8138
8139> **说明:**
8140>
8141> 该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。
8142
8143**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8144
8145**参数:**
8146
8147| 参数名         | 类型                      | 必填 | 说明                                     |
8148| -------------- | ------------------------- | ---- |----------------------------------------|
8149| dimBehindValue | number                    | 是   | 表示靠后的窗口的暗度值,取值范围为[0.0, 1.0],取1.0时表示最暗。 |
8150| callback       | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                  |
8151
8152**示例:**
8153
8154```ts
8155import { BusinessError } from '@kit.BasicServicesKit';
8156
8157windowClass.setDimBehind(0.5, (err: BusinessError) => {
8158  const errCode: number = err.code;
8159  if (errCode) {
8160    console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`);
8161    return;
8162  }
8163  console.info('Succeeded in setting the dimness.');
8164});
8165```
8166
8167### setDimBehind<sup>(deprecated)</sup>
8168
8169setDimBehind(dimBehindValue: number): Promise&lt;void&gt;
8170
8171窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用Promise异步回调。
8172
8173> **说明:**
8174>
8175> 该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。
8176
8177**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8178
8179**参数:**
8180
8181| 参数名         | 类型   | 必填 | 说明                                               |
8182| -------------- | ------ | ---- | -------------------------------------------------- |
8183| dimBehindValue | number | 是   | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 |
8184
8185**返回值:**
8186
8187| 类型                | 说明                      |
8188| ------------------- | ------------------------- |
8189| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8190
8191**示例:**
8192
8193```ts
8194import { BusinessError } from '@kit.BasicServicesKit';
8195
8196let promise = windowClass.setDimBehind(0.5);
8197promise.then(() => {
8198  console.info('Succeeded in setting the dimness.');
8199}).catch((err: BusinessError) => {
8200  console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`);
8201});
8202```
8203
8204### setFocusable<sup>(deprecated)</sup>
8205
8206setFocusable(isFocusable: boolean, callback: AsyncCallback&lt;void&gt;): void
8207
8208设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从操作前的获焦窗口切换到该窗口,使用callback异步回调。
8209
8210> **说明:**
8211>
8212> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9)。
8213
8214**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8215
8216**参数:**
8217
8218| 参数名      | 类型                      | 必填 | 说明                         |
8219| ----------- | ------------------------- | ---- | ---------------------------- |
8220| isFocusable | boolean                   | 是   | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 |
8221| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数。                   |
8222
8223
8224**示例:**
8225
8226```ts
8227import { BusinessError } from '@kit.BasicServicesKit';
8228
8229let isFocusable: boolean = true;
8230windowClass.setFocusable(isFocusable, (err: BusinessError) => {
8231  const errCode: number = err.code;
8232  if (errCode) {
8233    console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`);
8234    return;
8235  }
8236  console.info('Succeeded in setting the window to be focusable.');
8237});
8238```
8239
8240### setFocusable<sup>(deprecated)</sup>
8241
8242setFocusable(isFocusable: boolean): Promise&lt;void&gt;
8243
8244设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用Promise异步回调。
8245
8246> **说明:**
8247>
8248> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9-1)。
8249
8250**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8251
8252**参数:**
8253
8254| 参数名      | 类型    | 必填 | 说明                         |
8255| ----------- | ------- | ---- | ---------------------------- |
8256| isFocusable | boolean | 是   | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 |
8257
8258**返回值:**
8259
8260| 类型                | 说明                      |
8261| ------------------- | ------------------------- |
8262| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8263
8264
8265**示例:**
8266
8267```ts
8268import { BusinessError } from '@kit.BasicServicesKit';
8269
8270let isFocusable: boolean = true;
8271let promise = windowClass.setFocusable(isFocusable);
8272promise.then(() => {
8273  console.info('Succeeded in setting the window to be focusable.');
8274}).catch((err: BusinessError) => {
8275  console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`);
8276});
8277```
8278
8279### setKeepScreenOn<sup>(deprecated)</sup>
8280
8281setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback&lt;void&gt;): void
8282
8283设置屏幕是否为常亮状态,使用callback异步回调。
8284
8285> **说明:**
8286>
8287> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9)。
8288
8289**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8290
8291**参数:**
8292
8293| 参数名         | 类型                      | 必填 | 说明                     |
8294| -------------- | ------------------------- | ---- | ------------------------ |
8295| isKeepScreenOn | boolean                   | 是   | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 |
8296| callback       | AsyncCallback&lt;void&gt; | 是   | 回调函数。               |
8297
8298
8299**示例:**
8300
8301```ts
8302import { BusinessError } from '@kit.BasicServicesKit';
8303
8304let isKeepScreenOn: boolean = true;
8305windowClass.setKeepScreenOn(isKeepScreenOn, (err: BusinessError) => {
8306  const errCode: number = err.code;
8307  if (errCode) {
8308    console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`);
8309    return;
8310  }
8311  console.info('Succeeded in setting the screen to be always on.');
8312});
8313```
8314
8315### setKeepScreenOn<sup>(deprecated)</sup>
8316
8317setKeepScreenOn(isKeepScreenOn: boolean): Promise&lt;void&gt;
8318
8319设置屏幕是否为常亮状态,使用Promise异步回调。
8320
8321> **说明:**
8322>
8323> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9-1)。
8324
8325**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8326
8327**参数:**
8328
8329| 参数名         | 类型    | 必填 | 说明                     |
8330| -------------- | ------- | ---- | ------------------------ |
8331| isKeepScreenOn | boolean | 是   | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 |
8332
8333**返回值:**
8334
8335| 类型                | 说明                      |
8336| ------------------- | ------------------------- |
8337| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8338
8339**示例:**
8340
8341```ts
8342import { BusinessError } from '@kit.BasicServicesKit';
8343
8344let isKeepScreenOn: boolean = true;
8345let promise = windowClass.setKeepScreenOn(isKeepScreenOn);
8346promise.then(() => {
8347  console.info('Succeeded in setting the screen to be always on.');
8348}).catch((err: BusinessError) => {
8349  console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`);
8350});
8351```
8352
8353### setOutsideTouchable<sup>(deprecated)</sup>
8354
8355setOutsideTouchable(touchable: boolean, callback: AsyncCallback&lt;void&gt;): void
8356
8357设置是否允许可点击子窗口之外的区域,使用callback异步回调。
8358
8359> **说明:**
8360>
8361> 从 API version 7开始支持,从API version 9开始废弃。
8362>
8363> 从 API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。
8364
8365**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8366
8367**参数:**
8368
8369| 参数名    | 类型                      | 必填 | 说明             |
8370| --------- | ------------------------- | ---- | ---------------- |
8371| touchable | boolean                   | 是   | 设置是否可点击。true表示可点击;false表示不可点击。 |
8372| callback  | AsyncCallback&lt;void&gt; | 是   | 回调函数。       |
8373
8374**示例:**
8375
8376```ts
8377import { BusinessError } from '@kit.BasicServicesKit';
8378
8379windowClass.setOutsideTouchable(true, (err: BusinessError) => {
8380  const errCode: number = err.code;
8381  if (errCode) {
8382    console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`);
8383    return;
8384  }
8385  console.info('Succeeded in setting the area to be touchable.');
8386});
8387```
8388
8389### setOutsideTouchable<sup>(deprecated)</sup>
8390
8391setOutsideTouchable(touchable: boolean): Promise&lt;void&gt;
8392
8393设置是否允许可点击子窗口之外的区域,使用Promise异步回调。
8394
8395> **说明:**
8396>
8397> 从 API version 7开始支持,从API version 9开始废弃。
8398>
8399> 从 API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。
8400
8401**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8402
8403**参数:**
8404
8405| 参数名    | 类型    | 必填 | 说明             |
8406| --------- | ------- | ---- | ---------------- |
8407| touchable | boolean | 是   | 设置是否可点击。true表示可点击;false表示不可点击。 |
8408
8409**返回值:**
8410
8411| 类型                | 说明                      |
8412| ------------------- | ------------------------- |
8413| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8414
8415**示例:**
8416
8417```ts
8418import { BusinessError } from '@kit.BasicServicesKit';
8419
8420let promise = windowClass.setOutsideTouchable(true);
8421promise.then(() => {
8422  console.info('Succeeded in setting the area to be touchable.');
8423}).catch((err: BusinessError) => {
8424  console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`);
8425});
8426```
8427
8428### setPrivacyMode<sup>(deprecated)</sup>
8429
8430setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback&lt;void&gt;): void
8431
8432设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。
8433
8434> **说明:**
8435>
8436> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9)。
8437
8438**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8439
8440**参数:**
8441
8442| 参数名        | 类型                      | 必填 | 说明                 |
8443| ------------- | ------------------------- | ---- | -------------------- |
8444| isPrivacyMode | boolean                   | 是   | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 |
8445| callback      | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
8446
8447**示例:**
8448
8449```ts
8450import { BusinessError } from '@kit.BasicServicesKit';
8451
8452let isPrivacyMode: boolean = true;
8453windowClass.setPrivacyMode(isPrivacyMode, (err: BusinessError) => {
8454  const errCode: number = err.code;
8455  if (errCode) {
8456    console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`);
8457    return;
8458  }
8459  console.info('Succeeded in setting the window to privacy mode.');
8460});
8461```
8462
8463### setPrivacyMode<sup>(deprecated)</sup>
8464
8465setPrivacyMode(isPrivacyMode: boolean): Promise&lt;void&gt;
8466
8467设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。
8468
8469> **说明:**
8470>
8471> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9-1)。
8472
8473**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8474
8475**参数:**
8476
8477| 参数名        | 类型    | 必填 | 说明                 |
8478| ------------- | ------- | ---- | -------------------- |
8479| isPrivacyMode | boolean | 是   | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 |
8480
8481**返回值:**
8482
8483| 类型                | 说明                      |
8484| ------------------- | ------------------------- |
8485| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8486
8487**示例:**
8488
8489```ts
8490import { BusinessError } from '@kit.BasicServicesKit';
8491
8492let isPrivacyMode: boolean = true;
8493let promise = windowClass.setPrivacyMode(isPrivacyMode);
8494promise.then(() => {
8495  console.info('Succeeded in setting the window to privacy mode.');
8496}).catch((err: BusinessError) => {
8497  console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`);
8498});
8499```
8500
8501### setTouchable<sup>(deprecated)</sup>
8502
8503setTouchable(isTouchable: boolean, callback: AsyncCallback&lt;void&gt;): void
8504
8505设置窗口是否为可触状态,使用callback异步回调。
8506
8507> **说明:**
8508>
8509> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9)。
8510
8511**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8512
8513**参数:**
8514
8515| 参数名      | 类型                      | 必填 | 说明                 |
8516| ----------- | ------------------------- | ---- | -------------------- |
8517| isTouchable | boolean                   | 是   | 窗口是否为可触状态。true表示可触;false表示不可触。 |
8518| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
8519
8520
8521**示例:**
8522
8523```ts
8524import { BusinessError } from '@kit.BasicServicesKit';
8525
8526let isTouchable = true;
8527windowClass.setTouchable(isTouchable, (err: BusinessError) => {
8528  const errCode: number = err.code;
8529  if (errCode) {
8530    console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`);
8531    return;
8532  }
8533  console.info('Succeeded in setting the window to be touchable.');
8534});
8535```
8536
8537### setTouchable<sup>(deprecated)</sup>
8538
8539setTouchable(isTouchable: boolean): Promise&lt;void&gt;
8540
8541设置窗口是否为可触状态,使用Promise异步回调。
8542
8543> **说明:**
8544>
8545> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9-1)。
8546
8547**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8548
8549**参数:**
8550
8551| 参数名      | 类型    | 必填 | 说明                 |
8552| ----------- | ------- | ---- | -------------------- |
8553| isTouchable | boolean | 是   | 窗口是否为可触状态。true表示可触;false表示不可触。 |
8554
8555**返回值:**
8556
8557| 类型                | 说明                      |
8558| ------------------- | ------------------------- |
8559| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8560
8561
8562**示例:**
8563
8564```ts
8565import { BusinessError } from '@kit.BasicServicesKit';
8566
8567let isTouchable = true;
8568let promise = windowClass.setTouchable(isTouchable);
8569promise.then(() => {
8570  console.info('Succeeded in setting the window to be touchable.');
8571}).catch((err: BusinessError) => {
8572  console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`);
8573});
8574```
8575
8576## WindowStageEventType<sup>9+</sup>
8577
8578WindowStage生命周期。
8579
8580**模型约束:** 此接口仅可在Stage模型下使用。
8581
8582**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8583
8584**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8585
8586| 名称       | 值 | 说明       |
8587| ---------- | ------ | ---------- |
8588| SHOWN      | 1      | 切到前台,例如点击应用图标启动,无论是首次启动还是从后台启动均会触发。 |
8589| ACTIVE     | 2      | 获焦状态,例如应用窗口处理点击事件后的状态、应用启动后的状态。 |
8590| INACTIVE   | 3      | 失焦状态,例如打开新应用或点击其他窗口后,原获焦窗口的状态。 |
8591| HIDDEN     | 4      | 切到后台,例如应用上滑退出、应用窗口关闭。 |
8592| RESUMED<sup>11+</sup> | 5      | 前台可交互状态,例如应用打开后,可以与用户交互的状态。 |
8593| PAUSED<sup>11+</sup>  | 6      | 前台不可交互状态,例如从屏幕底部上划,应用进入到多任务界面后的状态。 |
8594
8595## ModalityType<sup>14+</sup>
8596
8597子窗口模态类型枚举。
8598
8599**系统能力:** SystemCapability.Window.SessionManager
8600
8601**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
8602
8603| 名称                 | 值      | 说明       |
8604| -------------------- | ------ | ---------- |
8605| WINDOW_MODALITY      | 0      | 模态子窗类型为模窗口子窗,当仅需要其父级窗口不响应用户操作时,可选此参数。 |
8606| APPLICATION_MODALITY | 1      | 模态子窗类型为模应用子窗,除其父级窗口外还需要该应用其他实例的窗口不响应用户操作时,可选此参数。<br> 此接口仅支持在2in1设备下使用。 |
8607
8608## SubWindowOptions<sup>12+</sup>
8609
8610子窗口创建参数。
8611
8612**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8613
8614**系统能力:** SystemCapability.Window.SessionManager
8615
8616| 名称      | 类型  | 只读 | 可选 | 说明         |
8617| ---------- | ---- | ---- | ---- | ----------- |
8618| title<sup>12+</sup>    | string | 否 | 否 | 子窗口标题。       |
8619| decorEnabled<sup>12+</sup> | boolean | 否 | 否 | 子窗口是否显示装饰。true表示子窗口显示装饰,false表示子窗口不显示装饰。       |
8620| isModal<sup>12+</sup>    | boolean | 否 | 是 | 子窗口是否启用模态属性。true表示子窗口启用模态属性,false表示子窗口禁用模态属性。不设置,则默认为false。       |
8621| modalityType<sup>14+</sup>    | [ModalityType](#modalitytype14) | 否 | 是 | 子窗口模态类型,仅当子窗口启用模态属性时生效。WINDOW_MODALITY表示子窗口模态类型为模窗口子窗,APPLICATION_MODALITY表示子窗口模态类型为模应用子窗。不设置,则默认为WINDOW_MODALITY。       |
8622
8623## WindowStage<sup>9+</sup>
8624
8625窗口管理器。管理各个基本窗口单元,即[Window](#window)实例。
8626
8627下列API示例中都需在[onWindowStageCreate()](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate)函数中使用WindowStage的实例调用对应方法。
8628
8629### getMainWindow<sup>9+</sup>
8630
8631getMainWindow(callback: AsyncCallback&lt;Window&gt;): void
8632
8633获取该WindowStage实例下的主窗口,使用callback异步回调。
8634
8635**模型约束:** 此接口仅可在Stage模型下使用。
8636
8637**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8638
8639**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8640
8641**参数:**
8642
8643| 参数名   | 类型                                   | 必填 | 说明                                          |
8644| -------- | -------------------------------------- | ---- | --------------------------------------------- |
8645| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前WindowStage下的主窗口对象。 |
8646
8647**错误码:**
8648
8649以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
8650
8651| 错误码ID | 错误信息 |
8652| ------- | ------------------------------ |
8653| 1300002 | This window state is abnormal. |
8654| 1300005 | This window stage is abnormal. |
8655
8656**示例:**
8657
8658```ts
8659// EntryAbility.ets
8660import { UIAbility } from '@kit.AbilityKit';
8661import { BusinessError } from '@kit.BasicServicesKit';
8662
8663export default class EntryAbility extends UIAbility {
8664  // ...
8665
8666  onWindowStageCreate(windowStage: window.WindowStage) {
8667    console.log('onWindowStageCreate');
8668    let windowClass: window.Window | undefined = undefined;
8669    windowStage.getMainWindow((err: BusinessError, data) => {
8670      const errCode: number = err.code;
8671      if (errCode) {
8672        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
8673        return;
8674      }
8675      windowClass = data;
8676      console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
8677    });
8678  }
8679};
8680```
8681
8682### getMainWindow<sup>9+</sup>
8683
8684getMainWindow(): Promise&lt;Window&gt;
8685
8686获取该WindowStage实例下的主窗口,使用Promise异步回调。
8687
8688**模型约束:** 此接口仅可在Stage模型下使用。
8689
8690**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8691
8692**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8693
8694**返回值:**
8695
8696| 类型                             | 说明                                             |
8697| -------------------------------- | ------------------------------------------------ |
8698| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前WindowStage下的主窗口对象。 |
8699
8700**错误码:**
8701
8702以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
8703
8704| 错误码ID | 错误信息 |
8705| ------- | ------------------------------ |
8706| 1300002 | This window state is abnormal. |
8707| 1300005 | This window stage is abnormal. |
8708
8709**示例:**
8710
8711```ts
8712// EntryAbility.ets
8713import { UIAbility } from '@kit.AbilityKit';
8714import { BusinessError } from '@kit.BasicServicesKit';
8715
8716export default class EntryAbility extends UIAbility {
8717  // ...
8718
8719  onWindowStageCreate(windowStage: window.WindowStage) {
8720    console.log('onWindowStageCreate');
8721    let windowClass: window.Window | undefined = undefined;
8722    let promise = windowStage.getMainWindow();
8723    promise.then((data) => {
8724      windowClass = data;
8725      console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
8726    }).catch((err: BusinessError) => {
8727      console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
8728    });
8729  }
8730};
8731```
8732
8733### getMainWindowSync<sup>9+</sup>
8734
8735getMainWindowSync(): Window
8736
8737获取该WindowStage实例下的主窗口。
8738
8739**模型约束:** 此接口仅可在Stage模型下使用。
8740
8741**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8742
8743**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8744
8745**返回值:**
8746
8747| 类型 | 说明 |
8748| ----------------- | --------------------------------- |
8749| [Window](#window) | 返回当前WindowStage下的主窗口对象。 |
8750
8751**错误码:**
8752
8753以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
8754
8755| 错误码ID | 错误信息 |
8756| ------- | ------------------------------ |
8757| 1300002 | This window state is abnormal. |
8758| 1300005 | This window stage is abnormal. |
8759
8760**示例:**
8761<!--code_no_check-->
8762```ts
8763// EntryAbility.ets
8764import { UIAbility } from '@kit.AbilityKit';
8765
8766export default class EntryAbility extends UIAbility {
8767  // ...
8768
8769  onWindowStageCreate(windowStage: window.WindowStage) {
8770    console.log('onWindowStageCreate');
8771    try {
8772      let windowClass = windowStage.getMainWindowSync();
8773    } catch (exception) {
8774      console.error(`Failed to obtain the main window. Cause code: ${exception.code}, message: ${exception.message}`);
8775    }
8776  }
8777};
8778```
8779
8780### createSubWindow<sup>9+</sup>
8781
8782createSubWindow(name: string, callback: AsyncCallback&lt;Window&gt;): void
8783
8784创建该WindowStage实例下的子窗口,使用callback异步回调。
8785
8786**模型约束:** 此接口仅可在Stage模型下使用。
8787
8788**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8789
8790**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8791
8792**参数:**
8793
8794| 参数名   | 类型                                   | 必填 | 说明                                          |
8795| -------- | -------------------------------------- | ---- | --------------------------------------------- |
8796| name     | string                                 | 是   | 子窗口的名字。                                |
8797| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前WindowStage下的子窗口对象。 |
8798
8799**错误码:**
8800
8801以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8802
8803| 错误码ID | 错误信息 |
8804| ------- | ------------------------------ |
8805| 401     | Parameter error. Possible cause: Incorrect parameter types. |
8806| 1300002 | This window state is abnormal. |
8807| 1300005 | This window stage is abnormal. |
8808
8809**示例:**
8810
8811```ts
8812// EntryAbility.ets
8813import { UIAbility } from '@kit.AbilityKit';
8814import { BusinessError } from '@kit.BasicServicesKit';
8815
8816export default class EntryAbility extends UIAbility {
8817  // ...
8818
8819  onWindowStageCreate(windowStage: window.WindowStage) {
8820    console.log('onWindowStageCreate');
8821    let windowClass: window.Window | undefined = undefined;
8822    try {
8823      windowStage.createSubWindow('mySubWindow', (err: BusinessError, data) => {
8824        const errCode: number = err.code;
8825        if (errCode) {
8826          console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`);
8827          return;
8828        }
8829        windowClass = data;
8830        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
8831        if (!windowClass) {
8832          console.info('Failed to load the content. Cause: windowClass is null');
8833        }
8834        else {
8835          (windowClass as window.Window).resize(500, 1000);
8836        }
8837      });
8838    } catch (exception) {
8839      console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`);
8840    }
8841  }
8842};
8843```
8844
8845### createSubWindow<sup>9+</sup>
8846
8847createSubWindow(name: string): Promise&lt;Window&gt;
8848
8849创建该WindowStage实例下的子窗口,使用Promise异步回调。
8850
8851**模型约束:** 此接口仅可在Stage模型下使用。
8852
8853**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8854
8855**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8856
8857**参数:**
8858
8859| 参数名 | 类型   | 必填 | 说明           |
8860| ------ | ------ | ---- | -------------- |
8861| name   | string | 是   | 子窗口的名字。 |
8862
8863**返回值:**
8864
8865| 类型                             | 说明                                             |
8866| -------------------------------- | ------------------------------------------------ |
8867| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前WindowStage下的子窗口对象。 |
8868
8869**错误码:**
8870
8871以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8872
8873| 错误码ID | 错误信息 |
8874| ------- | ------------------------------ |
8875| 401     | Parameter error. Possible cause: Incorrect parameter types. |
8876| 1300002 | This window state is abnormal. |
8877| 1300005 | This window stage is abnormal. |
8878
8879**示例:**
8880
8881```ts
8882// EntryAbility.ets
8883import { UIAbility } from '@kit.AbilityKit';
8884import { BusinessError } from '@kit.BasicServicesKit';
8885
8886export default class EntryAbility extends UIAbility {
8887  // ...
8888
8889  onWindowStageCreate(windowStage: window.WindowStage) {
8890    console.log('onWindowStageCreate');
8891    let windowClass: window.Window | undefined = undefined;
8892    try {
8893      let promise = windowStage.createSubWindow('mySubWindow');
8894      promise.then((data) => {
8895        windowClass = data;
8896        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
8897      }).catch((err: BusinessError) => {
8898        console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`);
8899      });
8900    } catch (exception) {
8901      console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`);
8902    }
8903  }
8904};
8905```
8906
8907### createSubWindowWithOptions<sup>11+</sup>
8908
8909createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise&lt;Window&gt;
8910
8911创建该WindowStage实例下的子窗口,使用Promise异步回调。
8912
8913**模型约束:** 此接口仅可在Stage模型下使用。
8914
8915**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8916
8917**系统能力:** SystemCapability.Window.SessionManager
8918
8919**参数:**
8920
8921| 参数名 | 类型   | 必填 | 说明           |
8922| ------ | ------ | ---- | -------------- |
8923| name   | string | 是   | 子窗口的名字。 |
8924| options  | [SubWindowOptions](#subwindowoptions12) | 是   | 子窗口参数。  |
8925
8926**返回值:**
8927
8928| 类型                             | 说明                                             |
8929| -------------------------------- | ------------------------------------------------ |
8930| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前WindowStage下创建的子窗口对象。 |
8931
8932**错误码:**
8933
8934以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8935
8936| 错误码ID | 错误信息 |
8937| ------- | ------------------------------ |
8938| 401     | Parameter error. Possible cause: Incorrect parameter types. |
8939| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
8940| 1300002 | This window state is abnormal. |
8941| 1300005 | This window stage is abnormal. |
8942
8943**示例:**
8944
8945```ts
8946// EntryAbility.ets
8947import { UIAbility } from '@kit.AbilityKit';
8948import { BusinessError } from '@kit.BasicServicesKit';
8949
8950export default class EntryAbility extends UIAbility {
8951  // ...
8952
8953  onWindowStageCreate(windowStage: window.WindowStage) {
8954    console.info('onWindowStageCreate');
8955    let windowClass: window.Window | undefined = undefined;
8956    try {
8957      let options : window.SubWindowOptions = {
8958        title: 'title',
8959        decorEnabled: true
8960      };
8961      let promise = windowStage.createSubWindowWithOptions('mySubWindow', options);
8962      promise.then((data) => {
8963        windowClass = data;
8964        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
8965      }).catch((err: BusinessError) => {
8966        console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`);
8967      });
8968    } catch (exception) {
8969      console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`);
8970    }
8971  }
8972};
8973```
8974
8975### getSubWindow<sup>9+</sup>
8976
8977getSubWindow(callback: AsyncCallback&lt;Array&lt;Window&gt;&gt;): void
8978
8979获取该WindowStage实例下的所有子窗口,使用callback异步回调。
8980
8981**模型约束:** 此接口仅可在Stage模型下使用。
8982
8983**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8984
8985**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
8986
8987**参数:**
8988
8989| 参数名   | 类型                                                | 必填 | 说明                                              |
8990| -------- | --------------------------------------------------- | ---- | ------------------------------------------------- |
8991| callback | AsyncCallback&lt;Array&lt;[Window](#window)&gt;&gt; | 是   | 回调函数。返回当前WindowStage下的所有子窗口对象。 |
8992
8993**错误码:**
8994
8995以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
8996
8997| 错误码ID | 错误信息 |
8998| ------- | ------------------------------ |
8999| 1300005 | This window stage is abnormal. |
9000
9001**示例:**
9002<!--code_no_check-->
9003```ts
9004// EntryAbility.ets
9005import { UIAbility } from '@kit.AbilityKit';
9006import { BusinessError } from '@kit.BasicServicesKit';
9007
9008export default class EntryAbility extends UIAbility {
9009  // ...
9010
9011  onWindowStageCreate(windowStage: window.WindowStage) {
9012    console.log('onWindowStageCreate');
9013    let windowClass: window.Window[] = [];
9014    windowStage.getSubWindow((err: BusinessError, data) => {
9015      const errCode: number = err.code;
9016      if (errCode) {
9017        console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`);
9018        return;
9019      }
9020      windowClass = data;
9021      console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data));
9022    });
9023  }
9024};
9025```
9026
9027### getSubWindow<sup>9+</sup>
9028
9029getSubWindow(): Promise&lt;Array&lt;Window&gt;&gt;
9030
9031获取该WindowStage实例下的所有子窗口,使用Promise异步回调。
9032
9033**模型约束:** 此接口仅可在Stage模型下使用。
9034
9035**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9036
9037**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9038
9039**返回值:**
9040
9041| 类型                                          | 说明                                                 |
9042| --------------------------------------------- | ---------------------------------------------------- |
9043| Promise&lt;Array&lt;[Window](#window)&gt;&gt; | Promise对象。返回当前WindowStage下的所有子窗口对象。 |
9044
9045**错误码:**
9046
9047以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
9048
9049| 错误码ID | 错误信息 |
9050| ------- | ------------------------------ |
9051| 1300005 | This window stage is abnormal. |
9052
9053**示例:**
9054<!--code_no_check-->
9055```ts
9056// EntryAbility.ets
9057import { UIAbility } from '@kit.AbilityKit';
9058import { BusinessError } from '@kit.BasicServicesKit';
9059
9060export default class EntryAbility extends UIAbility {
9061  // ...
9062
9063  onWindowStageCreate(windowStage: window.WindowStage) {
9064    console.log('onWindowStageCreate');
9065    let windowClass: window.Window[] = [];
9066    let promise = windowStage.getSubWindow();
9067    promise.then((data) => {
9068      windowClass = data;
9069      console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data));
9070    }).catch((err: BusinessError) => {
9071      console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`);
9072    });
9073  }
9074};
9075```
9076
9077### loadContent<sup>9+</sup>
9078
9079loadContent(path: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
9080
9081为当前WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。
9082
9083**模型约束:** 此接口仅可在Stage模型下使用。
9084
9085**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9086
9087**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9088
9089**参数:**
9090
9091| 参数名   | 类型                                            | 必填 | 说明                                                         |
9092| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
9093| path     | string                                          | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。  |
9094| storage  | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
9095| callback | AsyncCallback&lt;void&gt;                       | 是   | 回调函数。                                                   |
9096
9097**错误码:**
9098
9099以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9100
9101| 错误码ID | 错误信息 |
9102| ------- | ------------------------------ |
9103| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9104| 1300002 | This window state is abnormal. |
9105| 1300005 | This window stage is abnormal. |
9106
9107**示例:**
9108
9109```ts
9110// EntryAbility.ets
9111import { UIAbility } from '@kit.AbilityKit';
9112import { BusinessError } from '@kit.BasicServicesKit';
9113
9114export default class EntryAbility extends UIAbility {
9115  // ...
9116
9117  storage: LocalStorage = new LocalStorage();
9118
9119  onWindowStageCreate(windowStage: window.WindowStage) {
9120    this.storage.setOrCreate('storageSimpleProp', 121);
9121    console.log('onWindowStageCreate');
9122    try {
9123      windowStage.loadContent('pages/page2', this.storage, (err: BusinessError) => {
9124        const errCode: number = err.code;
9125        if (errCode) {
9126          console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
9127          return;
9128        }
9129        console.info('Succeeded in loading the content.');
9130      });
9131    } catch (exception) {
9132      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
9133    }
9134  }
9135};
9136```
9137
9138### loadContent<sup>9+</sup>
9139
9140loadContent(path: string, storage?: LocalStorage): Promise&lt;void&gt;
9141
9142为当前WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。
9143
9144**模型约束:** 此接口仅可在Stage模型下使用。
9145
9146**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9147
9148**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9149
9150**参数:**
9151
9152| 参数名  | 类型                                            | 必填 | 说明                                                         |
9153| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
9154| path    | string                                          | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 |
9155| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 否   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
9156
9157**返回值:**
9158
9159| 类型                | 说明                      |
9160| ------------------- | ------------------------- |
9161| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9162
9163**错误码:**
9164
9165以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9166
9167| 错误码ID | 错误信息 |
9168| ------- | ------------------------------ |
9169| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9170| 1300002 | This window state is abnormal. |
9171| 1300005 | This window stage is abnormal. |
9172
9173**示例:**
9174
9175```ts
9176// EntryAbility.ets
9177import { UIAbility } from '@kit.AbilityKit';
9178import { BusinessError } from '@kit.BasicServicesKit';
9179
9180export default class EntryAbility extends UIAbility {
9181  // ...
9182
9183  storage: LocalStorage = new LocalStorage();
9184
9185  onWindowStageCreate(windowStage: window.WindowStage) {
9186    this.storage.setOrCreate('storageSimpleProp', 121);
9187    console.log('onWindowStageCreate');
9188    try {
9189      let promise = windowStage.loadContent('pages/page2', this.storage);
9190      promise.then(() => {
9191        console.info('Succeeded in loading the content.');
9192      }).catch((err: BusinessError) => {
9193        console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
9194      });
9195    } catch (exception) {
9196      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
9197    }
9198    ;
9199  }
9200};
9201```
9202
9203### loadContent<sup>9+</sup>
9204
9205loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void
9206
9207为当前WindowStage的主窗口加载具体页面内容,使用callback异步回调。
9208
9209**模型约束:** 此接口仅可在Stage模型下使用。
9210
9211**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9212
9213**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9214
9215**参数:**
9216
9217| 参数名   | 类型                      | 必填 | 说明                 |
9218| -------- | ------------------------- | ---- | -------------------- |
9219| path     | string                    | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 |
9220| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
9221
9222**错误码:**
9223
9224以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9225
9226| 错误码ID | 错误信息 |
9227| ------- | ------------------------------ |
9228| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9229| 1300002 | This window state is abnormal. |
9230| 1300005 | This window stage is abnormal. |
9231
9232**示例:**
9233
9234```ts
9235// EntryAbility.ets
9236import { UIAbility } from '@kit.AbilityKit';
9237import { BusinessError } from '@kit.BasicServicesKit';
9238
9239export default class EntryAbility extends UIAbility {
9240  // ...
9241
9242  onWindowStageCreate(windowStage: window.WindowStage) {
9243    console.log('onWindowStageCreate');
9244    try {
9245      windowStage.loadContent('pages/page2', (err: BusinessError) => {
9246        const errCode: number = err.code;
9247        if (errCode) {
9248          console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
9249          return;
9250        }
9251        console.info('Succeeded in loading the content.');
9252      });
9253    } catch (exception) {
9254      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
9255    }
9256  }
9257};
9258```
9259
9260### loadContentByName<sup>11+</sup>
9261
9262loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
9263
9264为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。
9265
9266**模型约束:** 此接口仅可在Stage模型下使用。
9267
9268**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9269
9270**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9271
9272**参数:**
9273
9274| 参数名   | 类型                                                    | 必填 | 说明                                                         |
9275| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
9276| name     | string                                                  | 是   | 命名路由页面的名称。                                             |
9277| storage  | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
9278| callback | AsyncCallback&lt;void&gt;                               | 是   | 回调函数。                                                   |
9279
9280**错误码:**
9281
9282以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9283
9284| 错误码ID | 错误信息                                      |
9285| -------- | --------------------------------------------- |
9286| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9287| 1300002  | This window state is abnormal.                |
9288| 1300003  | This window manager service works abnormally. |
9289
9290**示例:**
9291
9292<!--code_no_check-->
9293```ts
9294// EntryAbility.ets
9295import { UIAbility } from '@kit.AbilityKit';
9296import { BusinessError } from '@kit.BasicServicesKit';
9297import * as Index from '../pages/Index'; // 导入命名路由页面
9298
9299export default class EntryAbility extends UIAbility {
9300  // ...
9301
9302  storage: LocalStorage = new LocalStorage();
9303
9304  onWindowStageCreate(windowStage: window.WindowStage) {
9305    console.log('onWindowStageCreate');
9306    this.storage.setOrCreate('storageSimpleProp', 121);
9307    try {
9308      windowStage.loadContentByName(Index.entryName, this.storage, (err: BusinessError) => {
9309        const errCode: number = err.code;
9310        if (errCode) {
9311          console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
9312          return;
9313        }
9314        console.info('Succeeded in loading the content.');
9315      });
9316    } catch (exception) {
9317      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
9318    }
9319  }
9320};
9321```
9322<!--code_no_check-->
9323```ts
9324// ets/pages/Index.ets
9325export const entryName : string = 'Index';
9326@Entry({routeName: entryName, storage : LocalStorage.getShared()})
9327@Component
9328export struct Index {
9329  @State message: string = 'Hello World'
9330  build() {
9331    Row() {
9332      Column() {
9333        Text(this.message)
9334          .fontSize(50)
9335          .fontWeight(FontWeight.Bold)
9336      }
9337      .width('100%')
9338    }
9339    .height('100%')
9340  }
9341}
9342```
9343
9344### loadContentByName<sup>11+</sup>
9345
9346loadContentByName(name: string, callback: AsyncCallback&lt;void&gt;): void
9347
9348为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,使用callback异步回调。
9349
9350**模型约束:** 此接口仅可在Stage模型下使用。
9351
9352**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9353
9354**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9355
9356**参数:**
9357
9358| 参数名   | 类型                      | 必填 | 说明             |
9359| -------- | ------------------------- | ---- | ---------------- |
9360| name     | string                    | 是   | 命名路由页面的名称。 |
9361| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。       |
9362
9363**错误码:**
9364
9365以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9366
9367| 错误码ID | 错误信息                                      |
9368| -------- | --------------------------------------------- |
9369| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9370| 1300002  | This window state is abnormal.                |
9371| 1300003  | This window manager service works abnormally. |
9372
9373**示例:**
9374
9375<!--code_no_check-->
9376```ts
9377// EntryAbility.ets
9378import { UIAbility } from '@kit.AbilityKit';
9379import { BusinessError } from '@kit.BasicServicesKit';
9380import * as Index from '../pages/Index'; // 导入命名路由页面
9381
9382export default class EntryAbility extends UIAbility {
9383  // ...
9384
9385  onWindowStageCreate(windowStage: window.WindowStage) {
9386    console.log('onWindowStageCreate');
9387    try {
9388      windowStage.loadContentByName(Index.entryName, (err: BusinessError) => {
9389        const errCode: number = err.code;
9390        if (errCode) {
9391          console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
9392          return;
9393        }
9394        console.info('Succeeded in loading the content.');
9395      });
9396    } catch (exception) {
9397      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
9398    }
9399  }
9400};
9401```
9402<!--code_no_check-->
9403```ts
9404// ets/pages/Index.ets
9405export const entryName : string = 'Index';
9406@Entry({routeName: entryName})
9407@Component
9408export struct Index {
9409  @State message: string = 'Hello World'
9410  build() {
9411    Row() {
9412      Column() {
9413        Text(this.message)
9414          .fontSize(50)
9415          .fontWeight(FontWeight.Bold)
9416      }
9417      .width('100%')
9418    }
9419    .height('100%')
9420  }
9421}
9422```
9423
9424### loadContentByName<sup>11+</sup>
9425
9426loadContentByName(name: string, storage?: LocalStorage): Promise&lt;void&gt;;
9427
9428为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用promise异步回调。
9429
9430**模型约束:** 此接口仅可在Stage模型下使用。
9431
9432**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9433
9434**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9435
9436**参数:**
9437
9438| 参数名  | 类型         | 必填 | 说明                                                         |
9439| ------- | ------------ | ---- | ------------------------------------------------------------ |
9440| name    | string       | 是   | 命名路由页面的名称。                                             |
9441| storage | LocalStorage | 否   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
9442
9443**错误码:**
9444
9445以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9446
9447| 错误码ID | 错误信息                                      |
9448| -------- | --------------------------------------------- |
9449| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9450| 1300002  | This window state is abnormal.                |
9451| 1300003  | This window manager service works abnormally. |
9452
9453**示例:**
9454
9455<!--code_no_check-->
9456```ts
9457// EntryAbility.ets
9458import { UIAbility } from '@kit.AbilityKit';
9459import { BusinessError } from '@kit.BasicServicesKit';
9460import * as Index from '../pages/Index'; // 导入命名路由页面
9461
9462export default class EntryAbility extends UIAbility {
9463  // ...
9464
9465  storage: LocalStorage = new LocalStorage();
9466
9467  onWindowStageCreate(windowStage: window.WindowStage) {
9468    console.log('onWindowStageCreate');
9469    this.storage.setOrCreate('storageSimpleProp', 121);
9470    try {
9471      let promise = windowStage.loadContentByName(Index.entryName, this.storage);
9472      promise.then(() => {
9473        console.info('Succeeded in loading the content.');
9474      }).catch((err: BusinessError) => {
9475        console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
9476      });
9477    } catch (exception) {
9478      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
9479    }
9480  }
9481};
9482```
9483<!--code_no_check-->
9484```ts
9485// ets/pages/Index.ets
9486export const entryName : string = 'Index';
9487@Entry({routeName: entryName, storage : LocalStorage.getShared()})
9488@Component
9489export struct Index {
9490  @State message: string = 'Hello World'
9491  build() {
9492    Row() {
9493      Column() {
9494        Text(this.message)
9495          .fontSize(50)
9496          .fontWeight(FontWeight.Bold)
9497      }
9498      .width('100%')
9499    }
9500    .height('100%')
9501  }
9502}
9503```
9504
9505### on('windowStageEvent')<sup>9+</sup>
9506
9507on(eventType: 'windowStageEvent', callback: Callback&lt;WindowStageEventType&gt;): void
9508
9509开启WindowStage生命周期变化的监听。
9510
9511**模型约束:** 此接口仅可在Stage模型下使用。
9512
9513**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9514
9515**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9516
9517**参数:**
9518
9519| 参数名   | 类型                                                         | 必填 | 说明                                                         |
9520| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
9521| eventType  | string                                                       | 是   | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 |
9522| callback | Callback&lt;[WindowStageEventType](#windowstageeventtype9)&gt; | 是   | 回调函数。返回当前的WindowStage生命周期状态。                |
9523
9524**错误码:**
9525
9526以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9527
9528| 错误码ID | 错误信息 |
9529| ------- | ------------------------------ |
9530| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
9531| 1300002 | This window state is abnormal. |
9532| 1300005 | This window stage is abnormal. |
9533
9534**示例:**
9535
9536```ts
9537// EntryAbility.ets
9538import { UIAbility } from '@kit.AbilityKit';
9539
9540export default class EntryAbility extends UIAbility {
9541  // ...
9542
9543  onWindowStageCreate(windowStage: window.WindowStage) {
9544    console.log('onWindowStageCreate');
9545    try {
9546      windowStage.on('windowStageEvent', (data) => {
9547        console.info('Succeeded in enabling the listener for window stage event changes. Data: ' +
9548        JSON.stringify(data));
9549      });
9550    } catch (exception) {
9551      console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`);
9552    }
9553  }
9554};
9555```
9556
9557### off('windowStageEvent')<sup>9+</sup>
9558
9559off(eventType: 'windowStageEvent', callback?: Callback&lt;WindowStageEventType&gt;): void
9560
9561关闭WindowStage生命周期变化的监听。
9562
9563**模型约束:** 此接口仅可在Stage模型下使用。
9564
9565**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9566
9567**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
9568
9569**参数:**
9570
9571| 参数名   | 类型                                                         | 必填 | 说明                                                         |
9572| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
9573| eventType  | string                                                       | 是   | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 |
9574| callback | Callback&lt;[WindowStageEventType](#windowstageeventtype9)&gt; | 否   | 回调函数。返回当前的WindowStage生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有WindowStage生命周期变化的监听。                |
9575
9576**错误码:**
9577
9578以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9579
9580| 错误码ID | 错误信息 |
9581| ------- | ------------------------------ |
9582| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
9583| 1300002 | This window state is abnormal. |
9584| 1300005 | This window stage is abnormal. |
9585
9586**示例:**
9587
9588```ts
9589// EntryAbility.ets
9590import { UIAbility } from '@kit.AbilityKit';
9591
9592export default class EntryAbility extends UIAbility {
9593  // ...
9594
9595  onWindowStageCreate(windowStage: window.WindowStage) {
9596    console.log('onWindowStageCreate');
9597    const callback = (windowStageEventType: window.WindowStageEventType) => {
9598      // ...
9599    }
9600    try {
9601      windowStage.on('windowStageEvent', callback);
9602    } catch (exception) {
9603      console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`);
9604    }
9605    try {
9606      windowStage.off('windowStageEvent', callback);
9607      // 如果通过on开启多个callback进行监听,同时关闭所有监听:
9608      windowStage.off('windowStageEvent');
9609    } catch (exception) {
9610      console.error(`Failed to disable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`);
9611    }
9612  }
9613};
9614```
9615
9616### on('windowStageClose')<sup>14+</sup>
9617
9618on(eventType: 'windowStageClose', callback: Callback&lt;void&gt;): void
9619
9620开启点击主窗三键区的关闭按钮监听事件,仅在2in1设备中生效。点击主窗口的三键区域的关闭键时触发该回调函数,将不执行注册的[UIAbility.onPrepareToTerminate](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonpreparetoterminate10)生命周期回调函数。
9621
9622**模型约束:** 此接口仅可在Stage模型下使用。
9623
9624**系统能力:** SystemCapability.Window.SessionManager
9625
9626**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
9627
9628**参数:**
9629
9630| 参数名   | 类型                                                         | 必填 | 说明                                                         |
9631| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
9632| eventType  | string                                                       | 是   | 监听事件,固定为'windowStageClose',即开启主窗三键区的关闭按钮监听。|
9633| callback | Callback&lt;void&gt; | 是   | 回调函数。当点击主窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前主窗是否继续关闭,true表示不关闭,false表示关闭。|
9634
9635**错误码:**
9636
9637以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9638
9639| 错误码ID | 错误信息 |
9640| ------- | ------------------------------ |
9641| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
9642| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
9643| 1300002 | This window state is abnormal. |
9644
9645**示例:**
9646
9647```ts
9648// EntryAbility.ets
9649import { UIAbility } from '@kit.AbilityKit';
9650import { window } from '@kit.ArkUI';
9651
9652export default class EntryAbility extends UIAbility {
9653  // ...
9654
9655  onWindowStageCreate(windowStage: window.WindowStage) {
9656    console.info('onWindowStageCreate');
9657    try {
9658      windowStage.on('windowStageClose', () => {
9659        console.info('Succeeded in enabling the listener for window stage close event.');
9660        return false;
9661      });
9662    } catch (exception) {
9663      console.error(`Failed to enable the listener for window stage close event. Cause code: ${exception.code}, message: ${exception.message}`);
9664    }
9665  }
9666};
9667```
9668
9669### off('windowStageClose')<sup>14+</sup>
9670
9671off(eventType: 'windowStageClose', callback?: Callback&lt;void&gt;): void
9672
9673关闭主窗口关闭事件的监听,仅在2in1设备中生效。
9674
9675**模型约束:** 此接口仅可在Stage模型下使用。
9676
9677**系统能力:** SystemCapability.Window.SessionManager
9678
9679**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
9680
9681**参数:**
9682
9683| 参数名   | 类型                                                         | 必填 | 说明                                                         |
9684| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
9685| eventType  | string                                                       | 是   | 监听事件,固定为'windowStageClose',即关闭主窗口关闭事件的监听。 |
9686| callback | Callback&lt;void&gt; | 否   | 回调函数。当点击主窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前主窗是否继续关闭,true表示不关闭,false表示关闭。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有主窗口关闭的监听。 |
9687
9688**错误码:**
9689
9690以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9691
9692| 错误码ID | 错误信息 |
9693| ------- | ------------------------------ |
9694| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
9695| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
9696| 1300002 | This window state is abnormal. |
9697
9698**示例:**
9699
9700```ts
9701// EntryAbility.ets
9702import { UIAbility } from '@kit.AbilityKit';
9703import { window } from '@kit.ArkUI';
9704
9705export default class EntryAbility extends UIAbility {
9706  // ...
9707
9708  onWindowStageCreate(windowStage: window.WindowStage) {
9709    console.info('onWindowStageCreate');
9710    const callback = () => {
9711      // ...
9712      return false;
9713    }
9714    try {
9715      windowStage.on('windowStageClose', callback);
9716      windowStage.off('windowStageClose', callback);
9717      windowStage.off('windowStageClose');
9718    } catch (exception) {
9719      console.error(`Failed to disable the listener for window stage close changes. Cause code: ${exception.code}, message: ${exception.message}`);
9720    }
9721  }
9722};
9723```
9724
9725### setDefaultDensityEnabled<sup>12+</sup>
9726
9727setDefaultDensityEnabled(enabled: boolean): void
9728
9729设置应用是否使用系统默认Density。
9730
9731不调用此接口进行设置,则表示不使用系统默认Density,即窗口会跟随系统显示大小变化重新布局。
9732
9733**模型约束:** 此接口仅可在Stage模型下使用。
9734
9735**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
9736
9737**系统能力:** SystemCapability.Window.SessionManager
9738
9739**参数:**
9740
9741| 参数名           | 类型    | 必填 | 说明                         |
9742| ---------------- | ------- | ---- | ---------------------------- |
9743| enabled | boolean | 是   | 是否设置应用使用系统默认Density。true表示使用系统默认Density,窗口不跟随系统显示大小变化重新布局;false表示不使用系统默认Density,窗口跟随系统显示大小变化重新布局。 |
9744
9745**错误码:**
9746
9747以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9748
9749| 错误码ID | 错误信息 |
9750| ------- | ------------------------------ |
9751| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9752| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
9753| 1300002 | This window state is abnormal. |
9754| 1300005 | This window stage is abnormal. |
9755
9756**示例:**
9757
9758```ts
9759// EntryAbility.ets
9760import { UIAbility } from '@kit.AbilityKit';
9761
9762export default class EntryAbility extends UIAbility {
9763  // ...
9764
9765  onWindowStageCreate(windowStage: window.WindowStage) {
9766    console.log('onWindowStageCreate');
9767    try {
9768      windowStage.setDefaultDensityEnabled(true);
9769    } catch (exception) {
9770      console.error(`Failed to set default density enabled. Cause code: ${exception.code}, message: ${exception.message}`);
9771    }
9772  }
9773};
9774```
9775