• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# (已废弃)(不再使用)@ohos.window (窗口)
2
3窗口提供管理窗口的一些基础能力,包括对当前窗口的创建、销毁、各属性设置,以及对各窗口间的管理调度。
4
5该模块提供以下窗口相关的常用功能:
6
7- [Window](#window):当前窗口实例,窗口管理器管理的基本单元。
8- [WindowStage](#windowstage9):窗口管理器。管理各个基本窗口单元。
9
10> **说明:**
11>
12> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
13>
14> 本文件已废弃,请勿再修改或链接到此页面。最新内容已按规则拆分,具体可见[拆分后的文件](arkts-apis-window.md)。
15
16## 导入模块
17
18```ts
19import { window } from '@kit.ArkUI';
20```
21
22## WindowType<sup>7+</sup>
23
24窗口类型枚举。
25
26**系统能力:** SystemCapability.WindowManager.WindowManager.Core
27
28| 名称                                  | 值 | 说明                                                                                     |
29|-------------------------------------| ------ |----------------------------------------------------------------------------------------|
30| TYPE_APP                            | 0      | 表示应用子窗口。<br>**模型约束:** 此接口仅可在FA模型下使用。                                                   |
31| TYPE_SYSTEM_ALERT                   | 1      | 表示系统告警窗口。<br>- **说明:** 从API version 11开始废弃。<br>- 从API version 7开始支持。                               |
32| TYPE_FLOAT<sup>9+</sup>             | 8      | 表示悬浮窗。<br>**模型约束:** 此接口仅可在Stage模型下使用。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
33| TYPE_DIALOG<sup>10+</sup>           | 16      | 表示模态窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。                                                 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
34| TYPE_MAIN<sup>18+</sup>             | 32      | 表示应用主窗口。<br>此窗口类型不支持在创建窗口时使用,仅可在getWindowProperties接口的返回值中用于读取。                               |
35
36## Configuration<sup>9+</sup>
37
38创建子窗口或系统窗口时的参数。
39
40**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
41
42**系统能力:** SystemCapability.WindowManager.WindowManager.Core
43
44| 名称 | 类型 | 必填 | 说明                                                                          |
45| ---------- | -------------------------- | -- |-----------------------------------------------------------------------------|
46| name       | string                     | 是 | 窗口名字。                                                                       |
47| windowType | [WindowType](#windowtype7) | 是 | 窗口类型。                                                                       |
48| ctx        | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 否 | 当前应用上下文信息。不设置,则默认为空。<br>FA模型下不需要使用该参数,即可创建子窗口,使用该参数时会报错。<br>Stage模型必须使用该参数,用于创建悬浮窗、模态窗或系统窗口。 |
49| displayId  | number                     | 否 | 当前物理屏幕id。不设置,则默认为-1,该参数应为整数。                                             |
50| parentId   | number                     | 否 | 父窗口id。不设置,则默认为-1,该参数应为整数。                                                           |
51| decorEnabled<sup>12+</sup> | boolean | 否 | 是否显示窗口装饰,仅在windowType为TYPE_DIALOG时生效。true表示显示,false表示不显示。此参数默认值为false。<br>**系统能力:** SystemCapability.Window.SessionManager |
52| title<sup>12+</sup> | string| 否 | `decorEnabled`属性设置为true时,窗口的标题内容。标题显示区域最右端不超过系统三键区域最左端,超过部分以省略号表示。不设置,则默认为空字符串。 <br>**系统能力:** SystemCapability.Window.SessionManager |
53| defaultDensityEnabled<sup>20+</sup> | boolean| 否 | 是否使用系统默认Density,使用系统默认Density之后,窗口不会跟随系统显示大小变化重新布局。<br>当创建的系统窗口设置此参数为true时,表示当前窗口使用系统默认Density,且不受[setDefaultDensityEnabled()](#setdefaultdensityenabled12)和[setCustomDensity()](#setcustomdensity15)设置的主窗口的相关影响。<br>当创建的系统窗口设置此参数为false时,表示当前窗口不使用系统默认Density,且会受到[setDefaultDensityEnabled()](#setdefaultdensityenabled12)和[setCustomDensity()](#setcustomdensity15)设置的主窗口的相关影响。<br>默认为false。<br>**系统能力:** SystemCapability.Window.SessionManager |
54
55## AvoidAreaType<sup>7+</sup>
56
57窗口内容需要规避区域的类型枚举。
58
59**系统能力:** SystemCapability.WindowManager.WindowManager.Core
60
61**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
62
63| 名称                             | 值   | 说明                                                         |
64| -------------------------------- | ---- | ------------------------------------------------------------ |
65| TYPE_SYSTEM                      | 0    | 表示系统默认区域。<!--RP11-->包含状态栏和三键导航栏区域。<!--RP11End-->       |
66| TYPE_CUTOUT                      | 1    | 表示刘海屏区域。                                                              |
67| TYPE_SYSTEM_GESTURE<sup>9+</sup> | 2    | 表示手势区域。当前,各设备均无此类型避让区域。                                    |
68| TYPE_KEYBOARD<sup>9+</sup>       | 3    | 表示软键盘区域。                                                              |
69| TYPE_NAVIGATION_INDICATOR<sup>11+</sup> | 4    | 表示底部导航区域。<!--RP12-->OpenHarmony各设备不支持此能力。<!--RP12End-->                             |
70
71
72## SystemBarProperties
73
74状态栏<!--Del-->、三键导航栏的<!--DelEnd-->属性。在设置窗口级状态栏<!--Del-->、三键导航栏<!--DelEnd-->属性时使用。
75
76**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
77
78| 名称                                   | 类型 |  必填 | 说明                                                         |
79| -------------------------------------- | -------- | ---- | ------------------------------------------------------------ |
80| statusBarColor                         | string   |  否   | 状态栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。默认值:`'#66000000'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
81| isStatusBarLightIcon<sup>7+</sup>      | boolean  |  否   | 状态栏图标是否为高亮状态。true表示高亮;false表示不高亮。默认值:false。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
82| statusBarContentColor<sup>8+</sup>     | string   |  否   | 状态栏文字颜色。当设置此属性后,`isStatusBarLightIcon`属性设置无效。默认值:`'#E5FFFFFF'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
83| navigationBarColor                     | string   |  否   | 三键导航栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。默认值:`'#66000000'`。 <br><!--RP13--><!--RP13End--> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
84| isNavigationBarLightIcon<sup>7+</sup>  | boolean  |  否   | 三键导航栏图标是否为高亮状态。true表示高亮;false表示不高亮。默认值:false。 <br><!--RP13--><!--RP13End--> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
85| navigationBarContentColor<sup>8+</sup> | string   |  否   | 三键导航栏文字颜色。当设置此属性后,`isNavigationBarLightIcon`属性设置无效。默认值:`'#E5FFFFFF'`。 <br><!--RP13--><!--RP13End--> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
86| enableStatusBarAnimation<sup>12+</sup> | boolean   |  否   | 是否使能状态栏属性变化时动画效果。true表示变化时使能动画效果;false表示没有使能动画效果。默认值:false。 <br> **系统能力:** SystemCapability.Window.SessionManager|
87| enableNavigationBarAnimation<sup>12+</sup> | boolean   |  否   | 是否使能三键导航栏属性变化时动画效果。true表示变化时使能动画效果;false表示没有使能动画效果。默认值:false。 <br><!--RP13--><!--RP13End--> **系统能力:** SystemCapability.Window.SessionManager|
88
89## StatusBarProperty<sup>18+</sup>
90
91状态栏的属性。在获取状态栏属性信息时返回。
92
93**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
94
95| 名称                                   | 类型 |  必填 | 说明 |
96| ------------------------------------- | -------- | ---- |------- |
97| contentColor     | string   |  是   | 状态栏文字颜色,固定为ARGB格式, 如:`#E5FFFFFF`。 <br> **系统能力:** SystemCapability.Window.SessionManager|
98
99## SystemBarStyle<sup>12+</sup>
100
101状态栏的属性。在设置页面级状态栏属性时使用。
102
103**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
104
105**系统能力:** SystemCapability.WindowManager.WindowManager.Core
106
107| 名称   | 类型 | 只读 | 可选 | 说明               |
108| ------ | -------- | ---- | ---- | ------------------ |
109| statusBarContentColor   | string   | 是   | 是   | 状态栏文字颜色。默认值:`'#E5FFFFFF'`。|
110
111## Orientation<sup>9+</sup>
112
113窗口显示方向类型枚举。
114
115| 名称                                  | 值   | 说明                          |
116| ------------------------------------- | ---- | ----------------------------- |
117| UNSPECIFIED                           | 0    | 表示未定义方向模式,由系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
118| PORTRAIT                              | 1    | 表示竖屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。|
119| LANDSCAPE                             | 2    | 表示横屏显示模式。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
120| PORTRAIT_INVERTED                     | 3    | 表示反向竖屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
121| LANDSCAPE_INVERTED                    | 4    | 表示反向横屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
122| AUTO_ROTATION                         | 5    | 跟随传感器自动旋转,可以旋转到竖屏、横屏、反向竖屏、反向横屏四个方向。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。|
123| AUTO_ROTATION_PORTRAIT                | 6    | 跟随传感器自动竖向旋转,可以旋转到竖屏、反向竖屏,无法旋转到横屏、反向横屏。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
124| AUTO_ROTATION_LANDSCAPE               | 7    | 跟随传感器自动横向旋转,可以旋转到横屏、反向横屏,无法旋转到竖屏、反向竖屏。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
125| AUTO_ROTATION_RESTRICTED              | 8    | 跟随传感器自动旋转,可以旋转到竖屏、横屏、反向竖屏、反向横屏四个方向,且受控制中心的旋转开关控制。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
126| AUTO_ROTATION_PORTRAIT_RESTRICTED     | 9    | 跟随传感器自动竖向旋转,可以旋转到竖屏、反向竖屏,无法旋转到横屏、反向横屏,且受控制中心的旋转开关控制。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
127| AUTO_ROTATION_LANDSCAPE_RESTRICTED    | 10   | 跟随传感器自动横向旋转,可以旋转到横屏、反向横屏,无法旋转到竖屏、反向竖屏,且受控制中心的旋转开关控制。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
128| LOCKED                                | 11   | 表示锁定模式。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
129| AUTO_ROTATION_UNSPECIFIED<sup>12+</sup>        | 12   | 跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定(如在某种设备,可以旋转到竖屏、横屏、反向横屏三个方向,无法旋转到反向竖屏)。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager|
130| USER_ROTATION_PORTRAIT<sup>12+</sup>           | 13   | 调用时临时旋转到竖屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager|
131| USER_ROTATION_LANDSCAPE<sup>12+</sup>          | 14   | 调用时临时旋转到横屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager|
132| USER_ROTATION_PORTRAIT_INVERTED<sup>12+</sup>  | 15   | 调用时临时旋转到反向竖屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager|
133| USER_ROTATION_LANDSCAPE_INVERTED<sup>12+</sup> | 16   | 调用时临时旋转到反向横屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager|
134| FOLLOW_DESKTOP<sup>12+</sup>                   | 17   | 表示跟随桌面的旋转模式。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager|
135
136## Rect<sup>7+</sup>
137
138窗口矩形区域。
139
140**系统能力:** SystemCapability.WindowManager.WindowManager.Core
141
142**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
143
144| 名称   | 类型 | 可读 | 可写 | 说明               |
145| ------ | -------- | ---- | ---- | ------------------ |
146| left   | number   | 是   | 是   | 矩形区域的左边界,单位为px,该参数为整数。 |
147| top    | number   | 是   | 是   | 矩形区域的上边界,单位为px,该参数应为整数。 |
148| width  | number   | 是   | 是   | 矩形区域的宽度,单位为px,该参数应为整数。 |
149| height | number   | 是   | 是   | 矩形区域的高度,单位为px,该参数应为整数。 |
150
151## AvoidArea<sup>7+</sup>
152
153窗口内容规避区域。如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。在规避区无法响应用户点击事件。
154
155除此之外还需注意规避区域的如下约束,具体为:
156
157- 底部手势区域中非底部导航条区域支持点击、长按事件透传,不支持拖入。
158
159- 左右侧边手势区域支持点击、长按以及上下滑动事件透传,不支持拖入。
160
161- 底部导航条区域支持长按、点击、拖入事件响应,不支持事件向下透传。
162
163**系统能力:** SystemCapability.WindowManager.WindowManager.Core
164
165**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
166
167| 名称       | 类型      | 可读 | 可写 | 说明               |
168| ---------- | ------------- | ---- | ---- | ------------------ |
169| visible<sup>9+</sup>    | boolean       | 是   | 是   | 规避区域是否可见。true表示可见;false表示不可见。 |
170| leftRect   | [Rect](#rect7) | 是   | 是   | 屏幕左侧的矩形区。 |
171| topRect    | [Rect](#rect7) | 是   | 是   | 屏幕顶部的矩形区。 |
172| rightRect  | [Rect](#rect7) | 是   | 是   | 屏幕右侧的矩形区。 |
173| bottomRect | [Rect](#rect7) | 是   | 是   | 屏幕底部的矩形区。 |
174
175## Size<sup>7+</sup>
176
177窗口大小。
178
179**系统能力:** SystemCapability.WindowManager.WindowManager.Core
180
181**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
182
183| 名称   | 类型 | 可读 | 可写 | 说明       |
184| ------ | -------- | ---- | ---- | ---------- |
185| width  | number   | 是   | 是   | 窗口宽度,单位为px,该参数应为整数。 |
186| height | number   | 是   | 是   | 窗口高度,单位为px,该参数应为整数。 |
187
188## RectChangeReason<sup>12+</sup>
189
190窗口矩形(窗口位置及窗口大小)变化的原因。
191
192**系统能力:** SystemCapability.Window.SessionManager
193
194**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
195
196| 名称                  | 值   | 说明                                                         |
197| --------------------- | ---- | ------------------------------------------------------------ |
198| UNDEFINED                 | 0    | 默认值。                                                   |
199| MAXIMIZE                | 1    | 窗口最大化。                                                   |
200| RECOVER              | 2    | 窗口恢复到上一次的状态。                                                   |
201| MOVE | 3    | 窗口拖拽移动。 |
202| DRAG  | 4    | 窗口拖拽缩放。 |
203| DRAG_START  | 5    | 窗口开始拖拽缩放。 |
204| DRAG_END  | 6    | 窗口结束拖拽缩放。 |
205
206## RectChangeOptions<sup>12+</sup>
207
208窗口矩形(窗口位置及窗口大小)变化返回的值及变化原因。
209
210**系统能力:** SystemCapability.Window.SessionManager
211
212**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
213
214| 名称       | 类型      | 可读 | 可写 | 说明               |
215| ---------- | ------------- | ---- | ---- | ------------------ |
216| rect   | [Rect](#rect7) | 是   | 是   | 窗口矩形变化后的值。 |
217| reason    | [RectChangeReason](#rectchangereason12) | 是   | 是   | 窗口矩形变化的原因。 |
218
219## AvoidAreaOptions<sup>12+</sup>
220
221系统规避区变化后返回当前规避区域以及规避区域类型。
222
223**系统能力:** SystemCapability.WindowManager.WindowManager.Core
224
225**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
226
227| 名称       | 类型      | 可读 | 可写 | 说明               |
228| ---------- | ------------- | ---- | ---- | ------------------ |
229| type   | [AvoidAreaType](#avoidareatype7) | 是   | 是   | 系统规避区变化后返回的规避区域类型。 |
230| area   | [AvoidArea](#avoidarea7)         | 是   | 是   | 系统规避区变化后返回的规避区域。 |
231
232## WindowProperties
233
234窗口属性。
235
236**系统能力:** SystemCapability.WindowManager.WindowManager.Core
237
238| 名称                                  | 类型                  | 只读 | 可选 | 说明                                                                                                     |
239| ------------------------------------- | ------------------------- | ---- | ---- |--------------------------------------------------------------------------------------------------------|
240| windowRect<sup>7+</sup>               | [Rect](#rect7)             | 否   | 否   | 窗口尺寸,可在页面生命周期[onPageShow](./arkui-ts/ts-custom-component-lifecycle.md#onpageshow)或应用生命周期[onForeground](../apis-ability-kit/js-apis-app-ability-uiAbility.md#onforeground)阶段获取。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。                                                                                                  |
241| drawableRect<sup>11+</sup>            | [Rect](#rect7)             | 否   | 否   | 窗口内的可绘制区域尺寸,其中左边界上边界是相对于窗口计算。在Stage模型下,需要在调用[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)加载页面内容后使用该接口。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                  |
242| type<sup>7+</sup>                     | [WindowType](#windowtype7) | 否   | 否   | 窗口类型。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                  |
243| isFullScreen                          | boolean                   | 否   | 否   | 是否全屏,默认为false。true表示全屏;false表示非全屏。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                                                  |
244| isLayoutFullScreen<sup>7+</sup>       | boolean                   | 否   | 否   | 窗口是否为沉浸式且处于全屏模式(不在悬浮窗、分屏等场景下),默认为false。true表示沉浸式且处于全屏模式;false表示非沉浸式或非全屏模式。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                                                                                            |
245| focusable<sup>7+</sup>                | boolean                   | 是   | 否   | 窗口是否可聚焦,默认为true。true表示可聚焦;false表示不可聚焦。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                |
246| touchable<sup>7+</sup>                | boolean                   | 是   | 否   | 窗口是否可触摸,默认为true。true表示可触摸;false表示不可触摸。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                 |
247| brightness                            | number                    | 否   | 否   | 屏幕亮度。该参数为浮点数,可设置的亮度范围为[0.0, 1.0],其取1.0时表示最大亮度值。如果窗口没有设置亮度值,表示亮度跟随系统,此时获取到的亮度值为-1。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。                      |
248| dimBehindValue<sup>(deprecated)</sup> | number                    | 否   | 否   | 靠后窗口的暗度值。该参数为浮点数,取值范围为[0.0, 1.0],其取1.0表示最暗。<br>- **说明:** 从API version 9开始废弃。<br>- 从API version 7开始支持。当前无可替代接口。|
249| isKeepScreenOn                        | boolean                   | 否   | 否   | 屏幕是否常亮,默认为false。true表示常亮;false表示不常亮。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。                                                                   |
250| isPrivacyMode<sup>7+</sup>            | boolean                   | 否   | 否   | 隐私模式,默认为false。true表示模式开启;false表示模式关闭。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                  |
251| isRoundCorner<sup>(deprecated)</sup>  | boolean                   | 否   | 否   | 窗口是否为圆角。默认为false。true表示圆角;false表示非圆角。<br>- **说明:** 从API version 9开始废弃。<br/>- 从API version 7开始支持。当前无可替代接口。|
252| isTransparent<sup>7+</sup>            | boolean                   | 否   | 否   | 窗口背景是否透明。默认为false。true表示透明;false表示不透明。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                   |
253| id<sup>9+</sup>                       | number                    | 是   | 否   | 窗口ID,默认值为0,该参数应为整数。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                                    |
254| displayId<sup>12+</sup>               | number                    | 是   | 是   | 窗口所在屏幕ID,默认返回主屏幕ID,该参数应为整数。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
255| name<sup>18+</sup>               | string                    | 是   | 是   | 窗口名字,默认为空字符串。<br/>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 |
256
257## DecorButtonStyle<sup>14+</sup>
258
259系统装饰栏按钮样式。
260
261**系统能力:** SystemCapability.Window.SessionManager
262
263**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
264
265| 名称       | 类型      | 可读 | 可写 | 说明               |
266| ---------- | ------------- | ---- | ---- | ------------------ |
267| colorMode   | [ConfigurationConstant.ColorMode](../apis-ability-kit/js-apis-app-ability-configurationConstant.md#colormode) | 是   | 是   | 颜色模式。深色模式下按钮颜色适配为浅色,浅色模式下按钮颜色适配为深色。未设置则默认跟随系统颜色模式。 |
268| buttonBackgroundSize   | number        | 是   | 是   | 按钮高亮显示时的大小,取值范围20vp-40vp,默认值28vp。 |
269| spacingBetweenButtons  | number        | 是   | 是   | 按钮间距,取值范围8vp-24vp,默认值12vp。 |
270| closeButtonRightMargin | number        | 是   | 是   | 关闭按钮右侧距窗口边距,取值范围6vp-22vp,默认值20vp。 |
271| buttonIconSize<sup>20+</sup> | number        | 是   | 是   | 按键icon的大小,取值范围16vp-24vp,默认值20vp。 |
272| buttonBackgroundCornerRadius<sup>20+</sup> | number        | 是   | 是   | 按键背板圆角半径,取值范围4vp-8vp,默认值4vp。 |
273
274## ColorSpace<sup>8+</sup>
275
276色域模式。
277
278**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
279
280**系统能力:** SystemCapability.WindowManager.WindowManager.Core
281
282| 名称       | 值 | 说明           |
283| ---------- | ------ | -------------- |
284| DEFAULT    | 0      | 默认SRGB色域模式。 |
285| WIDE_GAMUT | 1      | 广色域模式。   |
286
287## WindowEventType<sup>10+</sup>
288
289窗口生命周期。
290
291**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
292
293| 名称       | 值 | 说明       |
294| ---------- | ------ | ---------- |
295| WINDOW_SHOWN      | 1      | 切到前台。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
296| WINDOW_ACTIVE     | 2      | 获焦状态。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
297| WINDOW_INACTIVE   | 3      | 失焦状态。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
298| WINDOW_HIDDEN     | 4      | 切到后台。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core|
299| WINDOW_DESTROYED<sup>11+</sup>  | 7      | 窗口销毁。<br> **系统能力:** SystemCapability.Window.SessionManager|
300
301## WindowLimits<sup>11+</sup>
302
303窗口尺寸限制参数。可以通过[setWindowLimits](#setwindowlimits11)设置窗口尺寸限制,并且可以通过[getWindowLimits](#getwindowlimits11)获得当前的窗口尺寸限制。
304
305**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
306
307**系统能力:** SystemCapability.Window.SessionManager
308
309| 名称      | 类型   | 可读 | 可写 | 说明                                                         |
310| :-------- | :----- | :--- | :--- | :----------------------------------------------------------- |
311| maxWidth  | number | 是   | 是   | 窗口的最大宽度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最大宽度。  |
312| maxHeight | number | 是   | 是   | 窗口的最大高度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最大高度。  |
313| minWidth  | number | 是   | 是   | 窗口的最小宽度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最小宽度。  |
314| minHeight | number | 是   | 是   | 窗口的最小高度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最小高度。  |
315
316## WindowStatusType<sup>11+</sup>
317
318窗口模式枚举。
319
320**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
321
322**系统能力:** SystemCapability.Window.SessionManager
323
324| 名称       | 值   | 说明                          |
325| ---------- | ---- | ----------------------------- |
326| UNDEFINED  | 0    | 表示APP未定义窗口模式。       |
327| FULL_SCREEN | 1    | 表示APP全屏模式。             |
328| MAXIMIZE    | 2    | 表示APP窗口最大化模式。   |
329| MINIMIZE    | 3    | 表示APP窗口最小化模式。   |
330| FLOATING    | 4    | 表示APP自由悬浮形式窗口模式。   |
331| SPLIT_SCREEN  | 5    | 表示APP分屏模式。   |
332
333## TitleButtonRect<sup>11+</sup>
334
335标题栏上的最小化、最大化、关闭按钮矩形区域,该区域位置坐标相对窗口右上角。
336
337**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
338
339**系统能力:**  SystemCapability.Window.SessionManager
340
341| 名称   | 类型   | 可读 | 可写 | 说明                                       |
342| ------ | ------ | ---- | ---- | ------------------------------------------ |
343| right  | number | 是   | 是   | 矩形区域的右边界,单位为vp,该参数为整数。 |
344| top    | number | 是   | 是   | 矩形区域的上边界,单位为vp,该参数为整数。 |
345| width  | number | 是   | 是   | 矩形区域的宽度,单位为vp,该参数为整数。   |
346| height | number | 是   | 是   | 矩形区域的高度,单位为vp,该参数为整数。   |
347
348## MaximizePresentation<sup>12+</sup>
349
350窗口最大化时的布局枚举。
351
352**系统能力:**  SystemCapability.Window.SessionManager
353
354| 名称       | 值   | 说明                          |
355| ---------- | ---- | ----------------------------- |
356| FOLLOW_APP_IMMERSIVE_SETTING  | 0    | 最大化时,跟随应用app当前设置的沉浸式布局。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。       |
357| EXIT_IMMERSIVE | 1    | 最大化时,如果当前窗口设置了沉浸式布局会退出沉浸式布局。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。             |
358| ENTER_IMMERSIVE    | 2    | 最大化时,进入沉浸式布局,鼠标Hover在热区上显示窗口标题栏和dock栏。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。   |
359| ENTER_IMMERSIVE_DISABLE_TITLE_AND_DOCK_HOVER<sup>14+</sup>    | 3    | 最大化时,进入沉浸式布局,鼠标Hover在热区上不显示窗口标题栏和dock栏。<br/>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。   |
360
361## MoveConfiguration<sup>15+</sup>
362
363窗口移动选项。
364
365**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
366
367**系统能力:**  SystemCapability.Window.SessionManager
368
369| 名称   | 类型   | 必填 | 说明                                       |
370| ------ | ------ | ---- | ------------------------------------------ |
371| displayId | number | 否 | 目标屏幕ID,该参数应为整数,输入非整数时将向下取整。填入该参数时,将移动到相对于目标屏幕左上角的指定位置。此参数不填或传入目标屏幕ID不存在时,将移动到相对于当前屏幕左上角的指定位置。 |
372
373## WindowDensityInfo<sup>15+</sup>
374
375窗口所在显示设备和窗口自定义的显示密度信息,是与像素单位无关的缩放系数,即显示大小缩放系数。
376
377**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
378
379**系统能力:** SystemCapability.Window.SessionManager
380
381| 名称   | 类型 | 可读 | 可写 | 说明       |
382| ------ | -------- | ---- | ---- | ---------- |
383| systemDensity  | number   | 是   | 否   | 窗口所在屏幕的系统显示大小缩放系数,跟随用户设置变化,该参数变化范围为0.5-4.0。 |
384| defaultDensity | number   | 是   | 否   | 窗口所在屏幕的系统默认显示大小缩放系数,跟随窗口所在屏幕变化,该参数变化范围为0.5-4.0。 |
385| customDensity | number   | 是   | 否   | 窗口自定义设置的显示大小缩放系数,该参数取值范围为0.5-4.0。未设置该参数时,将跟随系统显示大小缩放系数变化。 |
386
387## WindowLayoutInfo<sup>15+</sup>
388
389窗口布局信息。
390
391**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
392
393**系统能力:**  SystemCapability.Window.SessionManager
394
395| 名称   | 类型   | 必填 | 说明                                       |
396| ------ | ------ | ---- | ------------------------------------------ |
397| windowRect<sup>15+</sup> | [Rect](#rect7)  | 是 | 窗口尺寸,窗口在屏幕上的实际位置和大小。 |
398
399## KeyboardInfo<sup>18+</sup>
400
401软键盘窗口信息。
402
403**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
404
405**系统能力:** SystemCapability.Window.SessionManager
406
407| 名称   | 类型   | 必填 | 说明                                       |
408| ------ | ------ | ---- | ------------------------------------------ |
409| beginRect | [Rect](#rect7)  | 是 | 动画开始前软键盘的位置和大小。 |
410| endRect | [Rect](#rect7)  | 是 | 动画结束后软键盘的位置和大小。 |
411| animated<sup>20+</sup> | boolean  | 否 | 当前是否有显示/隐藏动画,true表示有动画,false表示没有。 |
412| config<sup>20+</sup> | [WindowAnimationConfig](#windowanimationconfig20)  | 否 | 动画配置信息。 |
413
414## ShowWindowOptions<sup>20+</sup>
415
416显示子窗口或系统窗口时的参数。
417
418**系统能力:** SystemCapability.Window.SessionManager
419
420**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
421
422| 名称   | 类型   | 必填 | 说明                                       |
423| ------ | ------ | ---- | ------------------------------------------ |
424| focusOnShow | boolean  | 否 | 窗口调用[showWindow()](#showwindow20)显示时是否自动获焦,默认为true。该参数对主窗、模态窗、dialog窗口不生效。|
425
426## WindowAnimationCurve<sup>20+</sup>
427
428窗口动画曲线类型。
429
430**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
431
432**系统能力:**  SystemCapability.Window.SessionManager
433
434| 名称                | 值   | 说明                                                         |
435| ------------------- | ---- | ------------------------------------------------------------ |
436| LINEAR              | 0    | 表示动画从头到尾的速度都是相同的。<br/>使用该曲线类型时[WindowAnimationConfig](#windowanimationconfig20)中duration必填。<br/>使用该曲线类型时[WindowAnimationConfig](#windowanimationconfig20)中param选填,且不生效。 |
437| INTERPOLATION_SPRING | 1    | 表示插值器弹簧曲线,一条从0到1的动画曲线,实际动画值根据曲线进行插值计算。动画时间由曲线参数决定,不受[WindowAnimationConfig](#windowanimationconfig20)中的duration参数控制。<br/>使用该曲线类型时[WindowAnimationConfig](#windowanimationconfig20)中duration选填,且不生效。<br/>使用该曲线类型时[WindowAnimationConfig](#windowanimationconfig20)中param必填。 |
438
439## WindowAnimationConfig<sup>20+</sup>
440
441窗口动画参数配置。
442
443**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
444
445**系统能力:** SystemCapability.Window.SessionManager
446
447| 名称     | 类型                                                      | 必填 | 说明                                                         |
448| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
449| curve    | [WindowAnimationCurve](#windowanimationcurve20)           | 是   | 动画曲线类型。                                               |
450| duration | number                                                    | 否   | 动画播放的时长,单位毫秒(ms)。<br/>默认值:0,最大值:3000。<br/>根据动画曲线类型决定是否必填。 |
451| param    | [WindowAnimationCurveParam](#windowanimationcurveparam20) | 否   | 动画曲线参数,根据动画曲线类型决定是否必填。                 |
452
453## WindowAnimationCurveParam<sup>20+</sup>
454
455type WindowAnimationCurveParam = Array&lt;number&gt;
456
457动画曲线参数。不同曲线类型[WindowAnimationCurve](#windowanimationcurve20),对应的WindowAnimationCurveParam参数含义不同。
458
459**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
460
461**系统能力:** SystemCapability.Window.SessionManager
462
463当曲线类型为LINEAR,动画曲线参数选填,且不生效。
464
465当曲线类型为INTERPOLATION_SPRING时,动画曲线参数需设置为长度为4的数组:[velocity,mass,stiffness,damping]。
466
467- velocity:表示初始速度,类型为number,必填。
468
469  用于描述外部因素对弹性动效产生的影响参数,目的是保证对象从之前的运动状态平滑地过渡到弹性动效。该速度是归一化速度,其值等于动画开始时的实际速度除以动画属性改变值。
470
471- mass:表示质量,类型为number。必填,取值范围为(0, +∞),当取值小于等于0时,按1处理。
472
473  用于描述弹性系统的受力对象,会对弹性系统产生惯性影响。质量越大,震荡的幅度越大,恢复到平衡位置的速度越慢。
474
475- stiffness:表示刚度,类型为number。必填,取值范围为(0, +∞),当取值小于等于0时,按1处理。
476
477  用于描述物体抵抗施加的力而形变的程度。刚度越大,抵抗变形的能力越强,恢复到平衡位置的速度越快。
478
479- damping:表示刚度,类型为number。必填,取值范围为(0, +∞),当取值小于等于0时,按1处理。
480
481  用于描述系统在受到扰动后震荡及衰减的情形。阻尼越大,弹性运动的震荡次数越少、震荡幅度越小。
482
483
484## WindowInfo<sup>18+</sup>
485
486当前窗口的详细信息。
487
488**系统能力:**  SystemCapability.Window.SessionManager
489
490| 名称   | 类型   | 只读 | 可选 | 说明                                       |
491| ------ | ------ | ---- | ---- | ------------------------------------------ |
492| rect  | [Rect](js-apis-window.md#rect7)   | 是   | 否   | 窗口尺寸。 |
493| bundleName  | string   | 是   | 否   | 应用Bundle的名称。          |
494| abilityName | string   | 是   | 否   | Ability的名称。               |
495| windowId | number | 是   | 否   | 窗口ID。   |
496| windowStatusType | [WindowStatusType](js-apis-window.md#windowstatustype11) | 是   | 否   | 窗口模式枚举。   |
497| isFocused | boolean | 是   | 是   | 窗口是否获焦。true表示窗口获焦;false表示窗口未获焦。   |
498
499## WindowTransitionType<sup>20+</sup>
500
501窗口转场动画类型枚举。
502
503**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
504
505**系统能力:**  SystemCapability.Window.SessionManager
506
507| 名称    | 值   | 说明                       |
508| ------- | ---- | -------------------------- |
509| DESTROY | 0    | 表示窗口销毁时的转场动画。 |
510
511## TransitionAnimation<sup>20+</sup>
512
513窗口转场动画配置。
514
515**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
516
517**系统能力:** SystemCapability.Window.SessionManager
518
519| 名称    | 类型                                              | 必填 | 说明                                                         |
520| ------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ |
521| config  | [WindowAnimationConfig](#windowanimationconfig20) | 是   | 本次转场动画配置。                                           |
522| opacity | number                                            | 否   | 不透明度,转场动画作用的窗口属性,值为0时窗口完全透明。当动画类型为WindowTransitionType.DESTROY时,代表动画终点的不透明度。取值范围0~1,在动画结束时恢复为1。 |
523
524## WindowAnchor<sup>20+</sup>
525
526窗口锚点枚举。
527
528**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
529
530**系统能力:**  SystemCapability.Window.SessionManager
531
532| 名称       | 值   | 说明                          |
533| ---------- | ---- | ----------------------------- |
534| TOP_START  | 0    | 窗口左上角。|
535| TOP  | 1    | 窗口上边界横向居中点。|
536| TOP_END  | 2    | 窗口右上角。|
537| START  | 3    | 窗口左边界纵向居中点。|
538| CENTER  | 4    | 窗口横向和纵向居中点。|
539| END  | 5    | 窗口右边界纵向居中点。|
540| BOTTOM_START  | 6    | 窗口左下角。|
541| BOTTOM  | 7    | 窗口下边界横向居中点。|
542| BOTTOM_END  | 8    | 窗口右下角。|
543
544## Callback<sup>15+</sup>
545
546### (data: T)<sup>15+</sup>
547
548(data: T): V;
549
550通用回调函数。
551
552开发者在使用时,可自定义data的参数类型,回调函数返回对应类型的信息。
553
554**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
555
556**系统能力:** SystemCapability.Window.SessionManager
557
558**参数:**
559
560| 参数名 | 类型 | 必填 | 说明 |
561| ---- | ---- | ---- | -------------------------- |
562| data | T    | 是   | 回调函数调用时需要传入T类型的参数。 |
563
564**返回值:**
565
566| 类型 | 说明 |
567| -------------------------------- | ------------------------------------ |
568| V | 回调函数需要返回V类型的返回值。 |
569
570## RotationChangeType<sup>19+</sup>
571
572窗口旋转事件类型。
573
574**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
575
576**系统能力:**  SystemCapability.Window.SessionManager
577
578| 名称   |  值 | 说明                   |
579| ------ | ---- | --------------------- |
580| WINDOW_WILL_ROTATE| 0 | 窗口即将旋转。 |
581| WINDOW_DID_ROTATE | 1 | 窗口旋转结束。 |
582
583## RectType<sup>19+</sup>
584
585窗口矩形区域坐标系类型。
586
587**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
588
589**系统能力:**  SystemCapability.Window.SessionManager
590
591| 名称   | 值 | 说明                   |
592| ------ | ---- | --------------------- |
593| RELATIVE_TO_SCREEN | 0 | 窗口矩形区域相对于屏幕坐标系。 |
594| RELATIVE_TO_PARENT_WINDOW | 1 | 窗口矩形区域相对于父窗口坐标系。 |
595
596## RotationChangeInfo<sup>19+</sup>
597
598窗口旋转变化时的窗口信息。
599
600**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
601
602**系统能力:**  SystemCapability.Window.SessionManager
603
604| 名称   | 类型 | 只读  | 可选 | 说明                    |
605| ------ | ---- | ----- | ---- | ----------------------- |
606| type | [RotationChangeType](#rotationchangetype19) | 否 | 否 | 窗口旋转事件类型。 |
607| orientation | number | 否 | 否 | 窗口显示方向。<br>- 0表示竖屏。<br>- 1表示反向横屏。<br>- 2表示反向竖屏。<br>- 3表示横屏。<br>开发者在使用时,需要注意该方向与display对象的属性orientation含义不一致。 |
608| displayId | number | 否 | 否 | 窗口所在屏幕Id。 |
609| displayRect | [Rect](#rect7) | 否 | 否 | 窗口所在屏幕旋转后的矩形区域大小。 |
610
611## RotationChangeResult<sup>19+</sup>
612
613应用在窗口旋转变化时返回的信息,系统会根据此信息改变当前窗口矩形区域大小。当返回主窗口旋转变化的信息时,系统不改变主窗口的大小。
614应用窗口与系统窗口大小存在限制,具体限制与相关规则可见[resize](#resize9)。
615
616**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
617
618**系统能力:**  SystemCapability.Window.SessionManager
619
620| 名称   | 类型 | 只读  | 可选 | 说明                    |
621| ------ | ---- | ----- | ---- | ----------------------- |
622| rectType | [RectType](#recttype19) | 否 | 否 | 窗口矩形区域坐标系类型。 |
623| windowRect | [Rect](#rect7) | 否 | 否 | 相对于屏幕或父窗坐标系的窗口矩形区域信息。|
624
625## RotationChangeCallback<sup>19+</sup>
626
627### (info: T)<sup>19+</sup>
628
629(info: T): U;
630
631旋转事件通知通用回调函数。
632
633开发者在使用时,回调函数参数类型为[RotationChangeInfo](#rotationchangeinfo19),返回值类型为[RotationChangeResult](#rotationchangeresult19)\|void。
634
635**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
636
637**系统能力:** SystemCapability.Window.SessionManager
638
639**参数:**
640
641| 参数名 | 类型 | 必填 | 说明 |
642| ---- | ---- | ---- | -------------------------- |
643| info | T    | 是   | 回调函数调用时系统传入[RotationChangeInfo](#rotationchangeinfo19)类型的参数。 |
644
645**返回值:**
646
647| 类型 | 说明 |
648| -------------------------------- | ------------------------------------ |
649| U | 回调函数需要返回[RotationChangeResult](#rotationchangeresult19)\|void类型的返回值。 |
650
651## GlobalWindowMode<sup>20+</sup>
652
653窗口模式。
654
655**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
656
657**系统能力:**  SystemCapability.Window.SessionManager
658
659| 名称   | 值 | 类型  | 说明                    |
660| ------ | --- | --- | ------------------------ |
661| FULLSCREEN | 1 | number | 全屏窗口。 |
662| SPLIT  | 1 << 1 | number | 分屏窗口。 |
663| FLOAT   | 1 << 2  | number | 悬浮窗。 |
664| PIP   | 1 << 3  | number | 画中画。 |
665
666## window.createWindow<sup>9+</sup>
667
668createWindow(config: Configuration, callback: AsyncCallback&lt;Window&gt;): void
669
670创建子窗口或者系统窗口,使用callback异步回调。
671
672**需要权限:** ohos.permission.SYSTEM_FLOAT_WINDOW(仅当创建窗口类型为window.WindowType.TYPE_FLOAT时需要申请)
673
674**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
675
676**系统能力:** SystemCapability.WindowManager.WindowManager.Core
677
678**参数:**
679
680| 参数名 | 类型 | 必填 | 说明 |
681| -------- | -------------------------------------- | -- | --------------------------------- |
682| config   | [Configuration](#configuration9)       | 是 | 创建窗口时的参数。   |
683| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调函数。返回当前创建的窗口对象。 |
684
685**错误码:**
686
687以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
688
689| 错误码ID | 错误信息 |
690| ------- | -------------------------------- |
691| 201     | Permission verification failed. The application does not have the permission required to call the API. |
692| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
693| 801     | Capability not supported. createWindow can not work correctly due to limited device capabilities. |
694| 1300001 | Repeated operation. |
695| 1300002 | This window state is abnormal. |
696| 1300004 | Unauthorized operation. |
697| 1300006 | This window context is abnormal. |
698| 1300009 | The parent window is invalid. |
699
700**示例:**
701
702```ts
703import { UIAbility } from '@kit.AbilityKit';
704import { window } from '@kit.ArkUI';
705import { BusinessError } from '@kit.BasicServicesKit';
706
707export default class EntryAbility extends UIAbility {
708  onWindowStageCreate(windowStage: window.WindowStage): void {
709    let windowClass: window.Window | undefined = undefined;
710    let config: window.Configuration = {
711      name: "test",
712      windowType: window.WindowType.TYPE_DIALOG,
713      ctx: this.context
714    };
715    try {
716      window.createWindow(config, (err: BusinessError, data) => {
717        const errCode: number = err.code;
718        if (errCode) {
719          console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`);
720          return;
721        }
722        windowClass = data;
723        console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data));
724        windowClass.resize(500, 1000);
725      });
726    } catch (exception) {
727      console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`);
728    }
729  }
730}
731```
732
733## window.createWindow<sup>9+</sup>
734
735createWindow(config: Configuration): Promise&lt;Window&gt;
736
737创建子窗口或者系统窗口,使用Promise异步回调。
738
739**需要权限:** ohos.permission.SYSTEM_FLOAT_WINDOW(仅当创建窗口类型为window.WindowType.TYPE_FLOAT时需要申请)
740
741**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
742
743**系统能力:** SystemCapability.WindowManager.WindowManager.Core
744
745**参数:**
746
747| 参数名 | 类型 | 必填 | 说明 |
748| ------ | -------------------------------- | -- | ------------------ |
749| config | [Configuration](#configuration9) | 是 | 创建窗口时的参数。 |
750
751**返回值:**
752
753| 类型 | 说明 |
754| -------------------------------- | ------------------------------------ |
755| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前创建的窗口对象。 |
756
757**错误码:**
758
759以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
760
761| 错误码ID | 错误信息 |
762| ------- | -------------------------------- |
763| 201     | Permission verification failed. The application does not have the permission required to call the API. |
764| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
765| 801     | Capability not supported. createWindow can not work correctly due to limited device capabilities. |
766| 1300001 | Repeated operation. |
767| 1300002 | This window state is abnormal. |
768| 1300004 | Unauthorized operation. |
769| 1300006 | This window context is abnormal. |
770| 1300009 | The parent window is invalid. |
771
772**示例:**
773
774```ts
775import { UIAbility } from '@kit.AbilityKit';
776import { window } from '@kit.ArkUI';
777import { BusinessError } from '@kit.BasicServicesKit';
778
779export default class EntryAbility extends UIAbility {
780  onWindowStageCreate(windowStage: window.WindowStage): void {
781    let config: window.Configuration = {
782      name: "test",
783      windowType: window.WindowType.TYPE_DIALOG,
784      ctx: this.context,
785      defaultDensityEnabled: true
786    };
787    try {
788      window.createWindow(config).then((value:window.Window) => {
789        console.info('Succeeded in creating the window. Data: ' + JSON.stringify(value));
790        value.resize(500, 1000);
791      }).catch((err:BusinessError)=> {
792        console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`);
793      });
794    } catch (exception) {
795      console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`);
796    }
797  }
798}
799```
800
801## window.findWindow<sup>9+</sup>
802
803findWindow(name: string): Window
804
805查找name所对应的窗口。
806
807**系统能力:** SystemCapability.WindowManager.WindowManager.Core
808
809**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
810
811**参数:**
812
813| 参数名 | 类型   | 必填 | 说明     |
814| ------ | ------ | ---- | -------- |
815| name   | string | 是   | 窗口名字,即[Configuration](#configuration9)中的name。 |
816
817**返回值:**
818
819| 类型 | 说明 |
820| ----------------- | ------------------- |
821| [Window](#window) | 当前查找的窗口对象。 |
822
823**错误码:**
824
825以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
826
827| 错误码ID | 错误信息 |
828| ------- | -------------------------------- |
829| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
830| 1300002 | This window state is abnormal. |
831
832**示例:**
833
834```ts
835let windowClass: window.Window | undefined = undefined;
836try {
837  windowClass = window.findWindow('test');
838} catch (exception) {
839  console.error(`Failed to find the Window. Cause code: ${exception.code}, message: ${exception.message}`);
840}
841```
842
843## window.getLastWindow<sup>9+</sup>
844
845getLastWindow(ctx: BaseContext, callback: AsyncCallback&lt;Window&gt;): void
846
847获取当前应用内最上层显示的子窗口,使用callback异步回调。
848
849若无应用子窗口或子窗口未调用[showWindow()](#showwindow9)进行显示,则返回应用主窗口。
850
851**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
852
853**系统能力:** SystemCapability.WindowManager.WindowManager.Core
854
855**参数:**
856
857| 参数名 | 类型 | 必填 | 说明 |
858| -------- | -------------------------------------- | -- | ---------------------------------------- |
859| ctx      | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 |
860| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调函数。返回当前应用内最上层的窗口对象。 |
861
862**错误码:**
863
864以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
865
866| 错误码ID | 错误信息 |
867| ------- | -------------------------------- |
868| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
869| 1300002 | This window state is abnormal. Top window or main window is null or destroyed.  |
870| 1300006 | This window context is abnormal. |
871
872**示例:**
873
874```ts
875import { UIAbility } from '@kit.AbilityKit';
876import { window } from '@kit.ArkUI';
877import { BusinessError } from '@kit.BasicServicesKit';
878
879export default class EntryAbility extends UIAbility {
880  // ...
881  onWindowStageCreate(windowStage: window.WindowStage): void {
882    console.info('onWindowStageCreate');
883    windowStage.createSubWindow('TestSubWindow').then((subWindow) => {
884      subWindow.showWindow().then(() => {
885        try {
886          window.getLastWindow(this.context, (err: BusinessError, topWindow) => {
887            const errCode: number = err.code;
888            if (errCode) {
889              console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
890              return;
891            }
892            console.info(`Succeeded in obtaining the top window. Window id: ${topWindow.getWindowProperties().id}`);
893          });
894        } catch (exception) {
895          console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`);
896        }
897      });
898    });
899  }
900  //...
901}
902```
903
904## window.getLastWindow<sup>9+</sup>
905
906getLastWindow(ctx: BaseContext): Promise&lt;Window&gt;
907
908获取当前应用内最上层显示的子窗口,使用Promise异步回调。
909
910若无应用子窗口或子窗口未调用[showWindow()](#showwindow9)进行显示,则返回应用主窗口。
911
912**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
913
914**系统能力:** SystemCapability.WindowManager.WindowManager.Core
915
916**参数:**
917
918| 参数名 | 类型 | 必填 | 说明 |
919| ------ | ----------- | ---- | ------------------------------------------------------------ |
920| ctx    | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用上下文信息。 |
921
922**返回值:**
923
924| 类型 | 说明 |
925| -------------------------------- | ------------------------------------------- |
926| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前应用内最上层的窗口对象。 |
927
928**错误码:**
929
930以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
931
932| 错误码ID | 错误信息 |
933| ------- | -------------------------------- |
934| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
935| 1300002 | This window state is abnormal. Top window or main window is null or destroyed.   |
936| 1300006 | This window context is abnormal. |
937
938**示例:**
939
940```ts
941// EntryAbility.ets
942import { UIAbility } from '@kit.AbilityKit';
943import { window } from '@kit.ArkUI';
944import { BusinessError } from '@kit.BasicServicesKit';
945
946export default class EntryAbility extends UIAbility {
947  // ...
948  onWindowStageCreate(windowStage: window.WindowStage): void {
949    console.info('onWindowStageCreate');
950    windowStage.createSubWindow('TestSubWindow').then((subWindow) => {
951      subWindow.showWindow().then(() => {
952        try {
953          window.getLastWindow(this.context).then((topWindow) => {
954            console.info(`Succeeded in obtaining the top window. Window id: ${topWindow.getWindowProperties().id}`);
955          }).catch((err: BusinessError) => {
956            console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
957          });
958        } catch (exception) {
959          console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`);
960        }
961      });
962    });
963  }
964  //...
965}
966```
967
968## window.shiftAppWindowFocus<sup>11+</sup>
969shiftAppWindowFocus(sourceWindowId: number, targetWindowId: number): Promise&lt;void&gt;
970
971在同应用内将窗口焦点从源窗口转移到目标窗口,仅支持应用主窗和子窗的焦点转移。
972
973目标窗口需确保可获焦属性为true(见[setWindowFocusable()](#setwindowfocusable9)),并确保调用[showWindow()](#showwindow9)成功并执行完毕。
974
975**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
976
977**系统能力:** SystemCapability.Window.SessionManager
978
979**参数:**
980
981| 参数名          | 类型   | 必填  | 说明                    |
982| -------------- | ------ | ----- | ----------------------- |
983| sourceWindowId | number | 是    | 源窗口id,必须是获焦状态。|
984| targetWindowId | number | 是    | 目标窗口id。             |
985
986**返回值:**
987
988| 类型                | 说明                      |
989| ------------------- | ------------------------- |
990| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
991
992**错误码:**
993
994以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
995
996| 错误码ID | 错误信息                                      |
997| ------- | --------------------------------------------- |
998| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
999| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
1000| 1300002 | This window state is abnormal.                |
1001| 1300003 | This window manager service works abnormally. |
1002| 1300004 | Unauthorized operation.                       |
1003
1004**示例:**
1005
1006```ts
1007// EntryAbility.ets
1008import { UIAbility } from '@kit.AbilityKit';
1009import { window } from '@kit.ArkUI';
1010import { BusinessError } from '@kit.BasicServicesKit';
1011
1012export default class EntryAbility extends UIAbility {
1013  onWindowStageCreate(windowStage: window.WindowStage) {
1014    // ...
1015    console.info('onWindowStageCreate');
1016    let mainWindow: window.Window | undefined = undefined;
1017    let subWindow: window.Window | undefined = undefined;
1018    let mainWindowId: number = -1;
1019    let subWindowId: number = -1;
1020
1021    try {
1022      // 获取应用主窗及ID
1023      windowStage.getMainWindow().then((data) => {
1024        if (data == null) {
1025          console.error('Failed to obtain the main window. Cause: The data is empty');
1026          return;
1027        }
1028        mainWindow = data;
1029        mainWindowId = mainWindow.getWindowProperties().id;
1030        console.info('Succeeded in obtaining the main window');
1031      }).catch((err: BusinessError) => {
1032        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
1033      });
1034
1035      // 创建或获取子窗及ID,此时子窗口获焦
1036      windowStage.createSubWindow('testSubWindow').then((data) => {
1037        if (data == null) {
1038          console.error('Failed to obtain the sub window. Cause: The data is empty');
1039          return;
1040        }
1041        subWindow = data;
1042        subWindowId = subWindow.getWindowProperties().id;
1043        subWindow.resize(500, 500);
1044        subWindow.showWindow();
1045
1046        // 监听Window状态,确保已经就绪
1047        subWindow.on("windowEvent", (windowEvent) => {
1048          if (windowEvent == window.WindowEventType.WINDOW_ACTIVE) {
1049            // 切换焦点
1050            window.shiftAppWindowFocus(subWindowId, mainWindowId).then(() => {
1051              console.info('Succeeded in shifting app window focus');
1052            }).catch((err: BusinessError) => {
1053              console.error(`Failed to shift app window focus. Cause code: ${err.code}, message: ${err.message}`);
1054            });
1055          }
1056        });
1057      });
1058    } catch (exception) {
1059      console.error(`Failed to shift app focus. Cause code: ${exception.code}, message: ${exception.message}`);
1060    }
1061  }
1062}
1063```
1064
1065## window.shiftAppWindowPointerEvent<sup>15+</sup>
1066shiftAppWindowPointerEvent(sourceWindowId: number, targetWindowId: number): Promise&lt;void&gt;
1067
1068在同应用内窗口分合场景下,需要将输入事件从源窗口转移到目标窗口,使用Promise异步回调,仅在2in1设备上,针对主窗和子窗生效。
1069
1070在2in1设备上,源窗口需要处于鼠标按下状态,否则调用此接口将不生效。输入事件转移后,会向源窗口补发鼠标抬起事件,并且向目标窗口补发鼠标按下事件。
1071
1072**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
1073
1074**系统能力:** SystemCapability.Window.SessionManager
1075
1076**参数:**
1077
1078| 参数名          | 类型   | 必填  | 说明                    |
1079| -------------- | ------ | ----- | ----------------------- |
1080| sourceWindowId | number | 是    | 源窗口id。推荐使用[getWindowProperties()](#getwindowproperties9)方法获取窗口id属性。            |
1081| targetWindowId | number | 是    | 目标窗口id。推荐使用[getWindowProperties()](#getwindowproperties9)方法获取窗口id属性。             |
1082
1083**返回值:**
1084
1085| 类型                | 说明                      |
1086| ------------------- | ------------------------- |
1087| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1088
1089**错误码:**
1090
1091以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1092
1093| 错误码ID | 错误信息                                      |
1094| ------- | --------------------------------------------- |
1095| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1096| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
1097| 1300002 | This window state is abnormal.                |
1098| 1300003 | This window manager service works abnormally. |
1099| 1300004 | Unauthorized operation.                       |
1100
1101**示例:**
1102
1103```ts
1104// ets/pages/Index.ets
1105import { window } from '@kit.ArkUI';
1106import { BusinessError } from '@kit.BasicServicesKit';
1107
1108@Entry
1109struct Index {
1110  build() {
1111    Row() {
1112      Column() {
1113        Blank('160')
1114          .color(Color.Blue)
1115          .onTouch((event: TouchEvent) => {
1116            if (event.type === TouchType.Down) {
1117              try {
1118                let sourceWindowId = 1;
1119                let targetWindowId = 2;
1120                let promise = window.shiftAppWindowPointerEvent(sourceWindowId, targetWindowId);
1121                promise.then(() => {
1122                  console.info('Succeeded in shifting app window pointer event');
1123                }).catch((err: BusinessError) => {
1124                  console.error(`Failed to shift app window pointer event. Cause code: ${err.code}, message: ${err.message}`);
1125                });
1126              } catch (exception) {
1127                console.error(`Failed to shift app pointer event. Cause code: ${exception.code}, message: ${exception.message}`);
1128              }
1129            }
1130          })
1131      }.width('100%')
1132    }.height('100%').width('100%')
1133  }
1134}
1135```
1136
1137## window.shiftAppWindowTouchEvent<sup>20+</sup>
1138shiftAppWindowTouchEvent(sourceWindowId: number, targetWindowId: number, fingerId: number): Promise&lt;void&gt;
1139
1140在同应用内窗口的分合场景下,需要将触屏输入事件从源窗口转移到目标窗口。使用Promise异步回调,仅在2in1设备上,针对主窗和子窗生效。
1141
1142在2in1设备上,源窗口仅在[onTouch](arkui-ts/ts-universal-events-touch.md#ontouch)事件(其中,事件类型必须为TouchType.Down)的回调方法中调用此接口才会有触屏输入事件转移效果,成功调用此接口后,系统会向源窗口补发触屏抬起(touch up)事件,并且向目标窗口补发触屏按下(touch down)事件。
1143
1144**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
1145
1146**系统能力:** SystemCapability.Window.SessionManager
1147
1148**参数:**
1149
1150| 参数名          | 类型   | 必填  | 说明                    |
1151| -------------- | ------ | ----- | ----------------------- |
1152| sourceWindowId | number | 是    | 源窗口id。推荐使用[getWindowProperties()](#getwindowproperties9)方法获取窗口id属性。            |
1153| targetWindowId | number | 是    | 目标窗口id。推荐使用[getWindowProperties()](#getwindowproperties9)方法获取窗口id属性。             |
1154| fingerId | number | 是    | 触屏事件的fingerId。推荐使用[touchEvent](arkui-ts/ts-universal-events-touch.md#TouchEvent对象说明)事件中[touches](arkui-ts/ts-universal-events-touch.md#TouchObject对象说明)属性获取id。             |
1155
1156**返回值:**
1157
1158| 类型                | 说明                      |
1159| ------------------- | ------------------------- |
1160| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1161
1162**错误码:**
1163
1164以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1165
1166| 错误码ID | 错误信息                                      |
1167| ------- | --------------------------------------------- |
1168| 801     | Capability not supported. Function shiftAppWindowTouchEvent can not work correctly due to limited device capabilities. |
1169| 1300002 | This window state is abnormal.                |
1170| 1300003 | This window manager service works abnormally. |
1171| 1300004 | Unauthorized operation.                       |
1172| 1300016 | Parameter error. Possible cause: 1. Invalid parameter range.|
1173
1174**示例:**
1175
1176```ts
1177// ets/pages/Index.ets
1178import { window } from '@kit.ArkUI';
1179import { BusinessError } from '@kit.BasicServicesKit';
1180
1181@Entry
1182struct Index {
1183  build() {
1184    Row() {
1185      Column() {
1186        Blank('160')
1187          .color(Color.Blue)
1188          .onTouch((event: TouchEvent) => {
1189            // 源窗口触屏事件类型必须为TouchType.Down
1190            if (event.type === TouchType.Down) {
1191              try {
1192                let sourceWindowId = 1;
1193                let targetWindowId = 2;
1194                let promise = window.shiftAppWindowTouchEvent(sourceWindowId, targetWindowId, event.touches[0].id);
1195                promise.then(() => {
1196                  console.info(`Succeeded in shifting app window touch event`);
1197                }).catch((err: BusinessError) => {
1198                  console.error(`Failed to shift app window touch event. Cause code: ${err.code}, message: ${err.message}`);
1199                });
1200              } catch (exception) {
1201                console.error(`Failed to shift app touch event. Cause code: ${exception.code}, message: ${exception.message}`);
1202              }
1203            }
1204          })
1205      }.width('100%')
1206    }.height('100%').width('100%')
1207  }
1208}
1209```
1210
1211## window.getWindowsByCoordinate<sup>14+</sup>
1212
1213getWindowsByCoordinate(displayId: number, windowNumber?: number, x?: number, y?: number): Promise&lt;Array&lt;Window&gt;&gt;
1214
1215查询本应用指定坐标下的可见窗口数组,按当前窗口层级排列,层级最高的窗口对应数组下标为0,使用Promise异步回调。
1216
1217**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
1218
1219**系统能力:** SystemCapability.Window.SessionManager
1220
1221**参数:**
1222
1223| 参数名 | 类型   | 必填 | 说明                                                                        |
1224| ------ | ---------- |----|---------------------------------------------------------------------------|
1225| displayId   | number| 是  | 查询窗口所在的displayId,该参数应为整数,可以在窗口属性[WindowProperties](#windowproperties)中获取。 |
1226| windowNumber    | number| 否  | 查询的窗口数量,该参数应为大于0整数,未设置或小于等于0返回所有满足条件的窗口。                                  |
1227| x    | number | 否  | 查询的x坐标,该参数应为非负整数,未设置或小于0返回所有可见窗口。                                         |
1228| y    | number| 否  | 查询的y坐标,该参数应为非负整数,未设置或小于0返回所有可见窗口。                                         |
1229
1230**返回值:**
1231
1232| 类型                             | 说明                      |
1233| -------------------------------- |-------------------------|
1234| Promise&lt;Array&lt;[Window](#window)&gt;&gt; | Promise对象。返回获取到的窗口对象数组。 |
1235
1236**错误码:**
1237
1238以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1239
1240| 错误码ID    | 错误信息 |
1241|----------| ------------------------------ |
1242| 401      | Parameter error. Possible cause: Incorrect parameter types. |
1243| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
1244| 1300003 | This window manager service works abnormally. |
1245
1246```ts
1247import { UIAbility } from '@kit.AbilityKit';
1248import { window } from '@kit.ArkUI';
1249import { BusinessError } from '@kit.BasicServicesKit';
1250
1251export default class EntryAbility extends UIAbility {
1252
1253  onWindowStageCreate(windowStage: window.WindowStage): void {
1254    try {
1255      let windowClass = windowStage.getMainWindowSync();
1256      let properties = windowClass.getWindowProperties();
1257      window.getWindowsByCoordinate(properties.displayId).then((data) => {
1258        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
1259        for (let window of data) {
1260          // do something with window
1261        }
1262      }).catch((err: BusinessError) => {
1263        console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`);
1264      });
1265      window.getWindowsByCoordinate(properties.displayId, 2, 500, 500).then((data) => {
1266        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
1267        for (let window of data) {
1268          // do something with window
1269        }
1270      }).catch((err: BusinessError) => {
1271        console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`);
1272      });
1273    } catch (exception) {
1274      console.error(`Failed to get window from point. Cause code: ${exception.code}, message: ${exception.message}`);
1275    }
1276  }
1277}
1278```
1279
1280## window.getAllWindowLayoutInfo<sup>15+</sup>
1281
1282getAllWindowLayoutInfo(displayId: number): Promise&lt;Array&lt;WindowLayoutInfo&gt;&gt;
1283
1284获取指定屏幕上可见的窗口布局信息数组,按当前窗口层级排列,层级最高的对应数组index为0,使用Promise异步回调。
1285
1286**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
1287
1288**系统能力:** SystemCapability.Window.SessionManager
1289
1290**参数:**
1291
1292| 参数名 | 类型   | 必填 | 说明                                                                        |
1293| ------ | ---------- |----|---------------------------------------------------------------------------|
1294| displayId   | number| 是  | 需要获取窗口布局信息的displayId,该参数应为整数,且为当前实际存在屏幕的displayId,可以通过窗口属性[WindowProperties](#windowproperties)获取。 |
1295
1296**返回值:**
1297
1298| 类型                             | 说明                      |
1299| -------------------------------- |-------------------------|
1300| Promise&lt;Array&lt;[WindowLayoutInfo](#windowlayoutinfo15)&gt;&gt; | Promise对象。返回获取到的窗口布局信息对象数组。 |
1301
1302**错误码:**
1303
1304以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1305
1306| 错误码ID    | 错误信息 |
1307|----------| ------------------------------ |
1308| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
1309| 801      | Capability not supported. function getAllWindowLayoutInfo can not work correctly due to limited device capabilities. |
1310| 1300003 | This window manager service works abnormally. |
1311
1312```ts
1313import { window } from '@kit.ArkUI';
1314import { BusinessError } from '@kit.BasicServicesKit';
1315
1316try {
1317  let displayId = 0;
1318  let promise = window.getAllWindowLayoutInfo(displayId);
1319  promise.then((data) => {
1320    console.info('Succeeded in obtaining all window layout info. Data: ' + JSON.stringify(data));
1321  }).catch((err: BusinessError) => {
1322    console.error(`Failed to obtain all window layout info. Cause code: ${err.code}, message: ${err.message}`);
1323  });
1324} catch (exception) {
1325  console.error(`Failed to obtain all window layout info. Cause code: ${exception.code}, message: ${exception.message}`);
1326}
1327```
1328
1329## window.getGlobalWindowMode<sup>20+</sup>
1330
1331getGlobalWindowMode(displayId?: number): Promise&lt;number&gt;
1332
1333获取指定屏幕上生命周期位于前台的窗口对应的窗口模式,使用Promise异步回调。
1334
1335**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
1336
1337**系统能力:** SystemCapability.Window.SessionManager
1338
1339**参数:**
1340
1341| 参数名 | 类型   | 必填 | 说明                                                                        |
1342| ------ | ---------- |----|---------------------------------------------------------------------------|
1343| displayId   | number| 否  | 可选的屏幕ID,用于获取对应屏幕上的窗口模式信息。该参数应为大于等于0的整数,小于0时会返回错误码1300016,不传或传值为null以及undefined则代表查询所有屏幕。如果指定的屏幕不存在,返回值为0。|
1344
1345**返回值:**
1346
1347| 类型                             | 说明                      |
1348| -------------------------------- |-------------------------|
1349| Promise&lt;number&gt; | Promise对象。返回获取到的窗口模式。每一个二进制位代表一种窗口模式,当前支持的窗口模式见[GlobalWindowMode](#globalwindowmode20),返回值为对应窗口模式值按位进行或运算的结果,比如,当前屏幕上存在全屏窗口、悬浮窗和画中画三种窗口,则返回值为`0b1\|0b100\|0b1000 = 13`。|
1350
1351**错误码:**
1352
1353以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1354
1355| 错误码ID    | 错误信息 |
1356|----------| ------------------------------ |
1357| 801      | Capability not supported. function getGlobalWindowMode can not work correctly due to limited device capabilities. |
1358| 1300003 | This window manager service works abnormally. |
1359| 1300016 | Parameter error. Possible cause: 1. Invalid parameter range. |
1360
1361```ts
1362import { window } from '@ohos.window';
1363import { BusinessError } from '@kit.BasicServicesKit';
1364
1365try {
1366  let displayId = 0;
1367  let promise = window.getGlobalWindowMode(displayId);
1368  promise.then((data) => {
1369    console.info(`Succeeded in obtaining global window mode. Data: ${data}`);
1370  }).catch((err: BusinessError) => {
1371    console.error(`Failed to obtain global window mode. Cause code: ${err.code}, message: ${err.message}`);
1372  });
1373} catch (exception) {
1374  console.error(`Failed to obtain global window mode. Cause code: ${exception.code}, message: ${exception.message}`);
1375}
1376```
1377
1378## window.create<sup>(deprecated)</sup>
1379
1380create(id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void
1381
1382创建子窗口,使用callback异步回调。
1383
1384> **说明:**
1385>
1386> 从API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。
1387
1388**模型约束:** 此接口仅可在FA模型下使用。
1389
1390**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1391
1392**参数:**
1393
1394| 参数名   | 类型                                   | 必填 | 说明                                 |
1395| -------- | -------------------------------------- | ---- | ------------------------------------ |
1396| id       | string                                 | 是   | 窗口名字,即[Configuration](#configuration9)中的name。|
1397| type     | [WindowType](#windowtype7)              | 是   | 窗口类型。                           |
1398| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前创建的子窗口对象。 |
1399
1400
1401**示例:**
1402
1403```ts
1404import { BusinessError } from '@kit.BasicServicesKit';
1405
1406let windowClass: window.Window | undefined = undefined;
1407window.create('test', window.WindowType.TYPE_APP, (err: BusinessError, data) => {
1408  const errCode: number = err.code;
1409  if (errCode) {
1410    console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`);
1411    return;
1412  }
1413  windowClass = data;
1414  console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data));
1415});
1416```
1417
1418## window.create<sup>(deprecated)</sup>
1419
1420create(id: string, type: WindowType): Promise&lt;Window&gt;
1421
1422创建子窗口,使用Promise异步回调。
1423
1424> **说明:**
1425>
1426> 从API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。
1427
1428**模型约束:** 此接口仅可在FA模型下使用。
1429
1430**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1431
1432**参数:**
1433
1434| 参数名 | 类型                      | 必填 | 说明       |
1435| ------ | ------------------------- | ---- | ---------- |
1436| id     | string                    | 是   | 窗口名字,即[Configuration](#configuration9)中的name。   |
1437| type   | [WindowType](#windowtype7) | 是   | 窗口类型。 |
1438
1439**返回值:**
1440
1441| 类型                             | 说明                                    |
1442| -------------------------------- | --------------------------------------- |
1443| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前创建的子窗口对象。 |
1444
1445
1446**示例:**
1447
1448```ts
1449import { BusinessError } from '@kit.BasicServicesKit';
1450
1451let windowClass: window.Window | undefined = undefined;
1452let promise = window.create('test', window.WindowType.TYPE_APP);
1453promise.then((data) => {
1454  windowClass = data;
1455  console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data));
1456}).catch((err: BusinessError) => {
1457  console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`);
1458});
1459```
1460
1461## window.create<sup>(deprecated)</sup>
1462
1463create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void
1464
1465创建系统窗口,使用callback异步回调。
1466
1467> **说明:**
1468>
1469> 从API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。
1470
1471**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1472
1473**参数:**
1474
1475| 参数名   | 类型                                                    | 必填 | 说明                                 |
1476| -------- | ------------------------------------------------------- | ---- | ------------------------------------ |
1477| ctx      | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用上下文信息。                 |
1478| id       | string                                                  | 是   | 窗口名字,即[Configuration](#configuration9)中的name。   |
1479| type     | [WindowType](#windowtype7)                              | 是   | 窗口类型。                           |
1480| callback | AsyncCallback&lt;[Window](#window)&gt;                  | 是   | 回调函数。返回当前创建的子窗口对象。 |
1481
1482
1483**示例:**
1484
1485```ts
1486import { BusinessError } from '@kit.BasicServicesKit';
1487
1488let windowClass: window.Window | undefined = undefined;
1489window.create('test', window.WindowType.TYPE_SYSTEM_ALERT, (err: BusinessError, data) => {
1490  const errCode: number = err.code;
1491  if (errCode) {
1492    console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`);
1493    return;
1494  }
1495  windowClass = data;
1496  console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data));
1497  windowClass.resetSize(500, 1000);
1498});
1499```
1500
1501## window.create<sup>(deprecated)</sup>
1502
1503create(ctx: BaseContext, id: string, type: WindowType): Promise&lt;Window&gt;
1504
1505创建系统窗口,使用Promise异步回调。
1506
1507> **说明:**
1508>
1509> 从API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。
1510
1511**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1512
1513**参数:**
1514
1515| 参数名 | 类型                      | 必填 | 说明                                                         |
1516| ------ | ------------------------- | ---- | ------------------------------------------------------------ |
1517| ctx    | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用上下文信息。 |
1518| id     | string                    | 是   | 窗口名字,即[Configuration](#configuration9)中的name。 |
1519| type   | [WindowType](#windowtype7) | 是   | 窗口类型。                                                   |
1520
1521**返回值:**
1522
1523| 类型                             | 说明                                    |
1524| -------------------------------- | --------------------------------------- |
1525| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前创建的子窗口对象。 |
1526
1527
1528**示例:**
1529
1530```ts
1531import { BusinessError } from '@kit.BasicServicesKit';
1532
1533let windowClass: window.Window | undefined = undefined;
1534let promise = window.create('test', window.WindowType.TYPE_SYSTEM_ALERT);
1535promise.then((data) => {
1536  windowClass = data;
1537  console.info('Succeeded in creating the window. Data:' + JSON.stringify(data));
1538}).catch((err: BusinessError) => {
1539  console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`);
1540});
1541```
1542
1543## window.find<sup>(deprecated)</sup>
1544
1545find(id: string, callback: AsyncCallback&lt;Window&gt;): void
1546
1547查找id所对应的窗口,使用callback异步回调。
1548
1549> **说明:**
1550>
1551> 从API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。
1552
1553**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1554
1555**参数:**
1556
1557| 参数名   | 类型                                   | 必填 | 说明                                 |
1558| -------- | -------------------------------------- | ---- | ------------------------------------ |
1559| id       | string                                 | 是   | 窗口名字,即[Configuration](#configuration9)中的name。 |
1560| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前查找到的窗口对象。 |
1561
1562**示例:**
1563
1564```ts
1565import { BusinessError } from '@kit.BasicServicesKit';
1566
1567let windowClass: window.Window | undefined = undefined;
1568window.find('test', (err: BusinessError, data) => {
1569  const errCode: number = err.code;
1570  if (errCode) {
1571    console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`);
1572    return;
1573  }
1574  windowClass = data;
1575  console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data));
1576});
1577```
1578
1579## window.find<sup>(deprecated)</sup>
1580
1581find(id: string): Promise&lt;Window&gt;
1582
1583查找id所对应的窗口,使用Promise异步回调。
1584
1585> **说明:**
1586>
1587> 从API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。
1588
1589**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1590
1591**参数:**
1592
1593| 参数名 | 类型   | 必填 | 说明     |
1594| ------ | ------ | ---- | -------- |
1595| id     | string | 是   | 窗口名字,即[Configuration](#configuration9)中的name。 |
1596
1597**返回值:**
1598
1599| 类型                             | 说明                                  |
1600| -------------------------------- | ------------------------------------- |
1601| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前查找的窗口对象。 |
1602
1603**示例:**
1604
1605```ts
1606import { BusinessError } from '@kit.BasicServicesKit';
1607
1608let windowClass: window.Window | undefined = undefined;
1609let promise = window.find('test');
1610promise.then((data) => {
1611  windowClass = data;
1612  console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data));
1613}).catch((err: BusinessError) => {
1614  console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`);
1615});
1616```
1617
1618## window.getTopWindow<sup>(deprecated)</sup>
1619
1620getTopWindow(callback: AsyncCallback&lt;Window&gt;): void
1621
1622获取当前应用内最后显示的窗口,使用callback异步回调。
1623
1624> **说明:**
1625>
1626> 从API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。
1627
1628**模型约束:** 此接口仅可在FA模型下使用。
1629
1630**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1631
1632**参数:**
1633
1634| 参数名   | 类型                                   | 必填 | 说明                                         |
1635| -------- | -------------------------------------- | ---- | -------------------------------------------- |
1636| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前应用内最后显示的窗口对象。 |
1637
1638**示例:**
1639
1640```ts
1641import { BusinessError } from '@kit.BasicServicesKit';
1642
1643let windowClass: window.Window | undefined = undefined;
1644window.getTopWindow((err: BusinessError, data) => {
1645  const errCode: number = err.code;
1646  if (errCode) {
1647    console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
1648    return;
1649  }
1650  windowClass = data;
1651  console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1652});
1653```
1654
1655## window.getTopWindow<sup>(deprecated)</sup>
1656
1657getTopWindow(): Promise&lt;Window&gt;
1658
1659获取当前应用内最后显示的窗口,使用Promise异步回调。
1660
1661> **说明:**
1662>
1663> 从API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。
1664
1665**模型约束:** 此接口仅可在FA模型下使用。
1666
1667**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1668
1669**返回值:**
1670
1671| 类型                             | 说明                                            |
1672| -------------------------------- | ----------------------------------------------- |
1673| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前应用内最后显示的窗口对象。 |
1674
1675**示例:**
1676
1677```ts
1678import { BusinessError } from '@kit.BasicServicesKit';
1679
1680let windowClass: window.Window | undefined = undefined;
1681let promise = window.getTopWindow();
1682promise.then((data)=> {
1683    windowClass = data;
1684    console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1685}).catch((err: BusinessError)=>{
1686    console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
1687});
1688```
1689
1690## window.getTopWindow<sup>(deprecated)</sup>
1691
1692getTopWindow(ctx: BaseContext, callback: AsyncCallback&lt;Window&gt;): void
1693
1694获取当前应用内最后显示的窗口,使用callback异步回调。
1695
1696> **说明:**
1697>
1698> 从API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。
1699
1700**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1701
1702**参数:**
1703
1704| 参数名   | 类型                                   | 必填 | 说明                                                         |
1705| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
1706| ctx      | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md)                            | 是   | 当前应用上下文信息。 |
1707| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前应用内最后显示的窗口对象。                 |
1708
1709**示例:**
1710
1711```ts
1712// EntryAbility.ets
1713import { UIAbility } from '@kit.AbilityKit';
1714import { BusinessError } from '@kit.BasicServicesKit';
1715
1716export default class EntryAbility extends UIAbility {
1717  onWindowStageCreate(windowStage:window.WindowStage){
1718    console.info('onWindowStageCreate');
1719    let windowClass: window.Window | undefined = undefined;
1720    try {
1721      window.getTopWindow(this.context, (err: BusinessError, data) => {
1722        const errCode: number = err.code;
1723        if(errCode){
1724          console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
1725          return ;
1726        }
1727        windowClass = data;
1728        console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1729      });
1730    } catch(error){
1731      console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`);
1732    }
1733  }
1734}
1735```
1736
1737## window.getTopWindow<sup>(deprecated)</sup>
1738
1739getTopWindow(ctx: BaseContext): Promise&lt;Window&gt;
1740
1741获取当前应用内最后显示的窗口,使用Promise异步回调。
1742
1743> **说明:**
1744>
1745> 从API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。
1746
1747**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1748
1749**参数:**
1750
1751| 参数名 | 类型    | 必填 | 说明                                                         |
1752| ------ | ----------- | ---- | ------------------------------------------------------------ |
1753| ctx    | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用上下文信息。 |
1754
1755**返回值:**
1756
1757| 类型                             | 说明                                            |
1758| -------------------------------- | ----------------------------------------------- |
1759| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前应用内最后显示的窗口对象。 |
1760
1761**示例:**
1762
1763```ts
1764// EntryAbility.ets
1765import { UIAbility } from '@kit.AbilityKit';
1766import { BusinessError } from '@kit.BasicServicesKit';
1767
1768export default class EntryAbility extends UIAbility {
1769  onWindowStageCreate(windowStage:window.WindowStage) {
1770    console.info('onWindowStageCreate');
1771    let windowClass: window.Window | undefined = undefined;
1772    let promise = window.getTopWindow(this.context);
1773    promise.then((data) => {
1774      windowClass = data;
1775      console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1776    }).catch((error: BusinessError) => {
1777      console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`);
1778    });
1779  }
1780}
1781```
1782
1783## window.getVisibleWindowInfo<sup>18+</sup>
1784
1785getVisibleWindowInfo(): Promise&lt;Array&lt;WindowInfo&gt;&gt;
1786
1787获取当前屏幕的可见主窗口(未退至后台的主窗口)信息。使用Promise异步回调。
1788
1789**系统能力:** SystemCapability.Window.SessionManager
1790
1791**需要权限:** ohos.permission.VISIBLE_WINDOW_INFO
1792
1793**返回值:**
1794
1795| 类型 | 说明 |
1796| ------------------- | ----------------------- |
1797| Promise&lt;Array&lt;[WindowInfo](#windowinfo18)&gt;&gt; | Promise对象,返回当前可见窗口的相关信息。 |
1798
1799**错误码:**
1800
1801以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
1802
1803| 错误码ID | 错误信息 |
1804| ------- | ------------------------------ |
1805| 201     | Permission verification failed. The application does not have the permission required to call the API. |
1806| 801     | Capability not supported. Function getVisibleWindowInfo can not work correctly due to limited device capabilities. |
1807| 1300003 | This window manager service works abnormally. |
1808
1809**示例:**
1810
1811```ts
1812import { window } from '@kit.ArkUI';
1813import { BusinessError } from '@kit.BasicServicesKit';
1814
1815try {
1816  let promise = window.getVisibleWindowInfo();
1817  promise.then((data) => {
1818    data.forEach(windowInfo=>{
1819      console.info(`left:${windowInfo.rect.left}`);
1820      console.info(`top:${windowInfo.rect.top}`);
1821      console.info(`width:${windowInfo.rect.width}`);
1822      console.info(`height:${windowInfo.rect.height}`);
1823      console.info(`windowId:${windowInfo.windowId}`);
1824      console.info(`windowStatusType:${windowInfo.windowStatusType}`);
1825      console.info(`abilityName:${windowInfo.abilityName}`);
1826      console.info(`bundleName:${windowInfo.bundleName}`);
1827      console.info(`isFocused:${windowInfo.isFocused}`);
1828    })
1829  }).catch((err: BusinessError) => {
1830    console.error('Failed to getWindowInfo. Cause: ' + JSON.stringify(err));
1831  });
1832} catch (exception) {
1833  console.error(`Failed to get visible window info. Cause code: ${exception.code}, message: ${exception.message}`);
1834}
1835```
1836
1837## SpecificSystemBar<sup>11+</sup>
1838
1839type SpecificSystemBar = 'status' \| 'navigation' \| 'navigationIndicator'
1840
1841当前支持显示或隐藏的系统栏类型。
1842
1843**系统能力:** SystemCapability.Window.SessionManager
1844
1845**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1846
1847| 类型       | 说明     |
1848|------------|--------|
1849| 'status'   | 状态栏。   |
1850| 'navigation'   | <!--RP13--><!--RP13End-->三键导航栏。   |
1851| 'navigationIndicator'   | 底部导航。<!--RP12-->OpenHarmony各设备不支持此能力。<!--RP12End--> |
1852
1853## Window
1854
1855当前窗口实例,窗口管理器管理的基本单元。
1856
1857下列API示例中都需先使用[getLastWindow()](#windowgetlastwindow9)、[createWindow()](#windowcreatewindow9)、[findWindow()](#windowfindwindow9)中的任一方法获取到Window实例(windowClass),再通过此实例调用对应方法。
1858
1859### showWindow<sup>9+</sup>
1860
1861showWindow(callback: AsyncCallback&lt;void&gt;): void
1862
1863显示当前窗口,使用callback异步回调,仅支持系统窗口与应用子窗口,或将已显示的应用主窗口层级提升至顶部。
1864
1865**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1866
1867**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1868
1869**参数:**
1870
1871| 参数名 | 类型 | 必填 | 说明 |
1872| -------- | ------------------------- | -- | --------- |
1873| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
1874
1875**错误码:**
1876
1877以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
1878
1879| 错误码ID | 错误信息 |
1880| ------- | ------------------------------ |
1881| 1300002 | This window state is abnormal. |
1882
1883**示例:**
1884
1885```ts
1886import { BusinessError } from '@kit.BasicServicesKit';
1887
1888windowClass.showWindow((err: BusinessError) => {
1889  const errCode: number = err.code;
1890  if (errCode) {
1891    console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`);
1892    return;
1893  }
1894  console.info('Succeeded in showing the window.');
1895});
1896```
1897
1898### showWindow<sup>9+</sup>
1899
1900showWindow(): Promise&lt;void&gt;
1901
1902显示当前窗口,使用Promise异步回调,仅支持系统窗口与应用子窗口,或将已显示的应用主窗口层级提升至顶部。
1903
1904**系统能力:** SystemCapability.WindowManager.WindowManager.Core
1905
1906**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1907
1908**返回值:**
1909
1910| 类型 | 说明 |
1911| ------------------- | ----------------------- |
1912| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1913
1914**错误码:**
1915
1916以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
1917
1918| 错误码ID | 错误信息 |
1919| ------- | ------------------------------ |
1920| 1300002 | This window state is abnormal. |
1921
1922**示例:**
1923
1924```ts
1925import { BusinessError } from '@kit.BasicServicesKit';
1926
1927let promise = windowClass.showWindow();
1928promise.then(() => {
1929  console.info('Succeeded in showing the window.');
1930}).catch((err: BusinessError) => {
1931  console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`);
1932});
1933```
1934
1935### showWindow<sup>20+</sup>
1936
1937showWindow(options: ShowWindowOptions): Promise&lt;void&gt;
1938
1939显示当前窗口,使用Promise异步回调,仅支持系统窗口及应用子窗口,或将已显示的应用主窗口的层级提升至顶部。支持传入参数来控制窗口显示的行为。
1940
1941**系统能力:** SystemCapability.WindowManager.WindowManager
1942
1943**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
1944
1945**返回值:**
1946
1947| 类型 | 说明 |
1948| ------------------- | ----------------------- |
1949| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1950
1951**错误码:**
1952
1953以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
1954
1955| 错误码ID | 错误信息 |
1956| ------- | ------------------------------ |
1957| 801     | Capability not supported. Function showWindow can not work correctly due to limited device capabilities. |
1958| 1300002 | This window state is abnormal. |
1959| 1300004 | Unauthorized operation. |
1960| 1300016     | Parameter validation error. Possible cause: 1. The value of the parameter is out of the allowed range; 2. The length of the parameter exceeds the allowed length; 3. The parameter format is incorrect. |
1961
1962**示例:**
1963
1964```ts
1965// EntryAbility.ets
1966import { window } from '@kit.ArkUI';
1967import { UIAbility } from '@kit.AbilityKit';
1968import { BusinessError } from '@kit.BasicServicesKit';
1969
1970export default class EntryAbility extends UIAbility {
1971  onWindowStageCreate(windowStage: window.WindowStage): void {
1972    console.info('onWindowStageCreate');
1973    // 创建子窗
1974    try {
1975      windowStage.createSubWindow('subWindow').then((data) => {
1976        if (data == null) {
1977          console.error('Failed to create the sub window. Cause: The data is empty');
1978          return;
1979        }
1980        let options: window.ShowWindowOptions = {
1981          focusOnShow: false
1982        };
1983        try {
1984          data.showWindow(options).then(() => {
1985            console.info('Succeeded in showing window');
1986          }).catch((err: BusinessError) => {
1987            console.error(`Failed to show window. Cause code: ${err.code}, message: ${err.message}`);
1988          });
1989        } catch (exception) {
1990          console.error(`Failed to show window. Cause code: ${exception.code}, message: ${exception.message}`);
1991        }
1992      });
1993    } catch (exception) {
1994      console.error(`Failed to create the sub window. Cause code: ${exception.code}, message: ${exception.message}`);
1995    }
1996  }
1997}
1998```
1999
2000### destroyWindow<sup>9+</sup>
2001
2002destroyWindow(callback: AsyncCallback&lt;void&gt;): void
2003
2004销毁当前窗口,使用callback异步回调,仅支持系统窗口及应用子窗口。
2005
2006**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2007
2008**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2009
2010**参数:**
2011
2012| 参数名 | 类型 | 必填 | 说明 |
2013| -------- | ------------------------- | -- | --------- |
2014| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
2015
2016**错误码:**
2017
2018以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
2019
2020| 错误码ID | 错误信息 |
2021| ------- | -------------------------------------------- |
2022| 1300002 | This window state is abnormal.               |
2023
2024**示例:**
2025
2026```ts
2027import { BusinessError } from '@kit.BasicServicesKit';
2028
2029windowClass.destroyWindow((err) => {
2030  const errCode: number = err.code;
2031  if (errCode) {
2032    console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`);
2033    return;
2034  }
2035  console.info('Succeeded in destroying the window.');
2036});
2037```
2038
2039### destroyWindow<sup>9+</sup>
2040
2041destroyWindow(): Promise&lt;void&gt;
2042
2043销毁当前窗口,使用Promise异步回调,仅支持系统窗口及应用子窗口。
2044
2045**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2046
2047**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2048
2049**返回值:**
2050
2051| 类型 | 说明 |
2052| ------------------- | ------------------------ |
2053| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2054
2055**错误码:**
2056
2057以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
2058
2059| 错误码ID | 错误信息 |
2060| ------- | -------------------------------------------- |
2061| 1300002 | This window state is abnormal.               |
2062
2063**示例:**
2064
2065```ts
2066import { BusinessError } from '@kit.BasicServicesKit';
2067
2068let promise = windowClass.destroyWindow();
2069promise.then(() => {
2070  console.info('Succeeded in destroying the window.');
2071}).catch((err: BusinessError) => {
2072  console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`);
2073});
2074```
2075
2076### moveWindowTo<sup>9+</sup>
2077
2078moveWindowTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void
2079
2080移动窗口位置,使用callback异步回调。
2081
2082<!--RP4-->
2083全屏模式下,本接口仅在2in1设备上生效。<!--RP4End-->
2084在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。
2085
2086**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2087
2088**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2089
2090**参数:**
2091
2092| 参数名 | 类型 | 必填 | 说明 |
2093| -------- | ------------------------- | -- | --------------------------------------------- |
2094| x        | number                    | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 |
2095| y        | number                    | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在y轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 |
2096| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                     |
2097
2098**错误码:**
2099
2100以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2101
2102| 错误码ID | 错误信息 |
2103| ------- | -------------------------------------------- |
2104| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2105| 1300002 | This window state is abnormal.               |
2106| 1300003 | This window manager service works abnormally. |
2107
2108**示例:**
2109
2110```ts
2111import { BusinessError } from '@kit.BasicServicesKit';
2112
2113try {
2114  windowClass.moveWindowTo(300, 300, (err: BusinessError) => {
2115    const errCode: number = err.code;
2116    if (errCode) {
2117      console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
2118      return;
2119    }
2120    console.info('Succeeded in moving the window.');
2121  });
2122} catch (exception) {
2123  console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`);
2124}
2125```
2126
2127### moveWindowTo<sup>9+</sup>
2128
2129moveWindowTo(x: number, y: number): Promise&lt;void&gt;
2130
2131移动窗口位置,使用Promise异步回调。调用成功即返回,该接口返回后无法立即获取最终生效结果,如需立即获取,建议使用接口[moveWindowToAsync()](#movewindowtoasync12)。
2132
2133<!--RP4-->
2134全屏模式下,本接口仅在2in1设备上生效。<!--RP4End-->
2135使用此接口,在2in1设备上窗口相对于屏幕移动,在其他设备上窗口相对于父窗口移动。若需要在非2in1设备上相对于屏幕进行移动,建议使用接口[moveWindowToGlobal()](#movewindowtoglobal15)。
2136
2137**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2138
2139**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2140
2141**参数:**
2142
2143| 参数名 | 类型 | 必填 | 说明 |
2144| -- | ----- | -- | --------------------------------------------- |
2145| x | number | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 |
2146| y | number | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在y轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 |
2147
2148**返回值:**
2149
2150| 类型 | 说明 |
2151| ------------------- | ------------------------ |
2152| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2153
2154**错误码:**
2155
2156以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2157
2158| 错误码ID | 错误信息 |
2159| ------- | -------------------------------------------- |
2160| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2161| 1300002 | This window state is abnormal.               |
2162| 1300003 | This window manager service works abnormally. |
2163
2164**示例:**
2165
2166```ts
2167import { BusinessError } from '@kit.BasicServicesKit';
2168
2169try {
2170  let promise = windowClass.moveWindowTo(300, 300);
2171  promise.then(() => {
2172    console.info('Succeeded in moving the window.');
2173  }).catch((err: BusinessError) => {
2174    console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
2175  });
2176} catch (exception) {
2177  console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`);
2178}
2179```
2180
2181### moveWindowToAsync<sup>12+</sup>
2182
2183moveWindowToAsync(x: number, y: number): Promise&lt;void&gt;
2184
2185移动窗口位置,使用Promise异步回调。调用生效后返回,回调中可使用[getWindowProperties()](#getwindowproperties9)(见示例)立即获取最终生效结果。
2186
2187仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效。
2188在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。
2189
2190**系统能力:** SystemCapability.Window.SessionManager
2191
2192**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2193
2194**参数:**
2195
2196| 参数名 | 类型 | 必填 | 说明 |
2197| -- | ----- | -- | --------------------------------------------- |
2198| x | number | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 |
2199| y | number | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在y轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 |
2200
2201**返回值:**
2202
2203| 类型 | 说明 |
2204| ------------------- | ------------------------ |
2205| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2206
2207**错误码:**
2208
2209以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2210
2211| 错误码ID | 错误信息 |
2212| ------- | -------------------------------------------- |
2213| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2214| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
2215| 1300002 | This window state is abnormal.               |
2216| 1300003 | This window manager service works abnormally. |
2217| 1300010 | The operation in the current window status is invalid. |
2218
2219**示例:**
2220
2221```ts
2222import { BusinessError } from '@kit.BasicServicesKit';
2223
2224try {
2225  let promise = windowClass.moveWindowToAsync(300, 300);
2226  promise.then(() => {
2227    console.info('Succeeded in moving the window.');
2228    let rect = windowClass?.getWindowProperties().windowRect;
2229    console.info(`Get window rect: ` + JSON.stringify(rect));
2230  }).catch((err: BusinessError) => {
2231    console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
2232  });
2233} catch (exception) {
2234  console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`);
2235}
2236```
2237
2238### moveWindowToAsync<sup>15+</sup>
2239
2240moveWindowToAsync(x: number, y: number, moveConfiguration?: MoveConfiguration): Promise&lt;void&gt;
2241
2242移动窗口位置,使用Promise异步回调。调用生效后返回,回调中可使用[getWindowProperties()](#getwindowproperties9)(见示例)立即获取最终生效结果。
2243
2244仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效。
2245在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。
2246
2247**系统能力:** SystemCapability.Window.SessionManager
2248
2249**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
2250
2251**参数:**
2252
2253| 参数名 | 类型 | 必填 | 说明 |
2254| -- | ----- | -- | --------------------------------------------- |
2255| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数应该为整数,非整数输入将向下取整。 |
2256| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数应该为整数,非整数输入将向下取整。 |
2257| moveConfiguration | [MoveConfiguration](#moveconfiguration15) | 否 | 窗口移动选项,未设置将默认保持为当前屏幕。 |
2258
2259**返回值:**
2260
2261| 类型 | 说明 |
2262| ------------------- | ------------------------ |
2263| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2264
2265**错误码:**
2266
2267以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2268
2269| 错误码ID | 错误信息 |
2270| ------- | -------------------------------------------- |
2271| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2272| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
2273| 1300002 | This window state is abnormal.               |
2274| 1300003 | This window manager service works abnormally. |
2275| 1300010 | The operation in the current window status is invalid. |
2276
2277**示例:**
2278
2279```ts
2280import { window } from '@kit.ArkUI';
2281import { BusinessError } from '@kit.BasicServicesKit';
2282
2283try {
2284  let moveConfiguration: window.MoveConfiguration = {
2285    displayId: 0
2286  };
2287  let promise = windowClass.moveWindowToAsync(300, 300, moveConfiguration);
2288  promise.then(() => {
2289    console.info('Succeeded in moving the window.');
2290    let rect = windowClass?.getWindowProperties().windowRect;
2291    console.info(`Get window rect: ` + JSON.stringify(rect));
2292  }).catch((err: BusinessError) => {
2293    console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
2294  });
2295} catch (exception) {
2296  console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`);
2297}
2298```
2299
2300### moveWindowToGlobal<sup>13+</sup>
2301
2302moveWindowToGlobal(x: number, y: number): Promise&lt;void&gt;
2303
2304基于屏幕坐标移动窗口位置,使用Promise异步回调。调用生效后返回,回调中可使用[getWindowProperties()](#getwindowproperties9)(见示例)立即获取最终生效结果。
2305
2306全屏模式窗口不支持该操作。
2307
2308在非2in1设备下,子窗会跟随主窗移动。
2309
2310**系统能力:** SystemCapability.Window.SessionManager
2311
2312**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
2313
2314**参数:**
2315
2316| 参数名 | 类型 | 必填 | 说明 |
2317| -- | ----- | -- | --------------------------------------------- |
2318| x | number | 是 | 表示以屏幕左上角为起点,窗口在x轴方向移动的值,单位为px。值为正表示右移,值为负表示左移。该参数仅支持整数输入,浮点数输入将向下取整。 |
2319| y | number | 是 | 表示以屏幕左上角为起点,窗口在y轴方向移动的值,单位为px。值为正表示下移,值为负表示上移。该参数仅支持整数输入,浮点数输入将向下取整。 |
2320
2321**返回值:**
2322
2323| 类型 | 说明 |
2324| ------------------- | ------------------------ |
2325| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2326
2327**错误码:**
2328
2329以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2330
2331| 错误码ID | 错误信息 |
2332| ------- | -------------------------------------------- |
2333| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2334| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
2335| 1300002 | This window state is abnormal.               |
2336| 1300003 | This window manager service works abnormally. |
2337| 1300010 | The operation in the current window status is invalid. |
2338
2339**示例:**
2340
2341```ts
2342import { BusinessError } from '@kit.BasicServicesKit';
2343
2344try {
2345  let promise = windowClass.moveWindowToGlobal(300, 300);
2346  promise.then(() => {
2347    console.info('Succeeded in moving the window.');
2348    let rect = windowClass?.getWindowProperties().windowRect;
2349    console.info(`Get window rect: ` + JSON.stringify(rect));
2350  }).catch((err: BusinessError) => {
2351    console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
2352  });
2353} catch (exception) {
2354  console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`);
2355}
2356```
2357
2358### moveWindowToGlobal<sup>15+</sup>
2359
2360moveWindowToGlobal(x: number, y: number, moveConfiguration?: MoveConfiguration): Promise&lt;void&gt;
2361
2362基于屏幕坐标移动窗口位置,使用Promise异步回调。调用生效后返回,回调中可使用[getWindowProperties()](#getwindowproperties9)(见示例)立即获取最终生效结果。
2363
2364全屏模式窗口不支持该操作。
2365
2366在非2in1设备下,子窗会跟随主窗移动。
2367
2368**系统能力:** SystemCapability.Window.SessionManager
2369
2370**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
2371
2372**参数:**
2373
2374| 参数名 | 类型 | 必填 | 说明 |
2375| -- | ----- | -- | --------------------------------------------- |
2376| x | number | 是 | 表示以目标屏幕左上角为起点,窗口在x轴方向移动的值,单位为px。值为正表示右移,值为负表示左移。该参数应该为整数,非整数输入将向下取整。 |
2377| y | number | 是 | 表示以目标屏幕左上角为起点,窗口在y轴方向移动的值,单位为px。值为正表示下移,值为负表示上移。该参数应该为整数,非整数输入将向下取整。 |
2378| moveConfiguration | [MoveConfiguration](#moveconfiguration15) | 否 | 窗口移动选项,未设置将默认保持为当前屏幕。 |
2379
2380**返回值:**
2381
2382| 类型 | 说明 |
2383| ------------------- | ------------------------ |
2384| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2385
2386**错误码:**
2387
2388以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2389
2390| 错误码ID | 错误信息 |
2391| ------- | -------------------------------------------- |
2392| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2393| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
2394| 1300002 | This window state is abnormal.               |
2395| 1300003 | This window manager service works abnormally. |
2396| 1300010 | The operation in the current window status is invalid. |
2397
2398**示例:**
2399
2400```ts
2401import { window } from '@kit.ArkUI';
2402import { BusinessError } from '@kit.BasicServicesKit';
2403
2404try {
2405  let moveConfiguration: window.MoveConfiguration = {
2406    displayId: 0
2407  };
2408  let promise = windowClass.moveWindowToGlobal(300, 300, moveConfiguration);
2409  promise.then(() => {
2410    console.info('Succeeded in moving the window.');
2411    let rect = windowClass?.getWindowProperties().windowRect;
2412    console.info(`Get window rect: ` + JSON.stringify(rect));
2413  }).catch((err: BusinessError) => {
2414    console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
2415  });
2416} catch (exception) {
2417  console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`);
2418}
2419```
2420
2421### resize<sup>9+</sup>
2422
2423resize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void
2424
2425改变当前窗口大小,使用callback异步回调。
2426
2427应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。
2428应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品端配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
2429
2430系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。
2431
2432设置的宽度与高度受到此约束限制,规则:
2433若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
2434若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
2435
2436全屏模式窗口不支持该操作。
2437
2438**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2439
2440**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2441
2442**参数:**
2443
2444| 参数名 | 类型 | 必填 | 说明 |
2445| -------- | ------------------------- | -- | ------------------------ |
2446| width    | number                    | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
2447| height   | number                    | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
2448| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。                |
2449
2450**错误码:**
2451
2452以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2453
2454| 错误码ID | 错误信息 |
2455| ------- | -------------------------------------------- |
2456| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2457| 1300002 | This window state is abnormal.               |
2458| 1300003 | This window manager service works abnormally. |
2459
2460**示例:**
2461
2462```ts
2463import { BusinessError } from '@kit.BasicServicesKit';
2464
2465try {
2466  windowClass.resize(500, 1000, (err: BusinessError) => {
2467    const errCode: number = err.code;
2468    if (errCode) {
2469      console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
2470      return;
2471    }
2472    console.info('Succeeded in changing the window size.');
2473  });
2474} catch (exception) {
2475  console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`);
2476}
2477```
2478
2479### resize<sup>9+</sup>
2480
2481resize(width: number, height: number): Promise&lt;void&gt;
2482
2483改变当前窗口大小,使用Promise异步回调。调用成功即返回,该接口返回后无法立即获取最终生效结果,如需立即获取,建议使用接口[resizeAsync()](#resizeasync12)。
2484
2485应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。
2486应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品端配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
2487
2488系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。
2489
2490设置的宽度与高度受到此约束限制,规则:
2491若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
2492若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
2493
2494全屏模式窗口不支持该操作。
2495
2496**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2497
2498**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2499
2500**参数:**
2501
2502| 参数名 | 类型 | 必填 | 说明 |
2503| ------ | ------ | -- | ------------------------ |
2504| width  | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
2505| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
2506
2507**返回值:**
2508
2509| 类型 | 说明 |
2510| ------------------- | ------------------------ |
2511| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2512
2513**错误码:**
2514
2515以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2516
2517| 错误码ID | 错误信息 |
2518| ------- | -------------------------------------------- |
2519| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2520| 1300002 | This window state is abnormal.               |
2521| 1300003 | This window manager service works abnormally. |
2522
2523**示例:**
2524
2525```ts
2526import { BusinessError } from '@kit.BasicServicesKit';
2527
2528try {
2529  let promise = windowClass.resize(500, 1000);
2530  promise.then(() => {
2531    console.info('Succeeded in changing the window size.');
2532  }).catch((err: BusinessError) => {
2533    console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
2534  });
2535} catch (exception) {
2536  console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`);
2537}
2538```
2539
2540### resizeAsync<sup>12+</sup>
2541
2542resizeAsync(width: number, height: number): Promise&lt;void&gt;
2543
2544改变当前窗口大小,使用Promise异步回调。调用生效后返回,回调中可使用[getWindowProperties()](#getwindowproperties9)(见示例)立即获取最终生效结果。
2545
2546应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。
2547应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品端配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
2548
2549系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。
2550
2551设置的宽度与高度受到此约束限制,规则:
2552若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
2553若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
2554
2555全屏模式窗口不支持该操作。
2556
2557**系统能力:** SystemCapability.Window.SessionManager
2558
2559**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2560
2561**参数:**
2562
2563| 参数名 | 类型 | 必填 | 说明 |
2564| ------ | ------ | -- | ------------------------ |
2565| width  | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
2566| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
2567
2568**返回值:**
2569
2570| 类型 | 说明 |
2571| ------------------- | ------------------------ |
2572| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2573
2574**错误码:**
2575
2576以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2577
2578| 错误码ID | 错误信息 |
2579| ------- | -------------------------------------------- |
2580| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2581| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
2582| 1300002 | This window state is abnormal.               |
2583| 1300003 | This window manager service works abnormally. |
2584| 1300010 | The operation in the current window status is invalid. |
2585
2586**示例:**
2587
2588```ts
2589import { BusinessError } from '@kit.BasicServicesKit';
2590
2591try {
2592  let promise = windowClass.resizeAsync(500, 1000);
2593  promise.then(() => {
2594    console.info('Succeeded in changing the window size.');
2595    let rect = windowClass?.getWindowProperties().windowRect;
2596    console.info(`Get window rect: ` + JSON.stringify(rect));
2597  }).catch((err: BusinessError) => {
2598    console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
2599  });
2600} catch (exception) {
2601  console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`);
2602}
2603```
2604
2605### getWindowProperties<sup>9+</sup>
2606
2607getWindowProperties(): WindowProperties
2608
2609获取当前窗口的属性,返回WindowProperties。
2610
2611**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2612
2613**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2614
2615**返回值:**
2616
2617| 类型 | 说明 |
2618| ------------------------------------- | ------------- |
2619| [WindowProperties](#windowproperties) | 当前窗口属性。 |
2620
2621**错误码:**
2622
2623以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
2624
2625| 错误码ID | 错误信息 |
2626| ------- | ------------------------------ |
2627| 1300002 | This window state is abnormal. |
2628
2629**示例:**
2630
2631```ts
2632try {
2633  let properties = windowClass.getWindowProperties();
2634} catch (exception) {
2635  console.error(`Failed to obtain the window properties. Cause code: ${exception.code}, message: ${exception.message}`);
2636}
2637```
2638
2639### getWindowDensityInfo<sup>15+</sup>
2640
2641getWindowDensityInfo(): WindowDensityInfo
2642
2643获取当前窗口所在屏幕的系统显示大小缩放系数、系统默认显示大小缩放系数和自定义显示大小缩放系数信息。
2644
2645**系统能力:** SystemCapability.Window.SessionManager
2646
2647**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
2648
2649**返回值:**
2650
2651| 类型 | 说明 |
2652| ------------------------------------- | ------------- |
2653| [WindowDensityInfo](#windowdensityinfo15) | 当前窗口的显示大小缩放系数信息。当返回值为[-1, -1, -1]时,表示当前设备不支持使用该接口。 |
2654
2655**错误码:**
2656
2657以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2658
2659| 错误码ID | 错误信息 |
2660| ------- | ------------------------------ |
2661| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
2662| 1300002 | This window state is abnormal. |
2663
2664**示例:**
2665
2666```ts
2667try {
2668  let densityInfo = windowClass.getWindowDensityInfo();
2669} catch (exception) {
2670  console.error(`Failed to obtain the window densityInfo. Cause code: ${exception.code}, message: ${exception.message}`);
2671}
2672```
2673
2674### getGlobalRect<sup>13+</sup>
2675
2676getGlobalRect(): Rect
2677
2678获取窗口在屏幕上的真实显示区域,同步接口。
2679
2680在某些设备上,窗口显示时可能经过了缩放,此接口可以获取缩放后窗口在屏幕上的真实位置和大小。
2681
2682**系统能力:** SystemCapability.Window.SessionManager
2683
2684**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
2685
2686**返回值:**
2687
2688| 类型 | 说明 |
2689| ------------------- | ------------------------ |
2690| [Rect](#rect7) | 四元组分别表示距离屏幕左上角的x坐标、距离屏幕左上角的y坐标、缩放后的窗口宽度和缩放后的窗口高度。 |
2691
2692**错误码:**
2693
2694以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2695
2696| 错误码ID | 错误信息 |
2697| ------- | -------------------------------------------- |
2698| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
2699| 1300002 | This window state is abnormal.               |
2700| 1300003 | This window manager service works abnormally. |
2701
2702**示例:**
2703
2704```ts
2705try {
2706  let rect = windowClass.getGlobalRect();
2707  console.info(`Succeeded in getting window rect: ` + JSON.stringify(rect));
2708} catch (exception) {
2709  console.error(`Failed to get window rect. Cause code: ${exception.code}, message: ${exception.message}`);
2710}
2711```
2712
2713### getWindowAvoidArea<sup>9+</sup>
2714
2715getWindowAvoidArea(type: AvoidAreaType): AvoidArea
2716
2717获取当前应用窗口避让区。避让区指系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。
2718
2719该接口一般适用于三种场景:1、在onWindowStageCreate方法中,获取应用启动时的初始布局避让区域时可调用该接口;2、当应用内子窗需要临时显示,对显示内容做布局避让时可调用该接口;3、创建悬浮窗、模态窗或WindowType窗口类型为系统窗口时,调用[setSystemAvoidAreaEnabled](#setsystemavoidareaenabled18)方法使能后,该接口对此类窗口亦生效。
2720
2721**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2722
2723**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
2724
2725**参数:**
2726
2727| 参数名 | 类型 | 必填 | 说明 |
2728| ---- |----------------------------------| -- | ------------------------------------------------------------ |
2729| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。 |
2730
2731**返回值:**
2732
2733| 类型 | 说明 |
2734|--------------------------| ----------------- |
2735| [AvoidArea](#avoidarea7) | 窗口内容规避区域。 |
2736
2737**错误码:**
2738
2739以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2740
2741| 错误码ID | 错误信息 |
2742| ------- | ------------------------------ |
2743| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2744| 1300002 | This window state is abnormal. |
2745
2746**示例:**
2747
2748```ts
2749let type = window.AvoidAreaType.TYPE_SYSTEM;
2750try {
2751  let avoidArea = windowClass.getWindowAvoidArea(type);
2752} catch (exception) {
2753  console.error(`Failed to obtain the area. Cause code: ${exception.code}, message: ${exception.message}`);
2754}
2755```
2756
2757### setSystemAvoidAreaEnabled<sup>18+</sup>
2758
2759setSystemAvoidAreaEnabled(enabled: boolean): Promise&lt;void&gt;
2760
2761创建悬浮窗、模态窗或WindowType窗口类型为系统窗口时,可以调用该接口使能窗口获取[避让区](#avoidarea7)。
2762
2763该接口一般适用于此场景:应用于创建上述类型窗口并希望获取避让区信息时,需要在创建窗口后调用该接口设置使能该窗口,再调用[getWindowAvoidArea()](#getwindowavoidarea9)或[on('avoidAreaChange')](#onavoidareachange9)获取或监听避让区。
2764
2765**系统能力:** SystemCapability.Window.SessionManager
2766
2767**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
2768
2769**参数:**
2770
2771| 参数名 | 类型 | 必填 | 说明 |
2772| ---- |----------------------------------| -- | ------------------------------------------------------------ |
2773| enabled | boolean | 是 | 是否可以获取到避让区。<br> true表示可以获取避让区;false表示不可以获取避让区。默认值是false。 |
2774
2775**错误码:**
2776
2777以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2778
2779| 错误码ID | 错误信息 |
2780| ------- | ------------------------------ |
2781| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
2782| 1300002 | This window state is abnormal. |
2783| 1300003 | This window manager service works abnormally. |
2784| 1300004 | Unauthorized operation. |
2785
2786**示例:**
2787
2788```ts
2789import { BusinessError } from '@kit.BasicServicesKit';
2790
2791let windowClass: window.Window | undefined = undefined;
2792let config: window.Configuration = {
2793  name: "test",
2794  windowType: window.WindowType.TYPE_DIALOG,
2795  decorEnabled: true,
2796  ctx: this.context
2797};
2798try {
2799  window.createWindow(config, (err: BusinessError, data) => {
2800    const errCode: number = err.code;
2801    if (errCode) {
2802      console.error(`Failed to create the system window. Cause code: ${err.code}, message: ${err.message}`);
2803      return;
2804    }
2805    windowClass = data;
2806    windowClass.setUIContent("pages/Test");
2807    let enabled = true;
2808    let promise = windowClass.setSystemAvoidAreaEnabled(enabled);
2809    promise.then(() => {
2810      let type = window.AvoidAreaType.TYPE_SYSTEM;
2811      let avoidArea = windowClass?.getWindowAvoidArea(type);
2812    }).catch((err: BusinessError) => {
2813      console.error(`Failed to obtain the system window avoid area. Cause code: ${err.code}, message: ${err.message}`);
2814    });
2815  });
2816} catch (exception) {
2817  console.error(`Failed to create the system window. Cause code: ${exception.code}, message: ${exception.message}`);
2818}
2819```
2820
2821### isSystemAvoidAreaEnabled<sup>18+</sup>
2822
2823isSystemAvoidAreaEnabled(): boolean
2824
2825获取悬浮窗、模态窗或WindowType为系统类型的窗口是否可以获取窗口内容的[避让区](#avoidarea7)。
2826
2827**系统能力:** SystemCapability.Window.SessionManager
2828
2829**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
2830
2831**返回值:**
2832
2833| 类型 | 说明 |
2834| ------------------------------------- | ------------- |
2835| boolean | 是否可以获取窗口内容的避让区。<br> true表示可以获取避让区;false表示不可以获取避让区。 |
2836
2837**错误码:**
2838
2839以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2840
2841| 错误码ID | 错误信息 |
2842| ------- | ------------------------------ |
2843| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
2844| 1300002 | This window state is abnormal. |
2845| 1300003 | This window manager service works abnormally. |
2846| 1300004 | Unauthorized operation. |
2847
2848**示例:**
2849
2850```ts
2851import { BusinessError } from '@kit.BasicServicesKit';
2852
2853let windowClass: window.Window | undefined = undefined;
2854let config: window.Configuration = {
2855  name: "test",
2856  windowType: window.WindowType.TYPE_DIALOG,
2857  decorEnabled: true,
2858  ctx: this.context
2859};
2860try {
2861  window.createWindow(config, (err: BusinessError, data) => {
2862    const errCode: number = err.code;
2863    if (errCode) {
2864      console.error(`Failed to create the system window. Cause code: ${err.code}, message: ${err.message}`);
2865      return;
2866    }
2867    windowClass = data;
2868    windowClass.setUIContent("pages/Test");
2869    let enabled = true;
2870    let promise = windowClass.setSystemAvoidAreaEnabled(enabled);
2871    promise.then(() => {
2872      let enable = windowClass?.isSystemAvoidAreaEnabled();
2873    }).catch((err: BusinessError) => {
2874      console.error(`Failed to obtain whether the system window can get avoid area. Cause code: ${err.code}, message: ${err.message}`);
2875    });
2876  });
2877} catch (exception) {
2878  console.error(`Failed to create the system window. Cause code: ${exception.code}, message: ${exception.message}`);
2879}
2880```
2881
2882### setTitleAndDockHoverShown<sup>14+</sup>
2883
2884setTitleAndDockHoverShown(isTitleHoverShown?: boolean, isDockHoverShown?: boolean): Promise&lt;void&gt;
2885
2886设置主窗口进入全屏沉浸式时鼠标Hover到热区上是否显示窗口标题栏和dock栏,使用Promise异步回调,仅2in1设备可用。
2887
2888**系统能力**:SystemCapability.Window.SessionManager
2889
2890**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
2891
2892**参数:**
2893
2894| 参数名      | 类型    | 必填 | 说明                                                         |
2895| ---------- | ------- | ---- | ------------------------------------------------------------ |
2896| isTitleHoverShown    | boolean | 否   | 是否显示窗口标题栏。<br>true表示显示窗口标题栏;false表示不显示窗口标题栏。默认值是true。</br> |
2897| isDockHoverShown    | boolean | 否   | 是否显示dock栏。<br>true表示显示dock栏;false表示不显示dock栏。默认值是true。</br> |
2898
2899**错误码:**
2900
2901以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2902
2903| 错误码ID | 错误信息 |
2904| ------- | -------------------------------------------- |
2905| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
2906| 1300002 | This window state is abnormal. |
2907| 1300004 | Unauthorized operation. |
2908
2909**示例:**
2910
2911```ts
2912// EntryAbility.ets
2913import { UIAbility } from '@kit.AbilityKit';
2914import { BusinessError } from '@kit.BasicServicesKit';
2915import { window } from '@kit.ArkUI';
2916
2917export default class EntryAbility extends UIAbility {
2918  // ...
2919  onWindowStageCreate(windowStage: window.WindowStage): void {
2920    // 加载主窗口对应的页面。
2921    windowStage.loadContent('pages/Index', (err) => {
2922      let mainWindow: window.Window | undefined = undefined;
2923      // 获取应用主窗口。
2924      windowStage.getMainWindow().then(
2925        data => {
2926          mainWindow = data;
2927          console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
2928          // 调用maximize接口,设置窗口进入全屏沉浸式。
2929          mainWindow.maximize(window.MaximizePresentation.ENTER_IMMERSIVE);
2930          // 调用setTitleAndDockHoverShown接口,隐藏标题栏和dock栏。
2931          mainWindow.setTitleAndDockHoverShown(false, false);
2932        }
2933      ).catch((err: BusinessError) => {
2934          if(err.code){
2935            console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2936          }
2937      });
2938    });
2939  }
2940}
2941```
2942
2943### setWindowLayoutFullScreen<sup>9+</sup>
2944
2945setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise&lt;void&gt;
2946
2947设置主窗口或子窗口的布局是否为沉浸式布局,使用Promise异步回调。<!--RP8-->从API version 14开始,该接口在2in1设备上调用不生效。<!--RP8End-->
2948沉浸式布局生效时,布局不避让状态栏与<!--RP15-->三键导航栏<!--RP15End-->,组件可能产生与其重叠的情况。
2949非沉浸式布局生效时,布局避让状态栏与<!--RP15-->三键导航栏<!--RP15End-->,组件不会与其重叠。
2950
2951**系统能力:** SystemCapability.WindowManager.WindowManager.Core
2952
2953**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2954
2955**参数:**
2956
2957| 参数名 | 类型 | 必填 | 说明 |
2958| ------------------ | ------- | -- | ------------------------------------------------------------------------------------------------ |
2959| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、<!--RP15-->三键导航栏<!--RP15End-->仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 |
2960
2961**返回值:**
2962
2963| 类型 | 说明 |
2964| ------------------- | ------------------------ |
2965| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
2966
2967**错误码:**
2968
2969以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
2970
2971| 错误码ID | 错误信息 |
2972| ------- | -------------------------------------------- |
2973| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2974| 1300002 | This window state is abnormal.               |
2975| 1300003 | This window manager service works abnormally. |
2976
2977**示例:**
2978
2979```ts
2980// EntryAbility.ets
2981import { UIAbility } from '@kit.AbilityKit';
2982import { BusinessError } from '@kit.BasicServicesKit';
2983
2984export default class EntryAbility extends UIAbility {
2985  // ...
2986  onWindowStageCreate(windowStage: window.WindowStage): void {
2987    console.info('onWindowStageCreate');
2988    let windowClass: window.Window | undefined = undefined;
2989    windowStage.getMainWindow((err: BusinessError, data) => {
2990      const errCode: number = err.code;
2991      if (errCode) {
2992        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
2993        return;
2994      }
2995      windowClass = data;
2996      let isLayoutFullScreen = true;
2997      try {
2998        let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen);
2999        promise.then(() => {
3000          console.info('Succeeded in setting the window layout to full-screen mode.');
3001        }).catch((err: BusinessError) => {
3002          console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
3003        });
3004      } catch (exception) {
3005        console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`);
3006      }
3007    });
3008  }
3009}
3010```
3011
3012### setImmersiveModeEnabledState<sup>12+</sup>
3013
3014setImmersiveModeEnabledState(enabled: boolean): void
3015
3016设置当前窗口是否开启沉浸式布局,该调用不会改变窗口模式和窗口大小。<!--RP8-->从API version 14开始,该接口在2in1设备上调用不生效。<!--RP8End-->
3017
3018**系统能力**:SystemCapability.WindowManager.WindowManager.Core
3019
3020**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3021
3022**参数:**
3023
3024| 参数名      | 类型    | 必填 | 说明                                                         |
3025| ---------- | ------- | ---- | ------------------------------------------------------------ |
3026| enabled    | boolean | 是   | 是否开启沉浸式布局。<br>true表示开启,false表示关闭。</br> |
3027
3028**错误码:**
3029
3030以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3031
3032| 错误码ID | 错误信息 |
3033| ------- | -------------------------------------------- |
3034| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3035| 1300002 | This window state is abnormal.               |
3036| 1300003 | This window manager service works abnormally. |
3037| 1300004 | Unauthorized operation.                |
3038
3039**示例:**
3040
3041```ts
3042try {
3043  let enabled = false;
3044  windowClass.setImmersiveModeEnabledState(enabled);
3045} catch (exception) {
3046  console.error(`Failed to set the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`);
3047}
3048```
3049
3050### getImmersiveModeEnabledState<sup>12+</sup>
3051
3052getImmersiveModeEnabledState(): boolean
3053
3054查询当前窗口是否已经开启沉浸式布局。
3055
3056**系统能力**:SystemCapability.WindowManager.WindowManager.Core
3057
3058**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3059
3060**返回值:**
3061| 类型     | 说明                                                                                 |
3062| ------- | ------------------------------------------------------------------------------------ |
3063| boolean | 是否已经开启沉浸式布局。<br>true表示开启,false表示关闭。</br> |
3064
3065**错误码:**
3066
3067以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3068
3069| 错误码ID | 错误信息 |
3070| -------- | -------------------------------------------- |
3071| 1300002  | This window state is abnormal.               |
3072| 1300003  | This window manager service works abnormally. |
3073| 1300004  | Unauthorized operation.               |
3074
3075**示例:**
3076
3077```ts
3078try {
3079  let isEnabled = windowClass.getImmersiveModeEnabledState();
3080} catch (exception) {
3081  console.error(`Failed to get the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`);
3082}
3083```
3084
3085### setWindowDelayRaiseOnDrag<sup>19+</sup>
3086
3087setWindowDelayRaiseOnDrag(isEnabled: boolean): void
3088
3089设置窗口是否使能延迟抬升,仅主窗和子窗可设置。<br>
3090不调用此接口或传入false,主窗和子窗在鼠标左键按下时,默认立即抬升。<br>
3091调用此接口使能延迟抬升后,在跨窗拖拽场景,可拖拽组件所在窗口在鼠标左键按下时不会立即抬升,直到鼠标左键抬起。
3092<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
3093
3094**系统能力**:SystemCapability.Window.SessionManager
3095
3096**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
3097
3098**参数:**
3099
3100| 参数名      | 类型    | 必填 | 说明                                                         |
3101| ---------- | ------- | ---- | ------------------------------------------------------------ |
3102| isEnabled    | boolean | 是   | 是否使能延迟抬升。<br>true表示使能窗口延迟抬升;false表示不使能窗口延迟抬升。 |
3103
3104**错误码:**
3105
3106以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3107
3108| 错误码ID | 错误信息 |
3109| ------- | -------------------------------------------- |
3110| 801     | Capability not supported.function setWindowDelayRaiseOnDrag can not work correctly due to limited device capabilities. |
3111| 1300002 | This window state is abnormal. |
3112
3113**示例:**
3114
3115```ts
3116try {
3117  windowClass.setWindowDelayRaiseOnDrag(true);
3118} catch (exception) {
3119  console.error(`Failed to set window delay raise. Cause code: ${exception.code}, message: ${exception.message}`);
3120}
3121```
3122
3123### setWindowSystemBarEnable<sup>9+</sup>
3124
3125setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise&lt;void&gt;
3126
3127<!--RP14-->设置主窗口状态栏、三键导航栏的可见模式,状态栏通过status控制、三键导航栏通过navigation控制<!--RP14End-->,使用Promise异步回调。<br>从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
3128
3129调用生效后返回并不表示状态栏和<!--RP15-->三键导航栏<!--RP15End-->的显示或隐藏已完成。子窗口调用后不生效。非全屏模式(悬浮窗、分屏等场景)下配置不生效。
3130
3131**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3132
3133**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3134
3135**参数:**
3136
3137| 参数名 | 类型  | 必填 | 说明 |
3138| ----- | ---------------------------- | -- | --------------------------------- |
3139| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、<!--RP15-->三键导航栏<!--RP15End-->是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];设置为[],则不显示。 |
3140
3141**返回值:**
3142
3143| 类型 | 说明 |
3144| ------------------- | ------------------------ |
3145| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
3146
3147**错误码:**
3148
3149以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3150
3151| 错误码ID | 错误信息 |
3152| ------- | -------------------------------------------- |
3153| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3154| 1300002 | This window state is abnormal.               |
3155| 1300003 | This window manager service works abnormally. |
3156
3157**示例:**
3158
3159```ts
3160// 此处以状态栏等均不显示为例
3161// EntryAbility.ets
3162import { UIAbility } from '@kit.AbilityKit';
3163import { BusinessError } from '@kit.BasicServicesKit';
3164
3165export default class EntryAbility extends UIAbility {
3166  // ...
3167  onWindowStageCreate(windowStage: window.WindowStage): void {
3168    console.info('onWindowStageCreate');
3169    let windowClass: window.Window | undefined = undefined;
3170    windowStage.getMainWindow((err: BusinessError, data) => {
3171      const errCode: number = err.code;
3172      if (errCode) {
3173        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
3174        return;
3175      }
3176      windowClass = data;
3177      let names: Array<'status' | 'navigation'> = [];
3178      try {
3179        let promise = windowClass.setWindowSystemBarEnable(names);
3180        promise.then(() => {
3181          console.info('Succeeded in setting the system bar to be invisible.');
3182        }).catch((err: BusinessError) => {
3183          console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
3184        });
3185      } catch (exception) {
3186        console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`);
3187      }
3188    });
3189  }
3190}
3191```
3192
3193### setSpecificSystemBarEnabled<sup>11+</sup>
3194
3195setSpecificSystemBarEnabled(name: SpecificSystemBar, enable: boolean, enableAnimation?: boolean): Promise&lt;void&gt;
3196
3197设置主窗口状态栏、<!--RP15-->三键导航栏<!--RP15End-->的显示和隐藏,使用Promise异步回调。<br>从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
3198
3199调用生效后返回并不表示状态栏和<!--RP15-->三键导航栏<!--RP15End-->的显示或隐藏已完成。子窗口调用后不生效。非全屏模式(悬浮窗、分屏等场景)下配置不生效。
3200
3201**系统能力:** SystemCapability.Window.SessionManager
3202
3203**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3204
3205**参数:**
3206
3207| 参数名 | 类型  | 必填 | 说明 |
3208| ----- | ---------------------------- | -- | --------------------------------- |
3209| name  | [SpecificSystemBar](#specificsystembar11) | 是 | 设置窗口全屏模式时,显示或隐藏的系统栏类型。 |
3210| enable  | boolean | 是 | 设置窗口全屏模式时状态栏或<!--RP15-->三键导航栏<!--RP15End-->是否显示,true表示显示, false表示隐藏。|
3211| enableAnimation<sup>12+</sup>  | boolean | 否 | 设置状态栏或<!--RP15-->三键导航栏<!--RP15End-->显示状态变化时是否使用动画,true表示使用, false表示不使用,默认值为false。|
3212
3213**返回值:**
3214
3215| 类型 | 说明 |
3216| ------------------- | ------------------------ |
3217| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
3218
3219**错误码:**
3220
3221以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3222
3223| 错误码ID | 错误信息 |
3224| ------- | -------------------------------------------- |
3225| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3226| 1300002 | This window state is abnormal.               |
3227| 1300003 | This window manager service works abnormally. |
3228
3229**示例:**
3230
3231```ts
3232// 此处以隐藏状态栏为例
3233// EntryAbility.ets
3234import { UIAbility } from '@kit.AbilityKit';
3235import { BusinessError } from '@kit.BasicServicesKit';
3236
3237export default class EntryAbility extends UIAbility {
3238  // ...
3239  onWindowStageCreate(windowStage: window.WindowStage): void {
3240    console.info('onWindowStageCreate');
3241    let windowClass: window.Window | undefined = undefined;
3242    windowStage.getMainWindow((err: BusinessError, data) => {
3243      const errCode: number = err.code;
3244      if (errCode) {
3245        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
3246        return;
3247      }
3248      windowClass = data;
3249      try {
3250        let promise = windowClass.setSpecificSystemBarEnabled('status', false);
3251        promise.then(() => {
3252          console.info('Succeeded in setting the system bar to be invisible.');
3253        }).catch((err: BusinessError) => {
3254          console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
3255        });
3256      } catch (exception) {
3257        console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`);
3258      }
3259    });
3260  }
3261}
3262```
3263
3264### setWindowSystemBarProperties<sup>9+</sup>
3265
3266setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise&lt;void&gt;
3267
3268设置主窗口<!--Del-->三键导航栏、<!--DelEnd-->状态栏的属性,使用Promise异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
3269
3270子窗口调用后不生效。
3271
3272**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3273
3274**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3275
3276**参数:**
3277
3278| 参数名              | 类型                                        | 必填 | 说明                   |
3279| ------------------- | ------------------------------------------- | ---- | ---------------------- |
3280| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是   | <!--Del-->三键导航栏、<!--DelEnd-->状态栏的属性。 |
3281
3282**返回值:**
3283
3284| 类型                | 说明                      |
3285| ------------------- | ------------------------- |
3286| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
3287
3288**错误码:**
3289
3290以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3291
3292| 错误码ID | 错误信息 |
3293| ------- | -------------------------------------------- |
3294| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3295| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
3296| 1300002 | This window state is abnormal.               |
3297| 1300003 | This window manager service works abnormally. |
3298
3299**示例:**
3300
3301```ts
3302// EntryAbility.ets
3303import { UIAbility } from '@kit.AbilityKit';
3304import { BusinessError } from '@kit.BasicServicesKit';
3305
3306export default class EntryAbility extends UIAbility {
3307  // ...
3308  onWindowStageCreate(windowStage: window.WindowStage): void {
3309    console.info('onWindowStageCreate');
3310    let windowClass: window.Window | undefined = undefined;
3311    windowStage.getMainWindow((err: BusinessError, data) => {
3312      const errCode: number = err.code;
3313      if (errCode) {
3314        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
3315        return;
3316      }
3317      windowClass = data;
3318      let SystemBarProperties: window.SystemBarProperties = {
3319        statusBarColor: '#ff00ff',
3320        navigationBarColor: '#00ff00',
3321        //以下两个属性从API Version8开始支持
3322        statusBarContentColor: '#ffffff',
3323        navigationBarContentColor: '#00ffff'
3324      };
3325      try {
3326        let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties);
3327        promise.then(() => {
3328          console.info('Succeeded in setting the system bar properties.');
3329        }).catch((err: BusinessError) => {
3330          console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
3331        });
3332      } catch (exception) {
3333        console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`);
3334      }
3335    });
3336  }
3337}
3338```
3339
3340### getWindowSystemBarProperties<sup>12+</sup>
3341
3342getWindowSystemBarProperties(): SystemBarProperties
3343
3344主窗口获取<!--Del-->三键导航栏、<!--DelEnd-->状态栏的属性。
3345
3346**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3347
3348**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3349
3350**返回值:**
3351
3352| 类型 | 说明 |
3353| ------------------------------------- | ------------- |
3354| [SystemBarProperties](#systembarproperties) | 当前<!--Del-->三键导航栏、<!--DelEnd-->状态栏属性。 |
3355
3356**错误码:**
3357
3358以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
3359
3360| 错误码ID | 错误信息 |
3361| ------- | ------------------------------ |
3362| 1300002 | This window state is abnormal. |
3363| 1300003 | This window manager service works abnormally. |
3364| 1300004 | Unauthorized operation.                       |
3365
3366
3367**示例:**
3368
3369```ts
3370// EntryAbility.ets
3371import { UIAbility } from '@kit.AbilityKit';
3372import { BusinessError } from '@kit.BasicServicesKit';
3373
3374export default class EntryAbility extends UIAbility {
3375  // ...
3376
3377  onWindowStageCreate(windowStage: window.WindowStage) {
3378    let windowClass: window.Window | undefined = undefined;
3379    windowStage.getMainWindow((err: BusinessError, data) => {
3380      const errCode: number = err.code;
3381      if (errCode) {
3382        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
3383        return;
3384      }
3385      windowClass = data;
3386      try {
3387        let systemBarProperty = windowClass.getWindowSystemBarProperties();
3388        console.info('Success in obtaining system bar properties. Property: ' + JSON.stringify(systemBarProperty));
3389      } catch (err) {
3390        console.error(`Failed to get system bar properties. Code: ${err.code}, message: ${err.message}`);
3391      }
3392    });
3393  }
3394};
3395```
3396
3397### setStatusBarColor<sup>18+</sup>
3398
3399setStatusBarColor(color: ColorMetrics): Promise&lt;void&gt;
3400
3401设置主窗口状态栏的文字颜色,使用Promise异步回调。
3402
3403子窗口不支持设置状态栏文字颜色,调用无效果。该接口在2in1设备上调用不生效。
3404
3405**系统能力:** SystemCapability.Window.SessionManager
3406
3407**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
3408
3409**参数:**
3410
3411| 参数名              | 类型                                        | 必填 | 说明                   |
3412| ------------------- | ------------------------------------------- | ---- | ---------------------- |
3413| color | [ColorMetrics](js-apis-arkui-graphics.md#colormetrics12) | 是   | 要设置的状态栏颜色值。 |
3414
3415**返回值:**
3416
3417| 类型                | 说明                      |
3418| ------------------- | ------------------------- |
3419| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
3420
3421**错误码:**
3422
3423以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3424
3425| 错误码ID | 错误信息 |
3426| ------- | -------------------------------------------- |
3427| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3428| 801     | Capability not supported on this device. |
3429| 1300002 | This window state is abnormal.               |
3430| 1300003 | This window manager service works abnormally. |
3431
3432**示例:**
3433
3434```ts
3435// EntryAbility.ets
3436import { UIAbility } from '@kit.AbilityKit';
3437import { BusinessError } from '@kit.BasicServicesKit';
3438import { ColorMetrics, window } from '@kit.ArkUI';
3439
3440export default class EntryAbility extends UIAbility {
3441  // ...
3442  onWindowStageCreate(windowStage: window.WindowStage): void {
3443    console.info('onWindowStageCreate');
3444    let windowClass: window.Window | undefined = undefined;
3445    windowStage.getMainWindow((err: BusinessError, data) => {
3446      const errCode: number = err.code;
3447      if (errCode) {
3448        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
3449        return;
3450      }
3451      windowClass = data;
3452      try {
3453        let promise = windowClass.setStatusBarColor(ColorMetrics.numeric(0x112233));
3454        promise.then(() => {
3455          console.info('Succeeded in setting the status bar color.');
3456        }).catch((err: BusinessError) => {
3457          console.error(`Set the status bar color failed. Cause code: ${err.code}, message: ${err.message}`);
3458        });
3459      } catch (exception) {
3460        console.error(`Failed to set the status bar color. Cause code: ${exception.code}, message: ${exception.message}`);
3461      }
3462    });
3463  }
3464}
3465```
3466
3467### getStatusBarProperty<sup>18+</sup>
3468
3469getStatusBarProperty(): StatusBarProperty
3470
3471获取主窗口状态栏的属性,如状态栏文字颜色。
3472
3473子窗口不支持查询,调用会返回错误码1300002。
3474
3475**系统能力:** SystemCapability.Window.SessionManager
3476
3477**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
3478
3479**返回值:**
3480
3481| 类型 | 说明 |
3482| ------------------------------------- | ------------- |
3483| [StatusBarProperty](#statusbarproperty18) | 当前状态栏属性,如状态栏颜色。 |
3484
3485**错误码:**
3486
3487以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3488
3489| 错误码ID | 错误信息 |
3490| ------- | ------------------------------ |
3491| 801 | Capability not supported on this device. |
3492| 1300002 | This window state is abnormal. |
3493
3494**示例:**
3495
3496```ts
3497// EntryAbility.ets
3498import { UIAbility } from '@kit.AbilityKit';
3499import { BusinessError } from '@kit.BasicServicesKit';
3500import { window } from '@kit.ArkUI';
3501
3502export default class EntryAbility extends UIAbility {
3503  // ...
3504  onWindowStageCreate(windowStage: window.WindowStage) {
3505    let windowClass: window.Window | undefined = undefined;
3506    windowStage.getMainWindow((err: BusinessError, data) => {
3507      const errCode: number = err.code;
3508      if (errCode) {
3509        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
3510        return;
3511      }
3512      windowClass = data;
3513      try {
3514        let statusBarProperty = windowClass.getStatusBarProperty();
3515        console.info('Succeeded in obtaining system bar properties. Property: ' + JSON.stringify(statusBarProperty));
3516      } catch (err) {
3517        console.error(`Failed to get system bar properties. Code: ${err.code}, message: ${err.message}`);
3518      }
3519    });
3520  }
3521};
3522```
3523
3524### setPreferredOrientation<sup>9+</sup>
3525
3526setPreferredOrientation(orientation: Orientation, callback: AsyncCallback&lt;void&gt;): void
3527
3528设置主窗口的显示方向属性,使用callback异步回调。<!--RP9-->仅在支持跟随sensor旋转的设备上生效,2in1设备上调用不生效,子窗口调用后不生效。<!--RP9End-->
3529
3530**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3531
3532**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3533
3534**参数:**
3535
3536| 参数名              | 类型                                        | 必填 | 说明                   |
3537| ------------------- | ------------------------------------------- | ---- | ---------------------- |
3538| orientation         | [Orientation](#orientation9)                | 是   | 窗口显示方向的属性。         |
3539| callback            | AsyncCallback&lt;void&gt;                   | 是   | 回调函数。该回调函数返回调用结果是否成功,非应用旋转动效结束。 |
3540
3541**错误码:**
3542
3543以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3544
3545| 错误码ID | 错误信息 |
3546| ------- | ------------------------------ |
3547| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3548| 1300002 | This window state is abnormal. |
3549
3550**示例:**
3551
3552```ts
3553// EntryAbility.ets
3554import { UIAbility } from '@kit.AbilityKit';
3555import { BusinessError } from '@kit.BasicServicesKit';
3556
3557export default class EntryAbility extends UIAbility {
3558  // ...
3559  onWindowStageCreate(windowStage: window.WindowStage): void {
3560    console.info('onWindowStageCreate');
3561    let windowClass: window.Window | undefined = undefined;
3562    windowStage.getMainWindow((err: BusinessError, data) => {
3563      const errCode: number = err.code;
3564      if (errCode) {
3565        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
3566        return;
3567      }
3568      windowClass = data;
3569      let orientation = window.Orientation.AUTO_ROTATION;
3570      try {
3571        windowClass.setPreferredOrientation(orientation, (err: BusinessError) => {
3572          const errCode: number = err.code;
3573          if (errCode) {
3574            console.error(`Failed to set window orientation. Cause code: ${err.code}, message: ${err.message}`);
3575            return;
3576          }
3577          console.info('Succeeded in setting window orientation.');
3578        });
3579      } catch (exception) {
3580        console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`);
3581      }
3582    });
3583  }
3584}
3585```
3586
3587### setPreferredOrientation<sup>9+</sup>
3588
3589setPreferredOrientation(orientation: Orientation): Promise&lt;void&gt;
3590
3591设置主窗口的显示方向属性,使用Promise异步回调。<!--RP9-->仅在支持跟随sensor旋转的设备上生效,2in1设备上调用不生效,子窗口调用后不生效。<!--RP9End-->
3592
3593**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3594
3595**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3596
3597**参数:**
3598
3599| 参数名              | 类型                                        | 必填 | 说明                   |
3600| ------------------- | ------------------------------------------- | ---- | ---------------------- |
3601| orientation         | [Orientation](#orientation9)                | 是   | 窗口显示方向的属性。       |
3602
3603**返回值:**
3604
3605| 类型                | 说明                      |
3606| ------------------- | ------------------------- |
3607| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
3608
3609**错误码:**
3610
3611以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3612
3613| 错误码ID | 错误信息 |
3614| ------- | ------------------------------ |
3615| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
3616| 1300002 | This window state is abnormal. |
3617
3618**示例:**
3619
3620```ts
3621// EntryAbility.ets
3622import { UIAbility } from '@kit.AbilityKit';
3623import { BusinessError } from '@kit.BasicServicesKit';
3624
3625export default class EntryAbility extends UIAbility {
3626  // ...
3627  onWindowStageCreate(windowStage: window.WindowStage): void {
3628    console.info('onWindowStageCreate');
3629    let windowClass: window.Window | undefined = undefined;
3630    windowStage.getMainWindow((err: BusinessError, data) => {
3631      const errCode: number = err.code;
3632      if (errCode) {
3633        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
3634        return;
3635      }
3636      windowClass = data;
3637      let orientation = window.Orientation.AUTO_ROTATION;
3638      try {
3639        let promise = windowClass.setPreferredOrientation(orientation);
3640        promise.then(() => {
3641          console.info('Succeeded in setting the window orientation.');
3642        }).catch((err: BusinessError) => {
3643          console.error(`Failed to set the window orientation. Cause code: ${err.code}, message: ${err.message}`);
3644        });
3645      } catch (exception) {
3646        console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`);
3647      }
3648    });
3649  }
3650}
3651```
3652
3653### getPreferredOrientation<sup>12+</sup>
3654
3655getPreferredOrientation(): Orientation
3656
3657主窗口调用,获取窗口的显示方向属性。
3658
3659**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3660
3661**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3662
3663**返回值:**
3664
3665| 类型 | 说明 |
3666|------------------------------| ------------------ |
3667| [Orientation](#orientation9) | 窗口显示方向的属性。 |
3668
3669**错误码:**
3670
3671以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
3672
3673| 错误码ID | 错误信息 |
3674| ------- | ------------------------------ |
3675| 1300002 | This window state is abnormal. |
3676
3677**示例:**
3678
3679```ts
3680// EntryAbility.ets
3681import { UIAbility } from '@kit.AbilityKit';
3682import { BusinessError } from '@kit.BasicServicesKit';
3683export default class EntryAbility extends UIAbility {
3684  // ...
3685
3686  onWindowStageCreate(windowStage: window.WindowStage) {
3687    console.info('onWindowStageCreate');
3688    let windowClass: window.Window | undefined = undefined;
3689    windowStage.getMainWindow((err: BusinessError, data) => {
3690      const errCode: number = err.code;
3691      if (errCode) {
3692        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
3693        return;
3694      }
3695      windowClass = data;
3696      try {
3697        let orientation = windowClass.getPreferredOrientation();
3698      } catch (exception) {
3699        console.error(`Failed to get window orientation. Cause code: ${exception.code}, message: ${exception.message}`);
3700      }
3701    });
3702  }
3703};
3704```
3705
3706### getUIContext<sup>10+</sup>
3707
3708getUIContext(): UIContext
3709
3710获取UIContext实例。
3711
3712**模型约束:** 此接口仅可在Stage模型下使用。
3713
3714**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3715
3716**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3717
3718**返回值:**
3719
3720| 类型       | 说明                   |
3721| ---------- | ---------------------- |
3722| [UIContext](arkts-apis-uicontext-uicontext.md) | 返回UIContext实例对象。 |
3723
3724**错误码:**
3725
3726以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
3727
3728| 错误码ID | 错误信息 |
3729| ------- | ------------------------------ |
3730| 1300002 | This window state is abnormal. |
3731
3732**示例:**
3733
3734```ts
3735// EntryAbility.ets
3736import { UIAbility } from '@kit.AbilityKit';
3737import { window, UIContext } from '@kit.ArkUI';
3738import { BusinessError } from '@kit.BasicServicesKit';
3739
3740export default class EntryAbility extends UIAbility {
3741  onWindowStageCreate(windowStage: window.WindowStage) {
3742    // 为主窗口加载对应的目标页面。
3743    windowStage.loadContent("pages/page2", (err: BusinessError) => {
3744      let errCode: number = err.code;
3745      if (errCode) {
3746        console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
3747        return;
3748      }
3749      console.info('Succeeded in loading the content.');
3750      // 获取应用主窗口。
3751      let windowClass: window.Window | undefined = undefined;
3752      windowStage.getMainWindow((err: BusinessError, data) => {
3753        let errCode: number = err.code;
3754        if (errCode) {
3755          console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
3756          return;
3757        }
3758        windowClass = data;
3759        console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
3760        // 获取UIContext实例。
3761        let uiContext: UIContext | null = null;
3762        uiContext = windowClass.getUIContext();
3763      });
3764    });
3765  }
3766};
3767```
3768
3769### setUIContent<sup>9+</sup>
3770
3771setUIContent(path: string, callback: AsyncCallback&lt;void&gt;): void
3772
3773根据当前工程中指定的某个页面路径为窗口加载具体页面内容,使用callback异步回调。
3774
3775**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3776
3777**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3778
3779**参数:**
3780
3781| 参数名 | 类型 | 必填 | 说明 |
3782| -------- | ------------------------- | -- | -------------------- |
3783| path     | string                    | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 |
3784| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。          |
3785
3786**错误码:**
3787
3788以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3789
3790| 错误码ID | 错误信息 |
3791| ------- | -------------------------------------------- |
3792| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3793| 1300002 | This window state is abnormal.               |
3794
3795**示例:**
3796
3797```ts
3798import { BusinessError } from '@kit.BasicServicesKit';
3799
3800try {
3801  windowClass.setUIContent('pages/page2/page3', (err: BusinessError) => {
3802    const errCode: number = err.code;
3803    if (errCode) {
3804      console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
3805      return;
3806    }
3807    console.info('Succeeded in loading the content.');
3808  });
3809} catch (exception) {
3810  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
3811}
3812```
3813
3814### setUIContent<sup>9+</sup>
3815
3816setUIContent(path: string): Promise&lt;void&gt;
3817
3818根据当前工程中指定的某个页面路径为窗口加载具体页面内容,使用Promise异步回调。
3819
3820**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3821
3822**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3823
3824**参数:**
3825
3826| 参数名 | 类型 | 必填 | 说明 |
3827| ---- | ------ | -- | ------------------ |
3828| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 |
3829
3830**返回值:**
3831
3832| 类型 | 说明 |
3833| ------------------- | ------------------------ |
3834| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
3835
3836**错误码:**
3837
3838以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3839
3840| 错误码ID | 错误信息 |
3841| ------- | -------------------------------------------- |
3842| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3843| 1300002 | This window state is abnormal.               |
3844
3845**示例:**
3846
3847```ts
3848import { BusinessError } from '@kit.BasicServicesKit';
3849
3850try {
3851  let promise = windowClass.setUIContent('pages/page2/page3');
3852  promise.then(() => {
3853    console.info('Succeeded in loading the content.');
3854  }).catch((err: BusinessError) => {
3855    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
3856  });
3857} catch (exception) {
3858  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
3859}
3860```
3861
3862### loadContent<sup>9+</sup>
3863
3864loadContent(path: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
3865
3866根据当前工程中指定的页面路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,重复调用将先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。
3867
3868**模型约束:** 此接口仅可在Stage模型下使用。
3869
3870**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3871
3872**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3873
3874**参数:**
3875
3876| 参数名   | 类型                                            | 必填 | 说明                                                         |
3877| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
3878| path     | string                                          | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 |
3879| storage  | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
3880| callback | AsyncCallback&lt;void&gt;                       | 是   | 回调函数。                                                   |
3881
3882**错误码:**
3883
3884以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3885
3886| 错误码ID | 错误信息 |
3887| ------- | -------------------------------------------- |
3888| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Invalid path parameter.|
3889| 1300002 | This window state is abnormal.               |
3890
3891**示例:**
3892
3893```ts
3894import { BusinessError } from '@kit.BasicServicesKit';
3895
3896let storage: LocalStorage = new LocalStorage();
3897storage.setOrCreate('storageSimpleProp', 121);
3898windowClass.loadContent('pages/page2', storage, (err: BusinessError) => {
3899  const errCode: number = err.code;
3900  if (errCode) {
3901    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
3902    return;
3903  }
3904  console.info('Succeeded in loading the content.');
3905});
3906```
3907
3908### loadContent<sup>9+</sup>
3909
3910loadContent(path: string, storage: LocalStorage): Promise&lt;void&gt;
3911
3912根据当前工程中指定的页面路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。建议在UIAbility启动过程中使用该接口,重复调用将先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。
3913
3914**模型约束:** 此接口仅可在Stage模型下使用。
3915
3916**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3917
3918**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3919
3920**参数:**
3921
3922| 参数名  | 类型                                            | 必填 | 说明                                                         |
3923| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
3924| path    | string                                          | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 |
3925| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
3926
3927**返回值:**
3928
3929| 类型                | 说明                      |
3930| ------------------- | ------------------------- |
3931| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
3932
3933**错误码:**
3934
3935以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3936
3937| 错误码ID | 错误信息 |
3938| ------- | -------------------------------------------- |
3939| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Invalid path parameter.|
3940| 1300002 | This window state is abnormal.               |
3941
3942**示例:**
3943
3944```ts
3945import { BusinessError } from '@kit.BasicServicesKit';
3946
3947let storage: LocalStorage = new LocalStorage();
3948storage.setOrCreate('storageSimpleProp', 121);
3949let promise = windowClass.loadContent('pages/page2', storage);
3950promise.then(() => {
3951  console.info('Succeeded in loading the content.');
3952}).catch((err: BusinessError) => {
3953  console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
3954});
3955```
3956
3957### loadContentByName<sup>11+</sup>
3958
3959loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
3960
3961根据指定路由页面名称为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性至加载页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,重复调用该接口将先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。
3962
3963**模型约束:** 此接口仅可在Stage模型下使用。
3964
3965**系统能力:** SystemCapability.WindowManager.WindowManager.Core
3966
3967**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3968
3969**参数:**
3970
3971| 参数名   | 类型                                                    | 必填 | 说明                                                         |
3972| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
3973| name     | string                                                  | 是   | 命名路由页面的名称。                                             |
3974| storage  | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
3975| callback | AsyncCallback&lt;void&gt;                               | 是   | 回调函数。                                                   |
3976
3977**错误码:**
3978
3979以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
3980
3981| 错误码ID | 错误信息                                      |
3982| -------- | --------------------------------------------- |
3983| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3984| 1300002  | This window state is abnormal.                |
3985
3986**示例:**
3987<!--code_no_check-->
3988```ts
3989import { BusinessError } from '@kit.BasicServicesKit';
3990import * as Index from '../pages/Index'; // 导入命名路由页面
3991
3992console.info('onWindowStageCreate');
3993let storage: LocalStorage = new LocalStorage();
3994storage.setOrCreate('storageSimpleProp', 121);
3995try {
3996  (windowClass as window.Window).loadContentByName(Index.entryName, storage, (err: BusinessError) => {
3997    const errCode: number = err.code;
3998    if (errCode) {
3999      console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
4000      return;
4001    }
4002    console.info('Succeeded in loading the content.');
4003  });
4004} catch (exception) {
4005  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
4006}
4007```
4008<!--code_no_check-->
4009```ts
4010// ets/pages/Index.ets
4011export const entryName : string = 'Index';
4012@Entry({routeName: entryName, useSharedStorage: true})
4013@Component
4014export struct Index {
4015  @State message: string = 'Hello World'
4016  @LocalStorageLink('storageSimpleProp') storageSimpleProp: number = 1;
4017  build() {
4018    Row() {
4019      Column() {
4020        Text(this.message)
4021          .fontSize(50)
4022          .fontWeight(FontWeight.Bold)
4023      }
4024      .width('100%')
4025    }
4026    .height('100%')
4027  }
4028}
4029```
4030
4031### loadContentByName<sup>11+</sup>
4032
4033loadContentByName(name: string, callback: AsyncCallback&lt;void&gt;): void
4034
4035根据指定路由页面名称为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,重复调用该接口将先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。
4036
4037**模型约束:** 此接口仅可在Stage模型下使用。
4038
4039**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4040
4041**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4042
4043**参数:**
4044
4045| 参数名   | 类型                      | 必填 | 说明             |
4046| -------- | ------------------------- | ---- | ---------------- |
4047| name     | string                    | 是   | 命名路由页面的名称。 |
4048| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。       |
4049
4050**错误码:**
4051
4052以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4053
4054| 错误码ID | 错误信息                                      |
4055| -------- | --------------------------------------------- |
4056| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4057| 1300002  | This window state is abnormal.                |
4058
4059**示例:**
4060<!--code_no_check-->
4061```ts
4062import { BusinessError } from '@kit.BasicServicesKit';
4063import * as Index from '../pages/Index'; // 导入命名路由页面
4064
4065try {
4066  (windowClass as window.Window).loadContentByName(Index.entryName, (err: BusinessError) => {
4067    const errCode: number = err.code;
4068    if (errCode) {
4069      console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
4070      return;
4071    }
4072    console.info('Succeeded in loading the content.');
4073  });
4074} catch (exception) {
4075  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
4076}
4077```
4078<!--code_no_check-->
4079```ts
4080// ets/pages/Index.ets
4081export const entryName : string = 'Index';
4082@Entry({routeName: entryName})
4083@Component
4084export struct Index {
4085  @State message: string = 'Hello World'
4086  build() {
4087    Row() {
4088      Column() {
4089        Text(this.message)
4090          .fontSize(50)
4091          .fontWeight(FontWeight.Bold)
4092      }
4093      .width('100%')
4094    }
4095    .height('100%')
4096  }
4097}
4098```
4099
4100### loadContentByName<sup>11+</sup>
4101
4102loadContentByName(name: string, storage?: LocalStorage): Promise&lt;void&gt;
4103
4104根据指定路由页面名称为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性至加载页面,使用Promise异步回调。建议在UIAbility启动过程中使用该接口,重复调用该接口将先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。
4105
4106**模型约束:** 此接口仅可在Stage模型下使用。
4107
4108**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4109
4110**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4111
4112**参数:**
4113
4114| 参数名  | 类型                                                    | 必填 | 说明                                                         |
4115| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
4116| name    | string                                                  | 是   | 命名路由页面的名称。                                             |
4117| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 否   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
4118
4119**返回值:**
4120
4121| 类型                | 说明                      |
4122| ------------------- | ------------------------- |
4123| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4124
4125**错误码:**
4126
4127以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4128
4129| 错误码ID | 错误信息                                      |
4130| -------- | --------------------------------------------- |
4131| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4132| 1300002  | This window state is abnormal.                |
4133
4134**示例:**
4135<!--code_no_check-->
4136```ts
4137import { BusinessError } from '@kit.BasicServicesKit';
4138import * as Index from '../pages/Index'; // 导入命名路由页面
4139
4140let storage: LocalStorage = new LocalStorage();
4141storage.setOrCreate('storageSimpleProp', 121);
4142try {
4143  let promise = (windowClass as window.Window).loadContentByName(Index.entryName, storage);
4144  promise.then(() => {
4145    console.info('Succeeded in loading the content.');
4146  }).catch((err: BusinessError) => {
4147    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
4148  });
4149} catch (exception) {
4150  console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
4151}
4152```
4153<!--code_no_check-->
4154```ts
4155// ets/pages/Index.ets
4156export const entryName : string = 'Index';
4157@Entry({routeName: entryName, useSharedStorage: true})
4158@Component
4159export struct Index {
4160  @State message: string = 'Hello World'
4161  @LocalStorageLink('storageSimpleProp') storageSimpleProp: number = 1;
4162  build() {
4163    Row() {
4164      Column() {
4165        Text(this.message)
4166          .fontSize(50)
4167          .fontWeight(FontWeight.Bold)
4168      }
4169      .width('100%')
4170    }
4171    .height('100%')
4172  }
4173}
4174```
4175
4176### isWindowShowing<sup>9+</sup>
4177
4178isWindowShowing(): boolean
4179
4180判断当前窗口是否已显示。
4181
4182**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4183
4184**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4185
4186**返回值:**
4187
4188| 类型 | 说明 |
4189| ------- | ------------------------------------------------------------------ |
4190| boolean | 当前窗口是否已显示。true表示当前窗口已显示,false则表示当前窗口未显示。 |
4191
4192**错误码:**
4193
4194以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
4195
4196| 错误码ID | 错误信息 |
4197| ------- | ------------------------------ |
4198| 1300002 | This window state is abnormal. |
4199
4200**示例:**
4201
4202```ts
4203try {
4204  let data = windowClass.isWindowShowing();
4205  console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
4206} catch (exception) {
4207  console.error(`Failed to check whether the window is showing. Cause code: ${exception.code}, message: ${exception.message}`);
4208}
4209```
4210
4211### on('windowSizeChange')<sup>7+</sup>
4212
4213on(type:  'windowSizeChange', callback: Callback&lt;Size&gt;): void
4214
4215开启窗口尺寸变化的监听。
4216
4217**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4218
4219**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4220
4221**参数:**
4222
4223| 参数名   | 类型                           | 必填 | 说明                                                     |
4224| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
4225| type     | string                         | 是   | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 |
4226| callback | Callback&lt;[Size](#size7)&gt; | 是   | 回调函数。返回当前的窗口尺寸。                           |
4227
4228**错误码:**
4229
4230以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4231
4232| 错误码ID | 错误信息 |
4233| ------- | -------------------------------------------- |
4234| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
4235
4236**示例:**
4237
4238```ts
4239try {
4240  windowClass.on('windowSizeChange', (data) => {
4241    console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data));
4242  });
4243} catch (exception) {
4244  console.error(`Failed to enable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`);
4245}
4246```
4247
4248### off('windowSizeChange')<sup>7+</sup>
4249
4250off(type: 'windowSizeChange', callback?: Callback&lt;Size&gt;): void
4251
4252关闭窗口尺寸变化的监听。
4253
4254**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4255
4256**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4257
4258**参数:**
4259
4260| 参数名   | 类型                          | 必填 | 说明                                                     |
4261| -------- | ----------------------------- | ---- | -------------------------------------------------------- |
4262| type     | string                        | 是   | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 |
4263| callback | Callback&lt;[Size](#size7)&gt; | 否   | 回调函数。返回当前的窗口尺寸。如果传入参数,则关闭该监听。如果未传入参数,则关闭窗口尺寸变化的监听。                           |
4264
4265**错误码:**
4266
4267以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4268
4269| 错误码ID | 错误信息 |
4270| ------- | -------------------------------------------- |
4271| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
4272
4273**示例:**
4274
4275```ts
4276const callback = (size: window.Size) => {
4277  // ...
4278}
4279try {
4280  // 通过on接口开启监听
4281  windowClass.on('windowSizeChange', callback);
4282  // 关闭指定callback的监听
4283  windowClass.off('windowSizeChange', callback);
4284  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
4285  windowClass.off('windowSizeChange');
4286} catch (exception) {
4287  console.error(`Failed to disable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`);
4288}
4289```
4290
4291### on('avoidAreaChange')<sup>9+</sup>
4292
4293on(type: 'avoidAreaChange', callback: Callback&lt;AvoidAreaOptions&gt;): void
4294
4295开启当前应用窗口系统规避区变化的监听。
4296<!--RP7-->常见的触发避让区回调的场景如下:应用窗口在全屏模式、悬浮模式、分屏模式之间的切换;应用窗口旋转;多折叠设备在屏幕折叠态和展开态之间的切换;应用窗口在多设备之间的流转。<!--RP7End-->
4297
4298**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4299
4300**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4301
4302**参数:**
4303
4304| 参数名   | 类型                              | 必填 | 说明                                  |
4305| -------- |----------------------------------| ---- |--------------------------------------|
4306| type     | string                           | 是   | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 |
4307| callback | Callback&lt;[AvoidAreaOptions](#avoidareaoptions12)&gt; | 是   | 回调函数。返回当前规避区以及规避区类型。|
4308
4309**错误码:**
4310
4311以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4312
4313| 错误码ID | 错误信息 |
4314| ------- | -------------------------------------------- |
4315| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
4316
4317**示例:**
4318
4319```ts
4320try {
4321  windowClass.on('avoidAreaChange', (data) => {
4322    console.info('Succeeded in enabling the listener for system avoid area changes. type:' +
4323    JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area));
4324  });
4325} catch (exception) {
4326  console.error(`Failed to enable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`);
4327}
4328```
4329
4330### off('avoidAreaChange')<sup>9+</sup>
4331
4332off(type: 'avoidAreaChange', callback?: Callback&lt;AvoidAreaOptions&gt;): void
4333
4334关闭当前窗口系统规避区变化的监听。
4335
4336**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4337
4338**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4339
4340**参数:**
4341
4342| 参数名   | 类型                              | 必填 | 说明                                |
4343| -------- |----------------------------------|------|------------------------------------|
4344| type     | string                           | 是   | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 |
4345| callback | Callback&lt;[AvoidAreaOptions](#avoidareaoptions12)&gt; | 否   | 回调函数。返回当前规避区以及规避区类型。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有系统规避区变化的监听。|
4346
4347**错误码:**
4348
4349以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4350
4351| 错误码ID | 错误信息 |
4352| ------- | -------------------------------------------- |
4353| 401     | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed. |
4354
4355**示例:**
4356
4357```ts
4358interface Param {
4359  type: window.AvoidAreaType,
4360  area: window.AvoidArea
4361}
4362const callback = (data: Param) => {
4363  // ...
4364}
4365try {
4366  windowClass.on('avoidAreaChange', callback);
4367
4368  windowClass.off('avoidAreaChange', callback);
4369  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
4370  windowClass.off('avoidAreaChange');
4371} catch (exception) {
4372  console.error(`Failed to enable or disable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`);
4373}
4374```
4375
4376### on('keyboardHeightChange')<sup>7+</sup>
4377
4378on(type: 'keyboardHeightChange', callback: Callback&lt;number&gt;): void
4379
4380开启固定态软键盘高度变化的监听。当软键盘从本窗口唤出且与窗口有重叠区域时,通知键盘高度变化。从API version 10开始,有关将软键盘设置为固定态或悬浮态的方法,请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
4381
4382**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4383
4384**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4385
4386**参数:**
4387
4388| 参数名   | 类型                | 必填 | 说明                                        |
4389| -------- | ------------------- | ---- |-------------------------------------------|
4390| type     | string              | 是   | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 |
4391| callback | Callback&lt;number&gt; | 是   | 回调函数。返回当前的键盘高度。返回值为整数,单位为px。     |
4392
4393**错误码:**
4394
4395以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4396
4397| 错误码ID | 错误信息 |
4398| ------- | -------------------------------------------- |
4399| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
4400
4401**示例:**
4402
4403```ts
4404import { BusinessError } from '@kit.BasicServicesKit';
4405
4406try {
4407  windowClass.on('keyboardHeightChange', (data) => {
4408    console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data));
4409  });
4410} catch (exception) {
4411  console.error(`Failed to enable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`);
4412}
4413```
4414
4415### off('keyboardHeightChange')<sup>7+</sup>
4416
4417off(type: 'keyboardHeightChange', callback?: Callback&lt;number&gt;): void
4418
4419关闭固定态软键盘高度变化的监听,使应用程序不再接收键盘高度变化的通知。从API version 10开始,有关将软键盘设置为固定态或悬浮态的方法,请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
4420
4421**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4422
4423**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4424
4425**参数:**
4426
4427| 参数名   | 类型                   | 必填 | 说明                                                         |
4428| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
4429| type     | string                 | 是   | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 |
4430| callback | Callback&lt;number&gt; | 否   | 回调函数。返回当前的键盘高度,返回值为整数,单位为px。若传入参数,则关闭该监听;未传入参数,则关闭所有固定态软键盘高度变化的监听。                               |
4431
4432**错误码:**
4433
4434以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4435
4436| 错误码ID | 错误信息 |
4437| ------- | -------------------------------------------- |
4438| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
4439
4440**示例:**
4441
4442```ts
4443import { BusinessError } from '@kit.BasicServicesKit';
4444
4445const callback = (height: number) => {
4446  // ...
4447}
4448try {
4449  windowClass.on('keyboardHeightChange', callback);
4450
4451  windowClass.off('keyboardHeightChange', callback);
4452  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
4453  windowClass.off('keyboardHeightChange');
4454} catch (exception) {
4455  console.error(`Failed to disable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`);
4456}
4457```
4458
4459### on('keyboardWillShow')<sup>20+</sup>
4460
4461on(type: 'keyboardWillShow', callback: Callback&lt;KeyboardInfo&gt;): void
4462
4463开启固定态软键盘即将开始显示的监听。此监听在固定态软键盘即将开始显示或软键盘由悬浮态切换为固定态时触发。
4464
4465改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
4466
4467**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
4468
4469**系统能力:** SystemCapability.Window.SessionManager
4470
4471**参数:**
4472
4473| 参数名   | 类型                | 必填 | 说明                                        |
4474| -------- | ------------------- | ---- |-------------------------------------------|
4475| type     | string              | 是   | 监听事件,固定为'keyboardWillShow',即固定态软键盘即将开始显示的事件。 |
4476| callback | Callback&lt;[KeyboardInfo](#keyboardinfo18)&gt; | 是   | 回调函数。返回软键盘窗口信息。                    |
4477
4478**错误码:**
4479
4480以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4481
4482| 错误码ID | 错误信息 |
4483| ------- | -------------------------------------------- |
4484| 801     | Capability not supported. Function keyboardWillShow can not work correctly due to limited device capabilities. |
4485| 1300002 | This window state is abnormal.               |
4486
4487**示例:**
4488
4489```ts
4490import { BusinessError } from '@kit.BasicServicesKit';
4491
4492const callback = (keyboardInfo: window.KeyboardInfo) => {
4493  console.info(`Keyboard will show animation. keyboardInfo: ` + JSON.stringify(keyboardInfo));
4494}
4495try {
4496  windowClass.on('keyboardWillShow', callback);
4497  console.info(`Register keyboard will show animation success`);
4498} catch (exception) {
4499  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
4500}
4501```
4502
4503### off('keyboardWillShow')<sup>20</sup>
4504
4505off(type: 'keyboardWillShow', callback?: Callback&lt;KeyboardInfo&gt;): void
4506
4507关闭固定态软键盘即将开始显示的监听。改变输入法窗口为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
4508
4509**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
4510
4511**系统能力:** SystemCapability.Window.SessionManager
4512
4513**参数:**
4514
4515| 参数名   | 类型                   | 必填 | 说明                                                         |
4516| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
4517| type     | string                 | 是   | 监听事件,固定为'keyboardWillShow',即固定态软键盘即将开始显示的事件。 |
4518| callback | Callback&lt;[KeyboardInfo](#keyboardinfo18)&gt; | 否   |  回调函数。返回软键盘窗口信息。若传入参数,则关闭该监听。如果未传入参数,则关闭所有固定态软键盘即将开始显示的监听。                               |
4519
4520**错误码:**
4521
4522以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4523
4524| 错误码ID | 错误信息 |
4525| ------- | -------------------------------------------- |
4526| 801     | Capability not supported. Function keyboardWillShow can not work correctly due to limited device capabilities. |
4527| 1300002 | This window state is abnormal.               |
4528
4529**示例:**
4530
4531```ts
4532import { BusinessError } from '@kit.BasicServicesKit';
4533
4534const callback = (keyboardInfo: window.KeyboardInfo) => {
4535  console.info(`Keyboard will show animation. keyboardInfo: ` + JSON.stringify(keyboardInfo));
4536}
4537try {
4538  windowClass.on('keyboardWillShow', callback);
4539  windowClass.off('keyboardWillShow', callback);
4540  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
4541  windowClass.off('keyboardWillShow');
4542  console.info(`Unregister keyboard will show animation success`);
4543} catch (exception) {
4544  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
4545}
4546```
4547
4548### on('keyboardWillHide')<sup>20+</sup>
4549
4550on(type: 'keyboardWillHide', callback: Callback&lt;KeyboardInfo&gt;): void
4551
4552开启固定态软键盘即将开始隐藏的监听。此监听在固定态软键盘即将开始隐藏或软键盘由固定态切换为悬浮态时触发。
4553
4554改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
4555
4556**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
4557
4558**系统能力:** SystemCapability.Window.SessionManager
4559
4560**参数:**
4561
4562| 参数名   | 类型                | 必填 | 说明                                        |
4563| -------- | ------------------- | ---- |-------------------------------------------|
4564| type     | string              | 是   | 监听事件,固定为'keyboardWillHide',即固定态软键盘即将开始隐藏的事件。 |
4565| callback | Callback&lt;[KeyboardInfo](#keyboardinfo18)&gt; | 是   | 回调函数。返回软键盘窗口信息。                    |
4566
4567**错误码:**
4568
4569以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4570
4571| 错误码ID | 错误信息 |
4572| ------- | -------------------------------------------- |
4573| 801     | Capability not supported. Function keyboardWillHide can not work correctly due to limited device capabilities. |
4574| 1300002 | This window state is abnormal.               |
4575
4576**示例:**
4577
4578```ts
4579import { BusinessError } from '@kit.BasicServicesKit';
4580
4581const callback = (keyboardInfo: window.KeyboardInfo) => {
4582  console.info(`Keyboard will hide animation. keyboardInfo: ` + JSON.stringify(keyboardInfo));
4583}
4584try {
4585  windowClass.on('keyboardWillHide', callback);
4586  console.info(`Register keyboard will hide animation success`);
4587} catch (exception) {
4588  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
4589}
4590```
4591
4592### off('keyboardWillHide')<sup>20+</sup>
4593
4594off(type: 'keyboardWillHide', callback?: Callback&lt;KeyboardInfo&gt;): void
4595
4596关闭固定态软键盘即将开始隐藏的监听。改变输入法窗口为固定态切换至悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
4597
4598**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
4599
4600**系统能力:** SystemCapability.Window.SessionManager
4601
4602**参数:**
4603
4604| 参数名   | 类型                   | 必填 | 说明                                                         |
4605| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
4606| type     | string                 | 是   | 监听事件,固定为'keyboardWillHide',即固定态软键盘即将开始隐藏的事件。 |
4607| callback | Callback&lt;[KeyboardInfo](#keyboardinfo18)&gt; | 否   |  回调函数。返回软键盘窗口信息。若传入参数,则关闭该监听。如果未传入参数,则关闭所有固定态软键盘即将开始隐藏的监听。                               |
4608
4609**错误码:**
4610
4611以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4612
4613| 错误码ID | 错误信息 |
4614| ------- | -------------------------------------------- |
4615| 801     | Capability not supported. Function keyboardWillHide can not work correctly due to limited device capabilities. |
4616| 1300002 | This window state is abnormal.               |
4617
4618**示例:**
4619
4620```ts
4621import { BusinessError } from '@kit.BasicServicesKit';
4622
4623const callback = (keyboardInfo: window.KeyboardInfo) => {
4624  console.info(`Keyboard will hide animation. keyboardInfo: ` + JSON.stringify(keyboardInfo));
4625}
4626try {
4627  windowClass.on('keyboardWillHide', callback);
4628  windowClass.off('keyboardWillHide', callback);
4629  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
4630  windowClass.off('keyboardWillHide');
4631  console.info(`Unregister keyboard will hide animation success`);
4632} catch (exception) {
4633  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
4634}
4635```
4636
4637### on('keyboardDidShow')<sup>18+</sup>
4638
4639on(type: 'keyboardDidShow', callback: Callback&lt;KeyboardInfo&gt;): void
4640
4641开启固定态软键盘显示动画完成的监听。此监听在固定态软键盘显示动画完成或软键盘由悬浮态切换至固定态时触发。
4642
4643改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
4644
4645**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
4646
4647**系统能力:** SystemCapability.Window.SessionManager
4648
4649**参数:**
4650
4651| 参数名   | 类型                | 必填 | 说明                                        |
4652| -------- | ------------------- | ---- |-------------------------------------------|
4653| type     | string              | 是   | 监听事件,固定为'keyboardDidShow',即固定态软键盘显示动画完成事件。 |
4654| callback | Callback&lt;[KeyboardInfo](#keyboardinfo18)&gt; | 是   | 回调函数。返回软键盘窗口信息。                    |
4655
4656**错误码:**
4657
4658以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4659
4660| 错误码ID | 错误信息 |
4661| ------- | -------------------------------------------- |
4662| 801     | Capability not supported. Function keyboardDidShow can not work correctly due to limited device capabilities. |
4663| 1300002 | This window state is abnormal.               |
4664
4665**示例:**
4666
4667```ts
4668import { BusinessError } from '@kit.BasicServicesKit';
4669
4670try {
4671  windowClass.on('keyboardDidShow', (keyboardInfo) => {
4672    console.info('keyboard show animation completion. keyboardInfo: ' + JSON.stringify(keyboardInfo));
4673  });
4674} catch (exception) {
4675  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
4676}
4677```
4678
4679### off('keyboardDidShow')<sup>18+</sup>
4680
4681off(type: 'keyboardDidShow', callback?: Callback&lt;KeyboardInfo&gt;): void
4682
4683关闭固定态软键盘显示动画完成的监听。改变输入法窗口为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
4684
4685**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
4686
4687**系统能力:** SystemCapability.Window.SessionManager
4688
4689**参数:**
4690
4691| 参数名   | 类型                   | 必填 | 说明                                                         |
4692| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
4693| type     | string                 | 是   | 监听事件,固定为'keyboardDidShow',即固定态软键盘显示动画完成事件。 |
4694| callback | Callback&lt;[KeyboardInfo](#keyboardinfo18)&gt; | 否   |  回调函数。返回软键盘窗口信息。若传入参数,则关闭该监听。如果未传入参数,则关闭所有固定态软键盘显示动画完成的监听。                               |
4695
4696**错误码:**
4697
4698以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4699
4700| 错误码ID | 错误信息 |
4701| ------- | -------------------------------------------- |
4702| 801     | Capability not supported. Function keyboardDidShow can not work correctly due to limited device capabilities. |
4703| 1300002 | This window state is abnormal.               |
4704
4705**示例:**
4706
4707```ts
4708import { BusinessError } from '@kit.BasicServicesKit';
4709
4710const callback = (keyboardInfo: window.KeyboardInfo) => {
4711  // ...
4712}
4713try {
4714  windowClass.on('keyboardDidShow', callback);
4715  windowClass.off('keyboardDidShow', callback);
4716  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
4717  windowClass.off('keyboardDidShow');
4718} catch (exception) {
4719  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
4720}
4721```
4722
4723### on('keyboardDidHide')<sup>18+</sup>
4724
4725on(type: 'keyboardDidHide', callback: Callback&lt;KeyboardInfo&gt;): void
4726
4727开启固定态软键盘隐藏动画完成的监听。此监听在固定态软键盘隐藏动画完成或软键盘由固定态切换至悬浮态时触发。
4728
4729改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
4730
4731**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
4732
4733**系统能力:** SystemCapability.Window.SessionManager
4734
4735**参数:**
4736
4737| 参数名   | 类型                | 必填 | 说明                                        |
4738| -------- | ------------------- | ---- |-------------------------------------------|
4739| type     | string              | 是   | 监听事件,固定为'keyboardDidHide',即固定态软键盘隐藏动画完成事件。 |
4740| callback | Callback&lt;[KeyboardInfo](#keyboardinfo18)&gt; | 是   | 回调函数。返回软键盘窗口信息。                    |
4741
4742**错误码:**
4743
4744以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4745
4746| 错误码ID | 错误信息 |
4747| ------- | -------------------------------------------- |
4748| 801     | Capability not supported. Function keyboardDidHide can not work correctly due to limited device capabilities. |
4749| 1300002 | This window state is abnormal.               |
4750
4751**示例:**
4752
4753```ts
4754import { BusinessError } from '@kit.BasicServicesKit';
4755
4756try {
4757  windowClass.on('keyboardDidHide', (keyboardInfo) => {
4758    console.info('keyboard hide animation completion. keyboardInfo: ' + JSON.stringify(keyboardInfo));
4759  });
4760} catch (exception) {
4761  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
4762}
4763```
4764
4765### off('keyboardDidHide')<sup>18+</sup>
4766
4767off(type: 'keyboardDidHide', callback?: Callback&lt;KeyboardInfo&gt;): void
4768
4769关闭固定态软键盘隐藏动画完成的监听。改变输入法窗口为固定态切换至悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。
4770
4771**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
4772
4773**系统能力:** SystemCapability.Window.SessionManager
4774
4775**参数:**
4776
4777| 参数名   | 类型                   | 必填 | 说明                                                         |
4778| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
4779| type     | string                 | 是   | 监听事件,固定为'keyboardDidHide',即固定态软键盘隐藏动画完成事件。 |
4780| callback | Callback&lt;[KeyboardInfo](#keyboardinfo18)&gt; | 否   |  回调函数。返回软键盘窗口信息。若传入参数,则关闭该监听。如果未传入参数,则关闭所有固定态软键盘隐藏动画完成的监听。                               |
4781
4782**错误码:**
4783
4784以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
4785
4786| 错误码ID | 错误信息 |
4787| ------- | -------------------------------------------- |
4788| 801     | Capability not supported. Function keyboardDidHide can not work correctly due to limited device capabilities. |
4789| 1300002 | This window state is abnormal.               |
4790
4791**示例:**
4792
4793```ts
4794import { BusinessError } from '@kit.BasicServicesKit';
4795
4796const callback = (keyboardInfo: window.KeyboardInfo) => {
4797  // ...
4798}
4799try {
4800  windowClass.on('keyboardDidHide', callback);
4801  windowClass.off('keyboardDidHide', callback);
4802  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
4803  windowClass.off('keyboardDidHide');
4804} catch (exception) {
4805  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
4806}
4807```
4808
4809### on('touchOutside')<sup>11+</sup>
4810
4811on(type: 'touchOutside', callback: Callback&lt;void&gt;): void
4812
4813开启本窗口区域范围外的点击事件的监听。
4814
4815**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4816
4817**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4818
4819**参数:**
4820
4821| 参数名   | 类型                | 必填 | 说明                                                         |
4822| -------- | ------------------- | ---- | ------------------------------------------------------------ |
4823| type     | string              | 是   | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 |
4824| callback | Callback&lt;void&gt; | 是   | 回调函数。当点击事件发生在本窗口范围之外的回调。                               |
4825
4826**错误码:**
4827
4828以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4829
4830| 错误码ID | 错误信息 |
4831| ------- | -------------------------------------------- |
4832| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
4833
4834**示例:**
4835
4836```ts
4837try {
4838  windowClass.on('touchOutside', () => {
4839    console.info('touch outside');
4840  });
4841} catch (exception) {
4842  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
4843}
4844```
4845
4846### off('touchOutside')<sup>11+</sup>
4847
4848off(type: 'touchOutside', callback?: Callback&lt;void&gt;): void
4849
4850关闭本窗口区域范围外的点击事件的监听。
4851
4852**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4853
4854**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
4855
4856**参数:**
4857
4858| 参数名   | 类型                   | 必填 | 说明                                   |
4859| -------- |----------------------| ---- |--------------------------------------|
4860| type     | string               | 是   | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 |
4861| callback | Callback&lt;void&gt; | 否   | 回调函数。当点击事件发生在本窗口范围之外的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口区域范围外的点击事件的监听。            |
4862
4863**错误码:**
4864
4865以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4866
4867| 错误码ID | 错误信息 |
4868| ------- | -------------------------------------------- |
4869| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
4870
4871**示例:**
4872
4873```ts
4874const callback = () => {
4875  // ...
4876}
4877try {
4878  windowClass.on('touchOutside', callback);
4879  windowClass.off('touchOutside', callback);
4880  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
4881  windowClass.off('touchOutside');
4882} catch (exception) {
4883  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
4884}
4885```
4886
4887### on('screenshot')<sup>9+</sup>
4888
4889on(type: 'screenshot', callback: Callback&lt;void&gt;): void
4890
4891开启截屏事件的监听。
4892
4893**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4894
4895**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4896
4897**参数:**
4898
4899| 参数名   | 类型                | 必填 | 说明                                                         |
4900| -------- | ------------------- | ---- | ------------------------------------------------------------ |
4901| type     | string              | 是   | 监听事件,固定为'screenshot',即截屏事件,对控制中心截屏、hdc命令截屏、整屏截屏接口生效。 |
4902| callback | Callback&lt;void&gt; | 是   | 回调函数。发生截屏事件时的回调。                               |
4903
4904**错误码:**
4905
4906以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4907
4908| 错误码ID | 错误信息 |
4909| ------- | -------------------------------------------- |
4910| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
4911
4912**示例:**
4913
4914```ts
4915try {
4916  windowClass.on('screenshot', () => {
4917    console.info('screenshot happened');
4918  });
4919} catch (exception) {
4920  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
4921}
4922```
4923
4924### off('screenshot')<sup>9+</sup>
4925
4926off(type: 'screenshot', callback?: Callback&lt;void&gt;): void
4927
4928关闭截屏事件的监听。
4929
4930**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4931
4932**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4933
4934**参数:**
4935
4936| 参数名   | 类型                   | 必填 | 说明                                                         |
4937| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
4938| type     | string                 | 是   | 监听事件,固定为'screenshot',即截屏事件。 |
4939| callback | Callback&lt;void&gt; | 否   | 回调函数。发生截屏事件时的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有截屏事件的监听。 |
4940
4941**错误码:**
4942
4943以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4944
4945| 错误码ID | 错误信息 |
4946| ------- | -------------------------------------------- |
4947| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
4948
4949**示例:**
4950
4951```ts
4952let callback = () => {
4953  console.info('screenshot happened');
4954};
4955try {
4956  windowClass.on('screenshot', callback);
4957  windowClass.off('screenshot', callback);
4958  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
4959  windowClass.off('screenshot');
4960} catch (exception) {
4961  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
4962}
4963```
4964
4965### on('dialogTargetTouch')<sup>10+</sup>
4966
4967on(type: 'dialogTargetTouch', callback: Callback&lt;void&gt;): void
4968
4969开启模态窗口所遮盖窗口的点击或触摸事件的监听,除模态窗口以外其他窗口调用此接口不生效。
4970
4971**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4972
4973**系统能力:** SystemCapability.WindowManager.WindowManager.Core
4974
4975**参数:**
4976
4977| 参数名   | 类型                 | 必填 | 说明                                                          |
4978| -------- | ------------------- | ---- | ------------------------------------------------------------ |
4979| type     | string              | 是   | 监听事件,固定为'dialogTargetTouch',即模态窗口所遮盖窗口的点击或触摸事件。 |
4980| callback | Callback&lt;void&gt;| 是   | 回调函数。当点击或触摸事件发生在模态窗口所遮盖窗口的回调。 |
4981
4982**错误码:**
4983
4984以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4985
4986| 错误码ID | 错误信息 |
4987| ------- | -------------------------------------------- |
4988| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
4989
4990**示例:**
4991
4992```ts
4993try {
4994  windowClass.on('dialogTargetTouch', () => {
4995    console.info('touch dialog target');
4996  });
4997} catch (exception) {
4998  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
4999}
5000```
5001
5002### off('dialogTargetTouch')<sup>10+</sup>
5003
5004off(type: 'dialogTargetTouch', callback?: Callback&lt;void&gt;): void
5005
5006关闭模态窗口目标窗口的点击事件的监听。
5007
5008**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5009
5010**系统能力:** SystemCapability.WindowManager.WindowManager.Core
5011
5012**参数:**
5013
5014| 参数名   | 类型                    | 必填 | 说明                                                          |
5015| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
5016| type     | string                 | 是   | 监听事件,固定为'dialogTargetTouch',即模态窗口目标窗口的点击事件。 |
5017| callback | Callback&lt;void&gt;      | 否   | 回调函数。当点击事件发生在模态窗口目标窗口的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有模态窗口目标窗口的点击事件的监听。 |
5018
5019**错误码:**
5020
5021以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
5022
5023| 错误码ID | 错误信息 |
5024| ------- | -------------------------------------------- |
5025| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
5026
5027**示例:**
5028
5029```ts
5030const callback = () => {
5031  // ...
5032}
5033try {
5034  windowClass.on('dialogTargetTouch', callback);
5035  windowClass.off('dialogTargetTouch', callback);
5036  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
5037  windowClass.off('dialogTargetTouch');
5038} catch (exception) {
5039  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
5040}
5041```
5042
5043### on('windowEvent')<sup>10+</sup>
5044
5045on(type: 'windowEvent', callback: Callback&lt;WindowEventType&gt;): void
5046
5047开启窗口生命周期变化的监听。
5048
5049**系统能力:** SystemCapability.WindowManager.WindowManager.Core
5050
5051**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
5052
5053**参数:**
5054
5055| 参数名   | 类型                                                       | 必填 | 说明                                                         |
5056| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5057| type     | string                                                     | 是   | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 |
5058| callback | Callback&lt;[WindowEventType](#windoweventtype10)&gt; | 是   | 回调函数。返回当前的窗口生命周期状态。                 |
5059
5060**错误码:**
5061
5062以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
5063
5064| 错误码ID | 错误信息 |
5065| ------- | -------------------------------------------- |
5066| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5067
5068**示例:**
5069
5070```ts
5071try {
5072  windowClass.on('windowEvent', (data) => {
5073    console.info('Window event happened. Event:' + JSON.stringify(data));
5074  });
5075} catch (exception) {
5076  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
5077}
5078```
5079
5080### off('windowEvent')<sup>10+</sup>
5081
5082off(type: 'windowEvent', callback?: Callback&lt;WindowEventType&gt;): void
5083
5084关闭窗口生命周期变化的监听。
5085
5086**系统能力:** SystemCapability.WindowManager.WindowManager.Core
5087
5088**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
5089
5090**参数:**
5091
5092| 参数名   | 类型                                                       | 必填 | 说明                                                         |
5093| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5094| type     | string                                                     | 是   | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 |
5095| callback | Callback&lt;[WindowEventType](#windoweventtype10)&gt; | 否   | 回调函数。返回当前的窗口生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有窗口生命周期变化的监听。                 |
5096
5097**错误码:**
5098
5099以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
5100
5101| 错误码ID | 错误信息 |
5102| ------- | -------------------------------------------- |
5103| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
5104
5105**示例:**
5106
5107```ts
5108const callback = (windowEventType: window.WindowEventType) => {
5109  // ...
5110}
5111try {
5112  // 通过on接口开启监听
5113  windowClass.on('windowEvent', callback);
5114  // 关闭指定callback的监听
5115  windowClass.off('windowEvent', callback);
5116  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
5117  windowClass.off('windowEvent');
5118} catch (exception) {
5119  console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
5120}
5121```
5122
5123### on('displayIdChange')<sup>14+</sup>
5124
5125on(type: 'displayIdChange', callback: Callback&lt;number&gt;): void
5126
5127开启本窗口所处屏幕变化事件的监听。比如,当前窗口移动到其他屏幕时,可以从此接口监听到这个行为。
5128
5129**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
5130
5131**系统能力:** SystemCapability.Window.SessionManager
5132
5133**参数:**
5134
5135| 参数名   | 类型                       | 必填 | 说明                                                         |
5136| -------- | --------------------------| ---- | ------------------------------------------------------------ |
5137| type     | string                    | 是   | 监听事件,固定为'displayIdChange',即本窗口所处屏幕变化的事件。 |
5138| callback | Callback&lt;number&gt;   | 是   | 回调函数。当本窗口所处屏幕发生变化后的回调。回调函数返回number类型参数,表示窗口所处屏幕的displayId。                               |
5139
5140**错误码:**
5141
5142以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5143
5144| 错误码ID | 错误信息 |
5145| ------- | ------------------------------ |
5146| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5147| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5148| 1300002 | This window state is abnormal.                |
5149
5150**示例:**
5151
5152```ts
5153try {
5154  windowClass.on('displayIdChange', (data) => {
5155    console.info('Window displayId changed, displayId=' + JSON.stringify(data));
5156  });
5157} catch (exception) {
5158  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
5159}
5160```
5161### off('displayIdChange')<sup>14+</sup>
5162
5163off(type: 'displayIdChange', callback?: Callback&lt;number&gt;): void
5164
5165关闭本窗口所处屏幕变化事件的监听。
5166
5167**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
5168
5169**系统能力:** SystemCapability.Window.SessionManager
5170
5171**参数:**
5172
5173| 参数名   | 类型                        | 必填 | 说明                                   |
5174| -------- |----------------------------| ---- |--------------------------------------|
5175| type     | string                     | 是   | 监听事件,固定为'displayIdChange',即本窗口所处屏幕变化的事件。 |
5176| callback | Callback&lt;number&gt;    | 否   | 回调函数。当本窗口所处屏幕发生变化时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口所处屏幕变化事件的回调。            |
5177
5178**错误码:**
5179
5180以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5181
5182| 错误码ID | 错误信息 |
5183| ------- | ------------------------------ |
5184| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
5185| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5186| 1300002 | This window state is abnormal.                |
5187
5188**示例:**
5189
5190```ts
5191const callback = (displayId: number) => {
5192  // ...
5193}
5194try {
5195  // 通过on接口开启监听
5196  windowClass.on('displayIdChange', callback);
5197  // 关闭指定callback的监听
5198  windowClass.off('displayIdChange', callback);
5199  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
5200  windowClass.off('displayIdChange');
5201} catch (exception) {
5202  console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
5203}
5204```
5205
5206### on('windowVisibilityChange')<sup>11+</sup>
5207
5208on(type: 'windowVisibilityChange', callback: Callback&lt;boolean&gt;): void
5209
5210开启本窗口可见状态变化事件的监听。
5211
5212**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5213
5214**系统能力:** SystemCapability.Window.SessionManager
5215
5216**参数:**
5217
5218| 参数名   | 类型                       | 必填 | 说明                                                         |
5219| -------- | --------------------------| ---- | ------------------------------------------------------------ |
5220| type     | string                    | 是   | 监听事件,固定为'windowVisibilityChange',即本窗口可见状态变化的事件。 |
5221| callback | Callback&lt;boolean&gt;   | 是   | 回调函数。当本窗口可见状态发生变化后的回调。回调函数返回boolean类型参数,当返回参数为true时表示窗口可见,否则表示窗口不可见。                               |
5222
5223**错误码:**
5224
5225以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5226
5227| 错误码ID | 错误信息 |
5228| ------- | ------------------------------ |
5229| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5230| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5231| 1300002 | This window state is abnormal.                |
5232| 1300003 | This window manager service works abnormally. |
5233
5234**示例:**
5235
5236```ts
5237try {
5238  windowClass.on('windowVisibilityChange', (boolean) => {
5239    console.info('Window visibility changed, isVisible=' + boolean);
5240  });
5241} catch (exception) {
5242  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
5243}
5244```
5245
5246### off('windowVisibilityChange')<sup>11+</sup>
5247
5248off(type: 'windowVisibilityChange', callback?: Callback&lt;boolean&gt;): void
5249
5250关闭本窗口可见状态变化事件的监听。
5251
5252**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5253
5254**系统能力:** SystemCapability.Window.SessionManager
5255
5256**参数:**
5257
5258| 参数名   | 类型                        | 必填 | 说明                                   |
5259| -------- |----------------------------| ---- |--------------------------------------|
5260| type     | string                     | 是   | 监听事件,固定为'windowVisibilityChange',即本窗口可见状态变化的事件。 |
5261| callback | Callback&lt;boolean&gt;    | 否   | 回调函数。当本窗口可见状态发生变化时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口可见状态变化事件的回调。            |
5262
5263**错误码:**
5264
5265以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5266
5267| 错误码ID | 错误信息 |
5268| ------- | ------------------------------ |
5269| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
5270| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5271| 1300002 | This window state is abnormal.                |
5272| 1300003 | This window manager service works abnormally. |
5273
5274**示例:**
5275
5276```ts
5277const callback = (bool: boolean) => {
5278  // ...
5279}
5280try {
5281  // 通过on接口开启监听
5282  windowClass.on('windowVisibilityChange', callback);
5283  // 关闭指定callback的监听
5284  windowClass.off('windowVisibilityChange', callback);
5285  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
5286  windowClass.off('windowVisibilityChange');
5287} catch (exception) {
5288  console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
5289}
5290```
5291
5292### on('systemDensityChange')<sup>15+</sup>
5293
5294on(type: 'systemDensityChange', callback: Callback&lt;number&gt;): void
5295
5296开启本窗口所处屏幕的系统显示大小缩放系数变化事件的监听。比如,当调整窗口所处屏幕的显示大小缩放系数时,可以从此接口监听到这个行为。
5297
5298**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
5299
5300**系统能力:** SystemCapability.Window.SessionManager
5301
5302**参数:**
5303
5304| 参数名   | 类型                       | 必填 | 说明                                                         |
5305| -------- | --------------------------| ---- | ------------------------------------------------------------ |
5306| type     | string                    | 是   | 监听事件,固定为'systemDensityChange',即本窗口所处屏幕的系统显示大小缩放系数变化的事件。 |
5307| callback | Callback&lt;number&gt;   | 是   | 回调函数。当本窗口所处屏幕的系统显示大小缩放系数发生变化后的回调。回调函数返回number类型参数,表示当前窗口所处屏幕的系统显示大小缩放系数。                               |
5308
5309**错误码:**
5310
5311
5312以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5313
5314| 错误码ID | 错误信息 |
5315| ------- | ------------------------------ |
5316| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5317| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5318| 1300002 | This window state is abnormal.                |
5319
5320**示例:**
5321
5322```ts
5323const callback = (density: number) => {
5324  console.info('System density changed, density=' + JSON.stringify(density));
5325}
5326try {
5327  windowClass.on('systemDensityChange', callback);
5328} catch (exception) {
5329  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
5330}
5331```
5332### off('systemDensityChange')<sup>15+</sup>
5333
5334off(type: 'systemDensityChange', callback?: Callback&lt;number&gt;): void
5335
5336关闭本窗口所处屏幕的系统显示大小缩放系数变化事件的监听。
5337
5338**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
5339
5340**系统能力:** SystemCapability.Window.SessionManager
5341
5342**参数:**
5343
5344| 参数名   | 类型                        | 必填 | 说明                                   |
5345| -------- |----------------------------| ---- |--------------------------------------|
5346| type     | string                     | 是   | 监听事件,固定为'systemDensityChange',即本窗口所处屏幕的系统显示大小缩放系数变化的事件。 |
5347| callback | Callback&lt;number&gt;    | 否   | 回调函数。当本窗口所处屏幕的系统显示大小缩放系数发生变化后的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口所处屏幕的系统显示大小缩放系数变化事件的回调。            |
5348
5349**错误码:**
5350
5351以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5352
5353| 错误码ID | 错误信息 |
5354| ------- | ------------------------------ |
5355| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
5356| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5357| 1300002 | This window state is abnormal.                |
5358
5359**示例:**
5360
5361```ts
5362const callback = (density: number) => {
5363  // ...
5364}
5365try {
5366  // 通过on接口开启监听
5367  windowClass.on('systemDensityChange', callback);
5368  // 关闭指定callback的监听
5369  windowClass.off('systemDensityChange', callback);
5370  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
5371  windowClass.off('systemDensityChange');
5372} catch (exception) {
5373  console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
5374}
5375```
5376
5377### on('noInteractionDetected')<sup>12+</sup>
5378
5379on(type: 'noInteractionDetected', timeout: number, callback: Callback&lt;void&gt;): void
5380
5381开启本窗口在指定超时时间内无交互事件的监听,交互事件支持物理键盘输入事件和屏幕触控点击事件,不支持软键盘输入事件。
5382
5383**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5384
5385**系统能力:** SystemCapability.Window.SessionManager
5386
5387**参数:**
5388
5389| 参数名   | 类型                       | 必填 | 说明                                                         |
5390| -------- | --------------------------| ---- | ------------------------------------------------------------ |
5391| type     | string                    | 是   | 监听事件,固定为'noInteractionDetected',即本窗口在指定超时时间内无交互的事件。 |
5392| timeout     | number                    | 是   | 指定本窗口在多长时间内无交互即回调,单位为秒(s)。该参数仅支持整数输入,负数和小数为非法参数。 |
5393| callback | Callback&lt;void&gt;      | 是   | 回调函数。当本窗口在指定超时时间内无交互事件时的回调。  |
5394
5395**错误码:**
5396
5397以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5398
5399| 错误码ID | 错误信息 |
5400| ------- | ------------------------------ |
5401| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5402| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5403| 1300002 | This window state is abnormal.                |
5404| 1300003 | This window manager service works abnormally. |
5405
5406**示例:**
5407
5408```ts
5409try {
5410  windowClass.on('noInteractionDetected', 60, () => {
5411    console.info('no interaction in 60s');
5412  });
5413} catch (exception) {
5414  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
5415}
5416```
5417
5418### off('noInteractionDetected')<sup>12+</sup>
5419
5420off(type: 'noInteractionDetected', callback?: Callback&lt;void&gt;): void
5421
5422关闭本窗口在指定超时时间内无交互事件的监听,交互事件支持物理键盘输入事件和屏幕触控点击事件,不支持软键盘输入事件。
5423
5424**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5425
5426**系统能力:** SystemCapability.Window.SessionManager
5427
5428**参数:**
5429
5430| 参数名   | 类型                        | 必填 | 说明                                   |
5431| -------- |----------------------------| ---- |--------------------------------------|
5432| type     | string                     | 是   | 监听事件,固定为'noInteractionDetected',即本窗口在指定超时时间内无交互的事件。 |
5433| callback | Callback&lt;void&gt;    | 否   | 回调函数,当本窗口在指定超时时间内无交互事件时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口在指定超时时间内无交互事件的监听。 |
5434
5435**错误码:**
5436
5437以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5438
5439| 错误码ID | 错误信息 |
5440| ------- | ------------------------------ |
5441| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
5442| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5443| 1300002 | This window state is abnormal.                |
5444| 1300003 | This window manager service works abnormally. |
5445
5446**示例:**
5447
5448```ts
5449const callback = () => {
5450  // ...
5451}
5452try {
5453  windowClass.on('noInteractionDetected', 60, callback);
5454  windowClass.off('noInteractionDetected', callback);
5455  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
5456  windowClass.off('noInteractionDetected');
5457} catch (exception) {
5458  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
5459}
5460```
5461
5462### on('windowStatusChange')<sup>11+</sup>
5463
5464on(type:  'windowStatusChange', callback: Callback&lt;WindowStatusType&gt;): void
5465
5466开启窗口模式变化的监听,当窗口windowStatus发生变化时进行通知(此时窗口属性可能还没有更新)。
5467
5468**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5469
5470**系统能力:** SystemCapability.Window.SessionManager
5471
5472**参数:**
5473
5474| 参数名   | 类型                           | 必填 | 说明                                                     |
5475| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
5476| type     | string                         | 是   | 监听事件,固定为'windowStatusChange',即窗口模式变化事件。 |
5477| callback | Callback&lt;[WindowStatusType](#windowstatustype11)&gt; | 是   | 回调函数。返回当前的窗口模式。                           |
5478
5479**错误码:**
5480
5481以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
5482
5483| 错误码ID | 错误信息 |
5484| ------- | ------------------------------ |
5485| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5486| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5487
5488**示例:**
5489
5490```ts
5491try {
5492    windowClass.on('windowStatusChange', (WindowStatusType) => {
5493        console.info('Succeeded in enabling the listener for window status changes. Data: ' + JSON.stringify(WindowStatusType));
5494    });
5495} catch (exception) {
5496    console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
5497}
5498```
5499
5500### off('windowStatusChange')<sup>11+</sup>
5501
5502off(type: 'windowStatusChange', callback?: Callback&lt;WindowStatusType&gt;): void
5503
5504关闭窗口模式变化的监听。
5505
5506**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5507
5508**系统能力:** SystemCapability.Window.SessionManager
5509
5510**参数:**
5511
5512| 参数名   | 类型                          | 必填 | 说明                                                     |
5513| -------- | ----------------------------- | ---- | -------------------------------------------------------- |
5514| type     | string                        | 是   | 监听事件,固定为'windowStatusChange',即窗口模式变化事件。 |
5515| callback | Callback&lt;[WindowStatusType](#windowstatustype11)&gt; | 否   | 回调函数。返回当前的窗口模式。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有窗口模式变化的监听。                           |
5516
5517**错误码:**
5518
5519以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
5520
5521| 错误码ID | 错误信息 |
5522| ------- | ------------------------------ |
5523| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
5524| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5525
5526**示例:**
5527
5528```ts
5529const callback = (windowStatusType: window.WindowStatusType) => {
5530    // ...
5531}
5532try {
5533    windowClass.on('windowStatusChange', callback);
5534    windowClass.off('windowStatusChange', callback);
5535    // 如果通过on开启多个callback进行监听,同时关闭所有监听:
5536    windowClass.off('windowStatusChange');
5537} catch (exception) {
5538    console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
5539}
5540```
5541
5542### on('windowStatusDidChange')<sup>20+</sup>
5543
5544on(type: 'windowStatusDidChange', callback: Callback&lt;WindowStatusType&gt;): void
5545
5546开启窗口模式变化的监听,当窗口windowStatus发生变化后进行通知(此时窗口[Rect](#rect7)属性已经完成更新)。
5547
5548**系统能力:** SystemCapability.Window.SessionManager
5549
5550**参数:**
5551
5552| 参数名   | 类型                           | 必填 | 说明                                                     |
5553| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
5554| type     | string                         | 是   | 监听事件,固定为'windowStatusDidChange',即窗口模式变化完成事件。 |
5555| callback | Callback&lt;[WindowStatusType](#windowstatustype11)&gt; | 是   | 回调函数。返回当前的窗口模式。                           |
5556
5557**错误码:**
5558
5559以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
5560
5561| 错误码ID | 错误信息 |
5562| ------- | ------------------------------ |
5563| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5564| 1300002 | This window state is abnormal. |
5565
5566**示例:**
5567
5568```ts
5569try {
5570    windowClass.on('windowStatusDidChange', (WindowStatusType) => {
5571        console.info(`Succeeded in enabling the listener for window status changes. Data: ${JSON.stringify(WindowStatusType)}`);
5572    });
5573} catch (exception) {
5574    console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
5575}
5576```
5577
5578### off('windowStatusDidChange')<sup>20+</sup>
5579
5580off(type: 'windowStatusDidChange', callback?: Callback&lt;WindowStatusType&gt;): void
5581
5582关闭窗口模式变化的监听。
5583
5584**系统能力:** SystemCapability.Window.SessionManager
5585
5586**参数:**
5587
5588| 参数名   | 类型                          | 必填 | 说明                                                     |
5589| -------- | ----------------------------- | ---- | -------------------------------------------------------- |
5590| type     | string                        | 是   | 监听事件,固定为'windowStatusDidChange',即窗口模式变化完成事件。 |
5591| callback | Callback&lt;[WindowStatusType](#windowstatustype11)&gt; | 否   | 回调函数。返回当前的窗口模式。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有窗口模式变化的监听。                           |
5592
5593**错误码:**
5594
5595以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
5596
5597| 错误码ID | 错误信息 |
5598| ------- | ------------------------------ |
5599| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5600| 1300002 | This window state is abnormal. |
5601
5602**示例:**
5603
5604```ts
5605const callback = (windowStatusType: window.WindowStatusType) => {
5606    // ...
5607}
5608try {
5609    windowClass.on('windowStatusDidChange', callback);
5610    windowClass.off('windowStatusDidChange', callback);
5611    // 如果通过on开启多个callback进行监听,同时关闭所有监听:
5612    windowClass.off('windowStatusDidChange');
5613} catch (exception) {
5614    console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
5615}
5616```
5617
5618### setWindowGrayScale<sup>12+</sup>
5619
5620setWindowGrayScale(grayScale: number): Promise&lt;void&gt;
5621
5622设置窗口灰阶,使用Promise异步回调。该接口需要在调用[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)使窗口加载页面内容后调用。
5623
5624**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5625
5626**系统能力:** SystemCapability.Window.SessionManager
5627
5628**参数:**
5629
5630| 参数名 | 类型 | 必填 | 说明                                     |
5631| --------- | ------ | -- | ---------------------------------------- |
5632| grayScale | number | 是 | 窗口灰阶。该参数为浮点数,取值范围为[0.0, 1.0]。0.0表示窗口图像无变化,1.0表示窗口图像完全转为灰度图像,0.0至1.0之间时效果呈线性变化。 |
5633
5634**返回值:**
5635
5636| 类型 | 说明 |
5637| ------------------- | ------------------------ |
5638| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5639
5640**错误码:**
5641
5642以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5643
5644| 错误码ID | 错误信息 |
5645| ------- | --------------------------------------------- |
5646| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5647| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5648| 1300002 | This window state is abnormal.                |
5649| 1300003 | This window manager service works abnormally. |
5650
5651**示例:**
5652
5653```ts
5654import { BusinessError } from '@kit.BasicServicesKit';
5655
5656windowClass?.setUIContent('pages/Index', (error: BusinessError) => {
5657  if (error.code) {
5658    console.error(`Failed to set the content. Cause code: ${error.code}`);
5659    return;
5660  }
5661  console.info('Succeeded in setting the content.');
5662  let grayScale: number = 0.5;
5663  try {
5664    if (canIUse("SystemCapability.Window.SessionManager")) {
5665      let promise = windowClass?.setWindowGrayScale(grayScale);
5666      promise?.then(() => {
5667        console.info('Succeeded in setting the grayScale.');
5668      }).catch((err: BusinessError) => {
5669        console.error(`Failed to set the grayScale. Cause code: ${err.code}, message: ${err.message}`);
5670      });
5671    }
5672  } catch (exception) {
5673    console.error(`Failed to set the grayScale. Cause code: ${exception.code}, message: ${exception.message}`);
5674  }
5675});
5676```
5677
5678### on('windowTitleButtonRectChange')<sup>11+</sup>
5679
5680on(type: 'windowTitleButtonRectChange', callback: Callback&lt;TitleButtonRect&gt;): void
5681
5682开启窗口标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
5683
5684<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
5685
5686**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5687
5688**系统能力:** SystemCapability.Window.SessionManager
5689
5690**参数:**
5691
5692| 参数名   | 类型                                                  | 必填 | 说明                                                         |
5693| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
5694| type     | string                                                | 是   | 监听事件,固定为'windowTitleButtonRectChange',即标题栏上的最小化、最大化、关闭按钮矩形区域变化事件。 |
5695| callback | Callback&lt;[TitleButtonRect](#titlebuttonrect11)&gt; | 是   | 回调函数。返回当前标题栏上的最小化、最大化、关闭按钮矩形区域。 |
5696
5697**错误码:**
5698
5699以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5700
5701| 错误码ID | 错误信息                       |
5702| -------- | ------------------------------ |
5703| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5704| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5705| 1300002  | This window state is abnormal. |
5706
5707**示例:**
5708
5709```ts
5710windowClass.setUIContent('pages/WindowPage').then(() => {
5711  try {
5712    windowClass?.on('windowTitleButtonRectChange', (titleButtonRect) => {
5713      console.info('Succeeded in enabling the listener for window title buttons area changes. Data: ' + JSON.stringify(titleButtonRect));
5714    });
5715  } catch (exception) {
5716    console.error(`Failed to enable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`);
5717  }
5718})
5719```
5720
5721### off('windowTitleButtonRectChange')<sup>11+</sup>
5722
5723off(type: 'windowTitleButtonRectChange', callback?: Callback&lt;TitleButtonRect&gt;): void
5724
5725关闭窗口标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
5726
5727<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
5728
5729**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5730
5731**系统能力:** SystemCapability.Window.SessionManager
5732
5733**参数:**
5734
5735| 参数名   | 类型                                                  | 必填 | 说明                                                         |
5736| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
5737| type     | string                                                | 是   | 监听事件,固定为'windowTitleButtonRectChange',即标题栏上的最小化、最大化、关闭按钮矩形区域变化事件。 |
5738| callback | Callback&lt;[TitleButtonRect](#titlebuttonrect11)&gt; | 否   | 回调函数。返回当前标题栏上的最小化、最大化、关闭按钮矩形区域。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听。 |
5739
5740**错误码:**
5741
5742以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5743
5744| 错误码ID | 错误信息                       |
5745| -------- | ------------------------------ |
5746| 401      | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
5747| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
5748| 1300002  | This window state is abnormal. |
5749
5750**示例:**
5751
5752```ts
5753windowClass.setUIContent('pages/WindowPage').then(() => {
5754	const callback = (titleButtonRect: window.TitleButtonRect) => {
5755		// ...
5756	}
5757  try {
5758    // 通过on接口开启监听
5759    windowClass?.on('windowTitleButtonRectChange', callback);
5760    // 关闭指定callback的监听
5761    windowClass?.off('windowTitleButtonRectChange', callback);
5762    // 如果通过on开启多个callback进行监听,同时关闭所有监听:
5763    windowClass?.off('windowTitleButtonRectChange');
5764  } catch (exception) {
5765    console.error(`Failed to disable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`);
5766  }
5767})
5768```
5769
5770### on('windowRectChange')<sup>12+</sup>
5771
5772on(type:  'windowRectChange', callback: Callback&lt;RectChangeOptions&gt;): void
5773
5774开启窗口矩形(窗口位置及窗口大小)变化的监听。
5775
5776**系统能力:** SystemCapability.Window.SessionManager
5777
5778**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5779
5780**参数:**
5781
5782| 参数名   | 类型                           | 必填 | 说明                                                     |
5783| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
5784| type     | string                         | 是   | 监听事件,固定为'windowRectChange',即窗口矩形变化事件。 |
5785| callback | Callback&lt;[RectChangeOptions](#rectchangeoptions12)&gt; | 是   | 回调函数。返回当前窗口矩形变化值及变化原因。                           |
5786
5787**错误码:**
5788
5789以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5790
5791| 错误码ID | 错误信息 |
5792| ------- | -------------------------------------------- |
5793| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
5794| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5795| 1300002 | This window state is abnormal. |
5796| 1300003 | This window manager service works abnormally. |
5797
5798**示例:**
5799
5800```ts
5801try {
5802  windowClass.on('windowRectChange', (data: window.RectChangeOptions) => {
5803      console.info(`Succeeded window rect changes. Data: ` + JSON.stringify(data));
5804  });
5805} catch (exception) {
5806  console.error(`Failed to disable the listener for window rect changes. Cause code: ${exception.code}, message: ${exception.message}`);
5807}
5808```
5809
5810### off('windowRectChange')<sup>12+</sup>
5811
5812off(type: 'windowRectChange', callback?: Callback&lt;RectChangeOptions&gt;): void
5813
5814关闭窗口矩形(窗口位置及窗口大小)变化的监听。
5815
5816**系统能力:** SystemCapability.Window.SessionManager
5817
5818**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5819
5820**参数:**
5821
5822| 参数名   | 类型                           | 必填 | 说明                                                         |
5823| -------- | ------------------------------ | ---- | ------------------------------------------------------------ |
5824| type     | string                         | 是   | 监听事件,固定为'windowRectChange',即窗口矩形变化事件。     |
5825| callback | Callback&lt;[RectChangeOptions](#rectchangeoptions12)&gt; | 否   | 回调函数。返回当前的窗口矩形及变化原因。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有窗口矩形变化的监听。 |
5826
5827**错误码:**
5828
5829以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5830
5831| 错误码ID | 错误信息 |
5832| ------- | -------------------------------------------- |
5833| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
5834| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5835| 1300002 | This window state is abnormal. |
5836| 1300003 | This window manager service works abnormally. |
5837
5838**示例:**
5839
5840```ts
5841const callback = (rectChangeOptions: window.RectChangeOptions) => {
5842  // ...
5843}
5844
5845try {
5846  windowClass.on('windowRectChange', callback);
5847  windowClass.off('windowRectChange', callback);
5848  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
5849  windowClass.off('windowRectChange');
5850} catch (exception) {
5851  console.error(`Failed to disable the listener for window rect changes. Cause code: ${exception.code}, message: ${exception.message}`);
5852}
5853```
5854
5855### on('subWindowClose')<sup>12+</sup>
5856
5857on(type:  'subWindowClose', callback: Callback&lt;void&gt;): void
5858
5859开启子窗口关闭事件的监听。此监听仅在点击系统提供的右上角关闭按钮关闭子窗时触发,其余关闭方式不触发回调。
5860
5861当重复注册窗口关闭事件的监听时,最后一次注册成功的监听事件生效。
5862
5863该接口触发的窗口关闭事件监听回调函数是同步执行,子窗口的异步关闭事件监听参考[on('windowWillClose')](#onwindowwillclose15)方法。
5864
5865如果存在[on('windowWillClose')](#onwindowwillclose15)监听事件,只响应[on('windowWillClose')](#onwindowwillclose15)接口。
5866
5867**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5868
5869**系统能力:** SystemCapability.Window.SessionManager
5870
5871**参数:**
5872
5873| 参数名   | 类型                           | 必填 | 说明                                                     |
5874| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
5875| type     | string                         | 是   | 监听事件,固定为'subWindowClose',即子窗口关闭事件。 |
5876| callback | Callback&lt;void&gt; | 是   | 回调函数。当点击子窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑的返回值决定当前子窗是否继续关闭,如果返回boolean类型的true表示不关闭子窗,返回false或者其他非boolean类型表示关闭子窗。   |
5877
5878**错误码:**
5879
5880以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5881
5882| 错误码ID | 错误信息 |
5883| ------- | -------------------------------------------- |
5884| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
5885| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5886| 1300002 | This window state is abnormal. |
5887| 1300004 | Unauthorized operation. |
5888
5889**示例:**
5890
5891```ts
5892const callback = () => {
5893  // ...
5894  return true;
5895}
5896try {
5897  windowClass.on('subWindowClose', callback);
5898} catch (exception) {
5899  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
5900}
5901```
5902
5903### off('subWindowClose')<sup>12+</sup>
5904
5905off(type: 'subWindowClose', callback?: Callback&lt;void&gt;): void
5906
5907关闭子窗口关闭事件的监听。
5908
5909**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5910
5911**系统能力:** SystemCapability.Window.SessionManager
5912
5913**参数:**
5914
5915| 参数名   | 类型                           | 必填 | 说明                                                         |
5916| -------- | ------------------------------ | ---- | ------------------------------------------------------------ |
5917| type     | string                         | 是   | 监听事件,固定为'subWindowClose',即子窗口关闭事件。     |
5918| callback | Callback&lt;void&gt; | 否   | 回调函数。当点击子窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑的返回值决定当前子窗是否继续关闭,如果返回boolean类型的true表示不关闭子窗,返回false或者其他非boolean类型表示关闭子窗。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有子窗口关闭的监听。 |
5919
5920**错误码:**
5921
5922以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5923
5924| 错误码ID | 错误信息 |
5925| ------- | -------------------------------------------- |
5926| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
5927| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5928| 1300002 | This window state is abnormal. |
5929| 1300004 | Unauthorized operation. |
5930
5931**示例:**
5932
5933```ts
5934const callback = () => {
5935  // ...
5936  return true;
5937}
5938try {
5939  windowClass.on('subWindowClose', callback);
5940  windowClass.off('subWindowClose', callback);
5941  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
5942  windowClass.off('subWindowClose');
5943} catch (exception) {
5944  console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
5945}
5946```
5947
5948### on('windowWillClose')<sup>15+</sup>
5949
5950on(type: 'windowWillClose', callback: Callback&lt;void, Promise&lt;boolean&gt;&gt;): void
5951
5952开启主窗口或子窗口关闭事件的监听。此监听仅能通过系统提供的窗口标题栏关闭按键触发,其余关闭窗口的方式不触发回调。
5953
5954该接口触发的回调函数是异步执行。子窗口的同步关闭事件监听参考[on('subWindowClose')](#onsubwindowclose12)方法。主窗口的同步关闭事件监听参考[on('windowStageClose')](#onwindowstageclose14)方法。
5955
5956<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->  </br>
5957
5958**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
5959
5960**系统能力:** SystemCapability.Window.SessionManager
5961
5962**参数:**
5963
5964| 参数名   | 类型                           | 必填 | 说明                                                     |
5965| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
5966| type     | string                         | 是   | 监听事件,固定为'windowWillClose',即窗口关闭事件。 |
5967| callback | Callback&lt;void, Promise&lt;boolean&gt;&gt; | 是   | 回调函数。当点击窗口系统提供的右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有Promise&lt;boolean&gt;类型的返回值。在返回的Promise函数里,执行resolve(true) 方法表示不关闭当前窗口,执行resolve(false) 方法或者reject方法均表示关闭当前窗口。|
5968
5969**错误码:**
5970
5971以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
5972
5973| 错误码ID | 错误信息 |
5974| ------- | -------------------------------------------- |
5975| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
5976| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
5977| 1300002 | This window state is abnormal. |
5978| 1300004 | Unauthorized operation. |
5979
5980**示例:**
5981
5982```ts
5983// EntryAbility.ets
5984import { UIAbility } from '@kit.AbilityKit';
5985import { window } from '@kit.ArkUI';
5986
5987export default class EntryAbility extends UIAbility {
5988
5989  onWindowStageCreate(windowStage: window.WindowStage) {
5990    console.info('onWindowStageCreate');
5991    const callback = () => {
5992      // ...
5993      return new Promise<boolean>((resolve, reject) => {
5994        // 是否关闭该窗口
5995        let result: boolean = true;
5996        resolve(result);
5997      });
5998    }
5999    try {
6000      let windowClass = windowStage.getMainWindowSync();
6001      windowClass.on('windowWillClose', callback);
6002    } catch (exception) {
6003      console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
6004    }
6005  }
6006}
6007```
6008
6009### off('windowWillClose')<sup>15+</sup>
6010
6011off(type: 'windowWillClose', callback?: Callback&lt;void, Promise&lt;boolean&gt;&gt;): void
6012
6013关闭主窗口或子窗口关闭事件的监听。
6014
6015<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> </br>
6016
6017**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
6018
6019**系统能力:** SystemCapability.Window.SessionManager
6020
6021**参数:**
6022
6023| 参数名   | 类型                           | 必填 | 说明                                                     |
6024| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
6025| type     | string                         | 是   | 监听事件,固定为'windowWillClose',即窗口关闭事件。 |
6026| callback | Callback&lt;void, Promise&lt;boolean&gt;&gt; | 否   | 回调函数。当点击窗口系统提供的右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有Promise&lt;boolean&gt;类型的返回值。在返回的Promise函数里,执行resolve(true) 方法表示不关闭当前窗口,执行resolve(false) 方法或者reject方法均表示关闭当前窗口。|
6027
6028**错误码:**
6029
6030以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6031
6032| 错误码ID | 错误信息 |
6033| ------- | -------------------------------------------- |
6034| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
6035| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
6036| 1300002 | This window state is abnormal. |
6037| 1300004 | Unauthorized operation. |
6038
6039**示例:**
6040
6041```ts
6042// EntryAbility.ets
6043import { UIAbility } from '@kit.AbilityKit';
6044import { window } from '@kit.ArkUI';
6045
6046export default class EntryAbility extends UIAbility {
6047
6048  onWindowStageCreate(windowStage: window.WindowStage) {
6049    console.info('onWindowStageCreate');
6050    try {
6051      const callback = () => {
6052        // ...
6053        return new Promise<boolean>((resolve, reject) => {
6054          // 是否关闭该窗口
6055          let result: boolean = true;
6056          resolve(result);
6057        });
6058      }
6059      let windowClass = windowStage.getMainWindowSync();
6060      windowClass.on('windowWillClose', callback);
6061      windowClass.off('windowWillClose', callback);
6062      // 如果通过on开启多个callback进行监听,同时关闭所有监听:
6063      windowClass.off('windowWillClose');
6064    } catch (exception) {
6065      console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
6066    }
6067  }
6068}
6069```
6070
6071### on('windowHighlightChange')<sup>15+</sup>
6072
6073on(type: 'windowHighlightChange', callback: Callback&lt;boolean&gt;): void
6074
6075开启窗口激活态变化事件的监听。
6076
6077**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
6078
6079**系统能力:** SystemCapability.Window.SessionManager
6080
6081**参数:**
6082
6083| 参数名   | 类型                           | 必填 | 说明                                                     |
6084| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
6085| type     | string                         | 是   | 监听事件,固定为'windowHighlightChange',即窗口激活态变化事件。 |
6086| callback | Callback&lt;boolean&gt; | 是   | 回调函数。当本窗口的激活态发生变化时的回调。回调函数返回boolean类型参数。当返回参数为true表示激活态;false表示非激活态。   |
6087
6088**错误码:**
6089
6090以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6091
6092| 错误码ID | 错误信息 |
6093| ------- | -------------------------------------------- |
6094| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
6095| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
6096| 1300002 | This window state is abnormal. |
6097| 1300003 | This window manager service works abnormally. |
6098
6099**示例:**
6100
6101```ts
6102try {
6103  windowClass.on('windowHighlightChange', (data: boolean) => {
6104    console.info(`Window highlight Change: ${data}`);
6105  });
6106} catch (exception) {
6107  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
6108}
6109```
6110
6111### off('windowHighlightChange')<sup>15+</sup>
6112
6113off(type: 'windowHighlightChange', callback?: Callback&lt;boolean&gt;): void
6114
6115关闭窗口激活态变化事件的监听。
6116
6117**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
6118
6119**系统能力:** SystemCapability.Window.SessionManager
6120
6121**参数:**
6122
6123| 参数名   | 类型                           | 必填 | 说明                                                         |
6124| -------- | ------------------------------ | ---- | ------------------------------------------------------------ |
6125| type     | string                         | 是   | 监听事件,固定为'windowHighlightChange',即窗口激活态变化事件。     |
6126| callback | Callback&lt;boolean&gt; | 否   | 回调函数。当本窗口的激活态发生变化时的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有窗口激活态变化的监听。 |
6127
6128**错误码:**
6129
6130以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6131
6132| 错误码ID | 错误信息 |
6133| ------- | -------------------------------------------- |
6134| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
6135| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
6136| 1300002 | This window state is abnormal. |
6137| 1300003 | This window manager service works abnormally. |
6138
6139**示例:**
6140
6141```ts
6142const callback = (data: boolean) => {
6143  // ...
6144}
6145try {
6146  // 通过on接口开启监听
6147  windowClass.on('windowHighlightChange', callback);
6148  // 关闭指定callback的监听
6149  windowClass.off('windowHighlightChange', callback);
6150  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
6151  windowClass.off('windowHighlightChange');
6152} catch (exception) {
6153  console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
6154}
6155```
6156
6157### on('rotationChange')<sup>19+</sup>
6158
6159on(type: 'rotationChange', callback: RotationChangeCallback&lt;RotationChangeInfo, RotationChangeResult | void&gt;): void
6160
6161开启窗口旋转变化的监听。[RotationChangeInfo](#rotationchangeinfo19)中窗口旋转事件类型为窗口即将旋转时,必须返回[RotationChangeResult](#rotationchangeresult19)。窗口旋转事件类型为窗口旋转结束时返回[RotationChangeResult](#rotationchangeresult19)不生效。
6162
6163同一个窗口多次注册同类型回调函数,只生效最新注册的同类型回调函数返回值。系统提供了超时保护机制,若20ms内窗口未返回[RotationChangeResult](#rotationchangeresult19),系统不处理该返回值。
6164
6165<!--RP10-->此接口在2in1设备上调用不生效。<!--RP10End-->
6166
6167**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
6168
6169**系统能力:** SystemCapability.Window.SessionManager
6170
6171**参数:**
6172
6173| 参数名   | 类型                           | 必填 | 说明                                                     |
6174| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
6175| type     | string                         | 是   | 监听事件,固定为'rotationChange',即窗口旋转变化事件。 |
6176| callback | RotationChangeCallback&lt;[RotationChangeInfo](#rotationchangeinfo19), [RotationChangeResult](#rotationchangeresult19) \| void&gt; | 是 | 回调函数。返回窗口旋转信息[RotationChangeInfo](#rotationchangeinfo19),应用返回当前窗口变化结果[RotationChangeResult](#rotationchangeresult19)。   |
6177
6178**错误码:**
6179
6180以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6181
6182| 错误码ID | 错误信息 |
6183| ------- | -------------------------------------------- |
6184| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
6185| 1300002 | This window state is abnormal. |
6186| 1300003 | This window manager service works abnormally. |
6187
6188**示例:**
6189
6190```ts
6191function calculateRect(info: window.RotationChangeInfo): window.Rect {
6192    // calculate result with info
6193    let rect : window.Rect = {
6194      left: 0,
6195      top: 0,
6196      width: 500,
6197      height: 600,
6198    }
6199    return rect;
6200}
6201
6202const callback = (info: window.RotationChangeInfo): window.RotationChangeResult | void => {
6203  let result: window.RotationChangeResult = {
6204    rectType: window.RectType.RELATIVE_TO_SCREEN,
6205    windowRect: {
6206      left: 0,
6207      top: 0,
6208      width: 0,
6209      height: 0,
6210    }
6211  };
6212  if (info.type === window.RotationChangeType.WINDOW_WILL_ROTATE) {
6213      result.rectType = window.RectType.RELATIVE_TO_SCREEN;
6214      result.windowRect = calculateRect(info);
6215      return result;
6216  } else {
6217      // do something after rotate
6218      return;
6219  }
6220}
6221
6222try {
6223  windowClass.on('rotationChange', callback);
6224} catch (exception) {
6225  console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`);
6226}
6227```
6228
6229### off('rotationChange')<sup>19+</sup>
6230
6231off(type: 'rotationChange', callback?: RotationChangeCallback&lt;RotationChangeInfo, RotationChangeResult | void&gt;): void
6232
6233关闭窗口旋转变化的监听。
6234
6235<!--RP10-->此接口在2in1设备上调用不生效。<!--RP10End-->
6236
6237**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
6238
6239**系统能力:** SystemCapability.Window.SessionManager
6240
6241**参数:**
6242
6243| 参数名   | 类型                           | 必填 | 说明                                                         |
6244| -------- | ------------------------------ | ---- | ------------------------------------------------------------ |
6245| type     | string                         | 是   | 监听事件,固定为'rotationChange',即窗口旋转变化事件。     |
6246| callback | RotationChangeCallback&lt;info: [RotationChangeInfo](#rotationchangeinfo19), [RotationChangeResult](#rotationchangeresult19) \| void&gt; | 否   | 回调函数。如果传入参数,则关闭该监听。如果未传入参数,则关闭该窗口的所有监听。 |
6247
6248**错误码:**
6249
6250以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6251
6252| 错误码ID | 错误信息 |
6253| ------- | -------------------------------------------- |
6254| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
6255| 1300002 | This window state is abnormal. |
6256| 1300003 | This window manager service works abnormally. |
6257
6258**示例:**
6259
6260```ts
6261const callback = (info: window.RotationChangeInfo): window.RotationChangeResult | void => {
6262  // ...
6263  return;
6264}
6265try {
6266  windowClass.off('rotationChange', callback);
6267  // 如果通过on开启多个callback进行监听,同时关闭所有监听。
6268  windowClass.off('rotationChange');
6269} catch (exception) {
6270  console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`);
6271}
6272```
6273
6274### isWindowSupportWideGamut<sup>9+</sup>
6275
6276isWindowSupportWideGamut(callback: AsyncCallback&lt;boolean&gt;): void
6277
6278判断当前窗口是否支持广色域模式,使用callback异步回调。
6279
6280**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6281
6282**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6283
6284**参数:**
6285
6286| 参数名 | 类型 | 必填 | 说明 |
6287| -------- | ---------------------------- | -- | -------------------------------------------------------------------------------- |
6288| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 |
6289
6290**错误码:**
6291
6292以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
6293
6294| 错误码ID | 错误信息 |
6295| ------- | ------------------------------ |
6296| 1300002 | This window state is abnormal. |
6297
6298**示例:**
6299
6300```ts
6301import { BusinessError } from '@kit.BasicServicesKit';
6302
6303windowClass.isWindowSupportWideGamut((err: BusinessError, data) => {
6304  const errCode: number = err.code;
6305  if (errCode) {
6306    console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`);
6307    return;
6308  }
6309  console.info(`Succeeded in checking whether the window support WideGamut Data: ${data}`);
6310});
6311```
6312
6313### isWindowSupportWideGamut<sup>9+</sup>
6314
6315isWindowSupportWideGamut(): Promise&lt;boolean&gt;
6316
6317判断当前窗口是否支持广色域模式,使用Promise异步回调。
6318
6319**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6320
6321**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6322
6323**返回值:**
6324
6325| 类型 | 说明 |
6326| ---------------------- | ------------------------------------------------------------------------------------ |
6327| Promise&lt;boolean&gt; | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 |
6328
6329**错误码:**
6330
6331以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
6332
6333| 错误码ID | 错误信息 |
6334| ------- | ------------------------------ |
6335| 1300002 | This window state is abnormal. |
6336
6337**示例:**
6338
6339```ts
6340import { BusinessError } from '@kit.BasicServicesKit';
6341
6342let promise = windowClass.isWindowSupportWideGamut();
6343promise.then((data) => {
6344  console.info(`Succeeded in checking whether the window support WideGamut. Data: ${data}`);
6345}).catch((err: BusinessError) => {
6346  console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`);
6347});
6348```
6349
6350### setWindowColorSpace<sup>9+</sup>
6351
6352setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback&lt;void&gt;): void
6353
6354设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。
6355
6356**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6357
6358**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6359
6360**参数:**
6361
6362| 参数名 | 类型 | 必填 | 说明 |
6363| ---------- | ------------------------- | -- | ----------- |
6364| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 |
6365| callback   | AsyncCallback&lt;void&gt; | 是 | 回调函数。   |
6366
6367**错误码:**
6368
6369以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6370
6371| 错误码ID | 错误信息 |
6372| ------- | ------------------------------ |
6373| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
6374| 1300002 | This window state is abnormal. |
6375
6376**示例:**
6377
6378```ts
6379import { BusinessError } from '@kit.BasicServicesKit';
6380
6381try {
6382  windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => {
6383    const errCode: number = err.code;
6384    if (errCode) {
6385      console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`);
6386      return;
6387    }
6388    console.info('Succeeded in setting window colorspace.');
6389  });
6390} catch (exception) {
6391  console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`);
6392}
6393```
6394
6395### setWindowColorSpace<sup>9+</sup>
6396
6397setWindowColorSpace(colorSpace:ColorSpace): Promise&lt;void&gt;
6398
6399设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。
6400
6401**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6402
6403**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6404
6405**参数:**
6406
6407| 参数名 | 类型 | 必填 | 说明 |
6408| ---------- | ------------------------- | -- | ------------- |
6409| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 |
6410
6411**返回值:**
6412
6413| 类型 | 说明 |
6414| ------------------- | ------------------------ |
6415| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6416
6417**错误码:**
6418
6419以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6420
6421| 错误码ID | 错误信息 |
6422| ------- | ------------------------------ |
6423| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
6424| 1300002 | This window state is abnormal. |
6425
6426**示例:**
6427
6428```ts
6429import { BusinessError } from '@kit.BasicServicesKit';
6430
6431try {
6432  let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT);
6433  promise.then(() => {
6434    console.info('Succeeded in setting window colorspace.');
6435  }).catch((err: BusinessError) => {
6436    console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`);
6437  });
6438} catch (exception) {
6439  console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`);
6440}
6441```
6442
6443### getWindowColorSpace<sup>9+</sup>
6444
6445getWindowColorSpace(): ColorSpace
6446
6447获取当前窗口色域模式。
6448
6449**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6450
6451**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6452
6453**返回值:**
6454
6455| 类型 | 说明 |
6456| ------------------------- | ------------- |
6457| [ColorSpace](#colorspace8) | 当前色域模式。 |
6458
6459**错误码:**
6460
6461以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
6462
6463| 错误码ID | 错误信息 |
6464| ------- | ------------------------------ |
6465| 1300002 | This window state is abnormal. |
6466
6467**示例:**
6468
6469```ts
6470import { BusinessError } from '@kit.BasicServicesKit';
6471
6472try {
6473  let colorSpace = windowClass.getWindowColorSpace();
6474  console.info(`Succeeded in getting the window color space. ColorSpace: ${colorSpace}`);
6475} catch (exception) {
6476  console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`);
6477}
6478```
6479
6480### setWindowBackgroundColor<sup>9+</sup>
6481
6482setWindowBackgroundColor(color: string | ColorMetrics): void
6483
6484设置窗口的背景色。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
6485
6486**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6487
6488**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
6489
6490**参数:**
6491
6492| 参数名 | 类型 | 必填 | 说明 |
6493| ----- | ------ | -- | ----------------------------------------------------------------------- |
6494| color | string \| [ColorMetrics](js-apis-arkui-graphics.md#colormetrics12)<sup>18+</sup> | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。<br>从API version 18开始,此参数支持ColorMetrics类型。|
6495
6496**错误码:**
6497
6498以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6499
6500| 错误码ID | 错误信息 |
6501| ------- | ------------------------------ |
6502| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6503| 1300002 | This window state is abnormal. |
6504
6505**示例:**
6506
6507```ts
6508import { BusinessError } from '@kit.BasicServicesKit';
6509import { ColorMetrics } from '@kit.ArkUI';
6510
6511let storage: LocalStorage = new LocalStorage();
6512storage.setOrCreate('storageSimpleProp', 121);
6513windowClass.loadContent("pages/page2", storage, (err: BusinessError) => {
6514  let errCode: number = err.code;
6515  if (errCode) {
6516    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
6517    return;
6518  }
6519  console.info('Succeeded in loading the content.');
6520  let color1: string = '#00ff33';
6521  let color2: ColorMetrics = ColorMetrics.numeric(0xff112233);
6522  try {
6523    windowClass?.setWindowBackgroundColor(color1);
6524    windowClass?.setWindowBackgroundColor(color2);
6525  } catch (exception) {
6526    console.error(`Failed to set the background color. Cause code: ${exception.code}, message: ${exception.message}`);
6527  };
6528});
6529```
6530
6531### setWindowBrightness<sup>9+</sup>
6532
6533setWindowBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void
6534
6535允许应用主窗口设置屏幕亮度值,使用callback异步回调。
6536
6537非2in1设备,窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度;
65382in1设备,窗口设置屏幕亮度和控制中心调整屏幕亮度的优先级相同,窗口设置屏幕亮度生效后,控制中心也可以调整系统屏幕亮度。
6539
6540**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6541
6542**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
6543
6544**参数:**
6545
6546| 参数名 | 类型 | 必填 | 说明                                        |
6547| ---------- | ------------------------- | -- |-------------------------------------------|
6548| brightness | number                    | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 |
6549| callback   | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                     |
6550
6551**错误码:**
6552
6553以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6554
6555| 错误码ID | 错误信息 |
6556| ------- | -------------------------------------------- |
6557| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6558| 1300002 | This window state is abnormal.               |
6559| 1300003 | This window manager service works abnormally. |
6560
6561**示例:**
6562
6563```ts
6564// EntryAbility.ets
6565import { UIAbility } from '@kit.AbilityKit';
6566import { BusinessError } from '@kit.BasicServicesKit';
6567
6568export default class EntryAbility extends UIAbility {
6569  // ...
6570  onWindowStageCreate(windowStage: window.WindowStage): void {
6571    console.info('onWindowStageCreate');
6572    let windowClass: window.Window | undefined = undefined;
6573    windowStage.getMainWindow((err: BusinessError, data) => {
6574      const errCode: number = err.code;
6575      if (errCode) {
6576        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6577        return;
6578      }
6579      windowClass = data;
6580      let brightness: number = 1.0;
6581      try {
6582        windowClass.setWindowBrightness(brightness, (err: BusinessError) => {
6583          const errCode: number = err.code;
6584          if (errCode) {
6585            console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`);
6586            return;
6587          }
6588          console.info('Succeeded in setting the brightness.');
6589        });
6590      } catch (exception) {
6591        console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`);
6592      }
6593    });
6594  }
6595}
6596```
6597
6598### setWindowBrightness<sup>9+</sup>
6599
6600setWindowBrightness(brightness: number): Promise&lt;void&gt;
6601
6602允许应用主窗口设置屏幕亮度值,使用Promise异步回调。
6603
6604非2in1设备,窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度;
66052in1设备,窗口设置屏幕亮度和控制中心调整屏幕亮度的优先级相同,窗口设置屏幕亮度生效后,控制中心也可以调整系统屏幕亮度。
6606
6607**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6608
6609**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
6610
6611**参数:**
6612
6613| 参数名 | 类型 | 必填 | 说明                                     |
6614| ---------- | ------ | -- |----------------------------------------|
6615| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 |
6616
6617**返回值:**
6618
6619| 类型 | 说明 |
6620| ------------------- | ------------------------ |
6621| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6622
6623**错误码:**
6624
6625以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6626
6627| 错误码ID | 错误信息 |
6628| ------- | -------------------------------------------- |
6629| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6630| 1300002 | This window state is abnormal.               |
6631| 1300003 | This window manager service works abnormally. |
6632
6633**示例:**
6634
6635```ts
6636// EntryAbility.ets
6637import { UIAbility } from '@kit.AbilityKit';
6638import { BusinessError } from '@kit.BasicServicesKit';
6639
6640export default class EntryAbility extends UIAbility {
6641  // ...
6642  onWindowStageCreate(windowStage: window.WindowStage): void {
6643    console.info('onWindowStageCreate');
6644    let windowClass: window.Window | undefined = undefined;
6645    windowStage.getMainWindow((err: BusinessError, data) => {
6646      const errCode: number = err.code;
6647      if (errCode) {
6648        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
6649        return;
6650      }
6651      windowClass = data;
6652      let brightness: number = 1.0;
6653      try {
6654        let promise = windowClass.setWindowBrightness(brightness);
6655        promise.then(() => {
6656          console.info('Succeeded in setting the brightness.');
6657        }).catch((err: BusinessError) => {
6658          console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`);
6659        });
6660      } catch (exception) {
6661        console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`);
6662      }
6663    });
6664  }
6665}
6666```
6667
6668### setWindowFocusable<sup>9+</sup>
6669
6670setWindowFocusable(isFocusable: boolean, callback: AsyncCallback&lt;void&gt;): void
6671
6672设置窗口是否具有获得焦点的能力,使用callback异步回调。
6673
6674**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6675
6676**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6677
6678**参数:**
6679
6680| 参数名 | 类型 | 必填 | 说明 |
6681| ----------- | ------------------------- | -- | ------------------------------------------------------- |
6682| isFocusable | boolean                   | 是 | 窗口是否可获焦。true表示支持;false表示不支持。 |
6683| callback    | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                               |
6684
6685**错误码:**
6686
6687以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6688
6689| 错误码ID | 错误信息 |
6690| ------- | -------------------------------------------- |
6691| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6692| 1300002 | This window state is abnormal.               |
6693| 1300003 | This window manager service works abnormally. |
6694
6695**示例:**
6696
6697```ts
6698import { BusinessError } from '@kit.BasicServicesKit';
6699
6700let isFocusable: boolean = true;
6701try {
6702  windowClass.setWindowFocusable(isFocusable, (err: BusinessError) => {
6703    const errCode: number = err.code;
6704    if (errCode) {
6705      console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`);
6706      return;
6707    }
6708    console.info('Succeeded in setting the window to be focusable.');
6709  });
6710} catch (exception) {
6711  console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`);
6712}
6713```
6714
6715### setWindowFocusable<sup>9+</sup>
6716
6717setWindowFocusable(isFocusable: boolean): Promise&lt;void&gt;
6718
6719设置窗口是否具有获得焦点的能力,使用Promise异步回调。
6720
6721**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6722
6723**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6724
6725**参数:**
6726
6727| 参数名 | 类型 | 必填 | 说明 |
6728| ----------- | ------- | -- | -------------------------------------------------------- |
6729| isFocusable | boolean | 是 | 窗口是否可获焦。true表示支持;false表示不支持。  |
6730
6731**返回值:**
6732
6733| 类型 | 说明 |
6734| ------------------- | ------------------------ |
6735| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6736
6737**错误码:**
6738
6739以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6740
6741| 错误码ID | 错误信息 |
6742| ------- | -------------------------------------------- |
6743| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6744| 1300002 | This window state is abnormal.               |
6745| 1300003 | This window manager service works abnormally. |
6746
6747**示例:**
6748
6749```ts
6750import { BusinessError } from '@kit.BasicServicesKit';
6751
6752let isFocusable: boolean = true;
6753try {
6754  let promise = windowClass.setWindowFocusable(isFocusable);
6755  promise.then(() => {
6756    console.info('Succeeded in setting the window to be focusable.');
6757  }).catch((err: BusinessError) => {
6758    console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`);
6759  });
6760} catch (exception) {
6761  console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`);
6762}
6763```
6764
6765### setStartWindowBackgroundColor<sup>20+</sup>
6766
6767setStartWindowBackgroundColor(moduleName: string, abilityName: string, color: ColorMetrics): Promise&lt;void&gt;
6768
6769设置同应用内指定mouduleName、abilityName对应UIAbility的启动页背景色,使用Promise异步回调。
6770
6771该接口对同应用的所有进程生效,例如多实例或应用分身场景。
6772
6773**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
6774
6775**系统能力:** SystemCapability.Window.SessionManager
6776
6777**参数:**
6778
6779| 参数名   | 类型                          | 必填 | 说明                                                     |
6780| -------- | ----------------------------- | ---- | -------------------------------------------------------- |
6781| moduleName     | string                        | 是   | 需要设置的UIAbility所属module的名字,moduleName的长度范围为0-200,仅支持设置当前同一应用包名内的moduleName。 |
6782| abilityName     | string                        | 是   | 需要设置的UIAbility名字,abilityName的长度范围为0-200,仅支持设置当前同一应用包名内的abilityName。 |
6783| color | [ColorMetrics](js-apis-arkui-graphics.md#colormetrics12) | 是   | 设置的启动页背景色。                       |
6784
6785**返回值:**
6786
6787| 类型 | 说明 |
6788| ------------------- | ------------------------ |
6789| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6790
6791**错误码:**
6792
6793以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6794
6795| 错误码ID | 错误信息 |
6796| ------- | -------------------------------------------- |
6797| 801     | Capability not supported.function setStartWindowBackgroundColor can not to work correctly due to limited device capabilities. |
6798| 1300003 | This window manager service works abnormally. |
6799| 1300016 | Parameter error. Possible cause: 1. Invalid parameter range. |
6800
6801**示例:**
6802
6803```ts
6804// EntryAbility.ets
6805import { UIAbility } from '@kit.AbilityKit';
6806import { BusinessError } from '@kit.BasicServicesKit';
6807import { ColorMetrics, window } from '@kit.ArkUI';
6808
6809try {
6810  let promise =
6811    window.setStartWindowBackgroundColor("entry", "EntryAbility", ColorMetrics.numeric(0xff000000));
6812  promise.then(() => {
6813    console.log('Succeeded in setting the starting window color.');
6814  }).catch((err: BusinessError) => {
6815    console.error(`Set the starting window color failed. Cause code: ${err.code}, message:  ${err.message}`);
6816  });
6817} catch (exception) {
6818  console.error(`Failed to set the starting window color. Cause code: ${exception.code}, message:  ${exception.message}`);
6819}
6820```
6821
6822### setWindowKeepScreenOn<sup>9+</sup>
6823
6824setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback&lt;void&gt;): void
6825
6826设置屏幕是否为常亮状态,使用callback异步回调。
6827
6828规范使用该接口:仅在必要场景(导航、视频播放、绘画、游戏等场景)下,设置该属性为true;退出上述场景后,应当重置该属性为false;其他场景(无屏幕互动、音频播放等)下,不使用该接口;系统检测到非规范使用该接口时,可能会恢复自动灭屏功能。
6829
6830**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6831
6832**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
6833
6834**参数:**
6835
6836| 参数名 | 类型 | 必填 | 说明 |
6837| -------------- | ------------------------- | -- | ---------------------------------------------------- |
6838| isKeepScreenOn | boolean                   | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。  |
6839| callback       | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                            |
6840
6841**错误码:**
6842
6843以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6844
6845| 错误码ID | 错误信息 |
6846| ------- | -------------------------------------------- |
6847| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6848| 1300002 | This window state is abnormal.               |
6849| 1300003 | This window manager service works abnormally. |
6850
6851**示例:**
6852
6853```ts
6854import { BusinessError } from '@kit.BasicServicesKit';
6855
6856let isKeepScreenOn: boolean = true;
6857try {
6858  windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err: BusinessError) => {
6859    const errCode: number = err.code;
6860    if (errCode) {
6861      console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`);
6862      return;
6863    }
6864    console.info('Succeeded in setting the screen to be always on.');
6865  });
6866} catch (exception) {
6867  console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`);
6868}
6869```
6870
6871### setWindowKeepScreenOn<sup>9+</sup>
6872
6873setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise&lt;void&gt;
6874
6875设置屏幕是否为常亮状态,使用Promise异步回调。
6876
6877规范使用该接口:仅在必要场景(导航、视频播放、绘画、游戏等场景)下,设置该属性为true;退出上述场景后,应当重置该属性为false;其他场景(无屏幕互动、音频播放等)下,不使用该接口;系统检测到非规范使用该接口时,可能会恢复自动灭屏功能。
6878
6879**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6880
6881**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
6882
6883**参数:**
6884
6885| 参数名 | 类型 | 必填 | 说明 |
6886| -------------- | ------- | -- | --------------------------------------------------- |
6887| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 |
6888
6889**返回值:**
6890
6891| 类型 | 说明 |
6892| ------------------- | ------------------------ |
6893| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6894
6895**错误码:**
6896
6897以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6898
6899| 错误码ID | 错误信息 |
6900| ------- | -------------------------------------------- |
6901| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6902| 1300002 | This window state is abnormal.               |
6903| 1300003 | This window manager service works abnormally. |
6904
6905**示例:**
6906
6907```ts
6908import { BusinessError } from '@kit.BasicServicesKit';
6909
6910let isKeepScreenOn: boolean = true;
6911try {
6912  let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn);
6913  promise.then(() => {
6914    console.info('Succeeded in setting the screen to be always on.');
6915  }).catch((err: BusinessError) => {
6916    console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`);
6917  });
6918} catch (exception) {
6919  console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`);
6920}
6921```
6922
6923### setWindowPrivacyMode<sup>9+</sup>
6924
6925setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback&lt;void&gt;): void
6926
6927设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。
6928
6929**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6930
6931**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6932
6933**需要权限:** ohos.permission.PRIVACY_WINDOW
6934
6935**参数:**
6936
6937| 参数名 | 类型 | 必填 | 说明 |
6938| ------------- | ------------------------- | -- | ------------------------------------------------------ |
6939| isPrivacyMode | boolean                   | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。  |
6940| callback      | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                              |
6941
6942**错误码:**
6943
6944以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6945
6946| 错误码ID | 错误信息 |
6947| ------- | ------------------------------ |
6948| 201     | Permission verification failed. The application does not have the permission required to call the API. |
6949| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6950| 1300002 | This window state is abnormal. |
6951
6952**示例:**
6953
6954```ts
6955import { BusinessError } from '@kit.BasicServicesKit';
6956
6957let isPrivacyMode: boolean = true;
6958try {
6959  windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => {
6960    const errCode: number = err.code;
6961    if (errCode) {
6962      console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`);
6963      return;
6964    }
6965    console.info('Succeeded in setting the window to privacy mode.');
6966  });
6967} catch (exception) {
6968  console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`);
6969}
6970```
6971
6972### setWindowPrivacyMode<sup>9+</sup>
6973
6974setWindowPrivacyMode(isPrivacyMode: boolean): Promise&lt;void&gt;
6975
6976设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。
6977
6978**系统能力:** SystemCapability.WindowManager.WindowManager.Core
6979
6980**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6981
6982**需要权限:** ohos.permission.PRIVACY_WINDOW
6983
6984**参数:**
6985
6986| 参数名 | 类型 | 必填 | 说明 |
6987| ------------- | ------- | -- | ----------------------------------------------------- |
6988| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 |
6989
6990**返回值:**
6991
6992| 类型 | 说明 |
6993| ------------------- | ------------------------ |
6994| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6995
6996**错误码:**
6997
6998以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
6999
7000| 错误码ID | 错误信息 |
7001| ------- | ------------------------------ |
7002| 201     | Permission verification failed. The application does not have the permission required to call the API. |
7003| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7004| 1300002 | This window state is abnormal. |
7005
7006**示例:**
7007
7008```ts
7009import { BusinessError } from '@kit.BasicServicesKit';
7010
7011let isPrivacyMode: boolean = true;
7012try {
7013  let promise = windowClass.setWindowPrivacyMode(isPrivacyMode);
7014  promise.then(() => {
7015    console.info('Succeeded in setting the window to privacy mode.');
7016  }).catch((err: BusinessError) => {
7017    console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`);
7018  });
7019} catch (exception) {
7020  console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`);
7021}
7022```
7023
7024### setWindowTouchable<sup>9+</sup>
7025
7026setWindowTouchable(isTouchable: boolean, callback: AsyncCallback&lt;void&gt;): void
7027
7028设置窗口是否为可触状态,使用callback异步回调。
7029
7030**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7031
7032**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7033
7034**参数:**
7035
7036| 参数名 | 类型 | 必填 | 说明 |
7037| ----------- | ------------------------- | -- | ----------------------------------------------- |
7038| isTouchable | boolean                   | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 |
7039| callback    | AsyncCallback&lt;void&gt; | 是 | 回调函数。                                        |
7040
7041**错误码:**
7042
7043以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7044
7045| 错误码ID | 错误信息 |
7046| ------- | -------------------------------------------- |
7047| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7048| 1300002 | This window state is abnormal.               |
7049| 1300003 | This window manager service works abnormally. |
7050
7051**示例:**
7052
7053```ts
7054import { BusinessError } from '@kit.BasicServicesKit';
7055
7056let isTouchable = true;
7057try {
7058  windowClass.setWindowTouchable(isTouchable, (err: BusinessError) => {
7059    const errCode: number = err.code;
7060    if (errCode) {
7061      console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`);
7062      return;
7063    }
7064    console.info('Succeeded in setting the window to be touchable.');
7065  });
7066} catch (exception) {
7067  console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`);
7068}
7069```
7070
7071### setWindowTouchable<sup>9+</sup>
7072
7073setWindowTouchable(isTouchable: boolean): Promise&lt;void&gt;
7074
7075设置窗口是否为可触状态,使用Promise异步回调。
7076
7077**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7078
7079**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7080
7081**参数:**
7082
7083| 参数名 | 类型 | 必填 | 说明 |
7084| ----------- | ------- | -- | ----------------------------------------------- |
7085| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 |
7086
7087**返回值:**
7088
7089| 类型 | 说明 |
7090| ------------------- | ------------------------- |
7091| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7092
7093**错误码:**
7094
7095以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7096
7097| 错误码ID | 错误信息 |
7098| ------- | -------------------------------------------- |
7099| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7100| 1300002 | This window state is abnormal.               |
7101| 1300003 | This window manager service works abnormally. |
7102
7103**示例:**
7104
7105```ts
7106import { BusinessError } from '@kit.BasicServicesKit';
7107
7108let isTouchable: boolean = true;
7109try {
7110  let promise = windowClass.setWindowTouchable(isTouchable);
7111  promise.then(() => {
7112    console.info('Succeeded in setting the window to be touchable.');
7113  }).catch((err: BusinessError) => {
7114    console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`);
7115  });
7116} catch (exception) {
7117  console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`);
7118}
7119```
7120
7121### snapshot<sup>9+</sup>
7122
7123snapshot(callback: AsyncCallback&lt;image.PixelMap&gt;): void
7124
7125获取窗口截图,使用callback异步回调。若当前窗口设置为隐私模式(可通过[setWindowPrivacyMode](#setwindowprivacymode9)接口设置),截图结果为白屏。
7126
7127**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7128
7129**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7130
7131**参数:**
7132
7133| 参数名      | 类型                      | 必填 | 说明                 |
7134| ----------- | ------------------------- | ---- | -------------------- |
7135| callback    | AsyncCallback&lt;[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)&gt; | 是   | 回调函数。  |
7136
7137**错误码:**
7138
7139以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
7140
7141| 错误码ID | 错误信息 |
7142| ------- | ------------------------------ |
7143| 1300002 | This window state is abnormal. |
7144
7145**示例:**
7146
7147```ts
7148import { BusinessError } from '@kit.BasicServicesKit';
7149import { image } from '@kit.ImageKit';
7150
7151windowClass.snapshot((err: BusinessError, pixelMap: image.PixelMap) => {
7152  const errCode: number = err.code;
7153  if (errCode) {
7154    console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`);
7155    return;
7156  }
7157  console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
7158  pixelMap.release(); // PixelMap使用完后及时释放内存
7159});
7160```
7161
7162### snapshot<sup>9+</sup>
7163
7164snapshot(): Promise&lt;image.PixelMap&gt;
7165
7166获取当前窗口截图。若当前窗口设置为隐私模式(可通过[setWindowPrivacyMode](#setwindowprivacymode9)接口设置),截图结果为白屏。
7167
7168**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7169
7170**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7171
7172**返回值:**
7173
7174| 类型                | 说明                      |
7175| ------------------- | ------------------------- |
7176| Promise&lt;[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)&gt; | Promise对象。返回当前窗口截图。 |
7177
7178**错误码:**
7179
7180以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
7181
7182| 错误码ID | 错误信息 |
7183| ------- | ------------------------------ |
7184| 1300002 | This window state is abnormal. |
7185
7186**示例:**
7187
7188```ts
7189import { BusinessError } from '@kit.BasicServicesKit';
7190import { image } from '@kit.ImageKit';
7191
7192let promise = windowClass.snapshot();
7193promise.then((pixelMap: image.PixelMap) => {
7194  console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
7195  pixelMap.release(); // PixelMap使用完后及时释放内存
7196}).catch((err: BusinessError) => {
7197  console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`);
7198});
7199```
7200
7201### snapshotIgnorePrivacy<sup>18+</sup>
7202
7203snapshotIgnorePrivacy(): Promise&lt;image.PixelMap&gt;
7204
7205获取当前窗口截图。即使当前窗口设置为隐私模式(可通过[setWindowPrivacyMode](#setwindowprivacymode9)接口设置),仍可调用本接口返回当前窗口截图。
7206
7207**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
7208
7209**系统能力:** SystemCapability.Window.SessionManager
7210
7211**返回值:**
7212
7213| 类型                | 说明                      |
7214| ------------------- | ------------------------- |
7215| Promise&lt;[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)&gt; | Promise对象。返回当前窗口截图。 |
7216
7217**错误码:**
7218
7219以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7220
7221| 错误码ID | 错误信息 |
7222| ------- | ------------------------------ |
7223| 801     | Capability not supported. Function snapshotIgnorePrivacy can not work correctly due to limited device capabilities. |
7224| 1300002 | This window state is abnormal. |
7225
7226**示例:**
7227
7228```ts
7229import { BusinessError } from '@kit.BasicServicesKit';
7230import { image } from '@kit.ImageKit';
7231
7232let promise = windowClass.snapshotIgnorePrivacy();
7233promise.then((pixelMap: image.PixelMap) => {
7234  console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
7235  pixelMap.release(); // PixelMap使用完后及时释放内存
7236}).catch((err: BusinessError) => {
7237  console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`);
7238});
7239```
7240
7241### setAspectRatio<sup>10+</sup>
7242
7243setAspectRatio(ratio: number): Promise&lt;void&gt;
7244
7245设置窗口内容布局的比例,使用Promise异步回调。
7246
7247通过其他接口如[resize](#resize9)、[resizeAsync](#resizeasync12)设置窗口大小时,不受ratio约束。
7248
7249仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。
7250
7251**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7252
7253**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7254
7255**参数:**
7256
7257| 参数名             | 类型    | 必填 | 说明                                        |
7258| ------------------ | ------- | ---- |-------------------------------------------|
7259| ratio | number | 是   | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,受窗口最大最小尺寸限制,比例值下限为最小宽度/最大高度,上限为最大宽度/最小高度。窗口最大最小尺寸由[WindowLimits](#windowlimits11)和系统限制的交集决定,系统限制优先级高于[WindowLimits](#windowlimits11)。ratio的有效范围会随[WindowLimits](#windowlimits11)变化而变化。如果先设置了[WindowLimits](#windowlimits11),后设置的ratio与其冲突,会返回错误码;如果先设置了ratio,后设置的[WindowLimits](#windowlimits11)与其冲突,窗口的宽高比可能会不跟随设置的宽高比(ratio)。 |
7260
7261**返回值:**
7262
7263| 类型                | 说明                      |
7264| ------------------- | ------------------------- |
7265| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7266
7267**错误码:**
7268
7269以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7270
7271| 错误码ID | 错误信息 |
7272| ------- | -------------------------------------------- |
7273| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
7274| 1300002 | This window state is abnormal.               |
7275| 1300004 | Unauthorized operation.                      |
7276
7277**示例:**
7278<!--code_no_check-->
7279```ts
7280// EntryAbility.ets
7281import { UIAbility } from '@kit.AbilityKit';
7282import { BusinessError } from '@kit.BasicServicesKit';
7283
7284export default class EntryAbility extends UIAbility {
7285
7286  // ...
7287  onWindowStageCreate(windowStage: window.WindowStage) {
7288    console.info('onWindowStageCreate');
7289    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
7290    if (!windowClass) {
7291      console.info('windowClass is null');
7292    }
7293    try {
7294      let ratio = 1.0;
7295      let promise = windowClass.setAspectRatio(ratio);
7296      promise.then(() => {
7297        console.info('Succeeded in setting aspect ratio of window.');
7298      }).catch((err: BusinessError) => {
7299        console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`);
7300      });
7301    } catch (exception) {
7302      console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`);
7303    }
7304  }
7305}
7306```
7307
7308### setAspectRatio<sup>10+</sup>
7309
7310setAspectRatio(ratio: number, callback: AsyncCallback&lt;void&gt;): void
7311
7312设置窗口内容布局的比例,使用callback异步回调。
7313
7314通过其他接口如[resize](#resize9)、[resizeAsync](#resizeasync12)设置窗口大小时,不受ratio约束。
7315
7316仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。
7317
7318**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7319
7320**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7321
7322**参数:**
7323
7324| 参数名             | 类型    | 必填 | 说明                                         |
7325| ------------------ | ------- | ---- |--------------------------------------------|
7326| ratio | number | 是   | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,受窗口最大最小尺寸限制,比例值下限为最小宽度/最大高度,上限为最大宽度/最小高度。窗口最大最小尺寸由[WindowLimits](#windowlimits11)和系统限制的交集决定,系统限制优先级高于[WindowLimits](#windowlimits11)。ratio的有效范围会随[WindowLimits](#windowlimits11)变化而变化。如果先设置了[WindowLimits](#windowlimits11),后设置的ratio与其冲突,会返回错误码;如果先设置了ratio,后设置的[WindowLimits](#windowlimits11)与其冲突,窗口的宽高比可能会不跟随设置的宽高比(ratio)。 |
7327| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                      |
7328
7329**错误码:**
7330
7331以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7332
7333| 错误码ID | 错误信息 |
7334| ------- | -------------------------------------------- |
7335| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
7336| 1300002 | This window state is abnormal.               |
7337| 1300004 | Unauthorized operation.                      |
7338
7339**示例:**
7340<!--code_no_check-->
7341```ts
7342// EntryAbility.ets
7343import { UIAbility } from '@kit.AbilityKit';
7344import { BusinessError } from '@kit.BasicServicesKit';
7345
7346export default class EntryAbility extends UIAbility {
7347
7348  // ...
7349  onWindowStageCreate(windowStage: window.WindowStage) {
7350    console.info('onWindowStageCreate');
7351    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
7352    if (!windowClass) {
7353      console.info('Failed to load the content. Cause: windowClass is null');
7354    }
7355    try {
7356      let ratio = 1.0;
7357      windowClass.setAspectRatio(ratio, (err: BusinessError) => {
7358        const errCode: number = err.code;
7359        if (errCode) {
7360          console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`);
7361          return;
7362        }
7363        console.info('Succeeded in setting the aspect ratio of window.');
7364      });
7365    } catch (exception) {
7366      console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`);
7367    }
7368  }
7369}
7370
7371```
7372
7373### resetAspectRatio<sup>10+</sup>
7374
7375resetAspectRatio(): Promise&lt;void&gt;
7376
7377取消设置窗口内容布局的比例,使用Promise异步回调。
7378
7379仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,调用后将清除持久化储存的比例信息。
7380
7381**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7382
7383**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7384
7385**返回值:**
7386
7387| 类型                | 说明                      |
7388| ------------------- | ------------------------- |
7389| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7390
7391**错误码:**
7392
7393以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
7394
7395| 错误码ID | 错误信息 |
7396| ------- | -------------------------------------------- |
7397| 1300002 | This window state is abnormal.               |
7398| 1300004 | Unauthorized operation.                      |
7399
7400**示例:**
7401<!--code_no_check-->
7402```ts
7403// EntryAbility.ets
7404import { UIAbility } from '@kit.AbilityKit';
7405import { BusinessError } from '@kit.BasicServicesKit';
7406
7407export default class EntryAbility extends UIAbility {
7408
7409  // ...
7410  onWindowStageCreate(windowStage: window.WindowStage) {
7411    console.info('onWindowStageCreate');
7412    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
7413    if (!windowClass) {
7414      console.info('Failed to load the content. Cause: windowClass is null');
7415    }
7416    try {
7417      let promise = windowClass.resetAspectRatio();
7418      promise.then(() => {
7419        console.info('Succeeded in resetting aspect ratio of window.');
7420      }).catch((err: BusinessError) => {
7421        console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`);
7422      });
7423    } catch (exception) {
7424      console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`);
7425    }
7426  }
7427}
7428```
7429
7430### resetAspectRatio<sup>10+</sup>
7431
7432resetAspectRatio(callback: AsyncCallback&lt;void&gt;): void
7433
7434取消设置窗口内容布局的比例,使用callback异步回调。
7435
7436仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,调用后将清除持久化储存的比例信息。
7437
7438**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7439
7440**系统能力:** SystemCapability.WindowManager.WindowManager.Core
7441
7442**参数:**
7443
7444| 参数名             | 类型    | 必填 | 说明                                                         |
7445| ------------------ | ------- | ---- | ------------------------------------------------------------ |
7446| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
7447
7448**错误码:**
7449
7450以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
7451
7452| 错误码ID | 错误信息 |
7453| ------- | -------------------------------------------- |
7454| 1300002 | This window state is abnormal.               |
7455| 1300004 | Unauthorized operation.                      |
7456
7457**示例:**
7458<!--code_no_check-->
7459```ts
7460// EntryAbility.ets
7461import { UIAbility } from '@kit.AbilityKit';
7462import { BusinessError } from '@kit.BasicServicesKit';
7463
7464export default class EntryAbility extends UIAbility {
7465
7466  // ...
7467  onWindowStageCreate(windowStage: window.WindowStage) {
7468    console.info('onWindowStageCreate');
7469    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
7470    if (!windowClass) {
7471      console.info('Failed to load the content. Cause: windowClass is null');
7472    }
7473    try {
7474      windowClass.resetAspectRatio((err: BusinessError) => {
7475        const errCode: number = err.code;
7476        if (errCode) {
7477          console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`);
7478          return;
7479        }
7480        console.info('Succeeded in resetting aspect ratio of window.');
7481      });
7482    } catch (exception) {
7483      console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`);
7484    }
7485  }
7486}
7487```
7488
7489### minimize<sup>11+</sup>
7490
7491minimize(callback: AsyncCallback&lt;void&gt;): void
7492
7493此接口根据调用对象不同,实现不同的功能:
7494
7495- 当调用对象为主窗口时,实现最小化功能,可在Dock栏中还原,2in1 设备上可以使用[restore()](#restore14)进行还原。
7496
7497- 当调用对象为子窗口或悬浮窗时,实现隐藏功能,不可在Dock栏中还原,可以使用[showWindow()](#showwindow9)进行还原。
7498
7499使用callback异步回调。
7500
7501**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7502
7503**系统能力:** SystemCapability.Window.SessionManager
7504
7505**参数:**
7506
7507| 参数名   | 类型                      | 必填 | 说明       |
7508| -------- | ------------------------- | ---- | ---------- |
7509| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。 |
7510
7511**错误码:**
7512
7513以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7514
7515| 错误码ID | 错误信息 |
7516| ------- | ------------------------------ |
7517| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
7518| 1300002 | This window state is abnormal. |
7519| 1300003 | This window manager service works abnormally. |
7520
7521**示例:**
7522
7523```ts
7524import { BusinessError } from '@kit.BasicServicesKit';
7525
7526windowClass.minimize((err: BusinessError) => {
7527  const errCode: number = err.code;
7528  if (errCode) {
7529    console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`);
7530    return;
7531  }
7532  console.info('Succeeded in minimizing the window.');
7533});
7534```
7535
7536### minimize<sup>11+</sup>
7537
7538minimize(): Promise&lt;void&gt;
7539
7540此接口根据调用对象不同,实现不同的功能:
7541
7542- 当调用对象为主窗口时,实现最小化功能,可在Dock栏中还原,2in1 设备上可以使用[restore()](#restore14)进行还原。
7543
7544- 当调用对象为子窗口或悬浮窗时,实现隐藏功能,不可在Dock栏中还原,可以使用[showWindow()](#showwindow9)进行还原。
7545
7546使用Promise异步回调。
7547
7548**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7549
7550**系统能力:** SystemCapability.Window.SessionManager
7551
7552**返回值:**
7553
7554| 类型                | 说明                      |
7555| ------------------- | ------------------------- |
7556| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7557
7558**错误码:**
7559
7560以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7561
7562| 错误码ID | 错误信息 |
7563| ------- | ------------------------------ |
7564| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
7565| 1300002 | This window state is abnormal. |
7566| 1300003 | This window manager service works abnormally. |
7567
7568**示例:**
7569
7570```ts
7571import { BusinessError } from '@kit.BasicServicesKit';
7572
7573let promise = windowClass.minimize();
7574promise.then(() => {
7575  console.info('Succeeded in minimizing the window.');
7576}).catch((err: BusinessError) => {
7577  console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`);
7578});
7579```
7580
7581### maximize<sup>12+</sup>
7582maximize(presentation?: MaximizePresentation): Promise&lt;void&gt;
7583
7584实现最大化功能。主窗口可调用此接口实现最大化功能;子窗口需在创建时设置子窗口参数maximizeSupported为true,再调用此接口可实现最大化功能。使用Promise异步回调。
7585
7586<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
7587
7588**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7589
7590**系统能力:** SystemCapability.Window.SessionManager
7591
7592**参数:**
7593
7594| 参数名 | 类型  | 必填 | 说明 |
7595| ----- | ---------------------------- | -- | --------------------------------- |
7596| presentation  | [MaximizePresentation](#maximizepresentation12) | 否 | 主窗口或子窗口最大化时的布局枚举。默认值window.MaximizePresentation.ENTER_IMMERSIVE,即默认最大化时进入沉浸式布局。 |
7597
7598**返回值:**
7599
7600| 类型                | 说明                      |
7601| ------------------- | ------------------------- |
7602| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7603
7604**错误码:**
7605
7606以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7607
7608| 错误码ID | 错误信息 |
7609| ------- | ------------------------------ |
7610| 801     | Capability not supported. Function maximize can not work correctly due to limited device capabilities. |
7611| 1300002 | This window state is abnormal.                |
7612| 1300003 | This window manager service works abnormally. |
7613| 1300004 | Unauthorized operation.                       |
7614
7615**示例:**
7616
7617```ts
7618// EntryAbility.ets
7619import { UIAbility } from '@kit.AbilityKit';
7620import { BusinessError } from '@kit.BasicServicesKit';
7621export default class EntryAbility extends UIAbility {
7622  // ...
7623
7624  onWindowStageCreate(windowStage: window.WindowStage) {
7625    console.info('onWindowStageCreate');
7626    let windowClass: window.Window | undefined = undefined;
7627    windowStage.getMainWindow((err: BusinessError, data) => {
7628      const errCode: number = err.code;
7629      if (errCode) {
7630        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7631        return;
7632      }
7633      windowClass = data;
7634      let promise = windowClass.maximize();
7635      // let promise = windowClass.maximize(window.MaximizePresentation.ENTER_IMMERSIVE);
7636      promise.then(() => {
7637        console.info('Succeeded in maximizing the window.');
7638      }).catch((err: BusinessError) => {
7639        console.error(`Failed to maximize the window. Cause code: ${err.code}, message: ${err.message}`);
7640      });
7641    });
7642  }
7643};
7644```
7645
7646### setResizeByDragEnabled<sup>14+</sup>
7647setResizeByDragEnabled(enable: boolean, callback: AsyncCallback&lt;void&gt;): void
7648
7649禁止/使能通过拖拽方式缩放主窗口或启用装饰的子窗口的功能。使用callback异步回调。
7650
7651**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
7652
7653**系统能力:** SystemCapability.Window.SessionManager
7654
7655**参数:**
7656
7657| 参数名 | 类型  | 必填 | 说明 |
7658| ----- | ---------------------------- | -- | --------------------------------- |
7659| enable  | boolean | 是 | 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。 |
7660| callback  | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
7661
7662**错误码:**
7663
7664以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7665
7666| 错误码ID | 错误信息 |
7667| ------- | ------------------------------ |
7668| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7669| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
7670| 1300002 | This window state is abnormal.                |
7671| 1300003 | This window manager service works abnormally. |
7672
7673**示例:**
7674
7675```ts
7676try {
7677  let enabled = false;
7678  windowClass.setResizeByDragEnabled(enabled, (err) => {
7679    if (err.code) {
7680      console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${err.code}, message: ${err.message}`);
7681      return;
7682    }
7683    console.info(`Succeeded in setting the function of disabling the resize by drag window.`);
7684  });
7685} catch (exception) {
7686  console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${exception.code}, message: ${exception.message}`);
7687}
7688```
7689
7690### setResizeByDragEnabled<sup>14+</sup>
7691setResizeByDragEnabled(enable: boolean): Promise&lt;void&gt;
7692
7693禁止/使能通过拖拽方式缩放主窗口或启用装饰的子窗口的功能。使用Promise异步回调。
7694
7695**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
7696
7697**系统能力:** SystemCapability.Window.SessionManager
7698
7699**参数:**
7700
7701| 参数名 | 类型  | 必填 | 说明 |
7702| ----- | ---------------------------- | -- | --------------------------------- |
7703| enable  | boolean | 是 | 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。 |
7704
7705**返回值:**
7706
7707| 类型 | 说明 |
7708| ------------------- | ------------------------ |
7709| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7710
7711**错误码:**
7712
7713以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7714
7715| 错误码ID | 错误信息 |
7716| ------- | ------------------------------ |
7717| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7718| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
7719| 1300002 | This window state is abnormal.                |
7720| 1300003 | This window manager service works abnormally. |
7721
7722**示例:**
7723
7724```ts
7725import { BusinessError } from '@kit.BasicServicesKit';
7726
7727try {
7728  let enabled = false;
7729  let promise = windowClass.setResizeByDragEnabled(enabled);
7730  promise.then(() => {
7731    console.info(`Succeeded in setting the function of disabling the resize by drag window.`);
7732  }).catch((err: BusinessError) => {
7733    console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${err.code}, message: ${err.message}`);
7734  });
7735} catch (exception) {
7736  console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${exception.code}, message: ${exception.message}`);
7737}
7738```
7739
7740### recover<sup>11+</sup>
7741
7742recover(): Promise&lt;void&gt;
7743
7744将主窗口从全屏、最大化、分屏模式下还原为浮动窗口,并恢复到进入该模式之前的大小和位置,已经是浮动窗口模式不可再还原。使用Promise异步回调。此接口仅在多窗层叠布局效果下生效。
7745
7746<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
7747
7748**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7749
7750**系统能力:** SystemCapability.Window.SessionManager
7751
7752**返回值:**
7753
7754| 类型                | 说明                      |
7755| ------------------- | ------------------------- |
7756| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7757
7758**错误码:**
7759
7760以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7761
7762| 错误码ID | 错误信息 |
7763| ------- | ------------------------------ |
7764| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
7765| 1300001 | Repeated operation. |
7766| 1300002 | This window state is abnormal. |
7767
7768**示例:**
7769
7770```ts
7771// EntryAbility.ets
7772import { UIAbility } from '@kit.AbilityKit';
7773import { BusinessError } from '@kit.BasicServicesKit';
7774
7775export default class EntryAbility extends UIAbility {
7776  // ...
7777  onWindowStageCreate(windowStage: window.WindowStage): void {
7778    console.info('onWindowStageCreate');
7779    let windowClass: window.Window | undefined = undefined;
7780    windowStage.getMainWindow((err: BusinessError, data) => {
7781      const errCode: number = err.code;
7782      if (errCode) {
7783        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
7784        return;
7785      }
7786      windowClass = data;
7787      let promise = windowClass.recover();
7788      promise.then(() => {
7789        console.info('Succeeded in recovering the window.');
7790      }).catch((err: BusinessError) => {
7791        console.error(`Failed to recover the window. Cause code: ${err.code}, message: ${err.message}`);
7792      });
7793    });
7794  }
7795}
7796```
7797
7798### restore<sup>14+</sup>
7799
7800restore(): Promise&lt;void&gt;
7801
7802将主窗口从最小化状态,恢复到前台显示,并恢复到进入该模式之前的大小和位置。使用Promise异步回调。
7803此接口仅在多窗层叠布局效果下生效,仅在主窗口为最小化状态且UIAbility生命周期为onForeground时生效。
7804
7805<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
7806
7807**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
7808
7809**系统能力:** SystemCapability.Window.SessionManager
7810
7811**返回值:**
7812
7813| 类型                | 说明                      |
7814| ------------------- | ------------------------- |
7815| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
7816
7817**错误码:**
7818
7819以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7820
7821| **错误码ID** | **错误信息**                                                 |
7822| ------------ | ------------------------------------------------------------ |
7823| 801          | Capability not supported. Failed to call the API due to limited device capabilities. |
7824| 1300002      | This window state is abnormal.                               |
7825| 1300003      | This window manager service works abnormally.                |
7826| 1300004      | Unauthorized operation.                                      |
7827
7828**示例**
7829
7830```ts
7831// EntryAbility.ets
7832import { UIAbility } from '@kit.AbilityKit';
7833import { BusinessError } from '@kit.BasicServicesKit';
7834
7835export default class EntryAbility extends UIAbility {
7836  onWindowStageCreate(windowStage: window.WindowStage): void {
7837    try {
7838      let windowClass = windowStage.getMainWindowSync();
7839      // 调用minimize, 使主窗最小化
7840      windowClass.minimize();
7841      //设置延时函数延时5秒钟后对主窗进行恢复。
7842      setTimeout(()=>{
7843        //调用restore()函数对主窗进行恢复。
7844        let promise = windowClass.restore();
7845        promise.then(() => {
7846          console.info('Succeeded in restoring the window.');
7847        }).catch((err: BusinessError) => {
7848          console.error(`Failed to restore the window. Cause code: ${err.code}, message: ${err.message}`);
7849        });
7850      }, 5000);
7851    } catch (exception) {
7852      console.error(`Failed to restore the window. Cause code: ${exception.code}, message: ${exception.message}`);
7853    }
7854  }
7855}
7856```
7857
7858### getWindowLimits<sup>11+</sup>
7859
7860getWindowLimits(): WindowLimits
7861
7862获取当前应用窗口的尺寸限制。
7863
7864**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7865
7866**系统能力:** SystemCapability.Window.SessionManager
7867
7868**返回值:**
7869
7870| 类型                          | 说明           |
7871| ----------------------------- | ------------------ |
7872| [WindowLimits](#windowlimits11) | 当前窗口尺寸限制。 |
7873
7874**错误码:**
7875
7876以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7877
7878| 错误码ID | 错误信息                       |
7879| :------- | :----------------------------- |
7880| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
7881| 1300002  | This window state is abnormal. |
7882
7883**示例:**
7884
7885```ts
7886try {
7887  let windowLimits = windowClass.getWindowLimits();
7888} catch (exception) {
7889  console.error(`Failed to obtain the window limits of window. Cause code: ${exception.code}, message: ${exception.message}`);
7890}
7891```
7892
7893### setWindowLimits<sup>11+</sup>
7894
7895setWindowLimits(windowLimits: WindowLimits): Promise&lt;WindowLimits&gt;
7896
7897设置当前应用窗口的尺寸限制,使用Promise异步回调。
7898默认存在一个系统尺寸限制,系统尺寸限制由产品配置决定,不可修改。未调用setWindowLimits配置过WindowLimits时,使用[getWindowLimits](#getwindowlimits11)可获取系统限制。
7899
7900**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7901
7902**系统能力:** SystemCapability.Window.SessionManager
7903
7904**参数:**
7905
7906| 参数名       | 类型                          | 必填 | 说明                           |
7907| :----------- | :---------------------------- | :--- | :----------------------------- |
7908| windowLimits | [WindowLimits](#windowlimits11) | 是   | 目标窗口的尺寸限制,单位为px。 |
7909
7910**返回值:**
7911
7912| 类型                                         | 说明                                |
7913| :------------------------------------------- | :---------------------------------- |
7914| Promise&lt;[WindowLimits](#windowlimits11)&gt; | Promise对象。返回设置后的尺寸限制,为入参与系统尺寸限制的交集。 |
7915
7916**错误码:**
7917
7918以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7919
7920| 错误码ID | 错误信息                                      |
7921| :------- | :-------------------------------------------- |
7922| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
7923| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
7924| 1300002  | This window state is abnormal.                |
7925| 1300003  | This window manager service works abnormally. |
7926| 1300004 | Unauthorized operation.                |
7927
7928**示例:**
7929
7930```ts
7931import { BusinessError } from '@kit.BasicServicesKit';
7932try {
7933  let windowLimits: window.WindowLimits = {
7934    maxWidth: 1500,
7935    maxHeight: 1000,
7936    minWidth: 500,
7937    minHeight: 400
7938  };
7939  let promise = windowClass.setWindowLimits(windowLimits);
7940    promise.then((data) => {
7941    console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data));
7942  }).catch((err: BusinessError) => {
7943    console.error(`Failed to change the window limits. Cause code: ${err.code}, message: ${err.message}`);
7944  });
7945} catch (exception) {
7946  console.error(`Failed to change the window limits. Cause code: ${exception.code}, message: ${exception.message}`);
7947}
7948```
7949
7950### setWindowLimits<sup>15+</sup>
7951
7952setWindowLimits(windowLimits: WindowLimits, isForcible: boolean): Promise&lt;WindowLimits&gt;
7953
7954设置当前应用窗口的尺寸限制,使用Promise异步回调。
7955默认存在一个系统尺寸限制,系统尺寸限制由产品配置决定,不可修改。未调用setWindowLimits配置过WindowLimits时,使用[getWindowLimits](#getwindowlimits11)可获取系统限制。
7956此接口仅支持2in1设备。
7957
7958**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
7959
7960**系统能力:** SystemCapability.Window.SessionManager
7961
7962**参数:**
7963
7964| 参数名       | 类型                          | 必填 | 说明                           |
7965| :----------- | :---------------------------- | :--- | :----------------------------- |
7966| windowLimits | [WindowLimits](#windowlimits11) | 是   | 目标窗口的尺寸限制,单位为px。 |
7967| isForcible | boolean | 是   | 是否强制设置窗口的尺寸限制。<br>设置为true,表示窗口宽高最小值以系统限制值和40vp两者中的低数值为准,窗口宽高的最大值仍取决于系统限制。<br>设置为false,表示窗口宽高的最小值和最大值都取决于系统限制。|
7968
7969**返回值:**
7970
7971| 类型                                         | 说明                                |
7972| :------------------------------------------- | :---------------------------------- |
7973| Promise&lt;[WindowLimits](#windowlimits11)&gt; | Promise对象。返回设置后的窗口尺寸限制。根据isForcible判断为入参与系统默认窗口尺寸限制的交集。 |
7974
7975**错误码:**
7976
7977以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
7978
7979| 错误码ID | 错误信息                                      |
7980| :------- | :-------------------------------------------- |
7981| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
7982| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
7983| 1300002  | This window state is abnormal.                |
7984| 1300003  | This window manager service works abnormally. |
7985| 1300004 | Unauthorized operation.                |
7986
7987**示例:**
7988
7989```ts
7990import { BusinessError } from '@kit.BasicServicesKit';
7991try {
7992  let windowLimits: window.WindowLimits = {
7993    maxWidth: 1500,
7994    maxHeight: 1000,
7995    minWidth: 100,
7996    minHeight: 100
7997  };
7998  let promise = windowClass.setWindowLimits(windowLimits, true);
7999  promise.then((data) => {
8000    console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data));
8001  }).catch((err: BusinessError) => {
8002    console.error(`Failed to change the window limits. Cause code: ${err.code}, message: ${err.message}`);
8003  });
8004} catch (exception) {
8005  console.error(`Failed to change the window limits. Cause code: ${exception.code}, message: ${exception.message}`);
8006}
8007```
8008
8009### setWindowMask<sup>12+</sup>
8010
8011setWindowMask(windowMask: Array&lt;Array&lt;number&gt;&gt;): Promise&lt;void&gt;;
8012
8013设置异形窗口的掩码,使用Promise异步回调。异形窗口为非常规形状的窗口,掩码用于描述异形窗口的形状。此接口仅限子窗和全局悬浮窗可用。
8014当异形窗口大小发生变化时,实际的显示内容为掩码大小和窗口大小的交集部分。
8015
8016该接口只在多个线程操作同一个窗口时可能返回错误码1300002。窗口被销毁场景下错误码返回401。
8017
8018<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
8019
8020**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8021
8022**系统能力:** SystemCapability.Window.SessionManager
8023
8024**参数:**
8025
8026| 参数名       | 类型                          | 必填 | 说明                           |
8027| :----------- | :---------------------------- | :--- | :----------------------------- |
8028| windowMask | Array&lt;Array&lt;number&gt;&gt; | 是   | 异形窗口的掩码,该参数仅支持宽高为窗口宽高、取值为整数0和整数1的二维数组输入,整数0代表所在像素透明,整数1代表所在像素不透明,宽高不符合的二维数组或二维数组取值不为整数0和整数1的二维数组为非法参数。 |
8029
8030**返回值:**
8031
8032| 类型                                         | 说明                                |
8033| :------------------------------------------- | :---------------------------------- |
8034| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8035
8036**错误码:**
8037
8038以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8039
8040| 错误码ID | 错误信息                                      |
8041| :------- | :-------------------------------------------- |
8042| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8043| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
8044| 1300002  | This window state is abnormal.                |
8045| 1300003  | This window manager service works abnormally. |
8046| 1300004  | Unauthorized operation.                       |
8047
8048**示例:**
8049
8050```ts
8051import { BusinessError } from '@kit.BasicServicesKit';
8052try {
8053  let windowMask: Array<Array<number>> = [
8054      [0, 0, 0, 1, 0, 0, 0],
8055      [0, 0, 1, 1, 1, 0, 0],
8056      [0, 1, 1, 0, 1, 1, 0],
8057      [1, 1, 0, 0, 0, 1, 1]
8058    ];
8059  let promise = windowClass.setWindowMask(windowMask);
8060    promise.then(() => {
8061    console.info('Succeeded in setting the window mask.');
8062  }).catch((err: BusinessError) => {
8063    console.error(`Failed to set the window mask. Cause code: ${err.code}, message: ${err.message}`);
8064  });
8065} catch (exception) {
8066  console.error(`Failed to set the window mask. Cause code: ${exception.code}, message: ${exception.message}`);
8067}
8068```
8069
8070### keepKeyboardOnFocus<sup>11+</sup>
8071
8072keepKeyboardOnFocus(keepKeyboardFlag: boolean): void
8073
8074窗口获焦时保留由其他窗口创建的软键盘,仅支持系统窗口与应用子窗口。
8075
8076**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8077
8078**系统能力:** SystemCapability.Window.SessionManager
8079
8080**参数:**
8081
8082| 参数名           | 类型    | 必填 | 说明                                                         |
8083| ---------------- | ------- | ---- | ------------------------------------------------------------ |
8084| keepKeyboardFlag | boolean | 是   | 是否保留其他窗口创建的软键盘。true表示保留;false表示不保留。|
8085
8086**错误码:**
8087
8088以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8089
8090| 错误码ID | 错误信息 |
8091| ------- | ---------------------------------------- |
8092| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8093| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
8094| 1300002 | This window state is abnormal.           |
8095| 1300004 | Unauthorized operation.                  |
8096
8097**示例:**
8098
8099```ts
8100try {
8101  windowClass.keepKeyboardOnFocus(true);
8102} catch (exception) {
8103  console.error(`Failed to keep keyboard onFocus. Cause code: ${exception.code}, message: ${exception.message}`);
8104}
8105```
8106
8107### setWindowDecorVisible<sup>11+</sup>
8108
8109setWindowDecorVisible(isVisible: boolean): void
8110
8111设置窗口标题栏是否可见,对存在标题栏和三键区的窗口形态生效。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
8112
8113设置窗口标题栏不可见后,当主窗口进入全屏沉浸状态时,此时鼠标Hover到上方窗口标题栏热区上会显示悬浮标题栏。若想禁用悬浮标题栏显示,请使用[setTitleAndDockHoverShown()](#settitleanddockhovershown14)接口。
8114
8115**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8116
8117**系统能力:** SystemCapability.Window.SessionManager
8118
8119**参数:**
8120
8121| 参数名    | 类型    | 必填 | 说明                                          |
8122| --------- | ------- | ---- | --------------------------------------------- |
8123| isVisible | boolean | 是   | 设置标题栏是否可见,true为可见,false为隐藏。 |
8124
8125**错误码:**
8126
8127以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8128
8129| 错误码ID | 错误信息                       |
8130| -------- | ------------------------------ |
8131| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8132| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
8133| 1300002  | This window state is abnormal. |
8134
8135**示例:**
8136
8137```ts
8138import { BusinessError } from '@kit.BasicServicesKit';
8139let storage: LocalStorage = new LocalStorage();
8140storage.setOrCreate('storageSimpleProp', 121);
8141windowClass.loadContent("pages/page2", storage, (err: BusinessError) => {
8142  let errCode: number = err.code;
8143  if (errCode) {
8144    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
8145    return;
8146  }
8147  console.info('Succeeded in loading the content.');
8148  let isVisible = false;
8149  // 调用setWindowDecorVisible接口
8150  try {
8151      windowClass?.setWindowDecorVisible(isVisible);
8152  } catch (exception) {
8153      console.error(`Failed to set the visibility of window decor. Cause code: ${exception.code}, message: ${exception.message}`);
8154  }
8155});
8156```
8157
8158### getWindowDecorVisible<sup>18+</sup>
8159
8160getWindowDecorVisible(): boolean
8161
8162查询窗口标题栏是否可见。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
8163
8164<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
8165
8166**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
8167
8168**系统能力:** SystemCapability.Window.SessionManager
8169
8170**返回值:**
8171
8172| 类型   | 说明                                                         |
8173| ------ | ------------------------------------------------------------ |
8174| boolean | 返回当前窗口标题栏是否可见,true表示可见,false表示不可见。|
8175
8176**错误码:**
8177
8178以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8179
8180| 错误码ID | 错误信息                       |
8181| -------- | ------------------------------ |
8182| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
8183| 1300002  | This window state is abnormal. |
8184
8185**示例:**
8186
8187```ts
8188let isVisible: boolean | undefined = undefined;
8189windowClass.setUIContent('pages/WindowPage').then(() => {
8190  try {
8191    isVisible = windowClass?.getWindowDecorVisible();
8192  } catch (exception) {
8193    console.error(`Failed to get the window decor visibility. Cause code: ${exception.code}, message: ${exception.message}`);
8194  }
8195})
8196```
8197
8198### setWindowTitle<sup>15+</sup>
8199
8200setWindowTitle(titleName: string): Promise&lt;void&gt;
8201
8202设置窗口标题,存在标题栏的窗口形态生效,使用Promise异步回调。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
8203
8204此接口仅支持2in1设备和平板设备。
8205
8206**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
8207
8208**系统能力:** SystemCapability.Window.SessionManager
8209
8210**参数:**
8211
8212| 参数名    | 类型     | 必填 | 说明                                          |
8213| --------- | ------- | ---- | --------------------------------------------- |
8214| titleName | string  | 是   | 窗口标题。标题显示区域最右端不超过系统三键区域最左端,超过部分以省略号表示。 |
8215
8216**返回值:**
8217
8218| 类型 | 说明 |
8219| ------------------- | ------------------------ |
8220| Promise&lt;void&gt; | 无返回结果的Promise对象。  |
8221
8222**错误码:**
8223
8224以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8225
8226| 错误码ID | 错误信息                       |
8227| -------- | ------------------------------ |
8228| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8229| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
8230| 1300002  | This window state is abnormal. |
8231
8232**示例:**
8233
8234```ts
8235import { window } from '@kit.ArkUI';
8236import { BusinessError } from '@kit.BasicServicesKit';
8237
8238let windowClass: window.Window | undefined = undefined;
8239try {
8240  let promise = window.getLastWindow(this.context);
8241  promise.then((data) => {
8242    windowClass = data;
8243    let title = "title";
8244    windowClass.setWindowTitle(title).then(() => {
8245      console.info('Succeeded in setting the window title.');
8246    }).catch((err: BusinessError) => {
8247      console.error(`Failed to set the window title. Cause code: ${err.code}, message: ${err.message}`);
8248    });
8249  }).catch((err: BusinessError) => {
8250    console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
8251  });
8252} catch (exception) {
8253  console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`);
8254}
8255```
8256
8257### setWindowTitleMoveEnabled<sup>14+</sup>
8258
8259setWindowTitleMoveEnabled(enabled: boolean): void
8260
8261禁止/使能主窗或子窗标题栏默认移动窗口和双击最大化的功能,当禁用标题栏默认移动窗口和双击最大化的功能时,可使用[startMoving()](#startmoving14)在应用热区中发起拖拽移动,使用[maximize()](#maximize12)实现最大化功能。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
8262
8263<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
8264
8265**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
8266
8267**系统能力:** SystemCapability.Window.SessionManager
8268
8269**参数:**
8270
8271| 参数名    | 类型     | 必填 | 说明                                          |
8272| --------- | ------- | ---- | --------------------------------------------- |
8273| enabled    | boolean | 是   | 是否使能标题栏默认移动窗口和双击最大化功能,true表示使能,false表示不使能。|
8274
8275**错误码:**
8276
8277以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8278
8279| 错误码ID | 错误信息                       |
8280| -------- | ------------------------------ |
8281| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8282| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
8283| 1300002  | This window state is abnormal. |
8284| 1300004  | Unauthorized operation.        |
8285
8286**示例:**
8287
8288```ts
8289// EntryAbility.ets
8290import { UIAbility } from '@kit.AbilityKit';
8291
8292export default class EntryAbility extends UIAbility {
8293  onWindowStageCreate(windowStage: window.WindowStage): void {
8294    try {
8295      windowStage.loadContent("pages/Index").then(() =>{
8296        let windowClass = windowStage.getMainWindowSync();
8297        let enabled = false;
8298        windowClass.setWindowTitleMoveEnabled(enabled);
8299        console.info(`Succeeded in setting the the window title move enabled: ${enabled}`);
8300      });
8301    } catch (exception) {
8302      console.error(`Failed to set the window title move enabled. Cause code: ${exception.code}, message: ${exception.message}`);
8303    }
8304  }
8305}
8306```
8307
8308### setSubWindowModal<sup>12+</sup>
8309
8310setSubWindowModal(isModal: boolean): Promise&lt;void&gt;
8311
8312设置子窗的模态属性是否启用,使用Promise异步回调。
8313
8314子窗口调用该接口时,设置子窗口模态属性是否启用。启用子窗口模态属性后,其父级窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态属性被禁用。
8315
8316子窗口之外的窗口调用该接口时,会报错。
8317
8318**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8319
8320**系统能力:** SystemCapability.Window.SessionManager
8321
8322**参数:**
8323
8324| 参数名    | 类型    | 必填 | 说明                                          |
8325| --------- | ------- | ---- | --------------------------------------------- |
8326| isModal | boolean | 是   | 设置子窗口模态属性是否启用,true为启用,false为不启用。 |
8327
8328
8329**返回值:**
8330
8331| 类型 | 说明 |
8332| ------------------- | ------------------------ |
8333| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8334
8335**错误码:**
8336
8337以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8338
8339| 错误码ID | 错误信息                       |
8340| -------- | ------------------------------ |
8341| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8342| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
8343| 1300002  | This window state is abnormal. |
8344| 1300003  | This window manager service works abnormally. |
8345| 1300004  | Unauthorized operation.        |
8346
8347**示例:**
8348
8349```ts
8350// EntryAbility.ets
8351import { UIAbility } from '@kit.AbilityKit';
8352import { BusinessError } from '@kit.BasicServicesKit';
8353
8354export default class EntryAbility extends UIAbility {
8355  // ...
8356  onWindowStageCreate(windowStage: window.WindowStage): void {
8357    console.info('onWindowStageCreate');
8358    let windowClass: window.Window | undefined = undefined;
8359    // 创建子窗
8360    try {
8361      let subWindow = windowStage.createSubWindow("testSubWindow");
8362      subWindow.then((data) => {
8363        if (data == null) {
8364          console.error("Failed to create the subWindow. Cause: The data is empty");
8365          return;
8366        }
8367        windowClass = data;
8368        let promise = windowClass.setSubWindowModal(true);
8369        promise.then(() => {
8370          console.info('Succeeded in setting subwindow modal');
8371        }).catch((err: BusinessError) => {
8372          console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`);
8373        });
8374      });
8375    } catch (exception) {
8376      console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`);
8377    }
8378  }
8379}
8380```
8381
8382### setSubWindowModal<sup>14+</sup>
8383
8384setSubWindowModal(isModal: boolean, modalityType: ModalityType): Promise&lt;void&gt;
8385
8386设置子窗的模态类型,使用Promise异步回调。
8387
8388当子窗口模态类型为模窗口子窗时,其父级窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态类型被禁用。
8389
8390当子窗口模态类型为模应用子窗时,其父级窗口与该应用其他实例的窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态类型被禁用。
8391
8392此接口仅支持设置子窗口模态类型,当需要禁用子窗口模态属性时,建议使用[setSubWindowModal<sup>12+</sup>](#setsubwindowmodal12)。
8393
8394子窗口之外的窗口调用该接口时,会报错。
8395
8396**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
8397
8398**系统能力:** SystemCapability.Window.SessionManager
8399
8400**参数:**
8401
8402| 参数名    | 类型    | 必填 | 说明                                          |
8403| --------- | ------- | ---- | --------------------------------------------- |
8404| isModal | boolean | 是   | 设置子窗口模态属性是否启用,true为启用,false为不启用。当前仅支持设置为true。 |
8405| modalityType | [ModalityType](#modalitytype14) | 是   | 子窗口模态类型。 |
8406
8407**返回值:**
8408
8409| 类型 | 说明 |
8410| ------------------- | ------------------------ |
8411| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8412
8413**错误码:**
8414
8415以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8416
8417| 错误码ID | 错误信息                       |
8418| -------- | ------------------------------ |
8419| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8420| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
8421| 1300002  | This window state is abnormal. |
8422| 1300003  | This window manager service works abnormally. |
8423| 1300004  | Unauthorized operation.        |
8424
8425**示例:**
8426
8427```ts
8428// EntryAbility.ets
8429import { UIAbility } from '@kit.AbilityKit';
8430import { BusinessError } from '@kit.BasicServicesKit';
8431import { window } from '@kit.ArkUI';
8432
8433export default class EntryAbility extends UIAbility {
8434  // ...
8435  onWindowStageCreate(windowStage: window.WindowStage): void {
8436    console.info('onWindowStageCreate');
8437    let windowClass: window.Window | undefined = undefined;
8438    // 创建子窗
8439    try {
8440      let subWindow = windowStage.createSubWindow("testSubWindow");
8441      subWindow.then((data) => {
8442        if (data == null) {
8443          console.error("Failed to create the subWindow. Cause: The data is empty");
8444          return;
8445        }
8446        windowClass = data;
8447        let promise = windowClass.setSubWindowModal(true, window.ModalityType.WINDOW_MODALITY);
8448        promise.then(() => {
8449          console.info('Succeeded in setting subwindow modal');
8450        }).catch((err: BusinessError) => {
8451          console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`);
8452        });
8453      });
8454    } catch (exception) {
8455      console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`);
8456    }
8457  }
8458}
8459```
8460
8461### setWindowDecorHeight<sup>11+</sup>
8462
8463setWindowDecorHeight(height: number): void
8464
8465<!--RP1-->
8466设置窗口的标题栏高度,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
8467<!--RP1End-->
8468
8469当主窗口进入全屏沉浸状态时,此时鼠标Hover到窗口标题栏热区时,会显示悬浮标题栏,悬浮标题栏高度固定为37vp。
8470
8471**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8472
8473**系统能力:** SystemCapability.Window.SessionManager
8474
8475**参数:**
8476
8477| 参数名 | 类型   | 必填 | 说明                                                         |
8478| ------ | ------ | ---- | ------------------------------------------------------------ |
8479| height | number | 是   |设置的窗口标题栏高度,仅支持具有窗口标题栏的窗口。该参数为整数,浮点数输入将向下取整,取值范围为[37,112],范围外为非法参数,单位为vp。 |
8480
8481**错误码:**
8482
8483以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8484
8485| 错误码ID | 错误信息                       |
8486| -------- | ------------------------------ |
8487| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
8488| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
8489| 1300002  | This window state is abnormal. |
8490
8491**示例:**
8492
8493```ts
8494windowClass.setUIContent('pages/WindowPage').then(() => {
8495  let height: number = 50;
8496  try {
8497    windowClass?.setWindowDecorHeight(height);
8498    console.info(`Succeeded in setting the height of window decor: ${height}`);
8499  } catch (exception) {
8500    console.error(`Failed to set the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`);
8501  }
8502})
8503```
8504
8505### setDecorButtonStyle<sup>14+</sup>
8506
8507setDecorButtonStyle(dectorStyle: DecorButtonStyle): void
8508
8509设置装饰栏按钮样式,仅对主窗和子窗生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
8510
8511<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
8512
8513**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
8514
8515**系统能力:** SystemCapability.Window.SessionManager
8516
8517**参数:**
8518
8519| 参数名    | 类型    | 必填 | 说明                                          |
8520| --------- | ------- | ---- | --------------------------------------------- |
8521| dectorStyle | [DecorButtonStyle](#decorbuttonstyle14)  | 是   | 要设置的装饰栏按钮样式。 |
8522
8523**错误码:**
8524
8525以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8526
8527| 错误码ID | 错误信息                       |
8528| -------- | ------------------------------ |
8529| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8530| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
8531| 1300002  | This window state is abnormal. |
8532| 1300004  | Unauthorized operation. |
8533
8534**示例:**
8535
8536```ts
8537// EntryAbility.ets
8538import { UIAbility } from '@kit.AbilityKit';
8539import { ConfigurationConstant } from '@kit.AbilityKit';
8540
8541export default class EntryAbility extends UIAbility {
8542  onWindowStageCreate(windowStage: window.WindowStage): void {
8543    try {
8544      windowStage.loadContent("pages/Index").then(() =>{
8545        let windowClass = windowStage.getMainWindowSync();
8546        let colorMode : ConfigurationConstant.ColorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
8547        let style: window.DecorButtonStyle = {
8548          colorMode: colorMode,
8549          buttonBackgroundSize: 28,
8550          spacingBetweenButtons: 12,
8551          closeButtonRightMargin: 20,
8552          buttonIconSize: 20,
8553          buttonBackgroundCornerRadius: 4
8554        };
8555        windowClass.setDecorButtonStyle(style);
8556        console.info('Succeeded in setting the style of button. Data: ' + JSON.stringify(style));
8557      });
8558    } catch (exception) {
8559      console.error(`Failed to set the style of button. Cause code: ${exception.code}, message: ${exception.message}`);
8560    }
8561  }
8562}
8563```
8564
8565### getDecorButtonStyle<sup>14+</sup>
8566
8567getDecorButtonStyle(): DecorButtonStyle
8568
8569获取装饰栏按钮样式,仅对主窗和子窗生效。
8570
8571<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
8572
8573**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
8574
8575**系统能力:** SystemCapability.Window.SessionManager
8576
8577**返回值:**
8578
8579| 类型                                  | 说明                                                         |
8580| ------------------------------------- | ------------------------------------------------------------ |
8581| [DecorButtonStyle](#decorbuttonstyle14) | 返回当前窗口装饰栏上的按钮样式,窗口装饰按钮区域位于窗口的右上角。 |
8582
8583**错误码:**
8584
8585以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8586
8587| 错误码ID | 错误信息                       |
8588| -------- | ------------------------------ |
8589| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
8590| 1300002  | This window state is abnormal. |
8591| 1300003  | This window manager service works abnormally. |
8592| 1300004  | Unauthorized operation. |
8593
8594**示例:**
8595
8596```ts
8597try {
8598  let decorButtonStyle = windowClass.getDecorButtonStyle();
8599  console.info('Succeeded in getting the style of button. Data: ' + JSON.stringify(decorButtonStyle));
8600} catch (exception) {
8601  console.error(`Failed to get the style of button. Cause code: ${exception.code}, message: ${exception.message}`);
8602}
8603```
8604
8605### getWindowDecorHeight<sup>11+</sup>
8606
8607getWindowDecorHeight(): number
8608
8609<!--RP2-->
8610获取窗口的标题栏高度,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
8611<!--RP2End-->
8612
8613**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8614
8615**系统能力:** SystemCapability.Window.SessionManager
8616
8617**返回值:**
8618
8619| 类型   | 说明                                                         |
8620| ------ | ------------------------------------------------------------ |
8621| number | 返回的窗口标题栏高度。该参数为整数,取值范围为[37,112],单位为vp。 |
8622
8623**错误码:**
8624
8625以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8626
8627| 错误码ID | 错误信息                       |
8628| -------- | ------------------------------ |
8629| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
8630| 1300002  | This window state is abnormal. |
8631
8632**示例:**
8633
8634```ts
8635windowClass.setUIContent('pages/WindowPage').then(() => {
8636  try {
8637    let height = windowClass?.getWindowDecorHeight();
8638    console.info(`Succeeded in getting the height of window decor: ${height}`);
8639  } catch (exception) {
8640    console.error(`Failed to get the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`);
8641  }
8642})
8643```
8644
8645### getTitleButtonRect<sup>11+</sup>
8646
8647getTitleButtonRect(): TitleButtonRect
8648
8649获取主窗口或启用装饰的子窗口的标题栏上的最小化、最大化、关闭按钮矩形区域。
8650
8651**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8652
8653**系统能力:** SystemCapability.Window.SessionManager
8654
8655**返回值:**
8656
8657| 类型                                  | 说明                                                         |
8658| ------------------------------------- | ------------------------------------------------------------ |
8659| [TitleButtonRect](#titlebuttonrect11) | 标题栏上的最小化、最大化、关闭按钮矩形区域,该区域位置坐标相对窗口右上角。 |
8660
8661**错误码:**
8662
8663以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8664
8665| 错误码ID | 错误信息                       |
8666| -------- | ------------------------------ |
8667| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
8668| 1300002  | This window state is abnormal. |
8669
8670**示例:**
8671
8672```ts
8673// EntryAbility.ets
8674import { UIAbility } from '@kit.AbilityKit';
8675import { BusinessError } from '@kit.BasicServicesKit';
8676
8677export default class EntryAbility extends UIAbility {
8678  // ...
8679  onWindowStageCreate(windowStage: window.WindowStage): void {
8680    console.info('onWindowStageCreate');
8681    let windowClass: window.Window | undefined = undefined;
8682    windowStage.getMainWindow((err: BusinessError, data) => {
8683      const errCode: number = err.code;
8684      if (errCode) {
8685        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
8686        return;
8687      }
8688      windowClass = data;
8689      try {
8690        let titleButtonArea = windowClass.getTitleButtonRect();
8691        console.info('Succeeded in obtaining the area of title buttons. Data: ' + JSON.stringify(titleButtonArea));
8692      } catch (exception) {
8693        console.error(`Failed to get the area of title buttons. Cause code: ${exception.code}, message: ${exception.message}`);
8694      }
8695    });
8696  }
8697}
8698```
8699
8700### getWindowStatus<sup>12+</sup>
8701
8702getWindowStatus(): WindowStatusType
8703
8704获取当前应用窗口的模式。
8705
8706**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8707
8708**系统能力:** SystemCapability.Window.SessionManager
8709
8710**返回值:**
8711
8712| 类型                           | 说明                                   |
8713| ------------------------------ | ----------------------------------------|
8714| [WindowStatusType](#windowstatustype11) | 当前窗口模式。                              |
8715
8716**错误码:**
8717
8718以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8719
8720| 错误码ID | 错误信息 |
8721| ------- | ------------------------------ |
8722| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
8723| 1300002  | This window state is abnormal. |
8724
8725**示例:**
8726
8727```ts
8728try {
8729  let windowStatusType = windowClass.getWindowStatus();
8730} catch (exception) {
8731  console.error(`Failed to obtain the window status of window. Cause code: ${exception.code}, message: ${exception.message}`);
8732}
8733```
8734
8735### isFocused<sup>12+</sup>
8736
8737isFocused(): boolean
8738
8739判断当前窗口是否已获焦。
8740
8741**系统能力:** SystemCapability.WindowManager.WindowManager.Core
8742
8743**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8744
8745**返回值:**
8746
8747| 类型 | 说明 |
8748| ------- | ------------------------------------------------------------------ |
8749| boolean | 当前窗口是否已获焦。true表示当前窗口已获焦,false则表示当前窗口未获焦。 |
8750
8751**错误码:**
8752
8753以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
8754
8755| 错误码ID | 错误信息 |
8756| ------- | ------------------------------ |
8757| 1300002 | This window state is abnormal. |
8758
8759**示例:**
8760
8761```ts
8762try {
8763  let focus = windowClass.isFocused();
8764  console.info('Succeeded in checking whether the window is focused. Data: ' + JSON.stringify(focus));
8765} catch (exception) {
8766  console.error(`Failed to check whether the window is focused. Cause code: ${exception.code}, message: ${exception.message}`);
8767}
8768```
8769
8770### createSubWindowWithOptions<sup>12+</sup>
8771
8772createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise&lt;Window&gt;
8773
8774创建主窗口、子窗口或悬浮窗下的子窗口,使用Promise异步回调。
8775
8776<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
8777
8778**模型约束:** 此接口仅可在Stage模型下使用。
8779
8780**系统能力:** SystemCapability.Window.SessionManager
8781
8782**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8783
8784**参数:**
8785
8786| 参数名 | 类型   | 必填 | 说明           |
8787| ------ | ------ | ---- | -------------- |
8788| name   | string | 是   | 子窗口的名字。 |
8789| options  | [SubWindowOptions](#subwindowoptions11) | 是   | 子窗口参数。  |
8790
8791**返回值:**
8792
8793| 类型                             | 说明                                             |
8794| -------------------------------- | ------------------------------------------------ |
8795| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前Window下创建的子窗口对象。 |
8796
8797**错误码:**
8798
8799以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8800
8801| 错误码ID | 错误信息 |
8802| ------- | ------------------------------ |
8803| 401     | Parameter error. Possible cause: Incorrect parameter types. |
8804| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
8805| 1300002 | This window state is abnormal. |
8806| 1300003 | This window manager service works abnormally. |
8807| 1300004 | Unauthorized operation. |
8808
8809**示例:**
8810
8811```ts
8812import { BusinessError } from '@kit.BasicServicesKit';
8813
8814try {
8815  let options : window.SubWindowOptions = {
8816    title: 'title',
8817    decorEnabled: true,
8818    isModal: true
8819  };
8820  let promise = windowClass.createSubWindowWithOptions('mySubWindow', options);
8821  promise.then((data) => {
8822    console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
8823  }).catch((err: BusinessError) => {
8824    console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`);
8825  });
8826} catch (exception) {
8827  console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`);
8828}
8829```
8830
8831### setParentWindow<sup>19+</sup>
8832
8833setParentWindow(windowId: number): Promise&lt;void&gt;
8834
8835更改子窗口的父窗口,该父窗口仅支持主窗口、子窗口或悬浮窗,使用Promise异步回调。
8836
8837如果该子窗口处于获焦状态,且新的父窗口处于前台,则会抬升父窗口的层级。
8838
8839如果该子窗口处于获焦状态,且新的父窗口的子窗口存在层级更高的模态子窗口,则焦点会转移给该模态子窗口。
8840
8841此接口仅可在2in1设备下使用。
8842
8843**系统能力:** SystemCapability.Window.SessionManager
8844
8845**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
8846
8847**参数:**
8848
8849| 参数名 | 类型   | 必填 | 说明           |
8850| ------ | ------ | ---- | -------------- |
8851| windowId  | number | 是   | 父窗口id,该参数应为整数。推荐使用[getWindowProperties()](#getwindowproperties9)方法获取父窗口id属性。|
8852
8853**返回值:**
8854
8855| 类型                | 说明                     |
8856| ------------------- | ------------------------|
8857| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8858
8859**错误码:**
8860
8861以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8862
8863| 错误码ID | 错误信息 |
8864| ------- | ------------------------------ |
8865| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
8866| 1300002 | This window state is abnormal. |
8867| 1300003 | This window manager service works abnormally. |
8868| 1300004 | Unauthorized operation. |
8869| 1300009 | The parent window is invaild. |
8870
8871**示例:**
8872
8873```ts
8874import { BusinessError } from '@kit.BasicServicesKit';
8875
8876try {
8877  let windowClass: window.Window = window.findWindow("subWindow");
8878  let newParentWindow: window.Window = window.findWindow("newParentWindow");
8879  let newParentWindowId: number = newParentWindow.getWindowProperties().id;
8880  let promise = windowClass.setParentWindow(newParentWindowId);
8881  promise.then(() => {
8882    console.info('Succeeded in setting the new parent window.');
8883  }).catch((err: BusinessError) => {
8884    console.error(`Failed to set the new parent window. Cause code: ${err.code}, message: ${err.message}`);
8885  });
8886} catch (exception) {
8887  console.error(`Failed to set the new parent window. Cause code: ${exception.code}, message: ${exception.message}`);
8888}
8889```
8890
8891### getParentWindow<sup>19+</sup>
8892
8893getParentWindow(): Window
8894
8895获取子窗口的父窗口。
8896
8897此接口仅可在2in1设备下使用。
8898
8899**系统能力:** SystemCapability.Window.SessionManager
8900
8901**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
8902
8903**返回值:**
8904
8905| 类型 | 说明 |
8906| ----------------- | ------------------- |
8907| [Window](#window) | 子窗口的父窗口对象。 |
8908
8909**错误码:**
8910
8911以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8912
8913| 错误码ID | 错误信息 |
8914| ------- | ------------------------------ |
8915| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
8916| 1300002 | This window state is abnormal. |
8917| 1300004 | Unauthorized operation. |
8918| 1300009 | The parent window is invaild. |
8919
8920**示例:**
8921
8922```ts
8923try {
8924  let windowClass: window.Window = window.findWindow("subWindow");
8925  let parentWindow: window.Window = windowClass.getParentWindow();
8926  let properties = parentWindow.getWindowProperties();
8927  console.info('Succeeded in obtaining parent window properties. Property: ' + JSON.stringify(properties));
8928} catch (exception) {
8929  console.error(`Failed to get the parent window. Cause code: ${exception.code}, message: ${exception.message}`);
8930}
8931```
8932
8933### setWindowTitleButtonVisible<sup>14+</sup>
8934
8935setWindowTitleButtonVisible(isMaximizeButtonVisible: boolean, isMinimizeButtonVisible: boolean, isCloseButtonVisible?: boolean): void
8936
8937设置主窗标题栏上的最大化、最小化、关闭按钮是否可见。
8938
8939<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
8940
8941**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
8942
8943**系统能力:** SystemCapability.Window.SessionManager
8944
8945**参数:**
8946
8947| 参数名    | 类型    | 必填 | 说明                                          |
8948| --------- | ------- | ---- | --------------------------------------------- |
8949| isMaximizeButtonVisible | boolean | 是   | 设置最大化按钮是否可见,true为可见,false为隐藏。如果最大化按钮隐藏,那么在最大化场景下,也隐藏对应的还原按钮。 |
8950| isMinimizeButtonVisible | boolean | 是   | 设置最小化按钮是否可见,true为可见,false为隐藏。 |
8951| isCloseButtonVisible | boolean | 否   | 设置关闭按钮是否可见,true为可见,false为隐藏,默认值true。 |
8952
8953**错误码:**
8954
8955以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
8956
8957| 错误码ID | 错误信息                       |
8958| -------- | ------------------------------ |
8959| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8960| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
8961| 1300002  | This window state is abnormal. |
8962| 1300004  | Unauthorized operation. |
8963
8964**示例:**
8965
8966```ts
8967// EntryAbility.ets
8968import { UIAbility } from '@kit.AbilityKit';
8969import { BusinessError } from '@kit.BasicServicesKit';
8970import { window } from '@kit.ArkUI';
8971
8972export default class EntryAbility extends UIAbility {
8973  onWindowStageCreate(windowStage: window.WindowStage): void {
8974    // 加载主窗口对应的页面
8975    windowStage.loadContent('pages/Index', (err) => {
8976      let mainWindow: window.Window | undefined = undefined;
8977      // 获取应用主窗口。
8978      windowStage.getMainWindow().then(
8979        data => {
8980          mainWindow = data;
8981          console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
8982          // 调用setWindowTitleButtonVisible接口,隐藏主窗标题栏最大化、最小化、关闭按钮。
8983          mainWindow.setWindowTitleButtonVisible(false, false, false);
8984        }
8985      ).catch((err: BusinessError) => {
8986          if(err.code){
8987            console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
8988          }
8989      });
8990    });
8991  }
8992}
8993```
8994
8995### setWindowTopmost<sup>14+</sup>
8996
8997setWindowTopmost(isWindowTopmost: boolean): Promise&lt;void&gt;
8998
8999应用主窗口调用,实现将窗口置于其他应用窗口之上不被遮挡,使用Promise异步回调。
9000
9001应用可通过自定义快捷键实现主窗口的置顶和取消置顶。
9002
9003<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
9004
9005**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
9006
9007**系统能力:** SystemCapability.Window.SessionManager
9008
9009**需要权限:** ohos.permission.WINDOW_TOPMOST
9010
9011**参数:**
9012
9013| 参数名    | 类型    | 必填 | 说明                                          |
9014| --------- | ------- | ---- | --------------------------------------------- |
9015| isWindowTopmost | boolean | 是   | 设置主窗口置顶,true为置顶,false为取消置顶。 |
9016
9017
9018**错误码:**
9019
9020以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9021
9022| 错误码ID | 错误信息                       |
9023| -------- | ------------------------------ |
9024| 201      | Permission verification failed. The application does not have the permission required to call the API.  |
9025| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9026| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
9027| 1300002  | This window state is abnormal. |
9028| 1300004  | Unauthorized operation. |
9029
9030**示例:**
9031
9032```ts
9033// ets/pages/Index.ets
9034import { window } from '@kit.ArkUI';
9035import { common } from '@kit.AbilityKit';
9036import { BusinessError } from '@kit.BasicServicesKit';
9037
9038let windowClass: window.Window | undefined;
9039let keyUpEventAry: string[] = [];
9040
9041@Entry
9042@Component
9043struct Index {
9044  private context = (this.getUIContext()?.getHostContext() as common.UIAbilityContext);
9045
9046  build() {
9047    RelativeContainer() {
9048      Button("窗口置顶")
9049        .onClick(() => {
9050          try {
9051            let promiseCtx = window.getLastWindow(this.context);
9052            promiseCtx.then((data) => {
9053              windowClass = data;
9054              //  true:窗口置顶,false:取消窗口置顶
9055              let isWindowTopmost: boolean = true;
9056              let promiseTopmost = windowClass.setWindowTopmost(isWindowTopmost);
9057              promiseTopmost.then(() => {
9058                console.info('Succeeded in setting the main window to be topmost.');
9059              }).catch((err: BusinessError) => {
9060                console.error(`Failed to set the main window to be topmost. Cause code: ${err.code}, message: ${err.message}`);
9061              });
9062            })
9063          } catch (exception) {
9064            console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`)
9065          }
9066        })
9067    }
9068    .height('100%')
9069    .width('100%')
9070    .onKeyEvent((event) => {
9071      if(event) {
9072        if(event.type === KeyType.Down) {
9073          keyUpEventAry = [];
9074        }
9075        if(event.type === KeyType.Up) {
9076          keyUpEventAry.push(event.keyText);
9077          // 自定义快捷键 ctrl+T 执行主窗口置顶、取消置顶的操作
9078          if(windowClass && keyUpEventAry.includes('KEYCODE_CTRL_LEFT') && keyUpEventAry.includes('KEYCODE_T')) {
9079            let isWindowTopmost: boolean = false;
9080            windowClass.setWindowTopmost(isWindowTopmost);
9081          }
9082        }
9083      }
9084    })
9085  }
9086}
9087```
9088
9089### raiseToAppTop<sup>14+</sup>
9090
9091raiseToAppTop(): Promise&lt;void&gt;
9092
9093应用子窗口调用,提升应用子窗口到顶层,只在当前应用同一个父窗口下的相同类型子窗范围内生效,对于自定义了zLevel属性的子窗口,只在当前应用同一个父窗口下相同zLevel值的子窗范围内生效。使用Promise异步回调。
9094
9095使用该接口需要先创建子窗口,并确保该子窗口调用[showWindow()](#showwindow9)并执行完毕。
9096
9097**系统能力:** SystemCapability.WindowManager.WindowManager.Core
9098
9099**返回值:**
9100
9101| 类型                | 说明                      |
9102| ------------------- | ------------------------- |
9103| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9104
9105**错误码:**
9106
9107以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9108
9109| 错误码ID | 错误信息 |
9110| ------- | ------------------------------ |
9111| 1300002 | This window state is abnormal. |
9112| 1300003 | This window manager service works abnormally. |
9113| 1300004 | Unauthorized operation. |
9114| 1300009 | The parent window is invalid. |
9115
9116**示例:**
9117
9118```ts
9119// EntryAbility.ets
9120import { window } from '@kit.ArkUI';
9121import { UIAbility } from '@kit.AbilityKit';
9122import { BusinessError } from '@kit.BasicServicesKit';
9123
9124export default class EntryAbility extends UIAbility {
9125  // ...
9126  onWindowStageCreate(windowStage: window.WindowStage): void {
9127    console.info('onWindowStageCreate');
9128    // 创建子窗
9129    windowStage.createSubWindow('testSubWindow').then((subWindow) => {
9130      if (subWindow == null) {
9131        console.error('Failed to create the subWindow. Cause: The data is empty');
9132        return;
9133      }
9134      subWindow.showWindow().then(() => {
9135        subWindow.raiseToAppTop().then(() => {
9136          console.info('Succeeded in raising window to app top');
9137        }).catch((err: BusinessError)=>{
9138          console.error(`Failed to raise window to app top. Cause code: ${err.code}, message: ${err.message}`);
9139        });
9140      });
9141    });
9142  }
9143}
9144```
9145
9146### setRaiseByClickEnabled<sup>14+</sup>
9147
9148setRaiseByClickEnabled(enable: boolean): Promise&lt;void&gt;
9149
9150禁止/使能子窗点击抬升功能。使用Promise异步回调。
9151
9152通常来说,点击一个子窗口,会将该子窗口显示抬升到应用内同一个父窗口下同类型子窗口的最上方,如果设置为false,那么点击子窗口的时候,不会将该子窗口进行抬升,而是保持不变。
9153
9154使用该接口需要先创建子窗口,并确保该子窗口调用[showWindow()](#showwindow9)并执行完毕。
9155
9156**系统能力:** SystemCapability.Window.SessionManager
9157
9158**参数:**
9159
9160| 参数名   | 类型                      | 必填 | 说明       |
9161| -------- | ------------------------- | ---- | ---------- |
9162| enable   | boolean                   | 是   | 设置子窗口点击抬升功能是否使能,true表示使能,false表示禁止。 |
9163
9164**返回值:**
9165
9166| 类型                | 说明                      |
9167| ------------------- | ------------------------- |
9168| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9169
9170**错误码:**
9171
9172以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9173
9174| 错误码ID | 错误信息 |
9175| ------- | ------------------------------ |
9176| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9177| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
9178| 1300002 | This window state is abnormal. |
9179| 1300003 | This window manager service works abnormally. |
9180| 1300004 | Unauthorized operation. |
9181| 1300009 | The parent window is invalid. |
9182
9183**示例:**
9184
9185```ts
9186// EntryAbility.ets
9187import { window } from '@kit.ArkUI';
9188import { UIAbility } from '@kit.AbilityKit';
9189import { BusinessError } from '@kit.BasicServicesKit';
9190
9191export default class EntryAbility extends UIAbility {
9192  // ...
9193  onWindowStageCreate(windowStage: window.WindowStage): void {
9194    console.info('onWindowStageCreate');
9195    // 创建子窗
9196    windowStage.createSubWindow("testSubWindow").then((subWindow) => {
9197      if (subWindow == null) {
9198        console.error('Failed to create the subWindow. Cause: The data is empty');
9199        return;
9200      }
9201      subWindow.showWindow().then(() => {
9202        try {
9203          let enabled = false;
9204          subWindow.setRaiseByClickEnabled(enabled).then(() => {
9205            console.info('Succeeded in disabling the raise-by-click function.');
9206          }).catch((err: BusinessError) => {
9207            console.error(`Failed to disable the raise-by-click function. Cause code: ${err.code}, message: ${err.message}`);
9208          });
9209        } catch (err) {
9210          console.error(`Failed to disable the raise-by-click function. Cause code: ${err.code}, message: ${err.message}`);
9211        }
9212      });
9213    });
9214  }
9215}
9216```
9217
9218### enableLandscapeMultiWindow<sup>12+</sup>
9219
9220enableLandscapeMultiWindow(): Promise&lt;void&gt;
9221
9222应用部分界面支持横向布局时,在进入该界面时使能,使能后可支持进入横向多窗。不建议竖向布局界面使用。
9223
9224此接口只对应用主窗口生效,且需要在module.json5配置文件中[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中配置preferMultiWindowOrientation属性为"landscape_auto"。
9225
9226**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
9227
9228**系统能力:** SystemCapability.Window.SessionManager
9229
9230**返回值:**
9231
9232| 类型                | 说明                      |
9233| ------------------- | ------------------------- |
9234| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9235
9236**错误码:**
9237
9238以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
9239
9240| 错误码ID | 错误信息 |
9241| ------- | -------------------------------------------- |
9242| 1300002 | This window state is abnormal.               |
9243| 1300003 | This window manager service works abnormally. |
9244
9245**示例:**
9246
9247```ts
9248// EntryAbility.ets
9249import { UIAbility } from '@kit.AbilityKit';
9250import { BusinessError } from '@kit.BasicServicesKit';
9251import { window } from '@kit.ArkUI';
9252
9253export default class EntryAbility extends UIAbility {
9254  // ...
9255  onWindowStageCreate(windowStage: window.WindowStage): void {
9256    console.info('onWindowStageCreate');
9257    let windowClass: window.Window | undefined = undefined;
9258    windowStage.getMainWindow((err: BusinessError, data) => {
9259      const errCode: number = err.code;
9260      if (errCode) {
9261        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
9262        return;
9263      }
9264      windowClass = data;
9265      let promise = windowClass.enableLandscapeMultiWindow();
9266      promise.then(() => {
9267        console.info('Succeeded in making multi-window become landscape.');
9268      }).catch((err: BusinessError) => {
9269        console.error(`Failed to make multi-window become landscape. Cause code: ${err.code}, message: ${err.message}`);
9270      });
9271    });
9272  }
9273}
9274```
9275
9276### disableLandscapeMultiWindow<sup>12+</sup>
9277
9278disableLandscapeMultiWindow(): Promise&lt;void&gt;
9279
9280应用部分界面支持横向布局时,在退出该界面时去使能,去使能后不支持进入横向多窗。
9281
9282此接口只对应用主窗口生效,且需要在module.json5配置文件中[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中配置preferMultiWindowOrientation属性为"landscape_auto"。
9283
9284**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
9285
9286**系统能力:** SystemCapability.Window.SessionManager
9287
9288**返回值:**
9289
9290| 类型                | 说明                      |
9291| ------------------- | ------------------------- |
9292| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9293
9294**错误码:**
9295
9296以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
9297
9298| 错误码ID | 错误信息 |
9299| ------- | -------------------------------------------- |
9300| 1300002 | This window state is abnormal.               |
9301| 1300003 | This window manager service works abnormally. |
9302
9303**示例:**
9304
9305```ts
9306// EntryAbility.ets
9307import { UIAbility } from '@kit.AbilityKit';
9308import { BusinessError } from '@kit.BasicServicesKit';
9309import { window } from '@kit.ArkUI';
9310
9311export default class EntryAbility extends UIAbility {
9312  // ...
9313  onWindowStageCreate(windowStage: window.WindowStage): void {
9314    console.info('onWindowStageCreate');
9315    let windowClass: window.Window | undefined = undefined;
9316    windowStage.getMainWindow((err: BusinessError, data) => {
9317      const errCode: number = err.code;
9318      if (errCode) {
9319        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
9320        return;
9321      }
9322      windowClass = data;
9323      let promise = windowClass.disableLandscapeMultiWindow();
9324      promise.then(() => {
9325        console.info('Succeeded in making multi-window become not landscape.');
9326      }).catch((err: BusinessError) => {
9327        console.error(`Failed to make multi-window become not landscape. Cause code: ${err.code}, message: ${err.message}`);
9328      });
9329    });
9330  }
9331}
9332```
9333
9334### setDialogBackGestureEnabled<sup>12+</sup>
9335
9336setDialogBackGestureEnabled(enabled: boolean): Promise&lt;void&gt;
9337
9338设置模态窗口是否响应手势返回事件,非模态窗口调用返回错误码。
9339
9340**系统能力**:SystemCapability.Window.SessionManager
9341
9342**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
9343
9344**参数:**
9345
9346| 参数名      | 类型    | 必填 | 说明                                                         |
9347| ---------- | ------- | ---- | ------------------------------------------------------------ |
9348| enabled    | boolean | 是   | 是否响应手势返回事件。<br>true表示响应手势返回事件,触发onBackPress回调;false表示不响应手势返回事件,不触发onBackPress回调。</br> |
9349
9350**返回值:**
9351
9352| 类型                | 说明                      |
9353| ------------------- | ------------------------- |
9354| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9355
9356**错误码:**
9357
9358以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9359
9360| 错误码ID | 错误信息 |
9361| ------- | -------------------------------------------- |
9362| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9363| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
9364| 1300002 | This window state is abnormal. |
9365| 1300003  | This window manager service works abnormally. |
9366| 1300004 | Unauthorized operation. |
9367
9368**示例:**
9369
9370```ts
9371// EntryAbility.ets
9372import { UIAbility } from '@kit.AbilityKit';
9373import { BusinessError } from '@kit.BasicServicesKit';
9374
9375export default class EntryAbility extends UIAbility {
9376  onWindowStageCreate(windowStage: window.WindowStage): void {
9377    console.info('onWindowStageCreate');
9378    let windowClass: window.Window | undefined = undefined;
9379    let config: window.Configuration = {
9380      name: "test",
9381      windowType: window.WindowType.TYPE_DIALOG,
9382      ctx: this.context
9383    };
9384    try {
9385      window.createWindow(config, (err: BusinessError, data) => {
9386        const errCode: number = err.code;
9387        if (errCode) {
9388          console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`);
9389          return;
9390        }
9391        windowClass = data;
9392        windowClass.setUIContent("pages/Index");
9393        let enabled = true;
9394        let promise = windowClass.setDialogBackGestureEnabled(enabled);
9395        promise.then(() => {
9396          console.info('Succeeded in setting dialog window to respond back gesture.');
9397        }).catch((err: BusinessError) => {
9398          console.error(`Failed to set dialog window to respond back gesture. Cause code: ${err.code}, message: ${err.message}`);
9399        });
9400      });
9401    } catch (exception) {
9402      console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`);
9403    }
9404  }
9405}
9406```
9407
9408```ts
9409// ets/pages/Index.ets
9410@Entry
9411@Component
9412struct Index {
9413  @State message: string = 'Hello World'
9414  build() {
9415    RelativeContainer() {
9416      Text(this.message)
9417        .id('HelloWorld')
9418        .fontSize(50)
9419        .fontWeight(FontWeight.Bold)
9420    }
9421    .height('100%')
9422    .width('100%')
9423  }
9424
9425  onBackPress(): boolean | void {
9426    console.info('Succeeded in setting dialog window to respond back gesture.');
9427    return true;
9428  }
9429}
9430```
9431
9432### startMoving<sup>14+</sup>
9433
9434startMoving(): Promise&lt;void&gt;
9435
9436开始移动窗口,使用Promise异步回调。
9437
9438仅在[onTouch](./arkui-ts/ts-universal-events-touch.md#ontouch)事件(其中,事件类型必须为TouchType.Down)的回调方法中调用此接口才会有移动效果,成功调用此接口后,窗口将跟随鼠标或触摸点移动。
9439
9440<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
9441
9442仅对主窗、子窗、系统窗口生效,其它设备类型和窗口类型调用此接口会报错。
9443
9444**系统能力:** SystemCapability.Window.SessionManager
9445
9446**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
9447
9448**返回值:**
9449
9450| 类型                | 说明                      |
9451| ------------------- | ------------------------- |
9452| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9453
9454**错误码:**
9455
9456以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9457
9458| 错误码ID | 错误信息 |
9459| -------- | -------------------------------------------- |
9460| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
9461| 1300001 | Repeated operation. |
9462| 1300002 | This window state is abnormal.                |
9463| 1300003 | This window manager service works abnormally. |
9464| 1300004 | Unauthorized operation.                       |
9465
9466**示例:**
9467
9468```ts
9469// ets/pages/Index.ets
9470import { BusinessError } from '@kit.BasicServicesKit';
9471
9472@Entry
9473@Component
9474struct Index {
9475  build() {
9476    Row() {
9477      Column() {
9478        Blank('160')
9479          .color(Color.Blue)
9480          .onTouch((event: TouchEvent) => {
9481            if (event.type === TouchType.Down) {
9482              try {
9483                let windowClass: window.Window = window.findWindow("subWindow");
9484                windowClass.startMoving().then(() => {
9485                  console.info('Succeeded in starting moving window.')
9486                }).catch((err: BusinessError) => {
9487                  console.error(`Failed to start moving. Cause code: ${err.code}, message: ${err.message}`);
9488                });
9489              } catch (exception) {
9490                console.error(`Failed to start moving window. Cause code: ${exception.code}, message: ${exception.message}`);
9491              }
9492            }
9493          })
9494      }.width('100%')
9495    }.height('100%').width('100%')
9496  }
9497}
9498```
9499
9500### startMoving<sup>15+</sup>
9501
9502startMoving(offsetX: number, offsetY: number): Promise&lt;void&gt;
9503
9504指定鼠标在窗口内的位置并移动窗口,使用Promise异步回调。
9505
9506在同应用内窗口分合后,且鼠标保持按下状态直接移动新窗口,如果此时鼠标快速移动,窗口移动时鼠标可能会在窗口外。可以使用本接口指定窗口移动时鼠标在窗口内的位置,先移动窗口到鼠标位置,再开始移动窗口。
9507
9508仅在[onTouch](./arkui-ts/ts-universal-events-touch.md#ontouch)事件(其中,事件类型必须为TouchType.Down)的回调方法中调用此接口才会有移动效果,成功调用此接口后,窗口将跟随鼠标移动。
9509
9510<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
9511
9512**系统能力:** SystemCapability.Window.SessionManager
9513
9514**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
9515
9516**参数:**
9517
9518| 参数名     | 类型       | 必填     | 说明                                                 |
9519| --------- | --------- | ------- |----------------------------------------------------|
9520| offsetX | number | 是 | 窗口移动时预期鼠标位置相对窗口左上角的x轴偏移量,单位为px,该参数仅支持整数输入,浮点数向下取整。负值为非法参数,大于窗口宽度为非法参数,窗口宽度可以在窗口属性[WindowProperties](#windowproperties)中获取。 |
9521| offsetY | number | 是 | 窗口移动时预期鼠标位置相对窗口左上角的y轴偏移量,单位为px,该参数仅支持整数输入,浮点数向下取整。负值为非法参数,大于窗口高度为非法参数,窗口高度可以在窗口属性[WindowProperties](#windowproperties)中获取。 |
9522
9523**返回值:**
9524
9525| 类型                | 说明                         |
9526| ------------------- |----------------------------|
9527| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9528
9529**错误码:**
9530
9531以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9532
9533| 错误码ID | 错误信息 |
9534| ---- | -------------------------------------------- |
9535| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9536| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
9537| 1300001 | Repeated operation. |
9538| 1300002 | This window state is abnormal.                |
9539| 1300003 | This window manager service works abnormally. |
9540| 1300004 | Unauthorized operation.                       |
9541
9542**示例:**
9543
9544```ts
9545// ets/pages/Index.ets
9546import { BusinessError } from '@kit.BasicServicesKit';
9547
9548@Entry
9549@Component
9550struct Index {
9551  build() {
9552    Row() {
9553      Column() {
9554        Blank('160')
9555          .color(Color.Blue)
9556          .onTouch((event: TouchEvent) => {
9557            if (event.type === TouchType.Down) {
9558              try {
9559                let windowClass: window.Window = window.findWindow("subWindow");
9560                windowClass.startMoving(100, 50).then(() => {
9561                  console.info('Succeeded in starting moving window.')
9562                }).catch((err: BusinessError) => {
9563                  console.error(`Failed to start moving. Cause code: ${err.code}, message: ${err.message}`);
9564                });
9565              } catch (exception) {
9566                console.error(`Failed to start moving window. Cause code: ${exception.code}, message: ${exception.message}`);
9567              }
9568            }
9569          })
9570      }.width('100%')
9571    }.height('100%').width('100%')
9572  }
9573}
9574```
9575
9576### stopMoving<sup>15+</sup>
9577
9578stopMoving(): Promise&lt;void&gt;
9579
9580在窗口拖拽移动过程中,通过此接口来停止窗口移动,使用Promise异步回调。
9581
9582<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
9583
9584**系统能力:** SystemCapability.Window.SessionManager
9585
9586**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
9587
9588**返回值:**
9589
9590| 类型                | 说明                      |
9591| ------------------- | -------------------------|
9592| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9593
9594**错误码:**
9595
9596以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9597
9598| 错误码ID | 错误信息 |
9599| -------- | -------------------------------------------- |
9600| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
9601| 1300002 | This window state is abnormal.                |
9602| 1300003 | This window manager service works abnormally. |
9603| 1300004 | Unauthorized operation.                       |
9604
9605**示例:**
9606
9607```ts
9608// EntryAbility.ets
9609import { UIAbility } from '@kit.AbilityKit';
9610import { window } from '@kit.ArkUI';
9611import { BusinessError } from '@kit.BasicServicesKit';
9612
9613export default class EntryAbility extends UIAbility {
9614
9615  onWindowStageCreate(windowStage: window.WindowStage) {
9616    try {
9617      let windowClass = windowStage.getMainWindowSync();
9618      windowClass.on('windowRectChange', (data: window.RectChangeOptions) => {
9619        if (data.reason === window.RectChangeReason.MOVE) {
9620          windowClass.stopMoving().then(() => {
9621            console.info('Succeeded in stopping moving window.')
9622          }).catch((err: BusinessError) => {
9623            console.error(`Failed to stop moving. Cause code: ${err.code}, message: ${err.message}`);
9624          });
9625        }
9626      });
9627    } catch (exception) {
9628      console.error(`Failed to stop moving window. Cause code: ${exception.code}, message: ${exception.message}`);
9629    }
9630  }
9631}
9632```
9633
9634### setGestureBackEnabled<sup>13+<sup>
9635
9636setGestureBackEnabled(enabled: boolean): Promise&lt;void&gt;
9637
9638设置当前窗口是否禁用返回手势功能,仅主窗全屏模式下生效,2in1设备下不生效。
9639禁用返回手势功能后,当前应用会禁用手势热区,侧滑返回功能失效;切换到其他应用或者回到桌面后,手势热区恢复,侧滑返回功能正常。
9640开启返回手势功能后,当前应用会恢复手势热区,侧滑返回功能正常。
9641
9642**系统能力:** SystemCapability.Window.SessionManager
9643
9644**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
9645
9646**参数:**
9647
9648| 参数名     | 类型       | 必填     | 说明                                           |
9649| ---------- | --------- | -------- | --------------------------------------------- |
9650| enabled    | boolean   | 是       | true时开启返回手势功能,false时禁用返回手势功能。 |
9651
9652**返回值:**
9653
9654| 类型                | 说明                      |
9655| ------------------- | ------------------------- |
9656| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9657
9658**错误码:**
9659
9660以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9661
9662| 错误码ID | 错误信息                                                                                                     |
9663| -------- | ------------------------------------------------------------------------------------------------------------ |
9664| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9665| 801      | Capability not supported. Failed to call the API due to limited device capabilities.                         |
9666| 1300002  | This window state is abnormal.                                                                               |
9667| 1300003  | This window manager service works abnormally.                                                                |
9668| 1300004  | Unauthorized operation.                                                                                |
9669
9670**示例:**
9671
9672```ts
9673// EntryAbility.ets
9674import { UIAbility } from '@kit.AbilityKit';
9675import { BusinessError } from '@kit.BasicServicesKit';
9676import { window } from '@kit.ArkUI';
9677
9678export default class EntryAbility extends UIAbility {
9679  // ...
9680  onWindowStageCreate(windowStage: window.WindowStage): void {
9681    console.info('onWindowStageCreate');
9682    let windowClass: window.Window | undefined = undefined;
9683    windowStage.getMainWindow((err: BusinessError, data) => {
9684      const errCode: number = err.code;
9685      if (errCode) {
9686        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
9687        return;
9688      }
9689      windowClass = data;
9690
9691      // 设置当前窗口禁用返回手势功能
9692      try {
9693        let gestureBackEnabled: boolean = false;
9694        let promise = windowClass.setGestureBackEnabled(gestureBackEnabled);
9695        promise.then(() => {
9696          console.info(`Succeeded in setting gesture back disabled`);
9697        }).catch((err: BusinessError) => {
9698          console.error(`Failed to set gesture back disabled, Cause code: ${err.code}, message: ${err.message}`);
9699        });
9700      } catch(exception) {
9701        console.error(`Failed to set gesture back disabled, Cause code: ${exception.code}, message: ${exception.message}`);
9702      }
9703    });
9704  }
9705}
9706```
9707
9708### isGestureBackEnabled<sup>13+<sup>
9709
9710isGestureBackEnabled(): boolean
9711
9712获取当前窗口是否禁用返回手势功能,仅主窗全屏模式下生效,2in1设备不生效。
9713
9714**系统能力:** SystemCapability.Window.SessionManager
9715
9716**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
9717
9718**返回值:**
9719
9720| 类型                | 说明                                           |
9721| ------------------- | --------------------------------------------- |
9722| boolean             | 是否已经禁用返回手势。true表示未禁用返回手势功能,false表示已禁用返回手势功能。 |
9723
9724**错误码:**
9725
9726以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9727
9728| 错误码ID | 错误信息                                                                                                     |
9729| -------- | ------------------------------------------------------------------------------------------------------------ |
9730| 801      | Capability not supported. Failed to call the API due to limited device capabilities.                         |
9731| 1300002  | This window state is abnormal.                                                                               |
9732| 1300003  | This window manager service works abnormally.                                                                |
9733| 1300004  | Unauthorized operation.                                                                                |
9734
9735**示例:**
9736
9737```ts
9738// EntryAbility.ets
9739import { UIAbility } from '@kit.AbilityKit';
9740import { BusinessError } from '@kit.BasicServicesKit';
9741import { window } from '@kit.ArkUI';
9742
9743export default class EntryAbility extends UIAbility {
9744  // ...
9745  onWindowStageCreate(windowStage: window.WindowStage): void {
9746    console.info('onWindowStageCreate');
9747    let windowClass: window.Window | undefined = undefined;
9748    windowStage.getMainWindow((err: BusinessError, data) => {
9749      const errCode: number = err.code;
9750      if (errCode) {
9751        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
9752        return;
9753      }
9754      windowClass = data;
9755
9756      // 获取当前窗口是否禁用返回手势功能
9757      try {
9758        let gestureBackEnabled: boolean = windowClass.isGestureBackEnabled();
9759        console.info(`Succeeded in obtaining gesture back enabled status: ${gestureBackEnabled}`);
9760      } catch (exception) {
9761        console.error(`Failed to get gesture back enabled status. Cause code: ${exception.code}, message: ${exception.message}`);
9762      }
9763    });
9764  }
9765}
9766```
9767
9768### setWindowShadowRadius<sup>17+</sup>
9769
9770setWindowShadowRadius(radius: number): void
9771
9772设置子窗或悬浮窗窗口边缘阴影的模糊半径,此接口仅支持在2in1设备或平板设备上使用。
9773
9774**系统能力:** SystemCapability.Window.SessionManager
9775
9776**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。
9777
9778**参数:**
9779
9780| 参数名  | 类型   | 必填 | 说明                                                          |
9781| ------- | ------ | ---- |-------------------------------------------------------------|
9782| radius  | number | 是   | 表示窗口边缘阴影的模糊半径。该参数为浮点数,单位为px,取值范围为[0.0, +∞),取值为0.0时表示关闭窗口边缘阴影。     |
9783
9784**错误码:**
9785
9786以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9787
9788| 错误码ID | 错误信息 |
9789| ------- | ------------------------------ |
9790| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
9791| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
9792| 1300002 | This window state is abnormal. |
9793| 1300004 | Unauthorized operation.  |
9794
9795**示例:**
9796
9797```ts
9798try {
9799  windowClass.setWindowShadowRadius(4.0);
9800} catch (exception) {
9801  console.error(`Failed to set shadow. Cause code: ${exception.code}, message: ${exception.message}`);
9802}
9803```
9804
9805### setWindowCornerRadius<sup>17+</sup>
9806
9807setWindowCornerRadius(cornerRadius: number): Promise&lt;void&gt;
9808
9809设置子窗或悬浮窗的圆角半径值,使用Promise异步回调。
9810
9811<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
9812
9813圆角半径值过大将会导致三键(最大化、最小化、关闭按钮)位置被裁切,且会导致热区不易识别,请根据窗口大小设置合适的圆角半径值。
9814
9815在调用此接口之前调用[getWindowCornerRadius()](#getwindowcornerradius17)接口可以获得窗口默认圆角半径值。
9816
9817**系统能力**:SystemCapability.Window.SessionManager
9818
9819**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。
9820
9821**参数:**
9822
9823| 参数名      | 类型    | 必填 | 说明                                                 |
9824| ----------- | ------- | ---- |----------------------------------------------------|
9825| cornerRadius | number | 是   | 表示窗口圆角的半径值。该参数为浮点数,单位为vp,取值范围为[0.0, +∞),取值为0.0时表示没有窗口圆角。 |
9826
9827**返回值:**
9828
9829| 类型 | 说明 |
9830| ---------------------- | ------------------------------------------------------------------------------------ |
9831| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9832
9833**错误码:**
9834
9835以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9836
9837| 错误码ID | 错误信息 |
9838| ------- | ------------------------------ |
9839| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
9840| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
9841| 1300002 | This window state is abnormal. |
9842| 1300003  | This window manager service works abnormally. |
9843| 1300004 | Unauthorized operation.  |
9844
9845**示例:**
9846
9847```ts
9848import { BusinessError } from '@kit.BasicServicesKit';
9849
9850try{
9851  let promise = windowClass.setWindowCornerRadius(1.0);
9852  promise.then(() => {
9853    console.info('Succeeded in setting window corner radius.');
9854  }).catch((err: BusinessError) => {
9855    console.error(`Failed to set window corner radius. Cause code: ${err.code}, message: ${err.message}`);
9856  });
9857} catch (exception) {
9858  console.error(`Failed to set corner radius. Cause code: ${exception.code}, message: ${exception.message}`);
9859}
9860
9861```
9862
9863### getWindowCornerRadius<sup>17+</sup>
9864
9865getWindowCornerRadius(): number
9866
9867获取子窗或悬浮窗的圆角半径值,在未调用[setWindowCornerRadius()](#setwindowcornerradius17)接口设置窗口圆角半径值时,调用此接口可获取窗口默认圆角半径值。
9868
9869<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
9870
9871**系统能力**:SystemCapability.Window.SessionManager
9872
9873**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。
9874
9875**返回值:**
9876
9877| 类型 | 说明 |
9878| ---------------------- | ------------------------------------------------------------------------------------ |
9879| number | 当前子窗或悬浮窗的圆角半径值,单位为vp。 |
9880
9881**错误码:**
9882
9883以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9884
9885| 错误码ID | 错误信息 |
9886| ------- | ------------------------------ |
9887| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
9888| 1300002 | This window state is abnormal. |
9889| 1300004 | Unauthorized operation.  |
9890
9891**示例:**
9892
9893```ts
9894try {
9895  let cornerRadius = windowClass.getWindowCornerRadius();
9896} catch (exception) {
9897  console.error(`Failed to get corner radius. Cause code: ${exception.code}, message: ${exception.message}`);
9898}
9899```
9900
9901### setExclusivelyHighlighted<sup>15+<sup>
9902
9903setExclusivelyHighlighted(exclusivelyHighlighted: boolean): Promise&lt;void&gt;
9904
9905设置窗口独占激活态属性。独占激活态表示窗口获焦时,会导致当前父子窗口链中处于激活态的其他窗口失去激活态。使用Promise异步回调。
9906
9907此接口对主窗、模态窗、dialog窗口不生效。
9908
9909**系统能力:** SystemCapability.Window.SessionManager
9910
9911**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
9912
9913**参数:**
9914
9915| 参数名 | 类型 | 必填 | 说明 |
9916| ----------- | ------- | -- | -------------------------------------------------------- |
9917| exclusivelyHighlighted | boolean | 是 | 窗口是否独占激活态。true表示独占激活态;false表示不独占激活态。  |
9918
9919**返回值:**
9920
9921| 类型 | 说明 |
9922| ---------------------- | ------------------------------------------------------------------------------------ |
9923| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9924
9925**错误码:**
9926
9927以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9928
9929| 错误码ID | 错误信息                                                                                                     |
9930| -------- | ------------------------------------------------------------------------------------------------------------ |
9931| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
9932| 801      | Capability not supported. Failed to call the API due to limited device capabilities.                         |
9933| 1300002  | This window state is abnormal.                                                                               |
9934| 1300003  | This window manager service works abnormally.                                                                |
9935| 1300004  | Unauthorized operation.                                                                                |
9936
9937**示例:**
9938
9939```ts
9940import { BusinessError } from '@kit.BasicServicesKit';
9941
9942let exclusivelyHighlighted: boolean = true;
9943try {
9944  let promise = windowClass.setExclusivelyHighlighted(exclusivelyHighlighted);
9945  promise.then(() => {
9946    console.info('Succeeded in setting the window to be exclusively highlight.');
9947  }).catch((err: BusinessError) => {
9948    console.error(`Failed to set the window to be exclusively highlight. Cause code: ${err.code}, message: ${err.message}`);
9949  });
9950} catch (exception) {
9951  console.error(`Failed to set the window to be exclusively highlight. Cause code: ${exception.code}, message: ${exception.message}`);
9952}
9953```
9954
9955### isWindowHighlighted<sup>18+<sup>
9956
9957isWindowHighlighted(): boolean
9958
9959获取当前窗口是否为激活态。为准确获取激活态,需要在[WindowEventType](#windoweventtype10)生命周期处于WINDOW_ACTIVE之后调用。
9960
9961可使用[on('windowHighlightChange')](#onwindowhighlightchange15)监听对应状态变更,再执行对应具体业务。
9962
9963**系统能力:** SystemCapability.Window.SessionManager
9964
9965**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
9966
9967**返回值:**
9968
9969| 类型                | 说明                                           |
9970| ------------------- | --------------------------------------------- |
9971| boolean             | 当前窗口是否为激活态。true表示当前窗口为激活态,false表示当前窗口非激活态。 |
9972
9973**错误码:**
9974
9975以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
9976
9977| 错误码ID | 错误信息                                                                                                     |
9978| -------- | ------------------------------------------------------------------------------------------------------------ |
9979| 801      | Capability not supported. Failed to call the API due to limited device capabilities.                         |
9980| 1300002  | This window state is abnormal.                                                                               |
9981
9982**示例:**
9983
9984```ts
9985import { BusinessError } from '@kit.BasicServicesKit';
9986
9987try {
9988  let isHighlighted = windowClass.isWindowHighlighted();
9989  console.info(`Succeeded in getting the window highlight status: ${isHighlighted}`);
9990} catch (exception) {
9991  console.error(`Failed to get the window highlight status.. Cause code: ${exception.code}, message: ${exception.message}`);
9992}
9993```
9994
9995### setFollowParentMultiScreenPolicy<sup>17+<sup>
9996
9997setFollowParentMultiScreenPolicy(enabled: boolean): Promise&lt;void&gt;
9998
9999设置子窗口在其父窗口处于拖拽移动或拖拽缩放过程时,该子窗口是否支持跨多个屏幕同时显示。使用Promise异步回调。
10000
10001通过监听父窗口大小位置变化,对子窗口调用[moveWindowTo()](#movewindowto9)等接口实现子窗口跟随父窗口布局时,此时子窗口默认不支持跨多个屏幕同时显示。
10002
10003对子窗口调用此接口后可以使能子窗口在跟随父窗口布局过程中跨多个屏幕同时显示。
10004
10005<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
10006
10007**系统能力:** SystemCapability.Window.SessionManager
10008
10009**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。
10010
10011**参数:**
10012
10013| 参数名 | 类型 | 必填 | 说明 |
10014| ----------- | ------- | -- | -------------------------------------------------------- |
10015| enabled | boolean | 是 | 设置子窗口在其父窗口处于拖拽移动或拖拽缩放过程时,该子窗口是否支持跨多个屏幕同时显示。true表示支持;false表示不支持。  |
10016
10017**返回值:**
10018
10019| 类型 | 说明 |
10020| ---------------------- | ------------------------------------------------------------------------------------ |
10021| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
10022
10023**错误码:**
10024
10025以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
10026
10027| 错误码ID | 错误信息                                                                                                     |
10028| -------- | ------------------------------------------------------------------------------------------------------------ |
10029| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10030| 801      | Capability not supported.Function setFollowParentMultiScreenPolicy can not work correctly due to limited device capabilities.|
10031| 1300002  | This window state is abnormal.                                                                               |
10032| 1300003  | This window manager service works abnormally.                                                                |
10033| 1300004  | Unauthorized operation.                                                                                |
10034
10035**示例:**
10036
10037```ts
10038import { BusinessError } from '@kit.BasicServicesKit';
10039
10040try {
10041  let windowClass: window.Window = window.findWindow("subWindow");
10042  let enabled: boolean = true;
10043  let promise = windowClass?.setFollowParentMultiScreenPolicy(enabled);
10044  promise.then(() => {
10045    console.info('Succeeded in setting the sub window supports multi-screen simultaneous display')
10046  }).catch((err: BusinessError) => {
10047    console.error(`Failed to set the sub window supports multi-screen simultaneous display. Cause code: ${err.code}, message: ${err.message}`);
10048  });
10049} catch (exception) {
10050  console.error(`Failed to set the sub window supports multi-screen simultaneous display. Cause code: ${exception.code}, message: ${exception.message}`);
10051}
10052```
10053
10054### setFollowParentWindowLayoutEnabled<sup>17+</sup>
10055
10056setFollowParentWindowLayoutEnabled(enabled: boolean): Promise&lt;void&gt;
10057
10058设置子窗或模态窗口(即WindowType为TYPE_DIALOG的窗口)的布局信息(position和size)是否跟随主窗,使用Promise异步回调。
10059
100601、只支持主窗的一级子窗或模态窗口使用该接口。
10061
100622、当子窗或模态窗口调用该接口后,立即使其布局信息与主窗完全一致并保持,除非传入false再次调用该接口,否则效果将持续。
10063
100643、当子窗或模态窗口调用该接口后,再调用moveTo、resize等修改布局信息的接口将不生效。
10065
100664、当子窗或模态窗口不再使用该功能后,不保证子窗或模态窗口的布局信息(position和size)为确定的值,需要应用重新进行设置。
10067
10068该接口调用生效后,[setRelativePositionToParentWindowEnabled()](#setrelativepositiontoparentwindowenabled20)接口调用不生效。
10069
10070**模型约束:** 此接口仅可在Stage模型下使用。
10071
10072**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。
10073
10074**系统能力:** SystemCapability.Window.SessionManager
10075
10076**参数:**
10077
10078| 参数名 | 类型  | 必填  | 说明  |
10079| --- | --- | --- | --- |
10080| enabled | boolean | 是   | 设置是否启用跟随主窗布局。true表示启用,false表示不启用。|
10081
10082**返回值:**
10083
10084| 类型  | 说明  |
10085| --- | --- |
10086| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
10087
10088**错误码:**
10089
10090以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
10091
10092| 错误码ID | 错误信息 |
10093| --- | --- |
10094| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10095| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
10096| 1300002 | This window state is abnormal. |
10097| 1300003 | This window manager service works abnormally. |
10098| 1300004 | Unauthorized operation. |
10099
10100**示例:**
10101
10102```ts
10103// EntryAbility.ets
10104import { window } from '@kit.ArkUI';
10105import { BusinessError } from '@kit.BasicServicesKit';
10106import { UIAbility } from '@kit.AbilityKit';
10107
10108export default class EntryAbility extends UIAbility {
10109  onWindowStageCreate(windowStage: window.WindowStage): void {
10110    windowStage.loadContent('pages/Index', (loadError: BusinessError) => {
10111      if (loadError.code) {
10112        console.error(`Failed to load the content. Cause code: ${loadError.code}, message: ${loadError.message}`);
10113        return;
10114      }
10115      console.info("Succeeded in loading the content.");
10116      windowStage.createSubWindow("subWindow").then((subWindow: window.Window) => {
10117        if (subWindow === null) {
10118          console.error("Failed to create the subWindow. Cause: The data is empty");
10119          return;
10120        }
10121        subWindow.setFollowParentWindowLayoutEnabled(true).then(() => {
10122          console.info("after set follow parent window layout")
10123        }).catch((error: BusinessError) => {
10124          console.error(`setFollowParentWindowLayoutEnabled failed. ${error.code} ${error.message}`);
10125        })
10126      }).catch((error: BusinessError) => {
10127        console.error(`createSubWindow failed. ${error.code} ${error.message}`);
10128      })
10129    });
10130  }
10131}
10132```
10133
10134### setRelativePositionToParentWindowEnabled<sup>20+<sup>
10135
10136setRelativePositionToParentWindowEnabled(enabled: boolean, anchor?: WindowAnchor, offsetX?: number, offsetY?: number): Promise&lt;void&gt;
10137
10138设置一级子窗是否支持与主窗保持相对位置不变。使用Promise异步回调。
10139
10140该相对位置通过一级子窗与主窗之间锚点的偏移量表示,子窗和主窗使用的窗口锚点相同。
10141
101421、只支持非最大化一级子窗使用该接口。
10143
101442、当子窗调用该接口后,立即使其显示位置跟随主窗并保持相对位置不变,除非传入false再次调用该接口,否则效果将持续。
10145
101463、当子窗调用该接口后,再调用[moveWindowTo()](#movewindowto9)、[maximize()](#maximize12)等修改窗口位置或大小的接口将不生效。
10147
10148该接口调用生效后,[setFollowParentWindowLayoutEnabled()](#setfollowparentwindowlayoutenabled17)接口调用不生效。
10149
10150<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
10151
10152**系统能力:** SystemCapability.Window.SessionManager
10153
10154**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
10155
10156**参数:**
10157
10158| 参数名 | 类型 | 必填 | 说明 |
10159| ----------- | ------- | -- | -------------------------------------------------------- |
10160| enabled | boolean | 是 | 一级子窗是否支持与主窗保持相对位置不变。true表示支持;false表示不支持。  |
10161| anchor | [WindowAnchor](#windowanchor20) | 否 | 一级子窗与主窗保持相对位置不变时的窗口锚点枚举。该参数仅在enabled为true时生效,默认值为window.WindowAnchor.TopStart,即默认锚点为窗口左上角。  |
10162| offsetX | number | 否 | 一级子窗锚点与主窗锚点位置的x轴偏移量,单位为px。该参数仅在enabled为true时生效,仅支持整数输入,浮点数向下取整,默认值为0。  |
10163| offsetY | number | 否 | 一级子窗锚点与主窗锚点位置的y轴偏移量,单位为px。该参数仅在enabled为true时生效,仅支持整数输入,浮点数向下取整,默认值为0。  |
10164
10165**返回值:**
10166
10167| 类型 | 说明 |
10168| ---------------------- | ------------------------------------------------ |
10169| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
10170
10171**错误码:**
10172
10173以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
10174
10175| 错误码ID | 错误信息                                                                                                     |
10176| -------- | ------------------------------------------------------------------------------------------------------------ |
10177| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10178| 801      | Capability not supported.Function setRelativePositionToParentWindowEnabled can not work correctly due to limited device capabilities.|
10179| 1300002  | This window state is abnormal.                                                                               |
10180| 1300003  | This window manager service works abnormally.                                                                |
10181| 1300004  | Unauthorized operation.                                                                                |
10182
10183**示例:**
10184
10185```ts
10186import { BusinessError } from '@kit.BasicServicesKit';
10187
10188try {
10189  let windowClass: window.Window = window.findWindow("subWindow");
10190  let enabled: boolean = true;
10191  let promise = windowClass?.setRelativePositionToParentWindowEnabled(enabled);
10192  promise.then(() => {
10193    console.info('Succeeded in setting the sub window supports relative position to parent window.')
10194  }).catch((err: BusinessError) => {
10195    console.error(`Failed to set the sub window supports relative position to parent window. Cause code: ${err.code}, message: ${err.message}`);
10196  });
10197} catch (exception) {
10198  console.error(`Failed to set the sub window supports relative position to parent window. Cause code: ${exception.code}, message: ${exception.message}`);
10199}
10200```
10201
10202### setWindowTransitionAnimation<sup>20+</sup>
10203
10204setWindowTransitionAnimation(transitionType: WindowTransitionType, animation: TransitionAnimation): Promise&lt;void&gt;
10205
10206给特定场景下的窗口增加转场动画。
10207
10208当前只支持在应用主窗下使用。
10209
10210<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
10211
10212**模型约束:** 此接口仅可在Stage模型下使用。
10213
10214**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
10215
10216**系统能力:** SystemCapability.Window.SessionManager
10217
10218**参数:**
10219
10220| 参数名         | 类型                                            | 必填 | 说明                                   |
10221| -------------- | ----------------------------------------------- | ---- | -------------------------------------- |
10222| transitionType | [WindowTransitionType](#windowtransitiontype20) | 是   | 本次转场动画场景。当前只支持销毁场景。 |
10223| animation      | [TransitionAnimation](#transitionanimation20)   | 是   | 本次转场动画配置。                     |
10224
10225**返回值:**
10226
10227| 类型                | 说明                      |
10228| ------------------- | ------------------------- |
10229| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
10230
10231**错误码:**
10232
10233以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
10234
10235| 错误码ID | 错误信息                                                     |
10236| -------- | ------------------------------------------------------------ |
10237| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
10238| 1300002  | This window state is abnormal.                               |
10239| 1300003  | This window manager service works abnormally.                |
10240| 1300004  | Unauthorized operation.                                      |
10241| 1300016  | Parameter error. Possible cause: 1. Invalid parameter range; 2. Invalid parameter length. |
10242
10243**示例:**
10244
10245```typescript
10246// EntryAbility.ets
10247import { BusinessError } from '@kit.BasicServicesKit';
10248import { UIAbility } from '@kit.AbilityKit';
10249import { window } from '@kit.ArkUI';
10250
10251export default class EntryAbility extends UIAbility {
10252  // ...
10253  onWindowStageCreate(windowStage: window.WindowStage): void {
10254    console.info('onWindowStageCreate');
10255    let windowClass: window.Window | undefined = undefined;
10256    windowStage.getMainWindow((err: BusinessError, data) => {
10257      const errCode: number = err.code;
10258      if (errCode) {
10259        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
10260        return;
10261      }
10262      windowClass = data;
10263      try {
10264        const animationConfig: window.WindowAnimationConfig = {
10265          duration: 1000,
10266          curve: window.WindowAnimationCurve.LINEAR,
10267        };
10268        const transitionAnimation: window.TransitionAnimation = {
10269          opacity: 0.5,
10270          config: animationConfig
10271        };
10272        let promise = windowClass.setWindowTransitionAnimation(window.WindowTransitionType.DESTROY, transitionAnimation);
10273        promise.then((data) => {
10274          console.info('Succeeded in setting window transition animation. Cause:' + JSON.stringify(data));
10275        }).catch((err: BusinessError) => {
10276          console.error(`Failed to set window transition animation. Cause code: ${err.code}, message: ${err.message}`);
10277        });
10278      } catch (exception) {
10279        console.error(`Failed to obtain the window status of window. Cause code: ${exception.code}, message: ${exception.message}`);
10280      }
10281    })
10282  }
10283}
10284```
10285
10286### getWindowTransitionAnimation<sup>20+</sup>
10287
10288getWindowTransitionAnimation(transitionType: WindowTransitionType): TransitionAnimation | undefined
10289
10290获取特定场景下的窗口转场动画配置。
10291
10292当前只支持在应用主窗下使用。
10293
10294<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
10295
10296**模型约束:** 此接口仅可在Stage模型下使用。
10297
10298**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
10299
10300**系统能力:** SystemCapability.Window.SessionManager
10301
10302**参数:**
10303
10304| 参数名         | 类型                                            | 必填 | 说明                                   |
10305| -------------- | ----------------------------------------------- | ---- | -------------------------------------- |
10306| transitionType | [WindowTransitionType](#windowtransitiontype20) | 是   | 本次转场动画场景。当前只支持销毁场景。 |
10307
10308**返回值:**
10309
10310| 类型                                          | 说明                       |
10311| --------------------------------------------- | -------------------------- |
10312| [TransitionAnimation](#transitionanimation20) \| undefined | 对应场景下的转场动画配置。当未使用过[setWindowTransitionAnimation](#setwindowtransitionanimation20)接口时,返回undefined。|
10313
10314**错误码:**
10315
10316以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
10317
10318| 错误码ID | 错误信息                                                     |
10319| -------- | ------------------------------------------------------------ |
10320| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
10321| 1300002  | This window state is abnormal.                               |
10322| 1300003  | This window manager service works abnormally.                |
10323| 1300004  | Unauthorized operation.                                      |
10324| 1300016  | Parameter error. Possible cause: 1. Invalid parameter range; 2. Invalid parameter length. |
10325
10326**示例:**
10327
10328```typescript
10329// EntryAbility.ets
10330import { BusinessError } from '@kit.BasicServicesKit';
10331import { UIAbility } from '@kit.AbilityKit';
10332import { window } from '@kit.ArkUI';
10333
10334export default class EntryAbility extends UIAbility {
10335  // ...
10336  onWindowStageCreate(windowStage: window.WindowStage): void {
10337    console.info('onWindowStageCreate');
10338    let windowClass: window.Window | undefined = undefined;
10339    windowStage.getMainWindow((err: BusinessError, data) => {
10340      const errCode: number = err.code;
10341      if (errCode) {
10342        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
10343        return;
10344      }
10345      windowClass = data;
10346      try {
10347        let transitionAnimationResult = windowClass.getWindowTransitionAnimation(window.WindowTransitionType.DESTROY);
10348        console.info('Succeeded in getting window transition animation: ' + JSON.stringify(transitionAnimationResult));
10349      } catch (exception) {
10350        console.error(`Failed to obtain the window transition animation. Cause code: ${exception.code}, message: ${exception.message}`);
10351      }
10352    })
10353  }
10354}
10355```
10356
10357### setWindowSystemBarProperties<sup>(deprecated)</sup>
10358
10359setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback&lt;void&gt;): void
10360
10361设置主窗口<!--Del-->三键导航栏、<!--DelEnd-->状态栏的属性,使用callback异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
10362
10363子窗口调用后不生效。
10364
10365> **说明:**
10366>
10367> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowSystemBarProperties](#setwindowsystembarproperties9)。
10368
10369**系统能力:** SystemCapability.WindowManager.WindowManager.Core
10370
10371**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
10372
10373**参数:**
10374
10375| 参数名              | 类型                                        | 必填 | 说明                   |
10376| ------------------- | ------------------------------------------- | ---- | ---------------------- |
10377| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是   | <!--Del-->三键导航栏、<!--DelEnd-->状态栏的属性。 |
10378| callback            | AsyncCallback&lt;void&gt;                   | 是   | 回调函数。             |
10379
10380**错误码:**
10381
10382以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
10383
10384| 错误码ID | 错误信息                                                                                                     |
10385| -------- | ------------------------------------------------------------------------------------------------------------ |
10386| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10387| 801      | Capability not supported. Failed to call the API due to limited device capabilities.                         |
10388| 1300002  | This window state is abnormal.                                                                               |
10389| 1300003  | This window manager service works abnormally.                                                                |
10390
10391**示例:**
10392
10393```ts
10394// EntryAbility.ets
10395import { UIAbility } from '@kit.AbilityKit';
10396import { BusinessError } from '@kit.BasicServicesKit';
10397
10398export default class EntryAbility extends UIAbility {
10399  // ...
10400  onWindowStageCreate(windowStage: window.WindowStage): void {
10401    console.info('onWindowStageCreate');
10402    let windowClass: window.Window | undefined = undefined;
10403    windowStage.getMainWindow((err: BusinessError, data) => {
10404      const errCode: number = err.code;
10405      if (errCode) {
10406        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
10407        return;
10408      }
10409      windowClass = data;
10410      let SystemBarProperties: window.SystemBarProperties = {
10411        statusBarColor: '#ff00ff',
10412        navigationBarColor: '#00ff00',
10413        //以下两个属性从API Version8开始支持
10414        statusBarContentColor: '#ffffff',
10415        navigationBarContentColor: '#00ffff'
10416      };
10417      try {
10418        windowClass.setWindowSystemBarProperties(SystemBarProperties, (err: BusinessError) => {
10419          const errCode: number = err.code;
10420          if (errCode) {
10421            console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
10422            return;
10423          }
10424          console.info('Succeeded in setting the system bar properties.');
10425        });
10426      } catch (exception) {
10427        console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`);
10428      }
10429    });
10430  }
10431}
10432```
10433
10434### setSubWindowZLevel<sup>18+</sup>
10435
10436setSubWindowZLevel(zLevel: number): Promise&lt;void&gt;
10437
10438设置当前子窗口层级级别,设置了模态属性的子窗不支持。使用Promise异步回调。
10439
10440通过该接口改变子窗口的显示层级时,不会发生焦点切换。推荐使用[shiftAppWindowFocus()](#windowshiftappwindowfocus11)进行焦点切换。
10441
10442**系统能力:** SystemCapability.Window.SessionManager
10443
10444**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
10445
10446**参数:**
10447
10448| 参数名       | 类型                          | 必填 | 说明                           |
10449| :----------- | :---------------------------- | :--- | :----------------------------- |
10450| zLevel | number | 是   | 子窗口层级级别。默认值为0,取值范围为[-10000, 10000],该参数仅支持整数输入,浮点数输入将向下取整。 |
10451
10452**返回值:**
10453
10454| 类型                | 说明                      |
10455| ------------------- | ------------------------- |
10456| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
10457
10458**错误码:**
10459
10460以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
10461
10462| 错误码ID | 错误信息                                      |
10463| ------- | --------------------------------------------- |
10464| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
10465| 801     | Capability not supported. Function setSubWindowZLevel can not work correctly due to limited device capabilities. |
10466| 1300002 | This window state is abnormal.                |
10467| 1300003 | This window manager service works abnormally. |
10468| 1300004 | Unauthorized operation.                       |
10469| 1300009 | The parent window is invalid.                 |
10470
10471**示例:**
10472
10473```ts
10474// EntryAbility.ets
10475import { window } from '@kit.ArkUI';
10476import { UIAbility } from '@kit.AbilityKit';
10477import { BusinessError } from '@kit.BasicServicesKit';
10478
10479export default class EntryAbility extends UIAbility {
10480  // ...
10481  onWindowStageCreate(windowStage: window.WindowStage): void {
10482    console.info('onWindowStageCreate');
10483    let zLevel: number = 1;
10484    // 创建子窗
10485    try {
10486      windowStage.createSubWindow('testSubWindow').then((subWindow) => {
10487        if (subWindow == null) {
10488          console.error('Failed to create the sub window. Cause: The sub window is null');
10489          return;
10490        }
10491        subWindow.setSubWindowZLevel(zLevel).then(() => {
10492          console.info('Succeeded in setting sub window zLevel.');
10493        }).catch((err: BusinessError) => {
10494          console.error(`Failed to set sub window zLevel. Cause code: ${err.code}, message: ${err.message}`);
10495        });
10496      });
10497    } catch (err) {
10498      console.error(`Failed to create the sub window or set zLevel. Cause code: ${err.code}, message: ${err.message}`);
10499    }
10500  }
10501}
10502```
10503
10504### getSubWindowZLevel<sup>18+</sup>
10505
10506getSubWindowZLevel(): number
10507
10508获取当前子窗口层级级别。不支持主窗、系统窗调用。
10509
10510**系统能力:** SystemCapability.Window.SessionManager
10511
10512**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
10513
10514**返回值:**
10515
10516| 类型                | 说明                                           |
10517| ------------------- | --------------------------------------------- |
10518| number             | 当前子窗口层级级别。 |
10519
10520**错误码:**
10521
10522以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
10523
10524| 错误码ID | 错误信息                                                                                                     |
10525| -------- | ------------------------------------------------------------------------------------------------------------ |
10526| 801      | Capability not supported. Function getSubWindowZLevel can not work correctly due to limited device capabilities. |
10527| 1300002  | This window state is abnormal.                                                                               |
10528| 1300004  | Unauthorized operation.                                                                                |
10529
10530**示例:**
10531
10532```ts
10533// EntryAbility.ets
10534import { window } from '@kit.ArkUI';
10535import { UIAbility } from '@kit.AbilityKit';
10536
10537export default class EntryAbility extends UIAbility {
10538  // ...
10539  onWindowStageCreate(windowStage: window.WindowStage): void {
10540    console.info('onWindowStageCreate');
10541    let subWindowZLevel = -1;
10542    // 创建子窗
10543    windowStage.createSubWindow('testSubWindow').then((subWindow) => {
10544      if (subWindow == null) {
10545        console.error('Failed to create the sub window. Cause: The sub window is null');
10546        return;
10547      }
10548      try {
10549        subWindowZLevel = subWindow.getSubWindowZLevel();
10550        console.info(`Succeeded in obtaining sub window zLevel: ${subWindowZLevel}`);
10551      } catch (err) {
10552        console.error(`Failed to obtain the sub window zLevel. Cause code: ${err.code}, message: ${err.message}`);
10553      }
10554    });
10555  }
10556}
10557```
10558
10559### setWindowSystemBarEnable<sup>(deprecated)</sup>
10560
10561setWindowSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback&lt;void&gt;): void
10562
10563<!--RP14-->设置主窗口状态栏、三键导航栏的可见模式,状态栏通过status控制、三键导航栏通过navigation控制<!--RP14End-->,使用callback异步回调。<br>从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
10564
10565调用生效后返回并不表示状态栏和<!--RP15-->三键导航栏<!--RP15End-->的显示或隐藏已完成。子窗口调用后不生效。非全屏模式(悬浮窗、分屏等场景)下配置不生效。
10566
10567> **说明:**
10568>
10569> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowSystemBarEnable](#setwindowsystembarenable9)。
10570
10571**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
10572
10573**系统能力:** SystemCapability.WindowManager.WindowManager.Core
10574
10575**参数:**
10576
10577| 参数名   | 类型                          | 必填 | 说明                                                                                                                                          |
10578| -------- | ----------------------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------- |
10579| names    | Array<'status'\|'navigation'> | 是   | 设置窗口全屏模式时状态栏和<!--RP15-->三键导航栏<!--RP15End-->是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];设置为[],则不显示。 |
10580| callback | AsyncCallback&lt;void&gt;     | 是   | 回调函数。                                                                                                                                    |
10581
10582**错误码:**
10583
10584以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
10585
10586| 错误码ID | 错误信息                                                                                                     |
10587| -------- | ------------------------------------------------------------------------------------------------------------ |
10588| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10589| 1300002  | This window state is abnormal.                                                                               |
10590| 1300003  | This window manager service works abnormally.                                                                |
10591
10592**示例:**
10593
10594```ts
10595// 此处以状态栏等均不显示为例
10596// EntryAbility.ets
10597import { UIAbility } from '@kit.AbilityKit';
10598import { BusinessError } from '@kit.BasicServicesKit';
10599
10600export default class EntryAbility extends UIAbility {
10601  // ...
10602  onWindowStageCreate(windowStage: window.WindowStage): void {
10603    console.info('onWindowStageCreate');
10604    let windowClass: window.Window | undefined = undefined;
10605    windowStage.getMainWindow((err: BusinessError, data) => {
10606      const errCode: number = err.code;
10607      if (errCode) {
10608        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
10609        return;
10610      }
10611      windowClass = data;
10612      let names: Array<'status' | 'navigation'> = [];
10613      try {
10614        windowClass.setWindowSystemBarEnable(names, (err: BusinessError) => {
10615          const errCode: number = err.code;
10616          if (errCode) {
10617            console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
10618            return;
10619          }
10620          console.info('Succeeded in setting the system bar to be invisible.');
10621        });
10622      } catch (exception) {
10623        console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`);
10624      }
10625    });
10626  }
10627}
10628```
10629
10630### setWindowLayoutFullScreen<sup>(deprecated)</sup>
10631
10632setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void
10633
10634设置主窗口或子窗口的布局是否为沉浸式布局,使用callback异步回调。
10635沉浸式布局生效时,布局不避让状态栏与<!--RP15-->三键导航栏<!--RP15End-->,组件可能产生与其重叠的情况。
10636非沉浸式布局生效时,布局避让状态栏与<!--RP15-->三键导航栏<!--RP15End-->,组件不会与其重叠。
10637
10638> **说明:**
10639>
10640> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowLayoutFullScreen](#setwindowlayoutfullscreen9)。
10641
10642**系统能力:** SystemCapability.WindowManager.WindowManager.Core
10643
10644**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
10645
10646**参数:**
10647
10648| 参数名             | 类型                      | 必填 | 说明                                                                                                          |
10649| ------------------ | ------------------------- | ---- | ------------------------------------------------------------------------------------------------------------- |
10650| isLayoutFullScreen | boolean                   | 是   | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、<!--RP15-->三键导航栏<!--RP15End-->仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 |
10651| callback           | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                                                                                    |
10652
10653**错误码:**
10654
10655以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
10656
10657| 错误码ID | 错误信息                                                                                                     |
10658| -------- | ------------------------------------------------------------------------------------------------------------ |
10659| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10660| 1300002  | This window state is abnormal.                                                                               |
10661| 1300003  | This window manager service works abnormally.                                                                |
10662
10663**示例:**
10664
10665```ts
10666// EntryAbility.ets
10667import { UIAbility } from '@kit.AbilityKit';
10668import { BusinessError } from '@kit.BasicServicesKit';
10669
10670export default class EntryAbility extends UIAbility {
10671  // ...
10672  onWindowStageCreate(windowStage: window.WindowStage): void {
10673    console.info('onWindowStageCreate');
10674    let windowClass: window.Window | undefined = undefined;
10675    windowStage.getMainWindow((err: BusinessError, data) => {
10676      const errCode: number = err.code;
10677      if (errCode) {
10678        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
10679        return;
10680      }
10681      windowClass = data;
10682      let isLayoutFullScreen = true;
10683      try {
10684        windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => {
10685          const errCode: number = err.code;
10686          if (errCode) {
10687            console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
10688            return;
10689          }
10690          console.info('Succeeded in setting the window layout to full-screen mode.');
10691        });
10692      } catch (exception) {
10693        console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`);
10694      }
10695    });
10696  }
10697}
10698```
10699
10700### show<sup>(deprecated)</sup>
10701
10702show(callback: AsyncCallback&lt;void&gt;): void
10703
10704显示当前窗口,使用callback异步回调。
10705
10706> **说明:**
10707>
10708> 从API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9)。
10709
10710**系统能力:** SystemCapability.WindowManager.WindowManager.Core
10711
10712**参数:**
10713
10714| 参数名   | 类型                      | 必填 | 说明       |
10715| -------- | ------------------------- | ---- | ---------- |
10716| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。 |
10717
10718**示例:**
10719
10720```ts
10721import { BusinessError } from '@kit.BasicServicesKit';
10722
10723windowClass.show((err: BusinessError) => {
10724  const errCode: number = err.code;
10725  if (errCode) {
10726    console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`);
10727    return;
10728  }
10729  console.info('Succeeded in showing the window.');
10730});
10731```
10732
10733### show<sup>(deprecated)</sup>
10734
10735show(): Promise&lt;void&gt;
10736
10737显示当前窗口,使用Promise异步回调。
10738
10739> **说明:**
10740>
10741> 从API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9-1)。
10742
10743**系统能力:** SystemCapability.WindowManager.WindowManager.Core
10744
10745**返回值:**
10746
10747| 类型                | 说明                      |
10748| ------------------- | ------------------------- |
10749| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
10750
10751**示例:**
10752
10753```ts
10754import { BusinessError } from '@kit.BasicServicesKit';
10755
10756let promise = windowClass.show();
10757promise.then(() => {
10758  console.info('Succeeded in showing the window.');
10759}).catch((err: BusinessError) => {
10760  console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`);
10761});
10762```
10763
10764### destroy<sup>(deprecated)</sup>
10765
10766destroy(callback: AsyncCallback&lt;void&gt;): void
10767
10768销毁当前窗口,使用callback异步回调。
10769
10770> **说明:**
10771>
10772> 从API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9)。
10773
10774**系统能力:** SystemCapability.WindowManager.WindowManager.Core
10775
10776**参数:**
10777
10778| 参数名   | 类型                      | 必填 | 说明       |
10779| -------- | ------------------------- | ---- | ---------- |
10780| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。 |
10781
10782**示例:**
10783
10784```ts
10785import { BusinessError } from '@kit.BasicServicesKit';
10786
10787windowClass.destroy((err: BusinessError) => {
10788  const errCode: number = err.code;
10789  if (err.code) {
10790    console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`);
10791    return;
10792  }
10793  console.info('Succeeded in destroying the window.');
10794});
10795```
10796
10797### destroy<sup>(deprecated)</sup>
10798
10799destroy(): Promise&lt;void&gt;
10800
10801销毁当前窗口,使用Promise异步回调。
10802
10803> **说明:**
10804>
10805> 从API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9-1)。
10806
10807**系统能力:** SystemCapability.WindowManager.WindowManager.Core
10808
10809**返回值:**
10810
10811| 类型                | 说明                      |
10812| ------------------- | ------------------------- |
10813| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
10814
10815**示例:**
10816
10817```ts
10818import { BusinessError } from '@kit.BasicServicesKit';
10819
10820let promise = windowClass.destroy();
10821promise.then(() => {
10822  console.info('Succeeded in destroying the window.');
10823}).catch((err: BusinessError) => {
10824  console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`);
10825});
10826```
10827
10828### moveTo<sup>(deprecated)</sup>
10829
10830moveTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void
10831
10832移动窗口位置,使用callback异步回调。
10833
10834全屏模式窗口不支持该操作。
10835
10836> **说明:**
10837>
10838> 从API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9)。
10839
10840**系统能力:** SystemCapability.WindowManager.WindowManager.Core
10841
10842**参数:**
10843
10844| 参数名   | 类型                      | 必填 | 说明                                              |
10845| -------- | ------------------------- | ---- | ------------------------------------------------- |
10846| x        | number                    | 是   | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 |
10847| y        | number                    | 是   | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 |
10848| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                        |
10849
10850**示例:**
10851
10852```ts
10853import { BusinessError } from '@kit.BasicServicesKit';
10854
10855windowClass.moveTo(300, 300, (err: BusinessError) => {
10856  const errCode: number = err.code;
10857  if (errCode) {
10858    console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
10859    return;
10860  }
10861  console.info('Succeeded in moving the window.');
10862});
10863```
10864
10865### moveTo<sup>(deprecated)</sup>
10866
10867moveTo(x: number, y: number): Promise&lt;void&gt;
10868
10869移动窗口位置,使用Promise异步回调。
10870
10871全屏模式窗口不支持该操作。
10872
10873> **说明:**
10874>
10875> 从API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9-1)。
10876
10877**系统能力:** SystemCapability.WindowManager.WindowManager.Core
10878
10879**参数:**
10880
10881| 参数名 | 类型   | 必填 | 说明                                              |
10882| ------ | ------ | ---- | ------------------------------------------------- |
10883| x      | number | 是   | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 |
10884| y      | number | 是   | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在y轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 |
10885
10886**返回值:**
10887
10888| 类型                | 说明                      |
10889| ------------------- | ------------------------- |
10890| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
10891
10892**示例:**
10893
10894```ts
10895import { BusinessError } from '@kit.BasicServicesKit';
10896
10897let promise = windowClass.moveTo(300, 300);
10898promise.then(() => {
10899  console.info('Succeeded in moving the window.');
10900}).catch((err: BusinessError) => {
10901  console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`);
10902});
10903```
10904
10905### resetSize<sup>(deprecated)</sup>
10906
10907resetSize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void
10908
10909改变当前窗口大小,使用callback异步回调。
10910
10911应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。
10912应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
10913
10914系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。
10915
10916设置的宽度与高度受到此约束限制,规则:
10917若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
10918若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
10919
10920全屏模式窗口不支持该操作。
10921
10922> **说明:**
10923>
10924> 从API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9)。
10925
10926**系统能力:** SystemCapability.WindowManager.WindowManager.Core
10927
10928**参数:**
10929
10930| 参数名   | 类型                      | 必填 | 说明                       |
10931| -------- | ------------------------- | ---- | -------------------------- |
10932| width    | number                    | 是   | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
10933| height   | number                    | 是   | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
10934| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。                 |
10935
10936**示例:**
10937
10938```ts
10939import { BusinessError } from '@kit.BasicServicesKit';
10940
10941windowClass.resetSize(500, 1000, (err: BusinessError) => {
10942  const errCode: number = err.code;
10943  if (errCode) {
10944    console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
10945    return;
10946  }
10947  console.info('Succeeded in changing the window size.');
10948});
10949```
10950
10951### resetSize<sup>(deprecated)</sup>
10952
10953resetSize(width: number, height: number): Promise&lt;void&gt;
10954
10955改变当前窗口大小,使用Promise异步回调。
10956
10957应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。
10958应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。
10959
10960系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。
10961
10962设置的宽度与高度受到此约束限制,规则:
10963若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效;
10964若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。
10965
10966全屏模式窗口不支持该操作。
10967
10968> **说明:**
10969>
10970> 从API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9-1)。
10971
10972**系统能力:** SystemCapability.WindowManager.WindowManager.Core
10973
10974**参数:**
10975
10976| 参数名 | 类型   | 必填 | 说明                       |
10977| ------ | ------ | ---- | -------------------------- |
10978| width  | number | 是   | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
10979| height | number | 是   | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 |
10980
10981**返回值:**
10982
10983| 类型                | 说明                      |
10984| ------------------- | ------------------------- |
10985| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
10986
10987**示例:**
10988
10989```ts
10990import { BusinessError } from '@kit.BasicServicesKit';
10991
10992let promise = windowClass.resetSize(500, 1000);
10993promise.then(() => {
10994  console.info('Succeeded in changing the window size.');
10995}).catch((err: BusinessError) => {
10996  console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`);
10997});
10998```
10999
11000### getProperties<sup>(deprecated)</sup>
11001
11002getProperties(callback: AsyncCallback&lt;WindowProperties&gt;): void
11003
11004获取当前窗口的属性,使用callback异步回调,返回WindowProperties。
11005
11006> **说明:**
11007>
11008> 从API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。
11009
11010**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11011
11012**参数:**
11013
11014| 参数名   | 类型                                                       | 必填 | 说明                         |
11015| -------- | ---------------------------------------------------------- | ---- | ---------------------------- |
11016| callback | AsyncCallback&lt;[WindowProperties](#windowproperties)&gt; | 是   | 回调函数。返回当前窗口属性。 |
11017
11018**示例:**
11019
11020```ts
11021import { BusinessError } from '@kit.BasicServicesKit';
11022
11023windowClass.getProperties((err: BusinessError, data) => {
11024  const errCode: number = err.code;
11025  if (errCode) {
11026    console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`);
11027    return;
11028  }
11029  console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data));
11030});
11031```
11032
11033### getProperties<sup>(deprecated)</sup>
11034
11035getProperties(): Promise&lt;WindowProperties&gt;
11036
11037获取当前窗口的属性,使用Promise异步回调,返回WindowProperties。
11038
11039> **说明:**
11040>
11041> 从API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。
11042
11043**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11044
11045**返回值:**
11046
11047| 类型                                                 | 说明                            |
11048| ---------------------------------------------------- | ------------------------------- |
11049| Promise&lt;[WindowProperties](#windowproperties)&gt; | Promise对象。返回当前窗口属性。 |
11050
11051**示例:**
11052
11053```ts
11054import { BusinessError } from '@kit.BasicServicesKit';
11055
11056let promise = windowClass.getProperties();
11057promise.then((data) => {
11058  console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data));
11059}).catch((err: BusinessError) => {
11060  console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`);
11061});
11062```
11063
11064### getAvoidArea<sup>(deprecated)</sup>
11065
11066getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback&lt;[AvoidArea](#avoidarea7)&gt;): void
11067
11068获取当前窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。
11069
11070> **说明:**
11071>
11072> 从API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。
11073
11074**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11075
11076**参数:**
11077
11078| 参数名   | 类型                                            | 必填 | 说明                                                         |
11079| -------- |-----------------------------------------------| ---- | ------------------------------------------------------------ |
11080| type     | [AvoidAreaType](#avoidareatype7)              | 是   | 表示规避区类型。|
11081| callback | AsyncCallback&lt;[AvoidArea](#avoidarea7)&gt; | 是   | 回调函数。返回窗口内容规避区域。                             |
11082
11083**示例:**
11084
11085```ts
11086import { BusinessError } from '@kit.BasicServicesKit';
11087
11088let type = window.AvoidAreaType.TYPE_SYSTEM;
11089windowClass.getAvoidArea(type, (err: BusinessError, data) => {
11090  const errCode: number = err.code;
11091  if (errCode) {
11092    console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`);
11093    return;
11094  }
11095  console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
11096});
11097```
11098
11099### getAvoidArea<sup>(deprecated)</sup>
11100
11101getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise&lt;[AvoidArea](#avoidarea7)&gt;
11102
11103获取当前窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。
11104
11105> **说明:**
11106>
11107> 从API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。
11108
11109**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11110
11111**参数:**
11112
11113| 参数名 | 类型                               | 必填 | 说明                                                         |
11114| ------ |----------------------------------| ---- | ------------------------------------------------------------ |
11115| type   | [AvoidAreaType](#avoidareatype7) | 是   | 表示规避区类型。 |
11116
11117**返回值:**
11118
11119| 类型                                      | 说明                                |
11120|-----------------------------------------| ----------------------------------- |
11121| Promise&lt;[AvoidArea](#avoidarea7)&gt; | Promise对象。返回窗口内容规避区域。 |
11122
11123**示例:**
11124
11125```ts
11126import { BusinessError } from '@kit.BasicServicesKit';
11127
11128let type = window.AvoidAreaType.TYPE_SYSTEM;
11129let promise = windowClass.getAvoidArea(type);
11130promise.then((data) => {
11131  console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
11132}).catch((err: BusinessError) => {
11133  console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`);
11134});
11135```
11136
11137### setFullScreen<sup>(deprecated)</sup>
11138
11139setFullScreen(isFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void
11140
11141设置主窗口或子窗口的布局是否为全屏布局,使用callback异步回调。
11142全屏布局生效时,布局不避让状态栏与<!--RP15-->三键导航栏<!--RP15End-->,组件可能产生与其重叠的情况。
11143非全屏布局生效时,布局避让状态栏与<!--RP15-->三键导航栏<!--RP15End-->,组件不会与其重叠。
11144
11145> **说明:**
11146>
11147> 从API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)实现全屏。
11148
11149**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11150
11151**参数:**
11152
11153| 参数名       | 类型                      | 必填 | 说明                                           |
11154| ------------ | ------------------------- | ---- | ---------------------------------------------- |
11155| isFullScreen | boolean                   | 是   | 是否设为全屏布局(该全屏布局影响状态栏、<!--RP15-->三键导航栏<!--RP15End-->显示)。true表示全屏;false表示非全屏。 |
11156| callback     | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                     |
11157
11158**示例:**
11159
11160```ts
11161// EntryAbility.ets
11162import { UIAbility } from '@kit.AbilityKit';
11163import { BusinessError } from '@kit.BasicServicesKit';
11164
11165export default class EntryAbility extends UIAbility {
11166  // ...
11167  onWindowStageCreate(windowStage: window.WindowStage): void {
11168    console.info('onWindowStageCreate');
11169    let windowClass: window.Window | undefined = undefined;
11170    windowStage.getMainWindow((err: BusinessError, data) => {
11171      const errCode: number = err.code;
11172      if (errCode) {
11173        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
11174        return;
11175      }
11176      windowClass = data;
11177      let isFullScreen: boolean = true;
11178      windowClass.setFullScreen(isFullScreen, (err: BusinessError) => {
11179        const errCode: number = err.code;
11180        if (errCode) {
11181          console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
11182          return;
11183        }
11184        console.info('Succeeded in enabling the full-screen mode.');
11185      });
11186    });
11187  }
11188}
11189```
11190
11191### setFullScreen<sup>(deprecated)</sup>
11192
11193setFullScreen(isFullScreen: boolean): Promise&lt;void&gt;
11194
11195设置主窗口或子窗口的布局是否为全屏布局,使用Promise异步回调。
11196全屏布局生效时,布局不避让状态栏与<!--RP15-->三键导航栏<!--RP15End-->,组件可能产生与其重叠的情况。
11197非全屏布局生效时,布局避让状态栏与<!--RP15-->三键导航栏<!--RP15End-->,组件不会与其重叠。
11198
11199> **说明:**
11200>
11201> 从API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)实现全屏。
11202
11203**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11204
11205**参数:**
11206
11207| 参数名       | 类型    | 必填 | 说明                                           |
11208| ------------ | ------- | ---- | ---------------------------------------------- |
11209| isFullScreen | boolean | 是   | 是否设为全屏布局(该全屏布局影响状态栏、<!--RP15-->三键导航栏<!--RP15End-->显示)。true表示全屏;false表示非全屏。 |
11210
11211**返回值:**
11212
11213| 类型                | 说明                      |
11214| ------------------- | ------------------------- |
11215| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
11216
11217**示例:**
11218
11219```ts
11220// EntryAbility.ets
11221import { UIAbility } from '@kit.AbilityKit';
11222import { BusinessError } from '@kit.BasicServicesKit';
11223
11224export default class EntryAbility extends UIAbility {
11225  // ...
11226  onWindowStageCreate(windowStage: window.WindowStage): void {
11227    console.info('onWindowStageCreate');
11228    let windowClass: window.Window | undefined = undefined;
11229    windowStage.getMainWindow((err: BusinessError, data) => {
11230      const errCode: number = err.code;
11231      if (errCode) {
11232        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
11233        return;
11234      }
11235      windowClass = data;
11236      let isFullScreen: boolean = true;
11237      let promise = windowClass.setFullScreen(isFullScreen);
11238      promise.then(() => {
11239        console.info('Succeeded in enabling the full-screen mode.');
11240      }).catch((err: BusinessError) => {
11241        console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
11242      });
11243    });
11244  }
11245}
11246```
11247
11248### setLayoutFullScreen<sup>(deprecated)</sup>
11249
11250setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void
11251
11252设置主窗口或子窗口的布局是否为沉浸式布局,使用callback异步回调。
11253沉浸式布局生效时,布局不避让状态栏与<!--RP15-->三键导航栏<!--RP15End-->,组件可能产生与其重叠的情况。
11254非沉浸式布局生效时,布局避让状态栏与<!--RP15-->三键导航栏<!--RP15End-->,组件不会与其重叠。
11255
11256> **说明:**
11257>
11258> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)。
11259
11260**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11261
11262**参数:**
11263
11264| 参数名             | 类型                      | 必填 | 说明                                                         |
11265| ------------------ | ------------------------- | ---- | ------------------------------------------------------------ |
11266| isLayoutFullScreen | boolean                   | 是   | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、<!--RP15-->三键导航栏<!--RP15End-->显示)。true表示沉浸式布局;false表示非沉浸式布局。 |
11267| callback           | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                                   |
11268
11269**示例:**
11270
11271```ts
11272// EntryAbility.ets
11273import { UIAbility } from '@kit.AbilityKit';
11274import { BusinessError } from '@kit.BasicServicesKit';
11275
11276export default class EntryAbility extends UIAbility {
11277  // ...
11278  onWindowStageCreate(windowStage: window.WindowStage): void {
11279    console.info('onWindowStageCreate');
11280    let windowClass: window.Window | undefined = undefined;
11281    windowStage.getMainWindow((err: BusinessError, data) => {
11282      const errCode: number = err.code;
11283      if (errCode) {
11284        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
11285        return;
11286      }
11287      windowClass = data;
11288      let isLayoutFullScreen: boolean = true;
11289      windowClass.setLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => {
11290        const errCode: number = err.code;
11291        if (errCode) {
11292          console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
11293          return;
11294        }
11295        console.info('Succeeded in setting the window layout to full-screen mode.');
11296      });
11297    });
11298  }
11299}
11300```
11301
11302### setLayoutFullScreen<sup>(deprecated)</sup>
11303
11304setLayoutFullScreen(isLayoutFullScreen: boolean): Promise&lt;void&gt;
11305
11306设置主窗口或子窗口的布局是否为沉浸式布局,使用Promise异步回调。
11307沉浸式布局生效时,布局不避让状态栏与<!--RP15-->三键导航栏<!--RP15End-->,组件可能产生与其重叠的情况。
11308非沉浸式布局生效时,布局避让状态栏与<!--RP15-->三键导航栏<!--RP15End-->,组件不会与其重叠。
11309
11310> **说明:**
11311>
11312> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)。
11313
11314**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11315
11316**参数:**
11317
11318| 参数名             | 类型    | 必填 | 说明                                                         |
11319| ------------------ | ------- | ---- | ------------------------------------------------------------ |
11320| isLayoutFullScreen | boolean | 是   | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、<!--RP15-->三键导航栏<!--RP15End-->显示)。true表示沉浸式布局;false表示非沉浸式布局。 |
11321
11322**返回值:**
11323
11324| 类型                | 说明                      |
11325| ------------------- | ------------------------- |
11326| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
11327
11328**示例:**
11329
11330```ts
11331// EntryAbility.ets
11332import { UIAbility } from '@kit.AbilityKit';
11333import { BusinessError } from '@kit.BasicServicesKit';
11334
11335export default class EntryAbility extends UIAbility {
11336  // ...
11337  onWindowStageCreate(windowStage: window.WindowStage): void {
11338    console.info('onWindowStageCreate');
11339    let windowClass: window.Window | undefined = undefined;
11340    windowStage.getMainWindow((err: BusinessError, data) => {
11341      const errCode: number = err.code;
11342      if (errCode) {
11343        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
11344        return;
11345      }
11346      windowClass = data;
11347      let isLayoutFullScreen: boolean = true;
11348      let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen);
11349      promise.then(() => {
11350        console.info('Succeeded in setting the window layout to full-screen mode.');
11351      }).catch((err: BusinessError) => {
11352        console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
11353      });
11354    });
11355  }
11356}
11357```
11358
11359### setSystemBarEnable<sup>(deprecated)</sup>
11360
11361setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback&lt;void&gt;): void
11362
11363<!--RP14-->设置主窗口状态栏、三键导航栏的可见模式,状态栏通过status控制、三键导航栏通过navigation控制<!--RP14End-->,使用callback异步回调。<br>从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
11364
11365调用生效后返回并不表示状态栏和<!--RP15-->三键导航栏<!--RP15End-->的显示或隐藏已完成。子窗口调用后不生效。非全屏模式(悬浮窗、分屏等场景)下配置不生效。
11366
11367> **说明:**
11368>
11369> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)。
11370
11371**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11372
11373**参数:**
11374
11375| 参数名   | 类型                      | 必填 | 说明                                                         |
11376| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
11377| names    | Array<'status'\|'navigation'> | 是   | 设置窗口全屏模式时状态栏和<!--RP15-->三键导航栏<!--RP15End-->是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];设置为[],则不显示。 |
11378| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                                   |
11379
11380
11381**示例:**
11382
11383```ts
11384// 此处以状态栏等均不显示为例
11385// EntryAbility.ets
11386import { UIAbility } from '@kit.AbilityKit';
11387import { BusinessError } from '@kit.BasicServicesKit';
11388
11389export default class EntryAbility extends UIAbility {
11390  // ...
11391  onWindowStageCreate(windowStage: window.WindowStage): void {
11392    console.info('onWindowStageCreate');
11393    let windowClass: window.Window | undefined = undefined;
11394    windowStage.getMainWindow((err: BusinessError, data) => {
11395      const errCode: number = err.code;
11396      if (errCode) {
11397        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
11398        return;
11399      }
11400      windowClass = data;
11401      let names: Array<'status' | 'navigation'> = [];
11402      windowClass.setSystemBarEnable(names, (err: BusinessError) => {
11403        const errCode: number = err.code;
11404        if (errCode) {
11405          console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
11406          return;
11407        }
11408        console.info('Succeeded in setting the system bar to be invisible.');
11409      });
11410    });
11411  }
11412}
11413```
11414
11415### setSystemBarEnable<sup>(deprecated)</sup>
11416
11417setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise&lt;void&gt;
11418
11419<!--RP14-->设置主窗口状态栏、三键导航栏的可见模式,状态栏通过status控制、三键导航栏通过navigation控制<!--RP14End-->,使用Promise异步回调。<br>从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
11420
11421调用生效后返回并不表示状态栏和<!--RP15-->三键导航栏<!--RP15End-->的显示或隐藏已完成。子窗口调用后不生效。非全屏模式(悬浮窗、分屏等场景)下配置不生效。
11422
11423> **说明:**
11424>
11425> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)。
11426
11427**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11428
11429**参数:**
11430
11431| 参数名 | 类型  | 必填 | 说明                                                         |
11432| ------ | ---------------------------- | ---- | ------------------------ |
11433| names  | Array<'status'\|'navigation'> | 是   | 设置窗口全屏模式时状态栏和<!--RP15-->三键导航栏<!--RP15End-->是否显示。<br>例如,需全部显示,该参数设置为['status',&nbsp;'navigation'];设置为[],则不显示。 |
11434
11435**返回值:**
11436
11437| 类型                | 说明                      |
11438| ------------------- | ------------------------- |
11439| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
11440
11441
11442**示例:**
11443
11444```ts
11445// 此处以状态栏等均不显示为例
11446// EntryAbility.ets
11447import { UIAbility } from '@kit.AbilityKit';
11448import { BusinessError } from '@kit.BasicServicesKit';
11449
11450export default class EntryAbility extends UIAbility {
11451  // ...
11452  onWindowStageCreate(windowStage: window.WindowStage): void {
11453    console.info('onWindowStageCreate');
11454    let windowClass: window.Window | undefined = undefined;
11455    windowStage.getMainWindow((err: BusinessError, data) => {
11456      const errCode: number = err.code;
11457      if (errCode) {
11458        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
11459        return;
11460      }
11461      windowClass = data;
11462      let names: Array<'status' | 'navigation'> = [];
11463      let promise = windowClass.setSystemBarEnable(names);
11464      promise.then(() => {
11465        console.info('Succeeded in setting the system bar to be invisible.');
11466      }).catch((err: BusinessError) => {
11467        console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
11468      });
11469    });
11470  }
11471}
11472```
11473
11474### setSystemBarProperties<sup>(deprecated)</sup>
11475
11476setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback&lt;void&gt;): void
11477
11478设置主窗口<!--Del-->三键导航栏、<!--DelEnd-->状态栏的属性,使用callback异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
11479
11480子窗口调用后不生效。非全屏模式(悬浮窗、分屏等场景)下配置不生效。
11481
11482> **说明:**
11483>
11484> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9)。
11485
11486**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11487
11488**参数:**
11489
11490| 参数名              | 类型                                        | 必填 | 说明                   |
11491| ------------------- | ------------------------------------------- | ---- | ---------------------- |
11492| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是   | <!--Del-->三键导航栏、<!--DelEnd-->状态栏的属性。 |
11493| callback            | AsyncCallback&lt;void&gt;                   | 是   | 回调函数。             |
11494
11495**示例:**
11496
11497```ts
11498// EntryAbility.ets
11499import { UIAbility } from '@kit.AbilityKit';
11500import { BusinessError } from '@kit.BasicServicesKit';
11501
11502export default class EntryAbility extends UIAbility {
11503  // ...
11504  onWindowStageCreate(windowStage: window.WindowStage): void {
11505    console.info('onWindowStageCreate');
11506    let windowClass: window.Window | undefined = undefined;
11507    windowStage.getMainWindow((err: BusinessError, data) => {
11508      const errCode: number = err.code;
11509      if (errCode) {
11510        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
11511        return;
11512      }
11513      windowClass = data;
11514      let SystemBarProperties: window.SystemBarProperties = {
11515        statusBarColor: '#ff00ff',
11516        navigationBarColor: '#00ff00',
11517        //以下两个属性从API Version8开始支持
11518        statusBarContentColor: '#ffffff',
11519        navigationBarContentColor: '#00ffff'
11520      };
11521      windowClass.setSystemBarProperties(SystemBarProperties, (err) => {
11522        const errCode: number = err.code;
11523        if (errCode) {
11524          console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
11525          return;
11526        }
11527        console.info('Succeeded in setting the system bar properties.');
11528      });
11529    });
11530  }
11531}
11532```
11533
11534### setSystemBarProperties<sup>(deprecated)</sup>
11535
11536setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise&lt;void&gt;
11537
11538设置主窗口<!--Del-->三键导航栏、<!--DelEnd-->状态栏的属性,使用Promise异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End-->
11539
11540子窗口调用后不生效。
11541
11542> **说明:**
11543>
11544> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9-1)。
11545
11546**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11547
11548**参数:**
11549
11550| 参数名              | 类型                                        | 必填 | 说明                   |
11551| ------------------- | ------------------------------------------- | ---- | ---------------------- |
11552| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是   | <!--Del-->三键导航栏、<!--DelEnd-->状态栏的属性。 |
11553
11554**返回值:**
11555
11556| 类型                | 说明                      |
11557| ------------------- | ------------------------- |
11558| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
11559
11560**示例:**
11561
11562```ts
11563// EntryAbility.ets
11564import { UIAbility } from '@kit.AbilityKit';
11565import { BusinessError } from '@kit.BasicServicesKit';
11566
11567export default class EntryAbility extends UIAbility {
11568  // ...
11569  onWindowStageCreate(windowStage: window.WindowStage): void {
11570    console.info('onWindowStageCreate');
11571    let windowClass: window.Window | undefined = undefined;
11572    windowStage.getMainWindow((err: BusinessError, data) => {
11573      const errCode: number = err.code;
11574      if (errCode) {
11575        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
11576        return;
11577      }
11578      windowClass = data;
11579      let SystemBarProperties: window.SystemBarProperties = {
11580        statusBarColor: '#ff00ff',
11581        navigationBarColor: '#00ff00',
11582        //以下两个属性从API Version8开始支持
11583        statusBarContentColor: '#ffffff',
11584        navigationBarContentColor: '#00ffff'
11585      };
11586      let promise = windowClass.setSystemBarProperties(SystemBarProperties);
11587      promise.then(() => {
11588        console.info('Succeeded in setting the system bar properties.');
11589      }).catch((err: BusinessError) => {
11590        console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
11591      });
11592    });
11593  }
11594}
11595```
11596
11597### loadContent<sup>(deprecated)</sup>
11598
11599loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void
11600
11601为当前窗口加载具体页面内容,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。
11602
11603> **说明:**
11604>
11605> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9)。
11606
11607**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11608
11609**参数:**
11610
11611| 参数名   | 类型                      | 必填 | 说明                 |
11612| -------- | ------------------------- | ---- | -------------------- |
11613| path     | string                    | 是   | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 |
11614| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
11615
11616**示例:**
11617
11618```ts
11619import { BusinessError } from '@kit.BasicServicesKit';
11620
11621windowClass.loadContent('pages/page2/page3', (err: BusinessError) => {
11622  const errCode: number = err.code;
11623  if (errCode) {
11624    console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
11625    return;
11626  }
11627  console.info('Succeeded in loading the content.');
11628});
11629```
11630
11631### loadContent<sup>(deprecated)</sup>
11632
11633loadContent(path: string): Promise&lt;void&gt;
11634
11635为当前窗口加载具体页面内容,使用Promise异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。
11636
11637> **说明:**
11638>
11639> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9-1)。
11640
11641**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11642
11643**参数:**
11644
11645| 参数名 | 类型   | 必填 | 说明                 |
11646| ------ | ------ | ---- | -------------------- |
11647| path   | string | 是   | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 |
11648
11649**返回值:**
11650
11651| 类型                | 说明                      |
11652| ------------------- | ------------------------- |
11653| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
11654
11655**示例:**
11656
11657```ts
11658import { BusinessError } from '@kit.BasicServicesKit';
11659
11660let promise = windowClass.loadContent('pages/page2/page3');
11661promise.then(() => {
11662  console.info('Succeeded in loading the content.');
11663}).catch((err: BusinessError) => {
11664  console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
11665});
11666```
11667
11668### isShowing<sup>(deprecated)</sup>
11669
11670isShowing(callback: AsyncCallback&lt;boolean&gt;): void
11671
11672判断当前窗口是否已显示,使用callback异步回调。
11673
11674> **说明:**
11675>
11676> 从API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。
11677
11678**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11679
11680**参数:**
11681
11682| 参数名   | 类型                         | 必填 | 说明                                                         |
11683| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
11684| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 |
11685
11686**示例:**
11687
11688```ts
11689import { BusinessError } from '@kit.BasicServicesKit';
11690
11691windowClass.isShowing((err: BusinessError, data) => {
11692  const errCode: number = err.code;
11693  if (errCode) {
11694    console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`);
11695    return;
11696  }
11697  console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
11698});
11699```
11700
11701### isShowing<sup>(deprecated)</sup>
11702
11703isShowing(): Promise&lt;boolean&gt;
11704
11705判断当前窗口是否已显示,使用Promise异步回调。
11706
11707> **说明:**
11708>
11709> 从API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。
11710
11711**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11712
11713**返回值:**
11714
11715| 类型                   | 说明                                                         |
11716| ---------------------- | ------------------------------------------------------------ |
11717| Promise&lt;boolean&gt; | Promise对象。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 |
11718
11719**示例:**
11720
11721```ts
11722import { BusinessError } from '@kit.BasicServicesKit';
11723
11724let promise = windowClass.isShowing();
11725promise.then((data) => {
11726  console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
11727}).catch((err: BusinessError) => {
11728  console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`);
11729});
11730```
11731
11732### on('systemAvoidAreaChange')<sup>(deprecated)</sup>
11733
11734on(type: 'systemAvoidAreaChange', callback: Callback&lt;AvoidArea&gt;): void
11735
11736开启当前窗口系统规避区变化的监听。
11737
11738> **说明:**
11739>
11740> 从API version 7开始支持,从API version 9开始废弃,推荐使用[on('avoidAreaChange')](#onavoidareachange9)。
11741
11742**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11743
11744**参数:**
11745
11746| 参数名   | 类型                                       | 必填 | 说明                                                    |
11747| -------- |------------------------------------------| ---- | ------------------------------------------------------- |
11748| type     | string                                   | 是   | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 |
11749| callback | Callback&lt;[AvoidArea](#avoidarea7)&gt; | 是   | 回调函数。返回当前规避区。                             |
11750
11751
11752**示例:**
11753
11754```ts
11755windowClass.on('systemAvoidAreaChange', (data) => {
11756  console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data));
11757});
11758```
11759
11760### off('systemAvoidAreaChange')<sup>(deprecated)</sup>
11761
11762off(type: 'systemAvoidAreaChange', callback?: Callback&lt;AvoidArea&gt;): void
11763
11764关闭当前窗口系统规避区变化的监听。
11765
11766> **说明:**
11767>
11768> 从API version 7开始支持,从API version 9开始废弃,推荐使用[off('avoidAreaChange')](#offavoidareachange9)。
11769
11770**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11771
11772**参数:**
11773
11774| 参数名   | 类型                                       | 必填 | 说明                                                    |
11775| -------- |------------------------------------------| ---- | ------------------------------------------------------- |
11776| type     | string                                   | 是   | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 |
11777| callback | Callback&lt;[AvoidArea](#avoidarea7)&gt; | 否   | 回调函数。返回当前规避区。若传入参数,则关闭该监听。若未传入参数,则关闭所有系统规避区变化的监听。           |
11778
11779**示例:**
11780
11781```ts
11782const callback = (avoidArea: window.AvoidArea) => {
11783  // ...
11784}
11785windowClass.on('systemAvoidAreaChange', callback);
11786windowClass.off('systemAvoidAreaChange', callback);
11787// 如果通过on开启多个callback进行监听,同时关闭所有监听:
11788windowClass.off('systemAvoidAreaChange');
11789```
11790
11791### isSupportWideGamut<sup>(deprecated)</sup>
11792
11793isSupportWideGamut(callback: AsyncCallback&lt;boolean&gt;): void
11794
11795判断当前窗口是否支持广色域模式,使用callback异步回调。
11796
11797> **说明:**
11798>
11799> 从API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9)。
11800
11801**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11802
11803**参数:**
11804
11805| 参数名   | 类型                         | 必填 | 说明                                                         |
11806| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
11807| callback | AsyncCallback&lt;boolean&gt; | 是   | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 |
11808
11809**示例:**
11810
11811```ts
11812import { BusinessError } from '@kit.BasicServicesKit';
11813
11814windowClass.isSupportWideGamut((err: BusinessError, data) => {
11815  const errCode: number = err.code;
11816  if (errCode) {
11817    console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`);
11818    return;
11819  }
11820  console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data));
11821});
11822```
11823
11824### isSupportWideGamut<sup>(deprecated)</sup>
11825
11826isSupportWideGamut(): Promise&lt;boolean&gt;
11827
11828判断当前窗口是否支持广色域模式,使用Promise异步回调。
11829
11830> **说明:**
11831>
11832> 从API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9-1)。
11833
11834**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11835
11836**返回值:**
11837
11838| 类型                   | 说明                                                         |
11839| ---------------------- | ------------------------------------------------------------ |
11840| Promise&lt;boolean&gt; | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 |
11841
11842**示例:**
11843
11844```ts
11845import { BusinessError } from '@kit.BasicServicesKit';
11846
11847let promise = windowClass.isSupportWideGamut();
11848promise.then((data) => {
11849  console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data));
11850}).catch((err: BusinessError) => {
11851  console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`);
11852});
11853```
11854
11855### setColorSpace<sup>(deprecated)</sup>
11856
11857setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback&lt;void&gt;): void
11858
11859设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。
11860
11861> **说明:**
11862>
11863> 从API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9)。
11864
11865**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11866
11867**参数:**
11868
11869| 参数名     | 类型                      | 必填 | 说明         |
11870| ---------- | ------------------------- | ---- | ------------ |
11871| colorSpace | [ColorSpace](#colorspace8) | 是   | 设置色域模式。 |
11872| callback   | AsyncCallback&lt;void&gt; | 是   | 回调函数。   |
11873
11874
11875**示例:**
11876
11877```ts
11878import { BusinessError } from '@kit.BasicServicesKit';
11879
11880windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => {
11881  const errCode: number = err.code;
11882  if (errCode) {
11883    console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`);
11884    return;
11885  }
11886  console.info('Succeeded in setting window colorspace.');
11887});
11888```
11889
11890### setColorSpace<sup>(deprecated)</sup>
11891
11892setColorSpace(colorSpace:ColorSpace): Promise&lt;void&gt;
11893
11894设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。
11895
11896> **说明:**
11897>
11898> 从API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9-1)。
11899
11900**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11901
11902**参数:**
11903
11904| 参数名     | 类型                      | 必填 | 说明           |
11905| ---------- | ------------------------- | ---- | -------------- |
11906| colorSpace | [ColorSpace](#colorspace8) | 是   | 设置色域模式。 |
11907
11908**返回值:**
11909
11910| 类型                | 说明                      |
11911| ------------------- | ------------------------- |
11912| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
11913
11914
11915**示例:**
11916
11917```ts
11918import { BusinessError } from '@kit.BasicServicesKit';
11919
11920let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT);
11921promise.then(() => {
11922  console.info('Succeeded in setting window colorspace.');
11923}).catch((err: BusinessError) => {
11924  console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`);
11925});
11926```
11927
11928### getColorSpace<sup>(deprecated)</sup>
11929
11930getColorSpace(callback: AsyncCallback&lt;ColorSpace&gt;): void
11931
11932获取当前窗口色域模式,使用callback异步回调。
11933
11934> **说明:**
11935>
11936> 从API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。
11937
11938**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11939
11940**参数:**
11941
11942| 参数名   | 类型                                           | 必填 | 说明                                                       |
11943| -------- | ---------------------------------------------- | ---- | ---------------------------------------------------------- |
11944| callback | AsyncCallback&lt;[ColorSpace](#colorspace8)&gt; | 是   | 回调函数。当获取成功,err为undefined,data为当前色域模式。 |
11945
11946**示例:**
11947
11948```ts
11949import { BusinessError } from '@kit.BasicServicesKit';
11950
11951windowClass.getColorSpace((err: BusinessError, data) => {
11952  const errCode: number = err.code;
11953  if (errCode) {
11954    console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`);
11955    return;
11956  }
11957  console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data));
11958});
11959```
11960
11961### getColorSpace<sup>(deprecated)</sup>
11962
11963getColorSpace(): Promise&lt;ColorSpace&gt;
11964
11965获取当前窗口色域模式,使用Promise异步回调。
11966
11967> **说明:**
11968>
11969> 从API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。
11970
11971**系统能力:** SystemCapability.WindowManager.WindowManager.Core
11972
11973**返回值:**
11974
11975| 类型                                     | 说明                            |
11976| ---------------------------------------- | ------------------------------- |
11977| Promise&lt;[ColorSpace](#colorspace8)&gt; | Promise对象。返回当前色域模式。 |
11978
11979**示例:**
11980
11981```ts
11982import { BusinessError } from '@kit.BasicServicesKit';
11983
11984let promise = windowClass.getColorSpace();
11985promise.then((data) => {
11986  console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data));
11987}).catch((err: BusinessError) => {
11988  console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`);
11989});
11990```
11991
11992### setBackgroundColor<sup>(deprecated)</sup>
11993
11994setBackgroundColor(color: string, callback: AsyncCallback&lt;void&gt;): void
11995
11996设置窗口的背景色,使用callback异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
11997
11998> **说明:**
11999>
12000> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。
12001
12002**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12003
12004**参数:**
12005
12006| 参数名   | 类型                      | 必填 | 说明                                                         |
12007| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
12008| color    | string                    | 是   | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 |
12009| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                                   |
12010
12011
12012**示例:**
12013
12014```ts
12015import { BusinessError } from '@kit.BasicServicesKit';
12016
12017let color: string = '#00ff33';
12018windowClass.setBackgroundColor(color, (err: BusinessError) => {
12019  const errCode: number = err.code;
12020  if (errCode) {
12021    console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`);
12022    return;
12023  }
12024  console.info('Succeeded in setting the background color.');
12025});
12026```
12027
12028### setBackgroundColor<sup>(deprecated)</sup>
12029
12030setBackgroundColor(color: string): Promise&lt;void&gt;
12031
12032设置窗口的背景色,使用Promise异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。
12033
12034> **说明:**
12035>
12036> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。
12037
12038**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12039
12040**参数:**
12041
12042| 参数名 | 类型   | 必填 | 说明                                                         |
12043| ------ | ------ | ---- | ------------------------------------------------------------ |
12044| color  | string | 是   | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 |
12045
12046**返回值:**
12047
12048| 类型                | 说明                      |
12049| ------------------- | ------------------------- |
12050| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
12051
12052
12053**示例:**
12054
12055```ts
12056import { BusinessError } from '@kit.BasicServicesKit';
12057
12058let color: string = '#00ff33';
12059let promise = windowClass.setBackgroundColor(color);
12060promise.then(() => {
12061  console.info('Succeeded in setting the background color.');
12062}).catch((err: BusinessError) => {
12063  console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`);
12064});
12065```
12066
12067### setBrightness<sup>(deprecated)</sup>
12068
12069setBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void
12070
12071允许应用窗口设置屏幕亮度值,使用callback异步回调。
12072
12073当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。
12074
12075> **说明:**
12076>
12077> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9)。
12078
12079**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12080
12081**参数:**
12082
12083| 参数名     | 类型                      | 必填 | 说明                                    |
12084| ---------- | ------------------------- | ---- |---------------------------------------|
12085| brightness | number                    | 是   | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 |
12086| callback   | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                 |
12087
12088
12089**示例:**
12090
12091```ts
12092import { BusinessError } from '@kit.BasicServicesKit';
12093
12094let brightness: number = 1;
12095windowClass.setBrightness(brightness, (err: BusinessError) => {
12096  const errCode: number = err.code;
12097  if (errCode) {
12098    console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`);
12099    return;
12100  }
12101  console.info('Succeeded in setting the brightness.');
12102});
12103```
12104
12105### setBrightness<sup>(deprecated)</sup>
12106
12107setBrightness(brightness: number): Promise&lt;void&gt;
12108
12109允许应用窗口设置屏幕亮度值,使用Promise异步回调。
12110
12111当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。
12112
12113> **说明:**
12114>
12115> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9-1)。
12116
12117**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12118
12119**参数:**
12120
12121| 参数名     | 类型   | 必填 | 说明                                       |
12122| ---------- | ------ | ---- |------------------------------------------|
12123| brightness | number | 是   | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 |
12124
12125**返回值:**
12126
12127| 类型                | 说明                      |
12128| ------------------- | ------------------------- |
12129| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
12130
12131
12132**示例:**
12133
12134```ts
12135import { BusinessError } from '@kit.BasicServicesKit';
12136
12137let brightness: number = 1;
12138let promise = windowClass.setBrightness(brightness);
12139promise.then(() => {
12140  console.info('Succeeded in setting the brightness.');
12141}).catch((err: BusinessError) => {
12142  console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`);
12143});
12144```
12145
12146### setDimBehind<sup>(deprecated)</sup>
12147
12148setDimBehind(dimBehindValue: number, callback: AsyncCallback&lt;void&gt;): void
12149
12150窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用callback异步回调。
12151
12152> **说明:**
12153>
12154> 该接口不支持使用。从API version 7开始支持,从API version 9开始废弃。
12155
12156**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12157
12158**参数:**
12159
12160| 参数名         | 类型                      | 必填 | 说明                                     |
12161| -------------- | ------------------------- | ---- |----------------------------------------|
12162| dimBehindValue | number                    | 是   | 表示靠后的窗口的暗度值,取值范围为[0.0, 1.0],取1.0时表示最暗。 |
12163| callback       | AsyncCallback&lt;void&gt; | 是   | 回调函数。                                  |
12164
12165**示例:**
12166
12167```ts
12168import { BusinessError } from '@kit.BasicServicesKit';
12169
12170windowClass.setDimBehind(0.5, (err: BusinessError) => {
12171  const errCode: number = err.code;
12172  if (errCode) {
12173    console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`);
12174    return;
12175  }
12176  console.info('Succeeded in setting the dimness.');
12177});
12178```
12179
12180### setDimBehind<sup>(deprecated)</sup>
12181
12182setDimBehind(dimBehindValue: number): Promise&lt;void&gt;
12183
12184窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用Promise异步回调。
12185
12186> **说明:**
12187>
12188> 该接口不支持使用。从API version 7开始支持,从API version 9开始废弃。
12189
12190**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12191
12192**参数:**
12193
12194| 参数名         | 类型   | 必填 | 说明                                               |
12195| -------------- | ------ | ---- | -------------------------------------------------- |
12196| dimBehindValue | number | 是   | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 |
12197
12198**返回值:**
12199
12200| 类型                | 说明                      |
12201| ------------------- | ------------------------- |
12202| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
12203
12204**示例:**
12205
12206```ts
12207import { BusinessError } from '@kit.BasicServicesKit';
12208
12209let promise = windowClass.setDimBehind(0.5);
12210promise.then(() => {
12211  console.info('Succeeded in setting the dimness.');
12212}).catch((err: BusinessError) => {
12213  console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`);
12214});
12215```
12216
12217### setFocusable<sup>(deprecated)</sup>
12218
12219setFocusable(isFocusable: boolean, callback: AsyncCallback&lt;void&gt;): void
12220
12221设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从操作前的获焦窗口切换到该窗口,使用callback异步回调。
12222
12223> **说明:**
12224>
12225> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9)。
12226
12227**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12228
12229**参数:**
12230
12231| 参数名      | 类型                      | 必填 | 说明                         |
12232| ----------- | ------------------------- | ---- | ---------------------------- |
12233| isFocusable | boolean                   | 是   | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 |
12234| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数。                   |
12235
12236
12237**示例:**
12238
12239```ts
12240import { BusinessError } from '@kit.BasicServicesKit';
12241
12242let isFocusable: boolean = true;
12243windowClass.setFocusable(isFocusable, (err: BusinessError) => {
12244  const errCode: number = err.code;
12245  if (errCode) {
12246    console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`);
12247    return;
12248  }
12249  console.info('Succeeded in setting the window to be focusable.');
12250});
12251```
12252
12253### setFocusable<sup>(deprecated)</sup>
12254
12255setFocusable(isFocusable: boolean): Promise&lt;void&gt;
12256
12257设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用Promise异步回调。
12258
12259> **说明:**
12260>
12261> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9-1)。
12262
12263**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12264
12265**参数:**
12266
12267| 参数名      | 类型    | 必填 | 说明                         |
12268| ----------- | ------- | ---- | ---------------------------- |
12269| isFocusable | boolean | 是   | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 |
12270
12271**返回值:**
12272
12273| 类型                | 说明                      |
12274| ------------------- | ------------------------- |
12275| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
12276
12277
12278**示例:**
12279
12280```ts
12281import { BusinessError } from '@kit.BasicServicesKit';
12282
12283let isFocusable: boolean = true;
12284let promise = windowClass.setFocusable(isFocusable);
12285promise.then(() => {
12286  console.info('Succeeded in setting the window to be focusable.');
12287}).catch((err: BusinessError) => {
12288  console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`);
12289});
12290```
12291
12292### setKeepScreenOn<sup>(deprecated)</sup>
12293
12294setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback&lt;void&gt;): void
12295
12296设置屏幕是否为常亮状态,使用callback异步回调。
12297
12298> **说明:**
12299>
12300> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9)。
12301
12302**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12303
12304**参数:**
12305
12306| 参数名         | 类型                      | 必填 | 说明                     |
12307| -------------- | ------------------------- | ---- | ------------------------ |
12308| isKeepScreenOn | boolean                   | 是   | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 |
12309| callback       | AsyncCallback&lt;void&gt; | 是   | 回调函数。               |
12310
12311
12312**示例:**
12313
12314```ts
12315import { BusinessError } from '@kit.BasicServicesKit';
12316
12317let isKeepScreenOn: boolean = true;
12318windowClass.setKeepScreenOn(isKeepScreenOn, (err: BusinessError) => {
12319  const errCode: number = err.code;
12320  if (errCode) {
12321    console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`);
12322    return;
12323  }
12324  console.info('Succeeded in setting the screen to be always on.');
12325});
12326```
12327
12328### setKeepScreenOn<sup>(deprecated)</sup>
12329
12330setKeepScreenOn(isKeepScreenOn: boolean): Promise&lt;void&gt;
12331
12332设置屏幕是否为常亮状态,使用Promise异步回调。
12333
12334> **说明:**
12335>
12336> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9-1)。
12337
12338**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12339
12340**参数:**
12341
12342| 参数名         | 类型    | 必填 | 说明                     |
12343| -------------- | ------- | ---- | ------------------------ |
12344| isKeepScreenOn | boolean | 是   | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 |
12345
12346**返回值:**
12347
12348| 类型                | 说明                      |
12349| ------------------- | ------------------------- |
12350| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
12351
12352**示例:**
12353
12354```ts
12355import { BusinessError } from '@kit.BasicServicesKit';
12356
12357let isKeepScreenOn: boolean = true;
12358let promise = windowClass.setKeepScreenOn(isKeepScreenOn);
12359promise.then(() => {
12360  console.info('Succeeded in setting the screen to be always on.');
12361}).catch((err: BusinessError) => {
12362  console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`);
12363});
12364```
12365
12366### setOutsideTouchable<sup>(deprecated)</sup>
12367
12368setOutsideTouchable(touchable: boolean, callback: AsyncCallback&lt;void&gt;): void
12369
12370设置是否允许可点击子窗口之外的区域,使用callback异步回调。
12371
12372> **说明:**
12373>
12374> 从API version 7开始支持,从API version 9开始废弃。
12375>
12376> 从API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。
12377
12378**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12379
12380**参数:**
12381
12382| 参数名    | 类型                      | 必填 | 说明             |
12383| --------- | ------------------------- | ---- | ---------------- |
12384| touchable | boolean                   | 是   | 设置是否可点击。true表示可点击;false表示不可点击。 |
12385| callback  | AsyncCallback&lt;void&gt; | 是   | 回调函数。       |
12386
12387**示例:**
12388
12389```ts
12390import { BusinessError } from '@kit.BasicServicesKit';
12391
12392windowClass.setOutsideTouchable(true, (err: BusinessError) => {
12393  const errCode: number = err.code;
12394  if (errCode) {
12395    console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`);
12396    return;
12397  }
12398  console.info('Succeeded in setting the area to be touchable.');
12399});
12400```
12401
12402### setOutsideTouchable<sup>(deprecated)</sup>
12403
12404setOutsideTouchable(touchable: boolean): Promise&lt;void&gt;
12405
12406设置是否允许可点击子窗口之外的区域,使用Promise异步回调。
12407
12408> **说明:**
12409>
12410> 从API version 7开始支持,从API version 9开始废弃。
12411>
12412> 从API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。
12413
12414**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12415
12416**参数:**
12417
12418| 参数名    | 类型    | 必填 | 说明             |
12419| --------- | ------- | ---- | ---------------- |
12420| touchable | boolean | 是   | 设置是否可点击。true表示可点击;false表示不可点击。 |
12421
12422**返回值:**
12423
12424| 类型                | 说明                      |
12425| ------------------- | ------------------------- |
12426| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
12427
12428**示例:**
12429
12430```ts
12431import { BusinessError } from '@kit.BasicServicesKit';
12432
12433let promise = windowClass.setOutsideTouchable(true);
12434promise.then(() => {
12435  console.info('Succeeded in setting the area to be touchable.');
12436}).catch((err: BusinessError) => {
12437  console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`);
12438});
12439```
12440
12441### setPrivacyMode<sup>(deprecated)</sup>
12442
12443setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback&lt;void&gt;): void
12444
12445设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。
12446
12447> **说明:**
12448>
12449> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9)。
12450
12451**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12452
12453**参数:**
12454
12455| 参数名        | 类型                      | 必填 | 说明                 |
12456| ------------- | ------------------------- | ---- | -------------------- |
12457| isPrivacyMode | boolean                   | 是   | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 |
12458| callback      | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
12459
12460**示例:**
12461
12462```ts
12463import { BusinessError } from '@kit.BasicServicesKit';
12464
12465let isPrivacyMode: boolean = true;
12466windowClass.setPrivacyMode(isPrivacyMode, (err: BusinessError) => {
12467  const errCode: number = err.code;
12468  if (errCode) {
12469    console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`);
12470    return;
12471  }
12472  console.info('Succeeded in setting the window to privacy mode.');
12473});
12474```
12475
12476### setPrivacyMode<sup>(deprecated)</sup>
12477
12478setPrivacyMode(isPrivacyMode: boolean): Promise&lt;void&gt;
12479
12480设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。
12481
12482> **说明:**
12483>
12484> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9-1)。
12485
12486**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12487
12488**参数:**
12489
12490| 参数名        | 类型    | 必填 | 说明                 |
12491| ------------- | ------- | ---- | -------------------- |
12492| isPrivacyMode | boolean | 是   | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 |
12493
12494**返回值:**
12495
12496| 类型                | 说明                      |
12497| ------------------- | ------------------------- |
12498| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
12499
12500**示例:**
12501
12502```ts
12503import { BusinessError } from '@kit.BasicServicesKit';
12504
12505let isPrivacyMode: boolean = true;
12506let promise = windowClass.setPrivacyMode(isPrivacyMode);
12507promise.then(() => {
12508  console.info('Succeeded in setting the window to privacy mode.');
12509}).catch((err: BusinessError) => {
12510  console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`);
12511});
12512```
12513
12514### setTouchable<sup>(deprecated)</sup>
12515
12516setTouchable(isTouchable: boolean, callback: AsyncCallback&lt;void&gt;): void
12517
12518设置窗口是否为可触状态,使用callback异步回调。
12519
12520> **说明:**
12521>
12522> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9)。
12523
12524**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12525
12526**参数:**
12527
12528| 参数名      | 类型                      | 必填 | 说明                 |
12529| ----------- | ------------------------- | ---- | -------------------- |
12530| isTouchable | boolean                   | 是   | 窗口是否为可触状态。true表示可触;false表示不可触。 |
12531| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
12532
12533
12534**示例:**
12535
12536```ts
12537import { BusinessError } from '@kit.BasicServicesKit';
12538
12539let isTouchable = true;
12540windowClass.setTouchable(isTouchable, (err: BusinessError) => {
12541  const errCode: number = err.code;
12542  if (errCode) {
12543    console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`);
12544    return;
12545  }
12546  console.info('Succeeded in setting the window to be touchable.');
12547});
12548```
12549
12550### setTouchable<sup>(deprecated)</sup>
12551
12552setTouchable(isTouchable: boolean): Promise&lt;void&gt;
12553
12554设置窗口是否为可触状态,使用Promise异步回调。
12555
12556> **说明:**
12557>
12558> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9-1)。
12559
12560**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12561
12562**参数:**
12563
12564| 参数名      | 类型    | 必填 | 说明                 |
12565| ----------- | ------- | ---- | -------------------- |
12566| isTouchable | boolean | 是   | 窗口是否为可触状态。true表示可触;false表示不可触。 |
12567
12568**返回值:**
12569
12570| 类型                | 说明                      |
12571| ------------------- | ------------------------- |
12572| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
12573
12574
12575**示例:**
12576
12577```ts
12578import { BusinessError } from '@kit.BasicServicesKit';
12579
12580let isTouchable = true;
12581let promise = windowClass.setTouchable(isTouchable);
12582promise.then(() => {
12583  console.info('Succeeded in setting the window to be touchable.');
12584}).catch((err: BusinessError) => {
12585  console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`);
12586});
12587```
12588
12589## WindowStageEventType<sup>9+</sup>
12590
12591WindowStage生命周期。
12592
12593**模型约束:** 此接口仅可在Stage模型下使用。
12594
12595**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12596
12597**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
12598
12599| 名称       | 值 | 说明       |
12600| ---------- | ------ | ---------- |
12601| SHOWN      | 1      | 切到前台,例如点击应用图标启动,无论是首次启动还是从后台启动均会触发。 |
12602| ACTIVE     | 2      | 获焦状态,例如应用窗口处理点击事件后的状态、应用启动后的状态。 |
12603| INACTIVE   | 3      | 失焦状态,例如打开新应用或点击其他窗口后,原获焦窗口的状态。 |
12604| HIDDEN     | 4      | 切到后台,例如应用上滑退出、应用窗口关闭。 |
12605| RESUMED<sup>11+</sup> | 5      | 前台可交互状态,例如应用打开后,可以与用户交互的状态。 |
12606| PAUSED<sup>11+</sup>  | 6      | 前台不可交互状态,例如从屏幕底部上划,应用进入到多任务界面后的状态。 |
12607
12608## ModalityType<sup>14+</sup>
12609
12610子窗口模态类型枚举。
12611
12612**系统能力:** SystemCapability.Window.SessionManager
12613
12614**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
12615
12616| 名称                 | 值      | 说明       |
12617| -------------------- | ------ | ---------- |
12618| WINDOW_MODALITY      | 0      | 模态子窗类型为模窗口子窗,当仅需要其父级窗口不响应用户操作时,可选此参数。 |
12619| APPLICATION_MODALITY | 1      | 模态子窗类型为模应用子窗,除其父级窗口外还需要该应用其他实例的窗口不响应用户操作时,可选此参数。<br> 此接口仅支持在2in1设备下使用。 |
12620
12621## SubWindowOptions<sup>11+</sup>
12622
12623子窗口创建参数。
12624
12625**系统能力:** SystemCapability.Window.SessionManager
12626
12627| 名称      | 类型  | 只读 | 可选 | 说明         |
12628| ---------- | ---- | ---- | ---- | ----------- |
12629| title<sup>11+</sup>    | string | 否 | 否 | 子窗口标题。标题显示区域最右端不超过系统三键区域最左端,超过部分以省略号表示。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。      |
12630| decorEnabled<sup>11+</sup> | boolean | 否 | 否 | 子窗口是否显示装饰。true表示子窗口显示装饰,false表示子窗口不显示装饰。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。       |
12631| isModal<sup>12+</sup>    | boolean | 否 | 是 | 子窗口是否启用模态属性。true表示子窗口启用模态属性,false表示子窗口禁用模态属性。不设置,则默认为false。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。      |
12632| modalityType<sup>14+</sup>    | [ModalityType](#modalitytype14) | 否 | 是 | 子窗口模态类型,仅当子窗口启用模态属性时生效。WINDOW_MODALITY表示子窗口模态类型为模窗口子窗,APPLICATION_MODALITY表示子窗口模态类型为模应用子窗。不设置,则默认为WINDOW_MODALITY。<br>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。       |
12633| windowRect<sup>18+</sup>    | [Rect](#rect7) | 否 | 是 | 子窗口矩形区域,其中子窗存在大小限制,具体参考[resize()](#resize9)方法。不设置,此窗口在显示时默认为全屏大小。<br>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。|
12634| zLevel<sup>18+</sup>    | number | 否 | 是 | 子窗口层级级别,仅当子窗口未启用模态属性,即未设置isModal时生效。该参数是整数,取值范围为[-10000, 10000],浮点数输入将向下取整。不设置,则默认为0。<br>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。|
12635| maximizeSupported<sup>19+</sup>    | boolean | 否 | 是 | 子窗口是否支持最大化特性。<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->true表示子窗口支持最大化,false表示子窗口不支持最大化。不设置,则默认为false。<br>**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。|
12636| outlineEnabled<sup>20+</sup>    | boolean | 否 | 是 | 子窗口是否显示描边。<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->true表示子窗口显示描边,false表示子窗口不显示描边。不设置,则默认为false。<br>**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。|
12637
12638## WindowStage<sup>9+</sup>
12639
12640窗口管理器。管理各个基本窗口单元,即[Window](#window)实例。
12641
12642下列API示例中都需在[onWindowStageCreate()](../apis-ability-kit/js-apis-app-ability-uiAbility.md#onwindowstagecreate)函数中使用WindowStage的实例调用对应方法。
12643
12644### getMainWindow<sup>9+</sup>
12645
12646getMainWindow(callback: AsyncCallback&lt;Window&gt;): void
12647
12648获取该WindowStage实例下的主窗口,使用callback异步回调。
12649
12650**模型约束:** 此接口仅可在Stage模型下使用。
12651
12652**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12653
12654**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
12655
12656**参数:**
12657
12658| 参数名   | 类型                                   | 必填 | 说明                                          |
12659| -------- | -------------------------------------- | ---- | --------------------------------------------- |
12660| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前WindowStage下的主窗口对象。 |
12661
12662**错误码:**
12663
12664以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
12665
12666| 错误码ID | 错误信息 |
12667| ------- | ------------------------------ |
12668| 1300002 | This window state is abnormal. |
12669| 1300005 | This window stage is abnormal. |
12670
12671**示例:**
12672
12673```ts
12674// EntryAbility.ets
12675import { UIAbility } from '@kit.AbilityKit';
12676import { BusinessError } from '@kit.BasicServicesKit';
12677
12678export default class EntryAbility extends UIAbility {
12679  // ...
12680
12681  onWindowStageCreate(windowStage: window.WindowStage) {
12682    console.info('onWindowStageCreate');
12683    let windowClass: window.Window | undefined = undefined;
12684    windowStage.getMainWindow((err: BusinessError, data) => {
12685      const errCode: number = err.code;
12686      if (errCode) {
12687        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
12688        return;
12689      }
12690      windowClass = data;
12691      console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
12692    });
12693  }
12694};
12695```
12696
12697### getMainWindow<sup>9+</sup>
12698
12699getMainWindow(): Promise&lt;Window&gt;
12700
12701获取该WindowStage实例下的主窗口,使用Promise异步回调。
12702
12703**模型约束:** 此接口仅可在Stage模型下使用。
12704
12705**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12706
12707**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
12708
12709**返回值:**
12710
12711| 类型                             | 说明                                             |
12712| -------------------------------- | ------------------------------------------------ |
12713| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前WindowStage下的主窗口对象。 |
12714
12715**错误码:**
12716
12717以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
12718
12719| 错误码ID | 错误信息 |
12720| ------- | ------------------------------ |
12721| 1300002 | This window state is abnormal. |
12722| 1300005 | This window stage is abnormal. |
12723
12724**示例:**
12725
12726```ts
12727// EntryAbility.ets
12728import { UIAbility } from '@kit.AbilityKit';
12729import { BusinessError } from '@kit.BasicServicesKit';
12730
12731export default class EntryAbility extends UIAbility {
12732  // ...
12733
12734  onWindowStageCreate(windowStage: window.WindowStage) {
12735    console.info('onWindowStageCreate');
12736    let windowClass: window.Window | undefined = undefined;
12737    let promise = windowStage.getMainWindow();
12738    promise.then((data) => {
12739      windowClass = data;
12740      console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
12741    }).catch((err: BusinessError) => {
12742      console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
12743    });
12744  }
12745};
12746```
12747
12748### getMainWindowSync<sup>9+</sup>
12749
12750getMainWindowSync(): Window
12751
12752获取该WindowStage实例下的主窗口。
12753
12754**模型约束:** 此接口仅可在Stage模型下使用。
12755
12756**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12757
12758**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
12759
12760**返回值:**
12761
12762| 类型 | 说明 |
12763| ----------------- | --------------------------------- |
12764| [Window](#window) | 返回当前WindowStage下的主窗口对象。 |
12765
12766**错误码:**
12767
12768以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
12769
12770| 错误码ID | 错误信息 |
12771| ------- | ------------------------------ |
12772| 1300002 | This window state is abnormal. |
12773| 1300005 | This window stage is abnormal. |
12774
12775**示例:**
12776<!--code_no_check-->
12777```ts
12778// EntryAbility.ets
12779import { UIAbility } from '@kit.AbilityKit';
12780
12781export default class EntryAbility extends UIAbility {
12782  // ...
12783
12784  onWindowStageCreate(windowStage: window.WindowStage) {
12785    console.info('onWindowStageCreate');
12786    try {
12787      let windowClass = windowStage.getMainWindowSync();
12788    } catch (exception) {
12789      console.error(`Failed to obtain the main window. Cause code: ${exception.code}, message: ${exception.message}`);
12790    }
12791  }
12792};
12793```
12794
12795### createSubWindow<sup>9+</sup>
12796
12797createSubWindow(name: string, callback: AsyncCallback&lt;Window&gt;): void
12798
12799创建该WindowStage实例下的子窗口,使用callback异步回调。
12800
12801**模型约束:** 此接口仅可在Stage模型下使用。
12802
12803**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12804
12805**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
12806
12807**参数:**
12808
12809| 参数名   | 类型                                   | 必填 | 说明                                          |
12810| -------- | -------------------------------------- | ---- | --------------------------------------------- |
12811| name     | string                                 | 是   | 子窗口的名字。                                |
12812| callback | AsyncCallback&lt;[Window](#window)&gt; | 是   | 回调函数。返回当前WindowStage下的子窗口对象。 |
12813
12814**错误码:**
12815
12816以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
12817
12818| 错误码ID | 错误信息 |
12819| ------- | ------------------------------ |
12820| 401     | Parameter error. Possible cause: Incorrect parameter types. |
12821| 1300002 | This window state is abnormal. |
12822
12823**示例:**
12824
12825```ts
12826// EntryAbility.ets
12827import { UIAbility } from '@kit.AbilityKit';
12828import { BusinessError } from '@kit.BasicServicesKit';
12829
12830export default class EntryAbility extends UIAbility {
12831  // ...
12832
12833  onWindowStageCreate(windowStage: window.WindowStage) {
12834    console.info('onWindowStageCreate');
12835    let windowClass: window.Window | undefined = undefined;
12836    try {
12837      windowStage.createSubWindow('mySubWindow', (err: BusinessError, data) => {
12838        const errCode: number = err.code;
12839        if (errCode) {
12840          console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`);
12841          return;
12842        }
12843        windowClass = data;
12844        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
12845        if (!windowClass) {
12846          console.info('Failed to load the content. Cause: windowClass is null');
12847        }
12848        else {
12849          (windowClass as window.Window).resize(500, 1000);
12850        }
12851      });
12852    } catch (exception) {
12853      console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`);
12854    }
12855  }
12856};
12857```
12858
12859### createSubWindow<sup>9+</sup>
12860
12861createSubWindow(name: string): Promise&lt;Window&gt;
12862
12863创建该WindowStage实例下的子窗口,使用Promise异步回调。
12864
12865**模型约束:** 此接口仅可在Stage模型下使用。
12866
12867**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12868
12869**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
12870
12871**参数:**
12872
12873| 参数名 | 类型   | 必填 | 说明           |
12874| ------ | ------ | ---- | -------------- |
12875| name   | string | 是   | 子窗口的名字。 |
12876
12877**返回值:**
12878
12879| 类型                             | 说明                                             |
12880| -------------------------------- | ------------------------------------------------ |
12881| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前WindowStage下的子窗口对象。 |
12882
12883**错误码:**
12884
12885以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
12886
12887| 错误码ID | 错误信息 |
12888| ------- | ------------------------------ |
12889| 401     | Parameter error. Possible cause: Incorrect parameter types. |
12890| 1300002 | This window state is abnormal. |
12891
12892**示例:**
12893
12894```ts
12895// EntryAbility.ets
12896import { UIAbility } from '@kit.AbilityKit';
12897import { BusinessError } from '@kit.BasicServicesKit';
12898
12899export default class EntryAbility extends UIAbility {
12900  // ...
12901
12902  onWindowStageCreate(windowStage: window.WindowStage) {
12903    console.info('onWindowStageCreate');
12904    let windowClass: window.Window | undefined = undefined;
12905    try {
12906      let promise = windowStage.createSubWindow('mySubWindow');
12907      promise.then((data) => {
12908        windowClass = data;
12909        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
12910      }).catch((err: BusinessError) => {
12911        console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`);
12912      });
12913    } catch (exception) {
12914      console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`);
12915    }
12916  }
12917};
12918```
12919
12920### createSubWindowWithOptions<sup>11+</sup>
12921
12922createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise&lt;Window&gt;
12923
12924创建该WindowStage实例下的子窗口,使用Promise异步回调。
12925
12926**模型约束:** 此接口仅可在Stage模型下使用。
12927
12928**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
12929
12930**系统能力:** SystemCapability.Window.SessionManager
12931
12932**参数:**
12933
12934| 参数名 | 类型   | 必填 | 说明           |
12935| ------ | ------ | ---- | -------------- |
12936| name   | string | 是   | 子窗口的名字。 |
12937| options  | [SubWindowOptions](#subwindowoptions11) | 是   | 子窗口参数。  |
12938
12939**返回值:**
12940
12941| 类型                             | 说明                                             |
12942| -------------------------------- | ------------------------------------------------ |
12943| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前WindowStage下创建的子窗口对象。 |
12944
12945**错误码:**
12946
12947以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
12948
12949| 错误码ID | 错误信息 |
12950| ------- | ------------------------------ |
12951| 401     | Parameter error. Possible cause: Incorrect parameter types. |
12952| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
12953| 1300002 | This window state is abnormal. |
12954| 1300005 | This window stage is abnormal. |
12955
12956**示例:**
12957
12958```ts
12959// EntryAbility.ets
12960import { UIAbility } from '@kit.AbilityKit';
12961import { BusinessError } from '@kit.BasicServicesKit';
12962
12963export default class EntryAbility extends UIAbility {
12964  // ...
12965
12966  onWindowStageCreate(windowStage: window.WindowStage) {
12967    console.info('onWindowStageCreate');
12968    let windowClass: window.Window | undefined = undefined;
12969    try {
12970      let options : window.SubWindowOptions = {
12971        title: 'title',
12972        decorEnabled: true
12973      };
12974      let promise = windowStage.createSubWindowWithOptions('mySubWindow', options);
12975      promise.then((data) => {
12976        windowClass = data;
12977        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
12978      }).catch((err: BusinessError) => {
12979        console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`);
12980      });
12981    } catch (exception) {
12982      console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`);
12983    }
12984  }
12985};
12986```
12987
12988### getSubWindow<sup>9+</sup>
12989
12990getSubWindow(callback: AsyncCallback&lt;Array&lt;Window&gt;&gt;): void
12991
12992获取该WindowStage实例下的所有子窗口,使用callback异步回调。
12993
12994**模型约束:** 此接口仅可在Stage模型下使用。
12995
12996**系统能力:** SystemCapability.WindowManager.WindowManager.Core
12997
12998**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
12999
13000**参数:**
13001
13002| 参数名   | 类型                                                | 必填 | 说明                                              |
13003| -------- | --------------------------------------------------- | ---- | ------------------------------------------------- |
13004| callback | AsyncCallback&lt;Array&lt;[Window](#window)&gt;&gt; | 是   | 回调函数。返回当前WindowStage下的所有子窗口对象。 |
13005
13006**错误码:**
13007
13008以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
13009
13010| 错误码ID | 错误信息 |
13011| ------- | ------------------------------ |
13012| 1300002 | This window state is abnormal. |
13013
13014**示例:**
13015<!--code_no_check-->
13016```ts
13017// EntryAbility.ets
13018import { UIAbility } from '@kit.AbilityKit';
13019import { BusinessError } from '@kit.BasicServicesKit';
13020
13021export default class EntryAbility extends UIAbility {
13022  // ...
13023
13024  onWindowStageCreate(windowStage: window.WindowStage) {
13025    console.info('onWindowStageCreate');
13026    let windowClass: window.Window[] = [];
13027    windowStage.getSubWindow((err: BusinessError, data) => {
13028      const errCode: number = err.code;
13029      if (errCode) {
13030        console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`);
13031        return;
13032      }
13033      windowClass = data;
13034      console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data));
13035    });
13036  }
13037};
13038```
13039
13040### getSubWindow<sup>9+</sup>
13041
13042getSubWindow(): Promise&lt;Array&lt;Window&gt;&gt;
13043
13044获取该WindowStage实例下的所有子窗口,使用Promise异步回调。
13045
13046**模型约束:** 此接口仅可在Stage模型下使用。
13047
13048**系统能力:** SystemCapability.WindowManager.WindowManager.Core
13049
13050**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
13051
13052**返回值:**
13053
13054| 类型                                          | 说明                                                 |
13055| --------------------------------------------- | ---------------------------------------------------- |
13056| Promise&lt;Array&lt;[Window](#window)&gt;&gt; | Promise对象。返回当前WindowStage下的所有子窗口对象。 |
13057
13058**错误码:**
13059
13060以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
13061
13062| 错误码ID | 错误信息 |
13063| ------- | ------------------------------ |
13064| 1300002 | This window state is abnormal. |
13065
13066**示例:**
13067<!--code_no_check-->
13068```ts
13069// EntryAbility.ets
13070import { UIAbility } from '@kit.AbilityKit';
13071import { BusinessError } from '@kit.BasicServicesKit';
13072
13073export default class EntryAbility extends UIAbility {
13074  // ...
13075
13076  onWindowStageCreate(windowStage: window.WindowStage) {
13077    console.info('onWindowStageCreate');
13078    let windowClass: window.Window[] = [];
13079    let promise = windowStage.getSubWindow();
13080    promise.then((data) => {
13081      windowClass = data;
13082      console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data));
13083    }).catch((err: BusinessError) => {
13084      console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`);
13085    });
13086  }
13087};
13088```
13089
13090### loadContent<sup>9+</sup>
13091
13092loadContent(path: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
13093
13094根据当前工程中指定的页面路径为WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。建议在UIAbility启动过程中调用该接口,重复调用将首先销毁旧的页面内容(即UIContent)再加载新页面内容,请谨慎使用。
13095
13096**模型约束:** 此接口仅可在Stage模型下使用。
13097
13098**系统能力:** SystemCapability.WindowManager.WindowManager.Core
13099
13100**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
13101
13102**参数:**
13103
13104| 参数名   | 类型                                            | 必填 | 说明                                                         |
13105| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
13106| path     | string                                          | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。  |
13107| storage  | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
13108| callback | AsyncCallback&lt;void&gt;                       | 是   | 回调函数。                                                   |
13109
13110**错误码:**
13111
13112以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13113
13114| 错误码ID | 错误信息 |
13115| ------- | ------------------------------ |
13116| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Invalid path parameter.|
13117| 1300002 | This window state is abnormal. |
13118
13119**示例:**
13120
13121```ts
13122// EntryAbility.ets
13123import { UIAbility } from '@kit.AbilityKit';
13124import { BusinessError } from '@kit.BasicServicesKit';
13125
13126export default class EntryAbility extends UIAbility {
13127  // ...
13128
13129  storage: LocalStorage = new LocalStorage();
13130
13131  onWindowStageCreate(windowStage: window.WindowStage) {
13132    this.storage.setOrCreate('storageSimpleProp', 121);
13133    console.info('onWindowStageCreate');
13134    try {
13135      windowStage.loadContent('pages/page2', this.storage, (err: BusinessError) => {
13136        const errCode: number = err.code;
13137        if (errCode) {
13138          console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
13139          return;
13140        }
13141        console.info('Succeeded in loading the content.');
13142      });
13143    } catch (exception) {
13144      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
13145    }
13146  }
13147};
13148```
13149
13150### loadContent<sup>9+</sup>
13151
13152loadContent(path: string, storage?: LocalStorage): Promise&lt;void&gt;
13153
13154根据当前工程中指定的页面路径为WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。建议在UIAbility启动过程中调用该接口,重复调用将首先销毁旧的页面内容(即UIContent)再加载新页面内容,请谨慎使用。
13155
13156**模型约束:** 此接口仅可在Stage模型下使用。
13157
13158**系统能力:** SystemCapability.WindowManager.WindowManager.Core
13159
13160**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
13161
13162**参数:**
13163
13164| 参数名  | 类型                                            | 必填 | 说明                                                         |
13165| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
13166| path    | string                                          | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 |
13167| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 否   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
13168
13169**返回值:**
13170
13171| 类型                | 说明                      |
13172| ------------------- | ------------------------- |
13173| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
13174
13175**错误码:**
13176
13177以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13178
13179| 错误码ID | 错误信息 |
13180| ------- | ------------------------------ |
13181| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Invalid path parameter.|
13182| 1300002 | This window state is abnormal. |
13183
13184**示例:**
13185
13186```ts
13187// EntryAbility.ets
13188import { UIAbility } from '@kit.AbilityKit';
13189import { BusinessError } from '@kit.BasicServicesKit';
13190
13191export default class EntryAbility extends UIAbility {
13192  // ...
13193
13194  storage: LocalStorage = new LocalStorage();
13195
13196  onWindowStageCreate(windowStage: window.WindowStage) {
13197    this.storage.setOrCreate('storageSimpleProp', 121);
13198    console.info('onWindowStageCreate');
13199    try {
13200      let promise = windowStage.loadContent('pages/page2', this.storage);
13201      promise.then(() => {
13202        console.info('Succeeded in loading the content.');
13203      }).catch((err: BusinessError) => {
13204        console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
13205      });
13206    } catch (exception) {
13207      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
13208    }
13209    ;
13210  }
13211};
13212```
13213
13214### loadContent<sup>9+</sup>
13215
13216loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void
13217
13218根据当前工程中指定的页面路径为WindowStage的主窗口加载具体页面内容,使用callback异步回调。建议在UIAbility启动过程中调用该接口,重复调用将首先销毁旧的页面内容(即UIContent)再加载新页面内容,请谨慎使用。
13219
13220**模型约束:** 此接口仅可在Stage模型下使用。
13221
13222**系统能力:** SystemCapability.WindowManager.WindowManager.Core
13223
13224**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
13225
13226**参数:**
13227
13228| 参数名   | 类型                      | 必填 | 说明                 |
13229| -------- | ------------------------- | ---- | -------------------- |
13230| path     | string                    | 是   | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 |
13231| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。           |
13232
13233**错误码:**
13234
13235以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13236
13237| 错误码ID | 错误信息 |
13238| ------- | ------------------------------ |
13239| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Invalid path parameter.|
13240| 1300002 | This window state is abnormal. |
13241
13242**示例:**
13243
13244```ts
13245// EntryAbility.ets
13246import { UIAbility } from '@kit.AbilityKit';
13247import { BusinessError } from '@kit.BasicServicesKit';
13248
13249export default class EntryAbility extends UIAbility {
13250  // ...
13251
13252  onWindowStageCreate(windowStage: window.WindowStage) {
13253    console.info('onWindowStageCreate');
13254    try {
13255      windowStage.loadContent('pages/page2', (err: BusinessError) => {
13256        const errCode: number = err.code;
13257        if (errCode) {
13258          console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
13259          return;
13260        }
13261        console.info('Succeeded in loading the content.');
13262      });
13263    } catch (exception) {
13264      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
13265    }
13266  }
13267};
13268```
13269
13270### loadContentByName<sup>11+</sup>
13271
13272loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
13273
13274根据指定路由页面名称为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性至加载页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,重复调用该接口将先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。
13275
13276**模型约束:** 此接口仅可在Stage模型下使用。
13277
13278**系统能力:** SystemCapability.WindowManager.WindowManager.Core
13279
13280**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
13281
13282**参数:**
13283
13284| 参数名   | 类型                                                    | 必填 | 说明                                                         |
13285| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
13286| name     | string                                                  | 是   | 命名路由页面的名称。                                             |
13287| storage  | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 是   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
13288| callback | AsyncCallback&lt;void&gt;                               | 是   | 回调函数。                                                   |
13289
13290**错误码:**
13291
13292以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13293
13294| 错误码ID | 错误信息                                      |
13295| -------- | --------------------------------------------- |
13296| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
13297| 1300002  | This window state is abnormal.                |
13298
13299**示例:**
13300
13301<!--code_no_check-->
13302```ts
13303// EntryAbility.ets
13304import { UIAbility } from '@kit.AbilityKit';
13305import { BusinessError } from '@kit.BasicServicesKit';
13306import * as Index from '../pages/Index'; // 导入命名路由页面
13307
13308export default class EntryAbility extends UIAbility {
13309  // ...
13310
13311  storage: LocalStorage = new LocalStorage();
13312
13313  onWindowStageCreate(windowStage: window.WindowStage) {
13314    console.info('onWindowStageCreate');
13315    this.storage.setOrCreate('storageSimpleProp', 121);
13316    try {
13317      windowStage.loadContentByName(Index.entryName, this.storage, (err: BusinessError) => {
13318        const errCode: number = err.code;
13319        if (errCode) {
13320          console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
13321          return;
13322        }
13323        console.info('Succeeded in loading the content.');
13324      });
13325    } catch (exception) {
13326      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
13327    }
13328  }
13329};
13330```
13331<!--code_no_check-->
13332```ts
13333// ets/pages/Index.ets
13334export const entryName : string = 'Index';
13335@Entry({routeName: entryName, useSharedStorage: true})
13336@Component
13337export struct Index {
13338  @State message: string = 'Hello World'
13339  @LocalStorageLink('storageSimpleProp') storageSimpleProp: number = 1;
13340  build() {
13341    Row() {
13342      Column() {
13343        Text(this.message)
13344          .fontSize(50)
13345          .fontWeight(FontWeight.Bold)
13346      }
13347      .width('100%')
13348    }
13349    .height('100%')
13350  }
13351}
13352```
13353
13354### loadContentByName<sup>11+</sup>
13355
13356loadContentByName(name: string, callback: AsyncCallback&lt;void&gt;): void
13357
13358根据指定路由页面名称为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,重复调用该接口将先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。
13359
13360**模型约束:** 此接口仅可在Stage模型下使用。
13361
13362**系统能力:** SystemCapability.WindowManager.WindowManager.Core
13363
13364**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
13365
13366**参数:**
13367
13368| 参数名   | 类型                      | 必填 | 说明             |
13369| -------- | ------------------------- | ---- | ---------------- |
13370| name     | string                    | 是   | 命名路由页面的名称。 |
13371| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。       |
13372
13373**错误码:**
13374
13375以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13376
13377| 错误码ID | 错误信息                                      |
13378| -------- | --------------------------------------------- |
13379| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
13380| 1300002  | This window state is abnormal.                |
13381
13382**示例:**
13383
13384<!--code_no_check-->
13385```ts
13386// EntryAbility.ets
13387import { UIAbility } from '@kit.AbilityKit';
13388import { BusinessError } from '@kit.BasicServicesKit';
13389import * as Index from '../pages/Index'; // 导入命名路由页面
13390
13391export default class EntryAbility extends UIAbility {
13392  // ...
13393
13394  onWindowStageCreate(windowStage: window.WindowStage) {
13395    console.info('onWindowStageCreate');
13396    try {
13397      windowStage.loadContentByName(Index.entryName, (err: BusinessError) => {
13398        const errCode: number = err.code;
13399        if (errCode) {
13400          console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
13401          return;
13402        }
13403        console.info('Succeeded in loading the content.');
13404      });
13405    } catch (exception) {
13406      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
13407    }
13408  }
13409};
13410```
13411<!--code_no_check-->
13412```ts
13413// ets/pages/Index.ets
13414export const entryName : string = 'Index';
13415@Entry({routeName: entryName})
13416@Component
13417export struct Index {
13418  @State message: string = 'Hello World'
13419  build() {
13420    Row() {
13421      Column() {
13422        Text(this.message)
13423          .fontSize(50)
13424          .fontWeight(FontWeight.Bold)
13425      }
13426      .width('100%')
13427    }
13428    .height('100%')
13429  }
13430}
13431```
13432
13433### loadContentByName<sup>11+</sup>
13434
13435loadContentByName(name: string, storage?: LocalStorage): Promise&lt;void&gt;;
13436
13437根据指定路由页面名称为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性至加载页面,使用promise异步回调。建议在UIAbility启动过程中使用该接口,重复调用该接口将先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。
13438
13439**模型约束:** 此接口仅可在Stage模型下使用。
13440
13441**系统能力:** SystemCapability.WindowManager.WindowManager.Core
13442
13443**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
13444
13445**参数:**
13446
13447| 参数名  | 类型         | 必填 | 说明                                                         |
13448| ------- | ------------ | ---- | ------------------------------------------------------------ |
13449| name    | string       | 是   | 命名路由页面的名称。                                             |
13450| storage | LocalStorage | 否   | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 |
13451
13452**错误码:**
13453
13454以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13455
13456| 错误码ID | 错误信息                                      |
13457| -------- | --------------------------------------------- |
13458| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
13459| 1300002  | This window state is abnormal.                |
13460
13461**示例:**
13462
13463<!--code_no_check-->
13464```ts
13465// EntryAbility.ets
13466import { UIAbility } from '@kit.AbilityKit';
13467import { BusinessError } from '@kit.BasicServicesKit';
13468import * as Index from '../pages/Index'; // 导入命名路由页面
13469
13470export default class EntryAbility extends UIAbility {
13471  // ...
13472
13473  storage: LocalStorage = new LocalStorage();
13474
13475  onWindowStageCreate(windowStage: window.WindowStage) {
13476    console.info('onWindowStageCreate');
13477    this.storage.setOrCreate('storageSimpleProp', 121);
13478    try {
13479      let promise = windowStage.loadContentByName(Index.entryName, this.storage);
13480      promise.then(() => {
13481        console.info('Succeeded in loading the content.');
13482      }).catch((err: BusinessError) => {
13483        console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
13484      });
13485    } catch (exception) {
13486      console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`);
13487    }
13488  }
13489};
13490```
13491<!--code_no_check-->
13492```ts
13493// ets/pages/Index.ets
13494export const entryName : string = 'Index';
13495@Entry({routeName: entryName, useSharedStorage: true})
13496@Component
13497export struct Index {
13498  @State message: string = 'Hello World'
13499  @LocalStorageLink('storageSimpleProp') storageSimpleProp: number = 1;
13500  build() {
13501    Row() {
13502      Column() {
13503        Text(this.message)
13504          .fontSize(50)
13505          .fontWeight(FontWeight.Bold)
13506      }
13507      .width('100%')
13508    }
13509    .height('100%')
13510  }
13511}
13512```
13513
13514### on('windowStageEvent')<sup>9+</sup>
13515
13516on(eventType: 'windowStageEvent', callback: Callback&lt;WindowStageEventType&gt;): void
13517
13518开启WindowStage生命周期变化的监听。
13519
13520**模型约束:** 此接口仅可在Stage模型下使用。
13521
13522**系统能力:** SystemCapability.WindowManager.WindowManager.Core
13523
13524**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
13525
13526**参数:**
13527
13528| 参数名   | 类型                                                         | 必填 | 说明                                                         |
13529| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
13530| eventType  | string                                                       | 是   | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 |
13531| callback | Callback&lt;[WindowStageEventType](#windowstageeventtype9)&gt; | 是   | 回调函数。返回当前的WindowStage生命周期状态。                |
13532
13533**错误码:**
13534
13535以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13536
13537| 错误码ID | 错误信息 |
13538| ------- | ------------------------------ |
13539| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
13540| 1300002 | This window state is abnormal. |
13541| 1300005 | This window stage is abnormal. |
13542
13543**示例:**
13544
13545```ts
13546// EntryAbility.ets
13547import { UIAbility } from '@kit.AbilityKit';
13548
13549export default class EntryAbility extends UIAbility {
13550  // ...
13551
13552  onWindowStageCreate(windowStage: window.WindowStage) {
13553    console.info('onWindowStageCreate');
13554    try {
13555      windowStage.on('windowStageEvent', (data) => {
13556        console.info('Succeeded in enabling the listener for window stage event changes. Data: ' +
13557        JSON.stringify(data));
13558      });
13559    } catch (exception) {
13560      console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`);
13561    }
13562  }
13563};
13564```
13565
13566### off('windowStageEvent')<sup>9+</sup>
13567
13568off(eventType: 'windowStageEvent', callback?: Callback&lt;WindowStageEventType&gt;): void
13569
13570关闭WindowStage生命周期变化的监听。
13571
13572**模型约束:** 此接口仅可在Stage模型下使用。
13573
13574**系统能力:** SystemCapability.WindowManager.WindowManager.Core
13575
13576**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
13577
13578**参数:**
13579
13580| 参数名   | 类型                                                         | 必填 | 说明                                                         |
13581| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
13582| eventType  | string                                                       | 是   | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 |
13583| callback | Callback&lt;[WindowStageEventType](#windowstageeventtype9)&gt; | 否   | 回调函数。返回当前的WindowStage生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有WindowStage生命周期变化的监听。                |
13584
13585**错误码:**
13586
13587以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13588
13589| 错误码ID | 错误信息 |
13590| ------- | ------------------------------ |
13591| 401     | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. |
13592| 1300002 | This window state is abnormal. |
13593| 1300005 | This window stage is abnormal. |
13594
13595**示例:**
13596
13597```ts
13598// EntryAbility.ets
13599import { UIAbility } from '@kit.AbilityKit';
13600
13601export default class EntryAbility extends UIAbility {
13602  // ...
13603
13604  onWindowStageCreate(windowStage: window.WindowStage) {
13605    console.info('onWindowStageCreate');
13606    const callback = (windowStageEventType: window.WindowStageEventType) => {
13607      // ...
13608    }
13609    try {
13610      windowStage.on('windowStageEvent', callback);
13611    } catch (exception) {
13612      console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`);
13613    }
13614    try {
13615      windowStage.off('windowStageEvent', callback);
13616      // 如果通过on开启多个callback进行监听,同时关闭所有监听:
13617      windowStage.off('windowStageEvent');
13618    } catch (exception) {
13619      console.error(`Failed to disable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`);
13620    }
13621  }
13622};
13623```
13624
13625### on('windowStageClose')<sup>14+</sup>
13626
13627on(eventType: 'windowStageClose', callback: Callback&lt;void&gt;): void
13628
13629开启点击主窗三键区的关闭按钮监听事件。点击主窗口的三键区域的关闭键时触发该回调函数,将不执行注册的[UIAbility.onPrepareToTerminate](../apis-ability-kit/js-apis-app-ability-uiAbility.md#onpreparetoterminate10)生命周期回调函数。
13630
13631当重复注册窗口关闭事件的监听时,最后一次注册成功的监听事件生效。
13632
13633触发的回调函数是同步执行,主窗口的异步关闭事件监听参考[on('windowWillClose')](#onwindowwillclose15)方法。
13634
13635如果存在[on('windowWillClose')](#onwindowwillclose15)监听事件,只响应[on('windowWillClose')](#onwindowwillclose15)接口。
13636
13637<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
13638
13639**模型约束:** 此接口仅可在Stage模型下使用。
13640
13641**系统能力:** SystemCapability.Window.SessionManager
13642
13643**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
13644
13645**参数:**
13646
13647| 参数名   | 类型                                                         | 必填 | 说明                                                         |
13648| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
13649| eventType  | string                                                       | 是   | 监听事件,固定为'windowStageClose',即开启主窗三键区的关闭按钮监听。|
13650| callback | Callback&lt;void&gt; | 是   | 回调函数。当点击主窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前主窗是否继续关闭,true表示不关闭,false表示关闭。|
13651
13652**错误码:**
13653
13654以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13655
13656| 错误码ID | 错误信息 |
13657| ------- | ------------------------------ |
13658| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
13659| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
13660| 1300002 | This window state is abnormal. |
13661
13662**示例:**
13663
13664```ts
13665// EntryAbility.ets
13666import { UIAbility } from '@kit.AbilityKit';
13667import { window } from '@kit.ArkUI';
13668
13669export default class EntryAbility extends UIAbility {
13670  // ...
13671
13672  onWindowStageCreate(windowStage: window.WindowStage) {
13673    console.info('onWindowStageCreate');
13674    try {
13675      windowStage.on('windowStageClose', () => {
13676        console.info('Succeeded in enabling the listener for window stage close event.');
13677        return false;
13678      });
13679    } catch (exception) {
13680      console.error(`Failed to enable the listener for window stage close event. Cause code: ${exception.code}, message: ${exception.message}`);
13681    }
13682  }
13683};
13684```
13685
13686### off('windowStageClose')<sup>14+</sup>
13687
13688off(eventType: 'windowStageClose', callback?: Callback&lt;void&gt;): void
13689
13690关闭主窗口关闭事件的监听。
13691
13692<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
13693
13694**模型约束:** 此接口仅可在Stage模型下使用。
13695
13696**系统能力:** SystemCapability.Window.SessionManager
13697
13698**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
13699
13700**参数:**
13701
13702| 参数名   | 类型                                                         | 必填 | 说明                                                         |
13703| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
13704| eventType  | string                                                       | 是   | 监听事件,固定为'windowStageClose',即关闭主窗口关闭事件的监听。 |
13705| callback | Callback&lt;void&gt; | 否   | 回调函数。当点击主窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前主窗是否继续关闭,true表示不关闭,false表示关闭。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有主窗口关闭的监听。 |
13706
13707**错误码:**
13708
13709以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13710
13711| 错误码ID | 错误信息 |
13712| ------- | ------------------------------ |
13713| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
13714| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
13715| 1300002 | This window state is abnormal. |
13716
13717**示例:**
13718
13719```ts
13720// EntryAbility.ets
13721import { UIAbility } from '@kit.AbilityKit';
13722import { window } from '@kit.ArkUI';
13723
13724export default class EntryAbility extends UIAbility {
13725  // ...
13726
13727  onWindowStageCreate(windowStage: window.WindowStage) {
13728    console.info('onWindowStageCreate');
13729    const callback = () => {
13730      // ...
13731      return false;
13732    }
13733    try {
13734      windowStage.on('windowStageClose', callback);
13735      windowStage.off('windowStageClose', callback);
13736      windowStage.off('windowStageClose');
13737    } catch (exception) {
13738      console.error(`Failed to disable the listener for window stage close changes. Cause code: ${exception.code}, message: ${exception.message}`);
13739    }
13740  }
13741};
13742```
13743
13744### setDefaultDensityEnabled<sup>12+</sup>
13745
13746setDefaultDensityEnabled(enabled: boolean): void
13747
13748设置应用主窗口是否使用系统默认Density,子窗和系统窗口会跟随主窗生效。调用此接口前,需先调用[WindowStage.loadContent()](#loadcontent9-2)初始化布局,确保接口调用时序正确。
13749
13750不调用此接口进行设置,则表示不使用系统默认Density,即窗口会跟随系统显示大小变化重新布局。
13751
13752**模型约束:** 此接口仅可在Stage模型下使用。
13753
13754**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
13755
13756**系统能力:** SystemCapability.Window.SessionManager
13757
13758**参数:**
13759
13760| 参数名           | 类型    | 必填 | 说明                         |
13761| ---------------- | ------- | ---- | ---------------------------- |
13762| enabled | boolean | 是   | 是否设置应用使用系统默认Density。true表示使用系统默认Density,窗口不跟随系统显示大小变化重新布局;false表示不使用系统默认Density,窗口跟随系统显示大小变化重新布局。 |
13763
13764**错误码:**
13765
13766以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13767
13768| 错误码ID | 错误信息 |
13769| ------- | ------------------------------ |
13770| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
13771| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
13772| 1300002 | This window state is abnormal. |
13773| 1300005 | This window stage is abnormal. |
13774
13775**示例:**
13776
13777```ts
13778// EntryAbility.ets
13779import { UIAbility } from '@kit.AbilityKit';
13780import { window } from '@kit.ArkUI';
13781import { BusinessError } from '@kit.BasicServicesKit'
13782
13783export default class EntryAbility extends UIAbility {
13784  // ...
13785
13786  onWindowStageCreate(windowStage: window.WindowStage) {
13787      windowStage.loadContent("pages/page2", (err: BusinessError) => {
13788        let errCode: number = err.code;
13789        if (errCode) {
13790          console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`);
13791          return;
13792        }
13793        console.info('onWindowStageCreate');
13794      try {
13795        windowStage.setDefaultDensityEnabled(true);
13796        console.info('Succeeded in loading the content.');
13797      } catch (exception) {
13798        console.error(`Failed to set default density enabled. Cause code: ${exception.code}, message: ${exception.message}`);
13799      }
13800    });
13801  }
13802};
13803```
13804
13805### setCustomDensity<sup>15+</sup>
13806
13807setCustomDensity(density: number): void
13808
13809支持应用主窗口自定义其显示大小缩放系数,子窗和系统窗口会跟随主窗生效。当存在同时使用该接口和[setDefaultDensityEnabled(true)](#setdefaultdensityenabled12)时,以最后调用的设置效果为准。
13810
13811**模型约束:** 此接口仅可在Stage模型下使用。
13812
13813**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
13814
13815**系统能力:** SystemCapability.Window.SessionManager
13816
13817**参数:**
13818
13819| 参数名           | 类型    | 必填 | 说明                         |
13820| ---------------- | ------- | ---- | ---------------------------- |
13821| density | number | 是   | 自定义显示大小缩放系数。该参数为浮点数,取值范围为[0.5, 4.0]或-1.0。4.0表示窗口可显示的最大显示大小缩放系数,-1.0表示窗口使用系统显示大小缩放系数。 |
13822
13823**错误码:**
13824
13825以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13826
13827| 错误码ID | 错误信息 |
13828| ------- | ------------------------------ |
13829| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
13830| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
13831| 1300002 | This window state is abnormal. |
13832| 1300005 | This window stage is abnormal. |
13833
13834**示例:**
13835
13836```ts
13837// EntryAbility.ets
13838import { UIAbility } from '@kit.AbilityKit';
13839
13840export default class EntryAbility extends UIAbility {
13841  // ...
13842
13843  onWindowStageCreate(windowStage: window.WindowStage) {
13844    console.info('onWindowStageCreate');
13845    try {
13846      windowStage.setCustomDensity(-1.0);
13847    } catch (exception) {
13848      console.error(`Failed to set custom density. Cause code: ${exception.code}, message: ${exception.message}`);
13849    }
13850  }
13851};
13852```
13853
13854### setWindowModal<sup>14+</sup>
13855
13856setWindowModal(isModal: boolean): Promise&lt;void&gt;
13857
13858设置主窗的模态属性是否启用,使用Promise异步回调。
13859
13860主窗口调用该接口时,设置主窗口模态属性是否启用。启用主窗口模态属性后,其相同应用进程下的其他主窗口以及其他主窗口的子窗口不能响应用户操作,直到该主窗口关闭或者主窗口的模态属性被禁用。
13861
13862<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
13863
13864**模型约束:** 此接口仅可在Stage模型下使用。
13865
13866**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
13867
13868**系统能力:** SystemCapability.Window.SessionManager
13869
13870**参数:**
13871
13872| 参数名    | 类型    | 必填 | 说明                                          |
13873| --------- | ------- | ---- | --------------------------------------------- |
13874| isModal | boolean | 是   | 设置主窗口模态属性是否启用,true为启用,false为不启用。 |
13875
13876
13877**返回值:**
13878
13879| 类型 | 说明 |
13880| ------------------- | ------------------------ |
13881| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
13882
13883**错误码:**
13884
13885以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13886
13887| 错误码ID | 错误信息                       |
13888| -------- | ------------------------------ |
13889| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
13890| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
13891| 1300002  | This window state is abnormal. |
13892| 1300003  | This window manager service works abnormally. |
13893| 1300005 | This window stage is abnormal. |
13894
13895**示例:**
13896
13897```ts
13898// EntryAbility.ets
13899import { UIAbility } from '@kit.AbilityKit';
13900import { BusinessError } from '@kit.BasicServicesKit';
13901
13902export default class EntryAbility extends UIAbility {
13903  // ...
13904  onWindowStageCreate(windowStage: window.WindowStage): void {
13905    console.info('onWindowStageCreate');
13906    try {
13907      let promise = windowStage.setWindowModal(true);
13908      promise.then(() => {
13909        console.info('Succeeded in setting window modal');
13910      }).catch((err: BusinessError) => {
13911        console.error(`Failed to set window modal. Cause code: ${err.code}, message: ${err.message}`);
13912      });
13913    } catch (exception) {
13914      console.error(`Failed to set window modal. Cause code: ${exception.code}, message: ${exception.message}`);
13915    }
13916  }
13917}
13918```
13919
13920### removeStartingWindow<sup>14+</sup>
13921
13922removeStartingWindow(): Promise&lt;void&gt;
13923
13924支持应用控制启动页消失时机。
13925
13926此接口只对应用主窗口生效,且需要在module.json5配置文件[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中的metadata标签下配置"enable.remove.starting.window"为"true"才会生效。
13927
13928在标签配置为"true"的情况下,系统提供了启动页超时保护机制,若5s内未调用此接口,系统将自动移除启动页。
13929
13930若标签配置为"false"或未配置标签,则此接口不生效,启动页将会在应用首帧渲染完成后自动移除。
13931
13932**模型约束:** 此接口仅可在Stage模型下使用。
13933
13934**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
13935
13936**系统能力:** SystemCapability.Window.SessionManager
13937
13938**返回值:**
13939
13940| 类型                | 说明                      |
13941| ------------------- | ------------------------- |
13942| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
13943
13944**错误码:**
13945
13946以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
13947
13948| 错误码ID | 错误信息 |
13949| ------- | ------------------------------ |
13950| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
13951| 1300002 | This window state is abnormal. |
13952| 1300003 | This window manager service works abnormally. |
13953
13954**示例:**
13955
13956```ts
13957// EntryAbility.ets
13958import { UIAbility } from '@kit.AbilityKit';
13959import { BusinessError } from '@kit.BasicServicesKit';
13960
13961export default class EntryAbility extends UIAbility {
13962  // ...
13963
13964  onWindowStageCreate(windowStage: window.WindowStage) {
13965    console.info('onWindowStageCreate');
13966    windowStage.removeStartingWindow().then(() => {
13967      console.info('Succeeded in removing starting window.');
13968    }).catch((err: BusinessError) => {
13969        console.error(`Failed to remove starting window. Cause code: ${err.code}, message: ${err.message}`);
13970    });
13971  }
13972};
13973```
13974
13975### setWindowRectAutoSave<sup>14+</sup>
13976
13977setWindowRectAutoSave(enabled: boolean): Promise&lt;void&gt;
13978
13979设置是否启用最后关闭的主窗尺寸的记忆功能,使用Promise异步回调,仅对2in1设备生效。
13980
13981启用记忆功能后,在同一个UIAbility下,记忆最后关闭的主窗口的尺寸;此主窗口再次启动时,以记忆的尺寸按照规则进行打开。
13982
13983层叠规则: 1、当前实例是自由窗口时,打开下一实例窗口层叠时,大小要跟随。2、当前实例是最大化或全屏窗口时,打开下一个实例窗口层叠时,保持最大化。
13984
13985记忆规则:
13986|上一次窗口状态|记忆规则|
13987|-------------|-------|
13988|自由窗口|保留自由窗口的大小/位置,超出工作区回弹|
13989|二分屏窗口|保留二分屏之前自由窗口的大小/位置|
13990|最大化窗口|保留最大化|
13991|沉浸式窗口|保留沉浸式之前自由窗口的大小/位置|
13992|最小化窗口|保留最小化之前自由窗口的大小/位置|
13993
13994**模型约束:** 此接口仅可在Stage模型下使用。
13995
13996**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
13997
13998**系统能力:** SystemCapability.Window.SessionManager
13999
14000**参数:**
14001
14002| 参数名    | 类型    | 必填 | 说明                                          |
14003| --------- | ------- | ---- | --------------------------------------------- |
14004| enabled | boolean | 是   | 设置是否启用主窗尺寸的记忆功能,true为启用,false为不启用。 |
14005
14006
14007**返回值:**
14008
14009| 类型 | 说明 |
14010| ------------------- | ------------------------ |
14011| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
14012
14013**错误码:**
14014
14015以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
14016
14017| 错误码ID | 错误信息                       |
14018| -------- | ------------------------------ |
14019| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
14020| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
14021| 1300002  | This window state is abnormal. |
14022| 1300003  | This window manager service works abnormally. |
14023
14024**示例:**
14025
14026```ts
14027// EntryAbility.ets
14028import { UIAbility } from '@kit.AbilityKit';
14029import { BusinessError } from '@kit.BasicServicesKit';
14030
14031export default class EntryAbility extends UIAbility {
14032  // ...
14033  onWindowStageCreate(windowStage: window.WindowStage): void {
14034    console.info('onWindowStageCreate');
14035    try {
14036      let promise = windowStage.setWindowRectAutoSave(true);
14037      promise.then(() => {
14038        console.info('Succeeded in setting window rect auto-save');
14039      }).catch((err: BusinessError) => {
14040        console.error(`Failed to set window rect auto-save. Cause code: ${err.code}, message: ${err.message}`);
14041      });
14042    } catch (exception) {
14043      console.error(`Failed to set window rect auto-save. Cause code: ${exception.code}, message: ${exception.message}`);
14044    }
14045  }
14046}
14047```
14048
14049### setWindowRectAutoSave<sup>17+</sup>
14050
14051setWindowRectAutoSave(enabled: boolean, isSaveBySpecifiedFlag: boolean): Promise&lt;void&gt;
14052
14053设置是否启用主窗的尺寸记忆功能,使用Promise异步回调,仅对2in1设备生效。
14054
14055在同一个UIAbility下,可记忆最后关闭的主窗口尺寸,也可针对每个主窗口尺寸单独进行记忆。只有在UIAbility启动模式为specified,且isSaveBySpecifiedFlag设置为true时,才能针对每个主窗口尺寸进行单独记忆。
14056
14057启用记忆功能后,记忆主窗口关闭时的尺寸;对应主窗口再次启动时,以记忆的尺寸按照规则进行打开。
14058
14059记忆规则:
14060|上一次窗口状态|记忆规则|
14061|-------------|-------|
14062|自由窗口|保留自由窗口的大小/位置,超出工作区回弹。|
14063|二分屏窗口|保留二分屏之前自由窗口的大小/位置。|
14064|最大化窗口|保留最大化。|
14065|沉浸式窗口|保留沉浸式之前自由窗口的大小/位置。|
14066|最小化窗口|保留最小化之前自由窗口的大小/位置。|
14067
14068**模型约束:** 此接口仅可在Stage模型下使用。
14069
14070**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。
14071
14072**系统能力:** SystemCapability.Window.SessionManager
14073
14074**参数:**
14075
14076| 参数名    | 类型    | 必填 | 说明                                          |
14077| --------- | ------- | ---- | --------------------------------------------- |
14078| enabled | boolean | 是   | 设置是否启用主窗的尺寸记忆功能,true为启用,false为不启用。 |
14079| isSaveBySpecifiedFlag | boolean | 是   | 设置specified模式下是否启用对窗口进行单独记忆,true为启用,false为不启用。 |
14080
14081
14082**返回值:**
14083
14084| 类型 | 说明 |
14085| ------------------- | ------------------------ |
14086| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
14087
14088**错误码:**
14089
14090以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
14091
14092| 错误码ID | 错误信息                       |
14093| -------- | ------------------------------ |
14094| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
14095| 801      | Capability not supported. Function setWindowRectAutoSave can not work correctly due to limited device capabilities. |
14096| 1300002  | This window state is abnormal. |
14097| 1300003  | This window manager service works abnormally. |
14098
14099**示例:**
14100
14101```ts
14102// EntryAbility.ets
14103import { UIAbility } from '@kit.AbilityKit';
14104import { BusinessError } from '@kit.BasicServicesKit';
14105
14106export default class EntryAbility extends UIAbility {
14107  // ...
14108  onWindowStageCreate(windowStage: window.WindowStage): void {
14109    console.info('onWindowStageCreate');
14110    try {
14111      let promise = windowStage.setWindowRectAutoSave(true, true);
14112      promise.then(() => {
14113        console.info('Succeeded in setting window rect auto-save');
14114      }).catch((err: BusinessError) => {
14115        console.error(`Failed to set window rect auto-save. Cause code: ${err.code}, message: ${err.message}`);
14116      });
14117    } catch (exception) {
14118      console.error(`Failed to set window rect auto-save. Cause code: ${exception.code}, message: ${exception.message}`);
14119    }
14120  }
14121}
14122```
14123
14124### isWindowRectAutoSave<sup>14+</sup>
14125
14126isWindowRectAutoSave(): Promise&lt;boolean&gt;
14127
14128判断当前主窗口是否已经启用尺寸记忆,使用Promise异步回调,仅对2in1设备生效。
14129
14130**模型约束:** 此接口仅可在Stage模型下使用。
14131
14132**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
14133
14134**系统能力:** SystemCapability.Window.SessionManager
14135
14136**返回值:**
14137
14138| 类型 | 说明 |
14139| ---------------------- | ------------------------------------------------------------------------------------ |
14140| Promise&lt;boolean&gt; | Promise对象。返回true表示当前窗口启用尺寸记忆,返回false表示当前窗口禁用尺寸记忆。 |
14141
14142**错误码:**
14143
14144以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。
14145
14146| 错误码ID | 错误信息 |
14147| ------- | ------------------------------ |
14148| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
14149| 1300002 | This window state is abnormal. |
14150| 1300003 | This window manager services works abnormally. |
14151
14152**示例:**
14153
14154```ts
14155// EntryAbility.ets
14156import { UIAbility } from '@kit.AbilityKit';
14157import { BusinessError } from '@kit.BasicServicesKit';
14158
14159export default class EntryAbility extends UIAbility {
14160  // ...
14161  onWindowStageCreate(windowStage: window.WindowStage): void {
14162    console.info('onWindowStageCreate');
14163    try {
14164      let promise = windowStage.isWindowRectAutoSave();
14165      promise.then((data) => {
14166        console.info(`Succeeded in checking whether the window support the rect auto-save. Data: ${data}`);
14167      }).catch((err: BusinessError) => {
14168        console.error(`Failed to check whether the window support the rect auto-save. Cause code: ${err.code}, message: ${err.message}`);
14169      });
14170    } catch (exception) {
14171      console.error(`Failed to check whether the window support the rect auto-save. Cause code: ${exception.code}, message: ${exception.message}`);
14172    }
14173  }
14174}
14175```
14176
14177### setSupportedWindowModes<sup>15+</sup>
14178
14179setSupportedWindowModes(supportedWindowModes: Array<bundleManager.SupportWindowMode>): Promise&lt;void&gt;
14180
14181设置主窗的窗口支持模式,使用Promise异步回调。
14182
14183<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End-->
14184
14185**模型约束:** 此接口仅可在Stage模型下使用。
14186
14187**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
14188
14189**系统能力:** SystemCapability.Window.SessionManager
14190
14191**参数:**
14192
14193| 参数名    | 类型    | 必填 | 说明                                          |
14194| --------- | ------- | ---- | --------------------------------------------- |
14195| supportedWindowModes | Array&lt;[bundleManager.SupportWindowMode](../apis-ability-kit/js-apis-bundleManager.md#supportwindowmode)&gt; | 是   | 设置主窗的窗口支持模式。<br>- FULL_SCREEN:支持全屏模式。<br>- FLOATING:支持悬浮窗模式。<br>- SPLIT:支持分屏模式。需要配合FULL_SCREEN或FLOATING一起使用,不支持仅配置SPLIT。<br> 注:数组中SupportWindowMode字段取值不应该与该UIAbility对应的[module.json5配置文件](../../quick-start/module-configuration-file.md)中[abilities标签](../../quick-start/module-configuration-file.md#abilities标签)的supportWindowMode字段取值或者[StartOptions](../apis-ability-kit/js-apis-app-ability-startOptions.md)中[属性](../apis-ability-kit/js-apis-app-ability-startOptions.md#startoptions)的supportWindowModes字段取值冲突。当取值冲突时,最终以该参数设置的窗口支持模式为准。|
14196
14197**返回值:**
14198
14199| 类型 | 说明 |
14200| ------------------- | ------------------------ |
14201| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
14202
14203**错误码:**
14204
14205以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。
14206
14207| 错误码ID | 错误信息                       |
14208| -------- | ------------------------------ |
14209| 401      | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
14210| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
14211| 1300002  | This window state is abnormal. |
14212| 1300003  | This window manager service works abnormally. |
14213
14214**示例:**
14215
14216```ts
14217// EntryAbility.ets
14218import { UIAbility, bundleManager } from '@kit.AbilityKit';
14219import { BusinessError } from '@kit.BasicServicesKit';
14220
14221export default class EntryAbility extends UIAbility {
14222  // ...
14223  onWindowStageCreate(windowStage: window.WindowStage): void {
14224    console.info('onWindowStageCreate');
14225    try {
14226      let promise = windowStage.setSupportedWindowModes([
14227        bundleManager.SupportWindowMode.FULL_SCREEN,
14228        bundleManager.SupportWindowMode.SPLIT,
14229        bundleManager.SupportWindowMode.FLOATING
14230      ]);
14231      promise.then(() => {
14232        console.info('Succeeded in setting window support modes');
14233      }).catch((err: BusinessError) => {
14234        console.error(`Failed to set window support modes. Cause code: ${err.code}, message: ${err.message}`);
14235      });
14236    } catch (exception) {
14237      console.error(`Failed to set window support modes. Cause code: ${exception.code}, message: ${exception.message}`);
14238    }
14239  }
14240}
14241```