1# @ohos.window (窗口) 2 3窗口提供管理窗口的一些基础能力,包括对当前窗口的创建、销毁、各属性设置,以及对各窗口间的管理调度。 4 5该模块提供以下窗口相关的常用功能: 6 7- [Window](#window):当前窗口实例,窗口管理器管理的基本单元。 8- [WindowStage](#windowstage9):窗口管理器。管理各个基本窗口单元。 9 10> **说明:** 11> 12> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 13 14## 导入模块 15 16```ts 17import { window } from '@kit.ArkUI'; 18``` 19 20## WindowType<sup>7+</sup> 21 22窗口类型枚举。 23 24**系统能力:** SystemCapability.WindowManager.WindowManager.Core 25 26| 名称 | 值 | 说明 | 27|-------------------------------------| ------ |----------------------------------------------------------------------------------------| 28| TYPE_APP | 0 | 表示应用子窗口。<br>**模型约束:** 此接口仅可在FA模型下使用。 | 29| TYPE_SYSTEM_ALERT | 1 | 表示系统告警窗口。<br>- **说明:** 从API version 11开始废弃。<br>- 从API version 7开始支持。 | 30| TYPE_FLOAT<sup>9+</sup> | 8 | 表示悬浮窗。<br>**模型约束:** 此接口仅可在Stage模型下使用。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 31| TYPE_DIALOG<sup>10+</sup> | 16 | 表示模态窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 32 33## Configuration<sup>9+</sup> 34 35创建子窗口或系统窗口时的参数。 36 37**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 38 39**系统能力:** SystemCapability.WindowManager.WindowManager.Core 40 41| 名称 | 类型 | 必填 | 说明 | 42| ---------- | -------------------------- | -- |-----------------------------------------------------------------------------| 43| name | string | 是 | 窗口名字。 | 44| windowType | [WindowType](#windowtype7) | 是 | 窗口类型。 | 45| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 否 | 当前应用上下文信息。不设置,则默认为空。<br>FA模型下不需要使用该参数,即可创建子窗口,使用该参数时会报错。<br>Stage模型必须使用该参数,用于创建悬浮窗、模态窗或系统窗口。 | 46| displayId | number | 否 | 当前物理屏幕id。不设置,则默认为-1,该参数应为整数。 | 47| parentId | number | 否 | 父窗口id。不设置,则默认为-1,该参数应为整数。 | 48| decorEnabled<sup>12+</sup> | boolean | 否 | 是否显示窗口装饰,仅在windowType为TYPE_DIALOG时生效。true表示显示,false表示不显示。此参数默认值为false。<br>**系统能力:** SystemCapability.Window.SessionManager | 49| title<sup>12+</sup> | string| 否 | `decorEnabled`属性设置为true时,窗口的标题内容。标题显示区域最右端不超过系统三键区域最左端,超过部分以省略号表示。不设置,则默认为空字符串。 <br>**系统能力:** SystemCapability.Window.SessionManager | 50 51## AvoidAreaType<sup>7+</sup> 52 53窗口内容需要规避区域的类型枚举。 54 55**系统能力:** SystemCapability.WindowManager.WindowManager.Core 56 57**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 58 59| 名称 | 值 | 说明 | 60| -------------------------------- | ---- | ------------------------------------------------------------ | 61| TYPE_SYSTEM | 0 | 表示系统默认区域。一般包括状态栏、导航栏,各设备系统定义可能不同。 | 62| TYPE_CUTOUT | 1 | 表示刘海屏区域。 | 63| TYPE_SYSTEM_GESTURE<sup>9+</sup> | 2 | 表示手势区域。 | 64| TYPE_KEYBOARD<sup>9+</sup> | 3 | 表示软键盘区域。 | 65| TYPE_NAVIGATION_INDICATOR<sup>11+</sup> | 4 | 表示导航条区域。 | 66 67 68## SystemBarProperties 69 70状态栏、导航栏的属性。在设置窗口级状态栏、导航栏属性时使用。 71 72**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 73 74| 名称 | 类型 | 必填 | 说明 | 75| -------------------------------------- | -------- | ---- | ------------------------------------------------------------ | 76| statusBarColor | string | 否 | 状态栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。默认值:`'#66000000'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 77| isStatusBarLightIcon<sup>7+</sup> | boolean | 否 | 状态栏图标是否为高亮状态。true表示高亮;false表示不高亮。默认值:false。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 78| statusBarContentColor<sup>8+</sup> | string | 否 | 状态栏文字颜色。当设置此属性后, `isStatusBarLightIcon`属性设置无效。默认值:`'#E5FFFFFF'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 79| navigationBarColor | string | 否 | 导航栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。默认值:`'#66000000'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 80| isNavigationBarLightIcon<sup>7+</sup> | boolean | 否 | 导航栏图标是否为高亮状态。true表示高亮;false表示不高亮。默认值:false。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 81| navigationBarContentColor<sup>8+</sup> | string | 否 | 导航栏文字颜色。当设置此属性后, `isNavigationBarLightIcon`属性设置无效。默认值:`'#E5FFFFFF'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 82| enableStatusBarAnimation<sup>12+</sup> | boolean | 否 | 是否使能状态栏属性变化时动画效果。true表示变化时使能动画效果;false表示没有使能动画效果。默认值:false。 <br> **系统能力:** SystemCapability.Window.SessionManager| 83| enableNavigationBarAnimation<sup>12+</sup> | boolean | 否 | 是否使能导航栏属性变化时动画效果。true表示变化时使能动画效果;false表示没有使能动画效果。默认值:false。 <br> **系统能力:** SystemCapability.Window.SessionManager| 84 85## SystemBarStyle<sup>12+</sup> 86 87状态栏的属性。在设置页面级状态栏属性时使用。 88 89**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 90 91**系统能力:** SystemCapability.WindowManager.WindowManager.Core 92 93| 名称 | 类型 | 只读 | 可选 | 说明 | 94| ------ | -------- | ---- | ---- | ------------------ | 95| statusBarContentColor | string | 是 | 是 | 状态栏文字颜色。默认值:`'#E5FFFFFF'`。| 96 97## Orientation<sup>9+</sup> 98 99窗口显示方向类型枚举。 100 101| 名称 | 值 | 说明 | 102| ------------------------------------- | ---- | ----------------------------- | 103| UNSPECIFIED | 0 | 表示未定义方向模式,由系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 104| PORTRAIT | 1 | 表示竖屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。| 105| LANDSCAPE | 2 | 表示横屏显示模式。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 106| PORTRAIT_INVERTED | 3 | 表示反向竖屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 107| LANDSCAPE_INVERTED | 4 | 表示反向横屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 108| AUTO_ROTATION | 5 | 跟随传感器自动旋转,可以旋转到竖屏、横屏、反向竖屏、反向横屏四个方向。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。| 109| AUTO_ROTATION_PORTRAIT | 6 | 跟随传感器自动竖向旋转,可以旋转到竖屏、反向竖屏,无法旋转到横屏、反向横屏。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 110| AUTO_ROTATION_LANDSCAPE | 7 | 跟随传感器自动横向旋转,可以旋转到横屏、反向横屏,无法旋转到竖屏、反向竖屏。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 111| AUTO_ROTATION_RESTRICTED | 8 | 跟随传感器自动旋转,可以旋转到竖屏、横屏、反向竖屏、反向横屏四个方向,且受控制中心的旋转开关控制。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 112| AUTO_ROTATION_PORTRAIT_RESTRICTED | 9 | 跟随传感器自动竖向旋转,可以旋转到竖屏、反向竖屏,无法旋转到横屏、反向横屏,且受控制中心的旋转开关控制。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 113| AUTO_ROTATION_LANDSCAPE_RESTRICTED | 10 | 跟随传感器自动横向旋转,可以旋转到横屏、反向横屏,无法旋转到竖屏、反向竖屏,且受控制中心的旋转开关控制。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 114| LOCKED | 11 | 表示锁定模式。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 115| AUTO_ROTATION_UNSPECIFIED<sup>12+</sup> | 12 | 跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定(如在某种设备,可以旋转到竖屏、横屏、反向横屏三个方向,无法旋转到反向竖屏)。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager| 116| USER_ROTATION_PORTRAIT<sup>12+</sup> | 13 | 调用时临时旋转到竖屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager| 117| USER_ROTATION_LANDSCAPE<sup>12+</sup> | 14 | 调用时临时旋转到横屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager| 118| USER_ROTATION_PORTRAIT_INVERTED<sup>12+</sup> | 15 | 调用时临时旋转到反向竖屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager| 119| USER_ROTATION_LANDSCAPE_INVERTED<sup>12+</sup> | 16 | 调用时临时旋转到反向横屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager| 120| FOLLOW_DESKTOP<sup>12+</sup> | 17 | 表示跟随桌面的旋转模式。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager| 121 122## Rect<sup>7+</sup> 123 124窗口矩形区域。 125 126**系统能力:** SystemCapability.WindowManager.WindowManager.Core 127 128**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 129 130| 名称 | 类型 | 可读 | 可写 | 说明 | 131| ------ | -------- | ---- | ---- | ------------------ | 132| left | number | 是 | 是 | 矩形区域的左边界,单位为px,该参数为整数。 | 133| top | number | 是 | 是 | 矩形区域的上边界,单位为px,该参数应为整数。 | 134| width | number | 是 | 是 | 矩形区域的宽度,单位为px,该参数应为整数。 | 135| height | number | 是 | 是 | 矩形区域的高度,单位为px,该参数应为整数。 | 136 137## AvoidArea<sup>7+</sup> 138 139窗口内容规避区域。如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。在规避区无法响应用户点击事件。 140 141除此之外还需注意规避区域的如下约束,具体为: 142 143- 底部手势区域中非导航条区域支持点击、长按事件透传,不支持拖入。 144 145- 左右侧边手势区域支持点击、长按以及上下滑动事件透传,不支持拖入。 146 147- 导航条区域支持长按、点击、拖入事件响应,不支持事件向下透传。 148 149**系统能力:** SystemCapability.WindowManager.WindowManager.Core 150 151**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 152 153| 名称 | 类型 | 可读 | 可写 | 说明 | 154| ---------- | ------------- | ---- | ---- | ------------------ | 155| visible<sup>9+</sup> | boolean | 是 | 是 | 规避区域是否可见。true表示可见;false表示不可见。 | 156| leftRect | [Rect](#rect7) | 是 | 是 | 屏幕左侧的矩形区。 | 157| topRect | [Rect](#rect7) | 是 | 是 | 屏幕顶部的矩形区。 | 158| rightRect | [Rect](#rect7) | 是 | 是 | 屏幕右侧的矩形区。 | 159| bottomRect | [Rect](#rect7) | 是 | 是 | 屏幕底部的矩形区。 | 160 161## Size<sup>7+</sup> 162 163窗口大小。 164 165**系统能力:** SystemCapability.WindowManager.WindowManager.Core 166 167**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 168 169| 名称 | 类型 | 可读 | 可写 | 说明 | 170| ------ | -------- | ---- | ---- | ---------- | 171| width | number | 是 | 是 | 窗口宽度,单位为px,该参数应为整数。 | 172| height | number | 是 | 是 | 窗口高度,单位为px,该参数应为整数。 | 173 174## RectChangeReason<sup>12+</sup> 175 176窗口矩形(窗口位置及窗口大小)变化的原因。 177 178**系统能力:** SystemCapability.Window.SessionManager 179 180**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 181 182| 名称 | 值 | 说明 | 183| --------------------- | ---- | ------------------------------------------------------------ | 184| UNDEFINED | 0 | 默认值。 | 185| MAXIMIZE | 1 | 窗口最大化。 | 186| RECOVER | 2 | 窗口恢复到上一次的状态。 | 187| MOVE | 3 | 窗口拖拽移动。 | 188| DRAG | 4 | 窗口拖拽缩放。 | 189| DRAG_START | 5 | 窗口开始拖拽缩放。 | 190| DRAG_END | 6 | 窗口结束拖拽缩放。 | 191 192## RectChangeOptions<sup>12+</sup> 193 194窗口矩形(窗口位置及窗口大小)变化返回的值及变化原因。 195 196**系统能力:** SystemCapability.Window.SessionManager 197 198**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 199 200| 名称 | 类型 | 可读 | 可写 | 说明 | 201| ---------- | ------------- | ---- | ---- | ------------------ | 202| rect | [Rect](#rect7) | 是 | 是 | 窗口矩形变化后的值。 | 203| reason | [RectChangeReason](#rectchangereason12) | 是 | 是 | 窗口矩形变化的原因。 | 204 205## AvoidAreaOptions<sup>12+</sup> 206 207系统规避区变化后返回当前规避区域以及规避区域类型。 208 209**系统能力:** SystemCapability.WindowManager.WindowManager.Core 210 211**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 212 213| 名称 | 类型 | 可读 | 可写 | 说明 | 214| ---------- | ------------- | ---- | ---- | ------------------ | 215| type | [AvoidAreaType](#avoidareatype7) | 是 | 是 | 系统规避区变化后返回的规避区域类型。 | 216| area | [AvoidArea](#avoidarea7) | 是 | 是 | 系统规避区变化后返回的规避区域。 | 217 218## WindowProperties 219 220窗口属性。 221 222**系统能力:** SystemCapability.WindowManager.WindowManager.Core 223 224| 名称 | 类型 | 只读 | 可选 | 说明 | 225| ------------------------------------- | ------------------------- | ---- | ---- |--------------------------------------------------------------------------------------------------------| 226| windowRect<sup>7+</sup> | [Rect](#rect7) | 否 | 否 | 窗口尺寸,可在页面生命周期[onPageShow](./arkui-ts/ts-custom-component-lifecycle.md#onpageshow)或应用生命周期[onForeground](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonforeground)阶段获取。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 227| drawableRect<sup>11+</sup> | [Rect](#rect7) | 否 | 否 | 窗口内可绘制区域尺寸,其中左边界上边界是相对窗口计算。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 228| type<sup>7+</sup> | [WindowType](#windowtype7) | 否 | 否 | 窗口类型。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 229| isFullScreen | boolean | 否 | 否 | 是否全屏,默认为false。true表示全屏;false表示非全屏。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 230| isLayoutFullScreen<sup>7+</sup> | boolean | 否 | 否 | 窗口是否为沉浸式,默认为false。true表示沉浸式;false表示非沉浸式。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 231| focusable<sup>7+</sup> | boolean | 是 | 否 | 窗口是否可聚焦,默认为true。true表示可聚焦;false表示不可聚焦。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 232| touchable<sup>7+</sup> | boolean | 是 | 否 | 窗口是否可触摸,默认为true。true表示可触摸;false表示不可触摸。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 233| brightness | number | 否 | 否 | 屏幕亮度。该参数为浮点数,可设置的亮度范围为[0.0, 1.0],其取1.0时表示最大亮度值。如果窗口没有设置亮度值,表示亮度跟随系统,此时获取到的亮度值为-1。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 234| dimBehindValue<sup>(deprecated)</sup> | number | 否 | 否 | 靠后窗口的暗度值。该参数为浮点数,取值范围为[0.0, 1.0],其取1.0表示最暗。<br>- **说明:** 从API version 9开始废弃。<br>- 从API version 7开始支持。 | 235| isKeepScreenOn | boolean | 否 | 否 | 屏幕是否常亮,默认为false。true表示常亮;false表示不常亮。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 236| isPrivacyMode<sup>7+</sup> | boolean | 否 | 否 | 隐私模式,默认为false。true表示模式开启;false表示模式关闭。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 237| isRoundCorner<sup>(deprecated)</sup> | boolean | 否 | 否 | 窗口是否为圆角。默认为false。true表示圆角;false表示非圆角。<br>- **说明:** 从API version 9开始废弃。<br/>- 从API version 7开始支持。 | 238| isTransparent<sup>7+</sup> | boolean | 否 | 否 | 窗口是否透明。默认为false。true表示透明;false表示不透明。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 239| id<sup>9+</sup> | number | 是 | 否 | 窗口ID,默认值为0,该参数应为整数。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 240| displayId<sup>12+</sup> | number | 是 | 是 | 窗口所在屏幕ID,默认返回主屏幕ID,该参数应为整数。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 241 242## DecorButtonStyle<sup>14+</sup> 243 244系统装饰栏按钮样式。 245 246**系统能力:** SystemCapability.Window.SessionManager 247 248**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 249 250| 名称 | 类型 | 可读 | 可写 | 说明 | 251| ---------- | ------------- | ---- | ---- | ------------------ | 252| colorMode | [ConfigurationConstant.ColorMode](../apis-ability-kit/js-apis-app-ability-configurationConstant.md#colormode) | 是 | 是 | 颜色模式。深色模式下按钮颜色适配为浅色,浅色模式下按钮颜色适配为深色。未设置则默认跟随系统颜色模式。 | 253| buttonBackgroundSize | number | 是 | 是 | 按钮高亮显示时的大小,取值范围20vp-40vp,默认值28vp。 | 254| spacingBetweenButtons | number | 是 | 是 | 按钮间距,取值范围12vp-24vp,默认值12vp。 | 255| closeButtonRightMargin | number | 是 | 是 | 关闭按钮右侧距窗口边距,取值范围8vp-22vp,默认值20vp。 | 256 257## ColorSpace<sup>8+</sup> 258 259色域模式。 260 261**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 262 263**系统能力:** SystemCapability.WindowManager.WindowManager.Core 264 265| 名称 | 值 | 说明 | 266| ---------- | ------ | -------------- | 267| DEFAULT | 0 | 默认SRGB色域模式。 | 268| WIDE_GAMUT | 1 | 广色域模式。 | 269 270## WindowEventType<sup>10+</sup> 271 272窗口生命周期。 273 274**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 275 276| 名称 | 值 | 说明 | 277| ---------- | ------ | ---------- | 278| WINDOW_SHOWN | 1 | 切到前台。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 279| WINDOW_ACTIVE | 2 | 获焦状态。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 280| WINDOW_INACTIVE | 3 | 失焦状态。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 281| WINDOW_HIDDEN | 4 | 切到后台。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 282| WINDOW_DESTROYED<sup>11+</sup> | 7 | 窗口销毁。<br> **系统能力:** SystemCapability.Window.SessionManager| 283 284## WindowLimits<sup>11+</sup> 285 286窗口尺寸限制参数。可以通过[setWindowLimits](#setwindowlimits11)设置窗口尺寸限制,并且可以通过[getWindowLimits](#getwindowlimits11)获得当前的窗口尺寸限制。 287 288**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 289 290**系统能力:** SystemCapability.Window.SessionManager 291 292| 名称 | 类型 | 可读 | 可写 | 说明 | 293| :-------- | :----- | :--- | :--- | :----------------------------------------------------------- | 294| maxWidth | number | 是 | 是 | 窗口的最大宽度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最大宽度。 | 295| maxHeight | number | 是 | 是 | 窗口的最大高度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最大高度。 | 296| minWidth | number | 是 | 是 | 窗口的最小宽度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最小宽度。 | 297| minHeight | number | 是 | 是 | 窗口的最小高度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最小高度。 | 298 299## WindowStatusType<sup>11+</sup> 300 301窗口模式枚举。 302 303**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 304 305**系统能力:** SystemCapability.Window.SessionManager 306 307| 名称 | 值 | 说明 | 308| ---------- | ---- | ----------------------------- | 309| UNDEFINED | 0 | 表示APP未定义窗口模式。 | 310| FULL_SCREEN | 1 | 表示APP全屏模式。 | 311| MAXIMIZE | 2 | 表示APP窗口最大化模式。 | 312| MINIMIZE | 3 | 表示APP窗口最小化模式。 | 313| FLOATING | 4 | 表示APP自由悬浮形式窗口模式。 | 314| SPLIT_SCREEN | 5 | 表示APP分屏模式。 | 315 316## TitleButtonRect<sup>11+</sup> 317 318标题栏上的最小化、最大化、关闭按钮矩形区域,该区域位置坐标相对窗口右上角。 319 320**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 321 322**系统能力:** SystemCapability.Window.SessionManager 323 324| 名称 | 类型 | 可读 | 可写 | 说明 | 325| ------ | ------ | ---- | ---- | ------------------------------------------ | 326| right | number | 是 | 是 | 矩形区域的右边界,单位为vp,该参数为整数。 | 327| top | number | 是 | 是 | 矩形区域的上边界,单位为vp,该参数为整数。 | 328| width | number | 是 | 是 | 矩形区域的宽度,单位为vp,该参数为整数。 | 329| height | number | 是 | 是 | 矩形区域的高度,单位为vp,该参数为整数。 | 330 331## MaximizePresentation<sup>12+</sup> 332 333窗口最大化时的布局枚举。 334 335**系统能力:** SystemCapability.Window.SessionManager 336 337| 名称 | 值 | 说明 | 338| ---------- | ---- | ----------------------------- | 339| FOLLOW_APP_IMMERSIVE_SETTING | 0 | 最大化时,跟随应用app当前设置的沉浸式布局。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 340| EXIT_IMMERSIVE | 1 | 最大化时,如果当前窗口设置了沉浸式布局会退出沉浸式布局。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 341| ENTER_IMMERSIVE | 2 | 最大化时,进入沉浸式布局,鼠标Hover在热区上显示窗口标题栏和dock栏。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 342| ENTER_IMMERSIVE_DISABLE_TITLE_AND_DOCK_HOVER<sup>14+</sup> | 3 | 最大化时,进入沉浸式布局,鼠标Hover在热区上不显示窗口标题栏和dock栏。<br/>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 | 343 344## WindowDensityInfo<sup>15+</sup> 345 346窗口所在显示设备和窗口自定义的显示密度信息,是与像素单位无关的缩放系数,即显示大小缩放系数。 347 348**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 349 350**系统能力:** SystemCapability.Window.SessionManager 351 352| 名称 | 类型 | 可读 | 可写 | 说明 | 353| ------ | -------- | ---- | ---- | ---------- | 354| systemDensity | number | 是 | 否 | 窗口所在屏幕的系统显示大小缩放系数,跟随用户设置变化,该参数变化范围为0.5-4.0。 | 355| defaultDensity | number | 是 | 否 | 窗口所在屏幕的系统默认显示大小缩放系数,跟随窗口所在屏幕变化,该参数变化范围为0.5-4.0。 | 356| customDensity | number | 是 | 否 | 窗口自定义设置的显示大小缩放系数,该参数取值范围为0.5-4.0。未设置该参数时,将跟随系统显示大小缩放系数变化。 | 357 358## WindowLayoutInfo<sup>15+</sup> 359 360窗口布局信息。 361 362**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 363 364**系统能力:** SystemCapability.Window.SessionManager 365 366| 名称 | 类型 | 必填 | 说明 | 367| ------ | ------ | ---- | ------------------------------------------ | 368| windowRect<sup>15+</sup> | [Rect](#rect7) | 是 | 窗口尺寸,窗口在屏幕上的实际位置和大小。 | 369 370## MoveConfiguration<sup>15+</sup> 371 372窗口移动选项。 373 374**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 375 376**系统能力:** SystemCapability.Window.SessionManager 377 378| 名称 | 类型 | 必填 | 说明 | 379| ------ | ------ | ---- | ------------------------------------------ | 380| displayId | number | 否 | 目标屏幕ID,该参数应该为整数,非整数输入将向下取整。此参数不填或者传入目标屏幕ID不存在,将默认保持为当前屏幕。 | 381 382## Callback<sup>15+</sup> 383 384### (data: T)<sup>15+</sup> 385 386(data: T): V; 387 388通用回调函数。 389 390开发者在使用时,可自定义data的参数类型,回调函数返回对应类型的信息。 391 392**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 393 394**系统能力:** SystemCapability.Window.SessionManager 395 396**参数:** 397 398| 参数名 | 类型 | 必填 | 说明 | 399| ---- | ---- | ---- | -------------------------- | 400| data | T | 是 | 回调函数调用时需要传入T类型的参数。 | 401 402**返回值:** 403 404| 类型 | 说明 | 405| -------------------------------- | ------------------------------------ | 406| V | 回调函数需要返回V类型的返回值。 | 407 408## window.createWindow<sup>9+</sup> 409 410createWindow(config: Configuration, callback: AsyncCallback<Window>): void 411 412创建子窗口或者系统窗口,使用callback异步回调。 413 414**需要权限:** ohos.permission.SYSTEM_FLOAT_WINDOW(仅当创建窗口类型为window.WindowType.TYPE_FLOAT时需要申请) 415 416**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 417 418**系统能力:** SystemCapability.WindowManager.WindowManager.Core 419 420**参数:** 421 422| 参数名 | 类型 | 必填 | 说明 | 423| -------- | -------------------------------------- | -- | --------------------------------- | 424| config | [Configuration](#configuration9) | 是 | 创建窗口时的参数。 | 425| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的窗口对象。 | 426 427**错误码:** 428 429以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 430 431| 错误码ID | 错误信息 | 432| ------- | -------------------------------- | 433| 201 | Permission verification failed. The application does not have the permission required to call the API. | 434| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 435| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 436| 1300001 | Repeated operation. | 437| 1300002 | This window state is abnormal. | 438| 1300004 | Unauthorized operation. | 439| 1300006 | This window context is abnormal. | 440| 1300008 | The display device is abnormal. | 441| 1300009 | The parent window is invalid. | 442 443**示例:** 444 445```ts 446import { UIAbility } from '@kit.AbilityKit'; 447import { window } from '@kit.ArkUI'; 448import { BusinessError } from '@kit.BasicServicesKit'; 449 450export default class EntryAbility extends UIAbility { 451 onWindowStageCreate(windowStage: window.WindowStage): void { 452 let windowClass: window.Window | undefined = undefined; 453 let config: window.Configuration = { 454 name: "test", 455 windowType: window.WindowType.TYPE_DIALOG, 456 ctx: this.context // context对象也可在组件中通过getContext()方法获取 457 }; 458 try { 459 window.createWindow(config, (err: BusinessError, data) => { 460 const errCode: number = err.code; 461 if (errCode) { 462 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 463 return; 464 } 465 windowClass = data; 466 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 467 windowClass.resize(500, 1000); 468 }); 469 } catch (exception) { 470 console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`); 471 } 472 } 473} 474``` 475 476## window.createWindow<sup>9+</sup> 477 478createWindow(config: Configuration): Promise<Window> 479 480创建子窗口或者系统窗口,使用Promise异步回调。 481 482**需要权限:** ohos.permission.SYSTEM_FLOAT_WINDOW(仅当创建窗口类型为window.WindowType.TYPE_FLOAT时需要申请) 483 484**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 485 486**系统能力:** SystemCapability.WindowManager.WindowManager.Core 487 488**参数:** 489 490| 参数名 | 类型 | 必填 | 说明 | 491| ------ | -------------------------------- | -- | ------------------ | 492| config | [Configuration](#configuration9) | 是 | 创建窗口时的参数。 | 493 494**返回值:** 495 496| 类型 | 说明 | 497| -------------------------------- | ------------------------------------ | 498| Promise<[Window](#window)> | Promise对象。返回当前创建的窗口对象。 | 499 500**错误码:** 501 502以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 503 504| 错误码ID | 错误信息 | 505| ------- | -------------------------------- | 506| 201 | Permission verification failed. The application does not have the permission required to call the API. | 507| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 508| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 509| 1300001 | Repeated operation. | 510| 1300002 | This window state is abnormal. | 511| 1300004 | Unauthorized operation. | 512| 1300006 | This window context is abnormal. | 513| 1300008 | The display device is abnormal. | 514| 1300009 | The parent window is invalid. | 515 516**示例:** 517 518```ts 519import { UIAbility } from '@kit.AbilityKit'; 520import { window } from '@kit.ArkUI'; 521import { BusinessError } from '@kit.BasicServicesKit'; 522 523export default class EntryAbility extends UIAbility { 524 onWindowStageCreate(windowStage: window.WindowStage): void { 525 let config: window.Configuration = { 526 name: "test", 527 windowType: window.WindowType.TYPE_DIALOG, 528 ctx: this.context // context对象也可以在组件中通过getContext()方法获取 529 }; 530 try { 531 window.createWindow(config).then((value:window.Window) => { 532 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(value)); 533 value.resize(500, 1000); 534 }).catch((err:BusinessError)=> { 535 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 536 }); 537 } catch (exception) { 538 console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`); 539 } 540 } 541} 542``` 543 544## window.findWindow<sup>9+</sup> 545 546findWindow(name: string): Window 547 548查找name所对应的窗口。 549 550**系统能力:** SystemCapability.WindowManager.WindowManager.Core 551 552**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 553 554**参数:** 555 556| 参数名 | 类型 | 必填 | 说明 | 557| ------ | ------ | ---- | -------- | 558| name | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 559 560**返回值:** 561 562| 类型 | 说明 | 563| ----------------- | ------------------- | 564| [Window](#window) | 当前查找的窗口对象。 | 565 566**错误码:** 567 568以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 569 570| 错误码ID | 错误信息 | 571| ------- | -------------------------------- | 572| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 573| 1300002 | This window state is abnormal. | 574 575**示例:** 576 577```ts 578let windowClass: window.Window | undefined = undefined; 579try { 580 windowClass = window.findWindow('test'); 581} catch (exception) { 582 console.error(`Failed to find the Window. Cause code: ${exception.code}, message: ${exception.message}`); 583} 584``` 585 586## window.getLastWindow<sup>9+</sup> 587 588getLastWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 589 590获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口,使用callback异步回调。 591 592**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 593 594**系统能力:** SystemCapability.WindowManager.WindowManager.Core 595 596**参数:** 597 598| 参数名 | 类型 | 必填 | 说明 | 599| -------- | -------------------------------------- | -- | ---------------------------------------- | 600| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 601| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 602 603**错误码:** 604 605以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 606 607| 错误码ID | 错误信息 | 608| ------- | -------------------------------- | 609| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 610| 1300002 | This window state is abnormal. | 611| 1300006 | This window context is abnormal. | 612 613**示例:** 614 615```ts 616// EntryAbility.ets 617import { UIAbility } from '@kit.AbilityKit'; 618import { BusinessError } from '@kit.BasicServicesKit'; 619 620export default class EntryAbility extends UIAbility { 621 // ... 622 onWindowStageCreate(windowStage: window.WindowStage) { 623 console.info('onWindowStageCreate'); 624 let windowClass: window.Window | undefined = undefined; 625 try { 626 window.getLastWindow(this.context, (err: BusinessError, data) => { 627 const errCode: number = err.code; 628 if (errCode) { 629 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 630 return; 631 } 632 windowClass = data; 633 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 634 }); 635 } catch (exception) { 636 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`); 637 } 638 } 639} 640``` 641 642## window.getLastWindow<sup>9+</sup> 643 644getLastWindow(ctx: BaseContext): Promise<Window> 645 646获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口,使用Promise异步回调。 647 648**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 649 650**系统能力:** SystemCapability.WindowManager.WindowManager.Core 651 652**参数:** 653 654| 参数名 | 类型 | 必填 | 说明 | 655| ------ | ----------- | ---- | ------------------------------------------------------------ | 656| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 657 658**返回值:** 659 660| 类型 | 说明 | 661| -------------------------------- | ------------------------------------------- | 662| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 663 664**错误码:** 665 666以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 667 668| 错误码ID | 错误信息 | 669| ------- | -------------------------------- | 670| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 671| 1300002 | This window state is abnormal. | 672| 1300006 | This window context is abnormal. | 673 674**示例:** 675 676```ts 677// EntryAbility.ets 678import { UIAbility } from '@kit.AbilityKit'; 679import { BusinessError } from '@kit.BasicServicesKit'; 680 681export default class EntryAbility extends UIAbility { 682 // ... 683 onWindowStageCreate(windowStage: window.WindowStage) { 684 console.info('onWindowStageCreate'); 685 let windowClass: window.Window | undefined = undefined; 686 try { 687 let promise = window.getLastWindow(this.context); 688 promise.then((data) => { 689 windowClass = data; 690 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 691 }).catch((err: BusinessError) => { 692 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 693 }); 694 } catch (exception) { 695 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`); 696 } 697 } 698} 699``` 700 701## window.shiftAppWindowFocus<sup>11+</sup> 702shiftAppWindowFocus(sourceWindowId: number, targetWindowId: number): Promise<void> 703 704在同应用内将窗口焦点从源窗口转移到目标窗口,仅支持应用主窗和子窗的焦点转移。 705 706**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 707 708**系统能力:** SystemCapability.Window.SessionManager 709 710**参数:** 711 712| 参数名 | 类型 | 必填 | 说明 | 713| -------------- | ------ | ----- | ----------------------- | 714| sourceWindowId | number | 是 | 源窗口id,必须是获焦状态。| 715| targetWindowId | number | 是 | 目标窗口id。 | 716 717**返回值:** 718 719| 类型 | 说明 | 720| ------------------- | ------------------------- | 721| Promise<void> | 无返回结果的Promise对象。 | 722 723**错误码:** 724 725以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 726 727| 错误码ID | 错误信息 | 728| ------- | --------------------------------------------- | 729| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 730| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 731| 1300002 | This window state is abnormal. | 732| 1300003 | This window manager service works abnormally. | 733| 1300004 | Unauthorized operation. | 734 735**示例:** 736 737```ts 738// EntryAbility.ets 739import { UIAbility } from '@kit.AbilityKit'; 740import { BusinessError } from '@kit.BasicServicesKit'; 741 742export default class EntryAbility extends UIAbility { 743 onWindowStageCreate(windowStage: window.WindowStage) { 744 // ... 745 console.info('onWindowStageCreate'); 746 let windowClass: window.Window | undefined = undefined; 747 let subWindowClass: window.Window | undefined = undefined; 748 let windowClassId: number = -1; 749 let subWindowClassId: number = -1; 750 751 try { 752 // 获取应用主窗及ID 753 let promise = windowStage.getMainWindow(); 754 promise.then((data) => { 755 if (data == null) { 756 console.error("Failed to obtaining the window. Cause: The data is empty"); 757 return; 758 } 759 windowClass = data; 760 windowClass.setUIContent("pages/Index"); 761 windowClassId = windowClass.getWindowProperties().id; 762 console.info('Succeeded in obtaining the window') 763 }).catch((err: BusinessError) => { 764 console.error(`Failed to obtaining the window. Cause code: ${err.code}, message: ${err.message}`); 765 }); 766 767 // 创建或获取子窗及ID,此时子窗口获焦 768 let promiseSub = windowStage.createSubWindow("testSubWindow"); 769 promiseSub.then((data) => { 770 if (data == null) { 771 console.error("Failed to obtaining the window. Cause: The data is empty"); 772 return; 773 } 774 subWindowClass = data; 775 subWindowClassId = subWindowClass.getWindowProperties().id; 776 subWindowClass.resize(500, 500); 777 subWindowClass.setUIContent("pages/Index2"); 778 subWindowClass.showWindow(); 779 780 // 监听Window状态,确保已经就绪 781 subWindowClass.on("windowEvent", (windowEvent) => { 782 if (windowEvent == window.WindowEventType.WINDOW_ACTIVE) { 783 // 切换焦点 784 let promise = window.shiftAppWindowFocus(subWindowClassId, windowClassId); 785 promise.then(() => { 786 console.info('Succeeded in shifting app window focus'); 787 }).catch((err: BusinessError) => { 788 console.error(`Failed to shift app window focus. Cause code: ${err.code}, message: ${err.message}`); 789 }); 790 } 791 }); 792 }); 793 } catch (exception) { 794 console.error(`Failed to shift app focus. Cause code: ${exception.code}, message: ${exception.message}`); 795 } 796 } 797} 798``` 799 800## window.shiftAppWindowPointerEvent<sup>15+</sup> 801shiftAppWindowPointerEvent(sourceWindowId: number, targetWindowId: number): Promise<void> 802 803在同应用内窗口分合场景下,需要将输入事件从源窗口转移到目标窗口,使用Promise异步回调,仅在2in1设备上,针对主窗和子窗生效。 804 805在2in1设备上,源窗口需要处于鼠标按下状态,否则调用此接口将不生效。输入事件转移后,会向源窗口补发鼠标抬起事件,并且向目标窗口补发鼠标按下事件。 806 807**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 808 809**系统能力:** SystemCapability.Window.SessionManager 810 811**参数:** 812 813| 参数名 | 类型 | 必填 | 说明 | 814| -------------- | ------ | ----- | ----------------------- | 815| sourceWindowId | number | 是 | 源窗口id。推荐使用[getWindowProperties()](#getwindowproperties9)方法获取窗口id属性。 | 816| targetWindowId | number | 是 | 目标窗口id。推荐使用[getWindowProperties()](#getwindowproperties9)方法获取窗口id属性。 | 817 818**返回值:** 819 820| 类型 | 说明 | 821| ------------------- | ------------------------- | 822| Promise<void> | 无返回结果的Promise对象。 | 823 824**错误码:** 825 826以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 827 828| 错误码ID | 错误信息 | 829| ------- | --------------------------------------------- | 830| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 831| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 832| 1300002 | This window state is abnormal. | 833| 1300003 | This window manager service works abnormally. | 834| 1300004 | Unauthorized operation. | 835 836**示例:** 837 838```ts 839// ets/pages/Index.ets 840import { window } from '@kit.ArkUI'; 841import { BusinessError } from '@kit.BasicServicesKit'; 842 843@Entry 844struct Index { 845 build() { 846 Row() { 847 Column() { 848 Blank('160') 849 .color(Color.Blue) 850 .onTouch((event: TouchEvent) => { 851 if (event.type === TouchType.Down) { 852 try { 853 let sourceWindowId = 1; 854 let targetWindowId = 2; 855 let promise = window.shiftAppWindowPointerEvent(sourceWindowId, targetWindowId); 856 promise.then(() => { 857 console.info('Succeeded in shifting app window pointer event'); 858 }).catch((err: BusinessError) => { 859 console.error(`Failed to shift app window pointer event. Cause code: ${err.code}, message: ${err.message}`); 860 }); 861 } catch (exception) { 862 console.error(`Failed to shift app pointer event. Cause code: ${exception.code}, message: ${exception.message}`); 863 } 864 } 865 }) 866 }.width('100%') 867 }.height('100%').width('100%') 868 } 869} 870``` 871 872## window.getWindowsByCoordinate<sup>14+</sup> 873 874getWindowsByCoordinate(displayId: number, windowNumber?: number, x?: number, y?: number): Promise<Array<Window>> 875 876查询本应用指定坐标下的可见窗口,使用Promise异步回调。 877 878**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 879 880**系统能力:** SystemCapability.Window.SessionManager 881 882**参数:** 883 884| 参数名 | 类型 | 必填 | 说明 | 885| ------ | ---------- |----|---------------------------------------------------------------------------| 886| displayId | number| 是 | 查询窗口所在的displayId,该参数应为整数,可以在窗口属性[WindowProperties](#windowproperties)中获取。 | 887| windowNumber | number| 否 | 查询的窗口数量,该参数应为大于0整数,未设置或小于等于0返回所有满足条件的窗口。 | 888| x | number | 否 | 查询的x坐标,该参数应为非负整数,未设置或小于0返回所有可见窗口。 | 889| y | number| 否 | 查询的y坐标,该参数应为非负整数,未设置或小于0返回所有可见窗口。 | 890 891**返回值:** 892 893| 类型 | 说明 | 894| -------------------------------- |-------------------------| 895| Promise<Array<[Window](#window)>> | Promise对象。返回获取到的窗口对象数组。 | 896 897**错误码:** 898 899以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 900 901| 错误码ID | 错误信息 | 902|----------| ------------------------------ | 903| 401 | Parameter error. Possible cause: Incorrect parameter types. | 904| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 905| 1300003 | This window manager service works abnormally. | 906 907```ts 908import { UIAbility } from '@kit.AbilityKit'; 909import { window } from '@kit.ArkUI'; 910import { BusinessError } from '@kit.BasicServicesKit'; 911 912export default class EntryAbility extends UIAbility { 913 914 onWindowStageCreate(windowStage: window.WindowStage): void { 915 let windowClass = windowStage.getMainWindowSync(); 916 try { 917 let properties = windowClass.getWindowProperties(); 918 window.getWindowsByCoordinate(properties.displayId).then((data) => { 919 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 920 for (let window of data) { 921 // do something with window 922 } 923 }).catch((err: BusinessError) => { 924 console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`); 925 }); 926 window.getWindowsByCoordinate(properties.displayId, 2, 500, 500).then((data) => { 927 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 928 for (let window of data) { 929 // do something with window 930 } 931 }).catch((err: BusinessError) => { 932 console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`); 933 }); 934 } catch (exception) { 935 console.error(`Failed to get window from point. Cause code: ${exception.code}, message: ${exception.message}`); 936 } 937 } 938} 939``` 940 941## window.getAllWindowLayoutInfo<sup>15+</sup> 942 943getAllWindowLayoutInfo(displayId: number): Promise<Array<WindowLayoutInfo>> 944 945获取指定屏幕上可见的窗口布局信息数组,按当前窗口层级排列,层级最高的对应数组index为0,使用Promise异步回调。 946 947**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 948 949**系统能力:** SystemCapability.Window.SessionManager 950 951**参数:** 952 953| 参数名 | 类型 | 必填 | 说明 | 954| ------ | ---------- |----|---------------------------------------------------------------------------| 955| displayId | number| 是 | 需要获取窗口布局信息的displayId,该参数应为整数,且为当前实际存在屏幕的displayId,可以通过窗口属性[WindowProperties](#windowproperties)获取。 | 956 957**返回值:** 958 959| 类型 | 说明 | 960| -------------------------------- |-------------------------| 961| Promise<Array<[WindowLayoutInfo](#windowlayoutinfo15)>> | Promise对象。返回获取到的窗口布局信息对象数组。 | 962 963**错误码:** 964 965以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 966 967| 错误码ID | 错误信息 | 968|----------| ------------------------------ | 969| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 970| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 971| 1300002 | This window state is abnormal. | 972| 1300003 | This window manager service works abnormally. | 973 974```ts 975import { window } from '@kit.ArkUI'; 976import { BusinessError } from '@kit.BasicServicesKit'; 977 978try { 979 let displayId = 0; 980 let promise = window.getAllWindowLayoutInfo(displayId) 981 promise.then((data) => { 982 console.info('Succeeded in obtaining all window layout info. Data: ' + JSON.stringify(data)); 983 }).catch((err: BusinessError) => { 984 console.error(`Failed to obtain all window layout info. Cause code: ${err.code}, message: ${err.message}`); 985 }); 986} catch (exception) { 987 console.error(`Failed to obtain all window layout info. Cause code: ${exception.code}, message: ${exception.message}`); 988} 989``` 990 991## window.create<sup>(deprecated)</sup> 992 993create(id: string, type: WindowType, callback: AsyncCallback<Window>): void 994 995创建子窗口,使用callback异步回调。 996 997> **说明:** 998> 999> 从API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。 1000 1001**模型约束:** 此接口仅可在FA模型下使用。 1002 1003**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1004 1005**参数:** 1006 1007| 参数名 | 类型 | 必填 | 说明 | 1008| -------- | -------------------------------------- | ---- | ------------------------------------ | 1009| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。| 1010| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 1011| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的子窗口对象。 | 1012 1013 1014**示例:** 1015 1016```ts 1017import { BusinessError } from '@kit.BasicServicesKit'; 1018 1019let windowClass: window.Window | undefined = undefined; 1020window.create('test', window.WindowType.TYPE_APP, (err: BusinessError, data) => { 1021 const errCode: number = err.code; 1022 if (errCode) { 1023 console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`); 1024 return; 1025 } 1026 windowClass = data; 1027 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 1028}); 1029``` 1030 1031## window.create<sup>(deprecated)</sup> 1032 1033create(id: string, type: WindowType): Promise<Window> 1034 1035创建子窗口,使用Promise异步回调。 1036 1037> **说明:** 1038> 1039> 从API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。 1040 1041**模型约束:** 此接口仅可在FA模型下使用。 1042 1043**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1044 1045**参数:** 1046 1047| 参数名 | 类型 | 必填 | 说明 | 1048| ------ | ------------------------- | ---- | ---------- | 1049| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 1050| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 1051 1052**返回值:** 1053 1054| 类型 | 说明 | 1055| -------------------------------- | --------------------------------------- | 1056| Promise<[Window](#window)> | Promise对象。返回当前创建的子窗口对象。 | 1057 1058 1059**示例:** 1060 1061```ts 1062import { BusinessError } from '@kit.BasicServicesKit'; 1063 1064let windowClass: window.Window | undefined = undefined; 1065let promise = window.create('test', window.WindowType.TYPE_APP); 1066promise.then((data) => { 1067 windowClass = data; 1068 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 1069}).catch((err: BusinessError) => { 1070 console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`); 1071}); 1072``` 1073 1074## window.create<sup>(deprecated)</sup> 1075 1076create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback<Window>): void 1077 1078创建系统窗口,使用callback异步回调。 1079 1080> **说明:** 1081> 1082> 从API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。 1083 1084**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1085 1086**参数:** 1087 1088| 参数名 | 类型 | 必填 | 说明 | 1089| -------- | ------------------------------------------------------- | ---- | ------------------------------------ | 1090| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1091| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 1092| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 1093| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的子窗口对象。 | 1094 1095 1096**示例:** 1097 1098```ts 1099import { BusinessError } from '@kit.BasicServicesKit'; 1100 1101let windowClass: window.Window | undefined = undefined; 1102window.create('test', window.WindowType.TYPE_SYSTEM_ALERT, (err: BusinessError, data) => { 1103 const errCode: number = err.code; 1104 if (errCode) { 1105 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 1106 return; 1107 } 1108 windowClass = data; 1109 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 1110 windowClass.resetSize(500, 1000); 1111}); 1112``` 1113 1114## window.create<sup>(deprecated)</sup> 1115 1116create(ctx: BaseContext, id: string, type: WindowType): Promise<Window> 1117 1118创建系统窗口,使用Promise异步回调。 1119 1120> **说明:** 1121> 1122> 从API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。 1123 1124**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1125 1126**参数:** 1127 1128| 参数名 | 类型 | 必填 | 说明 | 1129| ------ | ------------------------- | ---- | ------------------------------------------------------------ | 1130| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1131| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 1132| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 1133 1134**返回值:** 1135 1136| 类型 | 说明 | 1137| -------------------------------- | --------------------------------------- | 1138| Promise<[Window](#window)> | Promise对象。返回当前创建的子窗口对象。 | 1139 1140 1141**示例:** 1142 1143```ts 1144import { BusinessError } from '@kit.BasicServicesKit'; 1145 1146let windowClass: window.Window | undefined = undefined; 1147let promise = window.create('test', window.WindowType.TYPE_SYSTEM_ALERT); 1148promise.then((data) => { 1149 windowClass = data; 1150 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 1151}).catch((err: BusinessError) => { 1152 console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`); 1153}); 1154``` 1155 1156## window.find<sup>(deprecated)</sup> 1157 1158find(id: string, callback: AsyncCallback<Window>): void 1159 1160查找id所对应的窗口,使用callback异步回调。 1161 1162> **说明:** 1163> 1164> 从API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。 1165 1166**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1167 1168**参数:** 1169 1170| 参数名 | 类型 | 必填 | 说明 | 1171| -------- | -------------------------------------- | ---- | ------------------------------------ | 1172| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 1173| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前查找到的窗口对象。 | 1174 1175**示例:** 1176 1177```ts 1178import { BusinessError } from '@kit.BasicServicesKit'; 1179 1180let windowClass: window.Window | undefined = undefined; 1181window.find('test', (err: BusinessError, data) => { 1182 const errCode: number = err.code; 1183 if (errCode) { 1184 console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`); 1185 return; 1186 } 1187 windowClass = data; 1188 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 1189}); 1190``` 1191 1192## window.find<sup>(deprecated)</sup> 1193 1194find(id: string): Promise<Window> 1195 1196查找id所对应的窗口,使用Promise异步回调。 1197 1198> **说明:** 1199> 1200> 从API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。 1201 1202**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1203 1204**参数:** 1205 1206| 参数名 | 类型 | 必填 | 说明 | 1207| ------ | ------ | ---- | -------- | 1208| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 1209 1210**返回值:** 1211 1212| 类型 | 说明 | 1213| -------------------------------- | ------------------------------------- | 1214| Promise<[Window](#window)> | Promise对象。返回当前查找的窗口对象。 | 1215 1216**示例:** 1217 1218```ts 1219import { BusinessError } from '@kit.BasicServicesKit'; 1220 1221let windowClass: window.Window | undefined = undefined; 1222let promise = window.find('test'); 1223promise.then((data) => { 1224 windowClass = data; 1225 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 1226}).catch((err: BusinessError) => { 1227 console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`); 1228}); 1229``` 1230 1231## window.getTopWindow<sup>(deprecated)</sup> 1232 1233getTopWindow(callback: AsyncCallback<Window>): void 1234 1235获取当前应用内最后显示的窗口,使用callback异步回调。 1236 1237> **说明:** 1238> 1239> 从API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。 1240 1241**模型约束:** 此接口仅可在FA模型下使用。 1242 1243**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1244 1245**参数:** 1246 1247| 参数名 | 类型 | 必填 | 说明 | 1248| -------- | -------------------------------------- | ---- | -------------------------------------------- | 1249| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 1250 1251**示例:** 1252 1253```ts 1254import { BusinessError } from '@kit.BasicServicesKit'; 1255 1256let windowClass: window.Window | undefined = undefined; 1257window.getTopWindow((err: BusinessError, data) => { 1258 const errCode: number = err.code; 1259 if (errCode) { 1260 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 1261 return; 1262 } 1263 windowClass = data; 1264 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1265}); 1266``` 1267 1268## window.getTopWindow<sup>(deprecated)</sup> 1269 1270getTopWindow(): Promise<Window> 1271 1272获取当前应用内最后显示的窗口,使用Promise异步回调。 1273 1274> **说明:** 1275> 1276> 从API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。 1277 1278**模型约束:** 此接口仅可在FA模型下使用。 1279 1280**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1281 1282**返回值:** 1283 1284| 类型 | 说明 | 1285| -------------------------------- | ----------------------------------------------- | 1286| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 1287 1288**示例:** 1289 1290```ts 1291import { BusinessError } from '@kit.BasicServicesKit'; 1292 1293let windowClass: window.Window | undefined = undefined; 1294let promise = window.getTopWindow(); 1295promise.then((data)=> { 1296 windowClass = data; 1297 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1298}).catch((err: BusinessError)=>{ 1299 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 1300}); 1301``` 1302 1303## window.getTopWindow<sup>(deprecated)</sup> 1304 1305getTopWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 1306 1307获取当前应用内最后显示的窗口,使用callback异步回调。 1308 1309> **说明:** 1310> 1311> 从API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。 1312 1313**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1314 1315**参数:** 1316 1317| 参数名 | 类型 | 必填 | 说明 | 1318| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 1319| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1320| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 1321 1322**示例:** 1323 1324```ts 1325// EntryAbility.ets 1326import { UIAbility } from '@kit.AbilityKit'; 1327import { BusinessError } from '@kit.BasicServicesKit'; 1328 1329export default class EntryAbility extends UIAbility { 1330 onWindowStageCreate(windowStage:window.WindowStage){ 1331 console.info('onWindowStageCreate'); 1332 let windowClass: window.Window | undefined = undefined; 1333 try { 1334 window.getTopWindow(this.context, (err: BusinessError, data) => { 1335 const errCode: number = err.code; 1336 if(errCode){ 1337 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 1338 return ; 1339 } 1340 windowClass = data; 1341 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1342 }); 1343 } catch(error){ 1344 console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`); 1345 } 1346 } 1347} 1348``` 1349 1350## window.getTopWindow<sup>(deprecated)</sup> 1351 1352getTopWindow(ctx: BaseContext): Promise<Window> 1353 1354获取当前应用内最后显示的窗口,使用Promise异步回调。 1355 1356> **说明:** 1357> 1358> 从API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。 1359 1360**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1361 1362**参数:** 1363 1364| 参数名 | 类型 | 必填 | 说明 | 1365| ------ | ----------- | ---- | ------------------------------------------------------------ | 1366| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1367 1368**返回值:** 1369 1370| 类型 | 说明 | 1371| -------------------------------- | ----------------------------------------------- | 1372| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 1373 1374**示例:** 1375 1376```ts 1377// EntryAbility.ets 1378import { UIAbility } from '@kit.AbilityKit'; 1379import { BusinessError } from '@kit.BasicServicesKit'; 1380 1381export default class EntryAbility extends UIAbility { 1382 onWindowStageCreate(windowStage:window.WindowStage) { 1383 console.info('onWindowStageCreate'); 1384 let windowClass: window.Window | undefined = undefined; 1385 let promise = window.getTopWindow(this.context); 1386 promise.then((data) => { 1387 windowClass = data; 1388 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1389 }).catch((error: BusinessError) => { 1390 console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`); 1391 }); 1392 } 1393} 1394``` 1395 1396## SpecificSystemBar<sup>11+</sup> 1397 1398type SpecificSystemBar = 'status' \| 'navigation' \| 'navigationIndicator' 1399 1400当前支持显示或隐藏的系统栏类型。 1401 1402**系统能力:** SystemCapability.Window.SessionManager 1403 1404**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1405 1406| 类型 | 说明 | 1407|------------|--------| 1408| 'status' | 状态栏。 | 1409| 'navigation' | 三键导航栏。 | 1410| 'navigationIndicator' | 底部导航条。 | 1411 1412## Window 1413 1414当前窗口实例,窗口管理器管理的基本单元。 1415 1416下列API示例中都需先使用[getLastWindow()](#windowgetlastwindow9)、[createWindow()](#windowcreatewindow9)、[findWindow()](#windowfindwindow9)中的任一方法获取到Window实例(windowClass),再通过此实例调用对应方法。 1417 1418### showWindow<sup>9+</sup> 1419 1420showWindow(callback: AsyncCallback<void>): void 1421 1422显示当前窗口,使用callback异步回调,仅支持系统窗口及应用子窗口,或将已显示的应用主窗口的层级提升至顶部。 1423 1424**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1425 1426**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1427 1428**参数:** 1429 1430| 参数名 | 类型 | 必填 | 说明 | 1431| -------- | ------------------------- | -- | --------- | 1432| callback | AsyncCallback<void> | 是 | 回调函数。 | 1433 1434**错误码:** 1435 1436以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1437 1438| 错误码ID | 错误信息 | 1439| ------- | ------------------------------ | 1440| 1300002 | This window state is abnormal. | 1441 1442**示例:** 1443 1444```ts 1445import { BusinessError } from '@kit.BasicServicesKit'; 1446 1447windowClass.showWindow((err: BusinessError) => { 1448 const errCode: number = err.code; 1449 if (errCode) { 1450 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 1451 return; 1452 } 1453 console.info('Succeeded in showing the window.'); 1454}); 1455``` 1456 1457### showWindow<sup>9+</sup> 1458 1459showWindow(): Promise<void> 1460 1461显示当前窗口,使用Promise异步回调,仅支持系统窗口及应用子窗口,或将已显示的应用主窗口的层级提升至顶部。 1462 1463**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1464 1465**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1466 1467**返回值:** 1468 1469| 类型 | 说明 | 1470| ------------------- | ----------------------- | 1471| Promise<void> | 无返回结果的Promise对象。 | 1472 1473**错误码:** 1474 1475以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1476 1477| 错误码ID | 错误信息 | 1478| ------- | ------------------------------ | 1479| 1300002 | This window state is abnormal. | 1480 1481**示例:** 1482 1483```ts 1484import { BusinessError } from '@kit.BasicServicesKit'; 1485 1486let promise = windowClass.showWindow(); 1487promise.then(() => { 1488 console.info('Succeeded in showing the window.'); 1489}).catch((err: BusinessError) => { 1490 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 1491}); 1492``` 1493 1494### destroyWindow<sup>9+</sup> 1495 1496destroyWindow(callback: AsyncCallback<void>): void 1497 1498销毁当前窗口,使用callback异步回调,仅支持系统窗口及应用子窗口。 1499 1500**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1501 1502**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1503 1504**参数:** 1505 1506| 参数名 | 类型 | 必填 | 说明 | 1507| -------- | ------------------------- | -- | --------- | 1508| callback | AsyncCallback<void> | 是 | 回调函数。 | 1509 1510**错误码:** 1511 1512以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1513 1514| 错误码ID | 错误信息 | 1515| ------- | -------------------------------------------- | 1516| 1300002 | This window state is abnormal. | 1517| 1300003 | This window manager service works abnormally. | 1518 1519**示例:** 1520 1521```ts 1522import { BusinessError } from '@kit.BasicServicesKit'; 1523 1524windowClass.destroyWindow((err) => { 1525 const errCode: number = err.code; 1526 if (errCode) { 1527 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 1528 return; 1529 } 1530 console.info('Succeeded in destroying the window.'); 1531}); 1532``` 1533 1534### destroyWindow<sup>9+</sup> 1535 1536destroyWindow(): Promise<void> 1537 1538销毁当前窗口,使用Promise异步回调,仅支持系统窗口及应用子窗口。 1539 1540**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1541 1542**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1543 1544**返回值:** 1545 1546| 类型 | 说明 | 1547| ------------------- | ------------------------ | 1548| Promise<void> | 无返回结果的Promise对象。 | 1549 1550**错误码:** 1551 1552以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1553 1554| 错误码ID | 错误信息 | 1555| ------- | -------------------------------------------- | 1556| 1300002 | This window state is abnormal. | 1557| 1300003 | This window manager service works abnormally. | 1558 1559**示例:** 1560 1561```ts 1562import { BusinessError } from '@kit.BasicServicesKit'; 1563 1564let promise = windowClass.destroyWindow(); 1565promise.then(() => { 1566 console.info('Succeeded in destroying the window.'); 1567}).catch((err: BusinessError) => { 1568 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 1569}); 1570``` 1571 1572### moveWindowTo<sup>9+</sup> 1573 1574moveWindowTo(x: number, y: number, callback: AsyncCallback<void>): void 1575 1576移动窗口位置,使用callback异步回调。 1577 1578<!--RP4--> 1579全屏模式下,本接口仅在2in1设备上生效。<!--RP4End--> 1580在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。 1581 1582**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1583 1584**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1585 1586**参数:** 1587 1588| 参数名 | 类型 | 必填 | 说明 | 1589| -------- | ------------------------- | -- | --------------------------------------------- | 1590| x | number | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1591| y | number | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在y轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1592| callback | AsyncCallback<void> | 是 | 回调函数。 | 1593 1594**错误码:** 1595 1596以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1597 1598| 错误码ID | 错误信息 | 1599| ------- | -------------------------------------------- | 1600| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1601| 1300002 | This window state is abnormal. | 1602| 1300003 | This window manager service works abnormally. | 1603 1604**示例:** 1605 1606```ts 1607import { BusinessError } from '@kit.BasicServicesKit'; 1608 1609try { 1610 windowClass.moveWindowTo(300, 300, (err: BusinessError) => { 1611 const errCode: number = err.code; 1612 if (errCode) { 1613 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1614 return; 1615 } 1616 console.info('Succeeded in moving the window.'); 1617 }); 1618} catch (exception) { 1619 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1620} 1621``` 1622 1623### moveWindowTo<sup>9+</sup> 1624 1625moveWindowTo(x: number, y: number): Promise<void> 1626 1627移动窗口位置,使用Promise异步回调。调用成功即返回,该接口返回后无法立即获取最终生效结果,如需立即获取,建议使用接口[moveWindowToAsync()](#movewindowtoasync12)。 1628 1629<!--RP4--> 1630全屏模式下,本接口仅在2in1设备上生效。<!--RP4End--> 1631在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。 1632 1633**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1634 1635**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1636 1637**参数:** 1638 1639| 参数名 | 类型 | 必填 | 说明 | 1640| -- | ----- | -- | --------------------------------------------- | 1641| x | number | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1642| y | number | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在y轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1643 1644**返回值:** 1645 1646| 类型 | 说明 | 1647| ------------------- | ------------------------ | 1648| Promise<void> | 无返回结果的Promise对象。 | 1649 1650**错误码:** 1651 1652以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1653 1654| 错误码ID | 错误信息 | 1655| ------- | -------------------------------------------- | 1656| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1657| 1300002 | This window state is abnormal. | 1658| 1300003 | This window manager service works abnormally. | 1659 1660**示例:** 1661 1662```ts 1663import { BusinessError } from '@kit.BasicServicesKit'; 1664 1665try { 1666 let promise = windowClass.moveWindowTo(300, 300); 1667 promise.then(() => { 1668 console.info('Succeeded in moving the window.'); 1669 }).catch((err: BusinessError) => { 1670 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1671 }); 1672} catch (exception) { 1673 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1674} 1675``` 1676 1677### moveWindowToAsync<sup>12+</sup> 1678 1679moveWindowToAsync(x: number, y: number): Promise<void> 1680 1681移动窗口位置,使用Promise异步回调。调用生效后返回,回调中可使用getWindowProperties(见示例)立即获取最终生效结果。 1682 1683仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效。 1684在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。 1685 1686**系统能力:** SystemCapability.Window.SessionManager 1687 1688**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1689 1690**参数:** 1691 1692| 参数名 | 类型 | 必填 | 说明 | 1693| -- | ----- | -- | --------------------------------------------- | 1694| x | number | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1695| y | number | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在y轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1696 1697**返回值:** 1698 1699| 类型 | 说明 | 1700| ------------------- | ------------------------ | 1701| Promise<void> | 无返回结果的Promise对象。 | 1702 1703**错误码:** 1704 1705以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1706 1707| 错误码ID | 错误信息 | 1708| ------- | -------------------------------------------- | 1709| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1710| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1711| 1300002 | This window state is abnormal. | 1712| 1300003 | This window manager service works abnormally. | 1713| 1300010 | The operation in the current window status is invalid. | 1714 1715**示例:** 1716 1717```ts 1718import { BusinessError } from '@kit.BasicServicesKit'; 1719 1720try { 1721 let promise = windowClass.moveWindowToAsync(300, 300); 1722 promise.then(() => { 1723 console.info('Succeeded in moving the window.'); 1724 let rect = windowClass?.getWindowProperties().windowRect; 1725 console.info(`Get window rect: ` + JSON.stringify(rect)); 1726 }).catch((err: BusinessError) => { 1727 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1728 }); 1729} catch (exception) { 1730 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1731} 1732``` 1733 1734### moveWindowToAsync<sup>15+</sup> 1735 1736moveWindowToAsync(x: number, y: number, moveConfiguration?: MoveConfiguration): Promise<void> 1737 1738移动窗口位置,当moveConfiguration中displayId设置为存在的屏幕ID时,将移动到此屏幕,使用Promise异步回调。调用生效后返回,回调中可使用getWindowProperties(见示例)立即获取最终生效结果。 1739 1740仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效。 1741在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。 1742 1743**系统能力:** SystemCapability.Window.SessionManager 1744 1745**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 1746 1747**参数:** 1748 1749| 参数名 | 类型 | 必填 | 说明 | 1750| -- | ----- | -- | --------------------------------------------- | 1751| x | number | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1752| y | number | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在y轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1753| moveConfiguration | [MoveConfiguration](#moveconfiguration15) | 否 | 窗口移动选项,未设置将默认保持为当前屏幕。 | 1754 1755**返回值:** 1756 1757| 类型 | 说明 | 1758| ------------------- | ------------------------ | 1759| Promise<void> | 无返回结果的Promise对象。 | 1760 1761**错误码:** 1762 1763以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1764 1765| 错误码ID | 错误信息 | 1766| ------- | -------------------------------------------- | 1767| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1768| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1769| 1300002 | This window state is abnormal. | 1770| 1300003 | This window manager service works abnormally. | 1771| 1300010 | The operation in the current window status is invalid. | 1772 1773**示例:** 1774 1775```ts 1776import { window } from '@kit.ArkUI'; 1777import { BusinessError } from '@kit.BasicServicesKit'; 1778 1779try { 1780 let moveConfiguration: window.MoveConfiguration = { 1781 displayId: 0 1782 }; 1783 let promise = windowClass.moveWindowToAsync(300, 300, moveConfiguration); 1784 promise.then(() => { 1785 console.info('Succeeded in moving the window.'); 1786 let rect = windowClass?.getWindowProperties().windowRect; 1787 console.info(`Get window rect: ` + JSON.stringify(rect)); 1788 }).catch((err: BusinessError) => { 1789 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1790 }); 1791} catch (exception) { 1792 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1793} 1794``` 1795 1796### moveWindowToGlobal<sup>13+</sup> 1797 1798moveWindowToGlobal(x: number, y: number): Promise<void> 1799 1800基于屏幕坐标移动窗口位置,使用Promise异步回调。调用生效后返回。 1801 1802全屏模式窗口不支持该操作。 1803 1804在非2in1设备下,子窗会跟随主窗移动。 1805 1806**系统能力:** SystemCapability.Window.SessionManager 1807 1808**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 1809 1810**参数:** 1811 1812| 参数名 | 类型 | 必填 | 说明 | 1813| -- | ----- | -- | --------------------------------------------- | 1814| x | number | 是 | 表示以屏幕左上角为起点,窗口在x轴方向移动的值,单位为px。值为正表示右移,值为负表示左移。该参数仅支持整数输入,浮点数输入将向下取整。 | 1815| y | number | 是 | 表示以屏幕左上角为起点,窗口在y轴方向移动的值,单位为px。值为正表示下移,值为负表示上移。该参数仅支持整数输入,浮点数输入将向下取整。 | 1816 1817**返回值:** 1818 1819| 类型 | 说明 | 1820| ------------------- | ------------------------ | 1821| Promise<void> | 无返回结果的Promise对象。 | 1822 1823**错误码:** 1824 1825以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1826 1827| 错误码ID | 错误信息 | 1828| ------- | -------------------------------------------- | 1829| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1830| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1831| 1300002 | This window state is abnormal. | 1832| 1300003 | This window manager service works abnormally. | 1833| 1300010 | The operation in the current window status is invalid. | 1834 1835**示例:** 1836 1837```ts 1838import { BusinessError } from '@kit.BasicServicesKit'; 1839 1840try { 1841 let promise = windowClass.moveWindowToGlobal(300, 300); 1842 promise.then(() => { 1843 console.info('Succeeded in moving the window.'); 1844 }).catch((err: BusinessError) => { 1845 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1846 }); 1847} catch (exception) { 1848 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1849} 1850``` 1851 1852### moveWindowToGlobal<sup>15+</sup> 1853 1854moveWindowToGlobal(x: number, y: number, moveConfiguration?: MoveConfiguration): Promise<void> 1855 1856基于屏幕坐标移动窗口位置,当moveConfiguration中displayId设置为存在的屏幕ID时,将移动到此屏幕,使用Promise异步回调。调用生效后返回。 1857 1858全屏模式窗口不支持该操作。 1859 1860在非2in1设备下,子窗会跟随主窗移动。 1861 1862**系统能力:** SystemCapability.Window.SessionManager 1863 1864**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 1865 1866**参数:** 1867 1868| 参数名 | 类型 | 必填 | 说明 | 1869| -- | ----- | -- | --------------------------------------------- | 1870| x | number | 是 | 表示以目标屏幕左上角为起点,窗口在x轴方向移动的值,单位为px。值为正表示右移,值为负表示左移。该参数仅支持整数输入,浮点数输入将向下取整。 | 1871| y | number | 是 | 表示以目标屏幕左上角为起点,窗口在y轴方向移动的值,单位为px。值为正表示下移,值为负表示上移。该参数仅支持整数输入,浮点数输入将向下取整。 | 1872| moveConfiguration | [MoveConfiguration](#moveconfiguration15) | 否 | 窗口移动选项,未设置将默认保持为当前屏幕。 | 1873 1874**返回值:** 1875 1876| 类型 | 说明 | 1877| ------------------- | ------------------------ | 1878| Promise<void> | 无返回结果的Promise对象。 | 1879 1880**错误码:** 1881 1882以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1883 1884| 错误码ID | 错误信息 | 1885| ------- | -------------------------------------------- | 1886| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1887| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1888| 1300002 | This window state is abnormal. | 1889| 1300003 | This window manager service works abnormally. | 1890| 1300010 | The operation in the current window status is invalid. | 1891 1892**示例:** 1893 1894```ts 1895import { window } from '@kit.ArkUI'; 1896import { BusinessError } from '@kit.BasicServicesKit'; 1897 1898try { 1899 let moveConfiguration: window.MoveConfiguration = { 1900 displayId: 0 1901 }; 1902 let promise = windowClass.moveWindowToGlobal(300, 300, moveConfiguration); 1903 promise.then(() => { 1904 console.info('Succeeded in moving the window.'); 1905 }).catch((err: BusinessError) => { 1906 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1907 }); 1908} catch (exception) { 1909 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1910} 1911``` 1912 1913### resize<sup>9+</sup> 1914 1915resize(width: number, height: number, callback: AsyncCallback<void>): void 1916 1917改变当前窗口大小,使用callback异步回调。 1918 1919应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 1920应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 1921 1922系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 1923 1924设置的宽度与高度受到此约束限制,规则: 1925若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 1926若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 1927 1928全屏模式窗口不支持该操作。 1929 1930**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1931 1932**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1933 1934**参数:** 1935 1936| 参数名 | 类型 | 必填 | 说明 | 1937| -------- | ------------------------- | -- | ------------------------ | 1938| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 1939| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 1940| callback | AsyncCallback<void> | 是 | 回调函数。 | 1941 1942**错误码:** 1943 1944以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1945 1946| 错误码ID | 错误信息 | 1947| ------- | -------------------------------------------- | 1948| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1949| 1300002 | This window state is abnormal. | 1950| 1300003 | This window manager service works abnormally. | 1951 1952**示例:** 1953 1954```ts 1955import { BusinessError } from '@kit.BasicServicesKit'; 1956 1957try { 1958 windowClass.resize(500, 1000, (err: BusinessError) => { 1959 const errCode: number = err.code; 1960 if (errCode) { 1961 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 1962 return; 1963 } 1964 console.info('Succeeded in changing the window size.'); 1965 }); 1966} catch (exception) { 1967 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 1968} 1969``` 1970 1971### resize<sup>9+</sup> 1972 1973resize(width: number, height: number): Promise<void> 1974 1975改变当前窗口大小,使用Promise异步回调。调用成功即返回,该接口返回后无法立即获取最终生效结果,如需立即获取,建议使用接口[resizeAsync()](#resizeasync12)。 1976 1977应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 1978应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 1979 1980系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 1981 1982设置的宽度与高度受到此约束限制,规则: 1983若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 1984若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 1985 1986全屏模式窗口不支持该操作。 1987 1988**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1989 1990**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1991 1992**参数:** 1993 1994| 参数名 | 类型 | 必填 | 说明 | 1995| ------ | ------ | -- | ------------------------ | 1996| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 1997| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 1998 1999**返回值:** 2000 2001| 类型 | 说明 | 2002| ------------------- | ------------------------ | 2003| Promise<void> | 无返回结果的Promise对象。 | 2004 2005**错误码:** 2006 2007以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2008 2009| 错误码ID | 错误信息 | 2010| ------- | -------------------------------------------- | 2011| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2012| 1300002 | This window state is abnormal. | 2013| 1300003 | This window manager service works abnormally. | 2014 2015**示例:** 2016 2017```ts 2018import { BusinessError } from '@kit.BasicServicesKit'; 2019 2020try { 2021 let promise = windowClass.resize(500, 1000); 2022 promise.then(() => { 2023 console.info('Succeeded in changing the window size.'); 2024 }).catch((err: BusinessError) => { 2025 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 2026 }); 2027} catch (exception) { 2028 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 2029} 2030``` 2031 2032### resizeAsync<sup>12+</sup> 2033 2034resizeAsync(width: number, height: number): Promise<void> 2035 2036改变当前窗口大小,使用Promise异步回调。调用生效后返回,回调中可使用getWindowProperties(见示例)立即获取最终生效结果。 2037 2038应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 2039应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 2040 2041系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 2042 2043设置的宽度与高度受到此约束限制,规则: 2044若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 2045若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 2046 2047全屏模式窗口不支持该操作。 2048 2049**系统能力:** SystemCapability.Window.SessionManager 2050 2051**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2052 2053**参数:** 2054 2055| 参数名 | 类型 | 必填 | 说明 | 2056| ------ | ------ | -- | ------------------------ | 2057| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 2058| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 2059 2060**返回值:** 2061 2062| 类型 | 说明 | 2063| ------------------- | ------------------------ | 2064| Promise<void> | 无返回结果的Promise对象。 | 2065 2066**错误码:** 2067 2068以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2069 2070| 错误码ID | 错误信息 | 2071| ------- | -------------------------------------------- | 2072| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2073| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2074| 1300002 | This window state is abnormal. | 2075| 1300003 | This window manager service works abnormally. | 2076| 1300010 | The operation in the current window status is invalid. | 2077 2078**示例:** 2079 2080```ts 2081import { BusinessError } from '@kit.BasicServicesKit'; 2082 2083try { 2084 let promise = windowClass.resizeAsync(500, 1000); 2085 promise.then(() => { 2086 console.info('Succeeded in changing the window size.'); 2087 let rect = windowClass?.getWindowProperties().windowRect; 2088 console.info(`Get window rect: ` + JSON.stringify(rect)); 2089 }).catch((err: BusinessError) => { 2090 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 2091 }); 2092} catch (exception) { 2093 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 2094} 2095``` 2096 2097### getWindowProperties<sup>9+</sup> 2098 2099getWindowProperties(): WindowProperties 2100 2101获取当前窗口的属性,返回WindowProperties。 2102 2103**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2104 2105**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2106 2107**返回值:** 2108 2109| 类型 | 说明 | 2110| ------------------------------------- | ------------- | 2111| [WindowProperties](#windowproperties) | 当前窗口属性。 | 2112 2113**错误码:** 2114 2115以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 2116 2117| 错误码ID | 错误信息 | 2118| ------- | ------------------------------ | 2119| 1300002 | This window state is abnormal. | 2120 2121**示例:** 2122 2123```ts 2124try { 2125 let properties = windowClass.getWindowProperties(); 2126} catch (exception) { 2127 console.error(`Failed to obtain the window properties. Cause code: ${exception.code}, message: ${exception.message}`); 2128} 2129``` 2130 2131### getWindowDensityInfo<sup>15+</sup> 2132 2133getWindowDensityInfo(): WindowDensityInfo 2134 2135获取当前窗口所在屏幕的系统显示大小缩放系数、系统默认显示大小缩放系数和自定义显示大小缩放系数信息。 2136 2137**系统能力:** SystemCapability.Window.SessionManager 2138 2139**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 2140 2141**返回值:** 2142 2143| 类型 | 说明 | 2144| ------------------------------------- | ------------- | 2145| [WindowDensityInfo](#windowdensityinfo15) | 当前窗口的显示大小缩放系数信息。当返回值为[-1, -1, -1]时,表示当前设备不支持使用该接口。 | 2146 2147**错误码:** 2148 2149以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2150 2151| 错误码ID | 错误信息 | 2152| ------- | ------------------------------ | 2153| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2154| 1300002 | This window state is abnormal. | 2155 2156**示例:** 2157 2158```ts 2159try { 2160 let densityInfo = windowClass.getWindowDensityInfo(); 2161} catch (exception) { 2162 console.error(`Failed to obtain the window densityInfo. Cause code: ${exception.code}, message: ${exception.message}`); 2163} 2164``` 2165 2166### getGlobalRect<sup>13+</sup> 2167 2168getGlobalRect(): Rect 2169 2170获取窗口在屏幕上的真实显示区域,同步接口。 2171 2172在某些设备上,窗口显示时可能经过了缩放,此接口可以获取缩放后窗口在屏幕上的真实位置和大小。 2173 2174**系统能力:** SystemCapability.Window.SessionManager 2175 2176**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 2177 2178**返回值:** 2179 2180| 类型 | 说明 | 2181| ------------------- | ------------------------ | 2182| [Rect](#rect7) | 四元组分别表示距离屏幕左上角的x坐标、距离屏幕左上角的y坐标、缩放后的窗口宽度和缩放后的窗口高度。 | 2183 2184**错误码:** 2185 2186以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2187 2188| 错误码ID | 错误信息 | 2189| ------- | -------------------------------------------- | 2190| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2191| 1300002 | This window state is abnormal. | 2192| 1300003 | This window manager service works abnormally. | 2193 2194**示例:** 2195 2196```ts 2197try { 2198 let rect = windowClass.getGlobalRect(); 2199 console.info(`Succeeded in getting window rect: ` + JSON.stringify(rect)); 2200} catch (exception) { 2201 console.error(`Failed to get window rect. Cause code: ${exception.code}, message: ${exception.message}`); 2202} 2203``` 2204 2205### getWindowAvoidArea<sup>9+</sup> 2206 2207getWindowAvoidArea(type: AvoidAreaType): AvoidArea 2208 2209获取当前应用窗口内容规避的区域。如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 2210 2211该接口一般适用于两种场景:1、在onWindowStageCreate方法中,获取应用启动时的初始布局避让区域时可调用该接口;2、当应用内子窗需要临时显示,对显示内容做布局避让时可调用该接口。 2212 2213**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2214 2215**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2216 2217**参数:** 2218 2219| 参数名 | 类型 | 必填 | 说明 | 2220| ---- |----------------------------------| -- | ------------------------------------------------------------ | 2221| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。 | 2222 2223**返回值:** 2224 2225| 类型 | 说明 | 2226|--------------------------| ----------------- | 2227| [AvoidArea](#avoidarea7) | 窗口内容规避区域。 | 2228 2229**错误码:** 2230 2231以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2232 2233| 错误码ID | 错误信息 | 2234| ------- | ------------------------------ | 2235| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2236| 1300002 | This window state is abnormal. | 2237 2238**示例:** 2239 2240```ts 2241let type = window.AvoidAreaType.TYPE_SYSTEM; 2242try { 2243 let avoidArea = windowClass.getWindowAvoidArea(type); 2244} catch (exception) { 2245 console.error(`Failed to obtain the area. Cause code: ${exception.code}, message: ${exception.message}`); 2246} 2247``` 2248 2249### setTitleAndDockHoverShown<sup>14+</sup> 2250 2251setTitleAndDockHoverShown(isTitleHoverShown?: boolean, isDockHoverShown?: boolean): Promise<void> 2252 2253设置主窗口进入全屏沉浸式时鼠标Hover到热区上是否显示窗口标题栏和dock栏,使用Promise异步回调,仅2in1设备可用。 2254 2255**系统能力**:SystemCapability.Window.SessionManager 2256 2257**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 2258 2259**参数:** 2260 2261| 参数名 | 类型 | 必填 | 说明 | 2262| ---------- | ------- | ---- | ------------------------------------------------------------ | 2263| isTitleHoverShown | boolean | 否 | 是否显示窗口标题栏。<br>true表示显示窗口标题栏;false表示不显示窗口标题栏。默认值是true。</br> | 2264| isDockHoverShown | boolean | 否 | 是否显示dock栏。<br>true表示显示dock栏;false表示不显示dock栏。默认值是true。</br> | 2265 2266**错误码:** 2267 2268以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2269 2270| 错误码ID | 错误信息 | 2271| ------- | -------------------------------------------- | 2272| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2273| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2274| 1300002 | This window state is abnormal. | 2275| 1300004 | Unauthorized operation. | 2276 2277**示例:** 2278 2279```ts 2280// EntryAbility.ets 2281import { UIAbility } from '@kit.AbilityKit'; 2282import { BusinessError } from '@kit.BasicServicesKit'; 2283import { window } from '@kit.ArkUI'; 2284 2285export default class EntryAbility extends UIAbility { 2286 // ... 2287 onWindowStageCreate(windowStage: window.WindowStage): void { 2288 // 加载主窗口对应的页面。 2289 windowStage.loadContent('pages/Index', (err) => { 2290 let mainWindow: window.Window | undefined = undefined; 2291 // 获取应用主窗口。 2292 windowStage.getMainWindow().then( 2293 data => { 2294 mainWindow = data; 2295 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 2296 // 调用maximize接口,设置窗口进入全屏沉浸式。 2297 mainWindow.maximize(window.MaximizePresentation.ENTER_IMMERSIVE); 2298 // 调用setTitleAndDockHoverShown接口,隐藏标题栏和dock栏。 2299 mainWindow.setTitleAndDockHoverShown(false, false); 2300 } 2301 ).catch((err: BusinessError) => { 2302 if(err.code){ 2303 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2304 } 2305 }); 2306 }); 2307 } 2308} 2309``` 2310 2311### setWindowLayoutFullScreen<sup>9+</sup> 2312 2313setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 2314 2315设置主窗口或子窗口的布局是否为沉浸式布局,使用Promise异步回调。<!--RP8-->从API version 14开始,该接口在2in1设备上调用不生效。<!--RP8End--> 2316沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 2317非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 2318 2319**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2320 2321**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2322 2323**参数:** 2324 2325| 参数名 | 类型 | 必填 | 说明 | 2326| ------------------ | ------- | -- | ------------------------------------------------------------------------------------------------ | 2327| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 2328 2329**返回值:** 2330 2331| 类型 | 说明 | 2332| ------------------- | ------------------------ | 2333| Promise<void> | 无返回结果的Promise对象。 | 2334 2335**错误码:** 2336 2337以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2338 2339| 错误码ID | 错误信息 | 2340| ------- | -------------------------------------------- | 2341| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2342| 1300002 | This window state is abnormal. | 2343| 1300003 | This window manager service works abnormally. | 2344 2345**示例:** 2346 2347```ts 2348// EntryAbility.ets 2349import { UIAbility } from '@kit.AbilityKit'; 2350import { BusinessError } from '@kit.BasicServicesKit'; 2351 2352export default class EntryAbility extends UIAbility { 2353 // ... 2354 onWindowStageCreate(windowStage: window.WindowStage): void { 2355 console.info('onWindowStageCreate'); 2356 let windowClass: window.Window | undefined = undefined; 2357 windowStage.getMainWindow((err: BusinessError, data) => { 2358 const errCode: number = err.code; 2359 if (errCode) { 2360 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2361 return; 2362 } 2363 windowClass = data; 2364 let isLayoutFullScreen = true; 2365 try { 2366 let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); 2367 promise.then(() => { 2368 console.info('Succeeded in setting the window layout to full-screen mode.'); 2369 }).catch((err: BusinessError) => { 2370 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 2371 }); 2372 } catch (exception) { 2373 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`); 2374 } 2375 }); 2376 } 2377} 2378``` 2379 2380### setImmersiveModeEnabledState<sup>12+</sup> 2381 2382setImmersiveModeEnabledState(enabled: boolean): void 2383 2384设置当前窗口是否开启沉浸式布局,该调用不会改变窗口模式和窗口大小。<!--RP8-->从API version 14开始,该接口在2in1设备上调用不生效。<!--RP8End--> 2385 2386**系统能力**:SystemCapability.WindowManager.WindowManager.Core 2387 2388**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2389 2390**参数:** 2391 2392| 参数名 | 类型 | 必填 | 说明 | 2393| ---------- | ------- | ---- | ------------------------------------------------------------ | 2394| enabled | boolean | 是 | 是否开启沉浸式布局。<br>true表示开启,false表示关闭。</br> | 2395 2396**错误码:** 2397 2398以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2399 2400| 错误码ID | 错误信息 | 2401| ------- | -------------------------------------------- | 2402| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2403| 1300002 | This window state is abnormal. | 2404| 1300003 | This window manager service works abnormally. | 2405| 1300004 | Unauthorized operation. | 2406 2407**示例:** 2408 2409```ts 2410try { 2411 let enabled = false; 2412 windowClass.setImmersiveModeEnabledState(enabled); 2413} catch (exception) { 2414 console.error(`Failed to set the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 2415} 2416``` 2417 2418### getImmersiveModeEnabledState<sup>12+</sup> 2419 2420getImmersiveModeEnabledState(): boolean 2421 2422查询当前窗口是否已经开启沉浸式布局。 2423 2424**系统能力**:SystemCapability.WindowManager.WindowManager.Core 2425 2426**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2427 2428**返回值:** 2429| 类型 | 说明 | 2430| ------- | ------------------------------------------------------------------------------------ | 2431| boolean | 是否已经开启沉浸式布局。<br>true表示开启,false表示关闭。</br> | 2432 2433**错误码:** 2434 2435以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2436 2437| 错误码ID | 错误信息 | 2438| -------- | -------------------------------------------- | 2439| 1300002 | This window state is abnormal. | 2440| 1300003 | This window manager service works abnormally. | 2441| 1300004 | Unauthorized operation. | 2442 2443**示例:** 2444 2445```ts 2446try { 2447 let isEnabled = windowClass.getImmersiveModeEnabledState(); 2448} catch (exception) { 2449 console.error(`Failed to get the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 2450} 2451``` 2452 2453### setWindowSystemBarEnable<sup>9+</sup> 2454 2455setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 2456 2457设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 2458 2459调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。 2460 2461**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2462 2463**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2464 2465**参数:** 2466 2467| 参数名 | 类型 | 必填 | 说明 | 2468| ----- | ---------------------------- | -- | --------------------------------- | 2469| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 2470 2471**返回值:** 2472 2473| 类型 | 说明 | 2474| ------------------- | ------------------------ | 2475| Promise<void> | 无返回结果的Promise对象。 | 2476 2477**错误码:** 2478 2479以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2480 2481| 错误码ID | 错误信息 | 2482| ------- | -------------------------------------------- | 2483| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2484| 1300002 | This window state is abnormal. | 2485| 1300003 | This window manager service works abnormally. | 2486 2487**示例:** 2488 2489```ts 2490// 此处以不显示三键导航栏、状态栏、底部导航条为例 2491// EntryAbility.ets 2492import { UIAbility } from '@kit.AbilityKit'; 2493import { BusinessError } from '@kit.BasicServicesKit'; 2494 2495export default class EntryAbility extends UIAbility { 2496 // ... 2497 onWindowStageCreate(windowStage: window.WindowStage): void { 2498 console.info('onWindowStageCreate'); 2499 let windowClass: window.Window | undefined = undefined; 2500 windowStage.getMainWindow((err: BusinessError, data) => { 2501 const errCode: number = err.code; 2502 if (errCode) { 2503 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2504 return; 2505 } 2506 windowClass = data; 2507 let names: Array<'status' | 'navigation'> = []; 2508 try { 2509 let promise = windowClass.setWindowSystemBarEnable(names); 2510 promise.then(() => { 2511 console.info('Succeeded in setting the system bar to be invisible.'); 2512 }).catch((err: BusinessError) => { 2513 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 2514 }); 2515 } catch (exception) { 2516 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 2517 } 2518 }); 2519 } 2520} 2521``` 2522 2523### setSpecificSystemBarEnabled<sup>11+</sup> 2524 2525setSpecificSystemBarEnabled(name: SpecificSystemBar, enable: boolean, enableAnimation?: boolean): Promise<void> 2526 2527设置主窗口三键导航栏、状态栏、底部导航条的显示和隐藏,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 2528 2529调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。 2530 2531**系统能力:** SystemCapability.Window.SessionManager 2532 2533**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2534 2535**参数:** 2536 2537| 参数名 | 类型 | 必填 | 说明 | 2538| ----- | ---------------------------- | -- | --------------------------------- | 2539| name | [SpecificSystemBar](#specificsystembar11) | 是 | 设置窗口全屏模式时,显示或隐藏的系统栏类型。 | 2540| enable | boolean | 是 | 设置窗口全屏模式时状态栏、三键导航栏或底部导航条是否显示,true表示显示, false表示隐藏。| 2541| enableAnimation<sup>12+</sup> | boolean | 否 | 设置状态栏、三键导航栏或底部导航条显示状态变化时是否使用动画,true表示使用, false表示不使用,默认值为false。| 2542 2543**返回值:** 2544 2545| 类型 | 说明 | 2546| ------------------- | ------------------------ | 2547| Promise<void> | 无返回结果的Promise对象。 | 2548 2549**错误码:** 2550 2551以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2552 2553| 错误码ID | 错误信息 | 2554| ------- | -------------------------------------------- | 2555| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2556| 1300002 | This window state is abnormal. | 2557| 1300003 | This window manager service works abnormally. | 2558 2559**示例:** 2560 2561```ts 2562// 此处以隐藏底部导航条为例 2563// EntryAbility.ets 2564import { UIAbility } from '@kit.AbilityKit'; 2565import { BusinessError } from '@kit.BasicServicesKit'; 2566 2567export default class EntryAbility extends UIAbility { 2568 // ... 2569 onWindowStageCreate(windowStage: window.WindowStage): void { 2570 console.info('onWindowStageCreate'); 2571 let windowClass: window.Window | undefined = undefined; 2572 windowStage.getMainWindow((err: BusinessError, data) => { 2573 const errCode: number = err.code; 2574 if (errCode) { 2575 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2576 return; 2577 } 2578 windowClass = data; 2579 try { 2580 let promise = windowClass.setSpecificSystemBarEnabled('navigationIndicator', false); 2581 promise.then(() => { 2582 console.info('Succeeded in setting the system bar to be invisible.'); 2583 }).catch((err: BusinessError) => { 2584 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 2585 }); 2586 } catch (exception) { 2587 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 2588 } 2589 }); 2590 } 2591} 2592``` 2593 2594### setWindowSystemBarProperties<sup>9+</sup> 2595 2596setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 2597 2598设置主窗口三键导航栏、状态栏的属性,使用Promise异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 2599 2600子窗口调用后不生效。 2601 2602**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2603 2604**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2605 2606**参数:** 2607 2608| 参数名 | 类型 | 必填 | 说明 | 2609| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2610| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 三键导航栏、状态栏的属性。 | 2611 2612**返回值:** 2613 2614| 类型 | 说明 | 2615| ------------------- | ------------------------- | 2616| Promise<void> | 无返回结果的Promise对象。 | 2617 2618**错误码:** 2619 2620以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2621 2622| 错误码ID | 错误信息 | 2623| ------- | -------------------------------------------- | 2624| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2625| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2626| 1300002 | This window state is abnormal. | 2627| 1300003 | This window manager service works abnormally. | 2628 2629**示例:** 2630 2631```ts 2632// EntryAbility.ets 2633import { UIAbility } from '@kit.AbilityKit'; 2634import { BusinessError } from '@kit.BasicServicesKit'; 2635 2636export default class EntryAbility extends UIAbility { 2637 // ... 2638 onWindowStageCreate(windowStage: window.WindowStage): void { 2639 console.info('onWindowStageCreate'); 2640 let windowClass: window.Window | undefined = undefined; 2641 windowStage.getMainWindow((err: BusinessError, data) => { 2642 const errCode: number = err.code; 2643 if (errCode) { 2644 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2645 return; 2646 } 2647 windowClass = data; 2648 let SystemBarProperties: window.SystemBarProperties = { 2649 statusBarColor: '#ff00ff', 2650 navigationBarColor: '#00ff00', 2651 //以下两个属性从API Version8开始支持 2652 statusBarContentColor: '#ffffff', 2653 navigationBarContentColor: '#00ffff' 2654 }; 2655 try { 2656 let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties); 2657 promise.then(() => { 2658 console.info('Succeeded in setting the system bar properties.'); 2659 }).catch((err: BusinessError) => { 2660 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 2661 }); 2662 } catch (exception) { 2663 console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); 2664 } 2665 }); 2666 } 2667} 2668``` 2669 2670### getWindowSystemBarProperties<sup>12+</sup> 2671 2672getWindowSystemBarProperties(): SystemBarProperties 2673 2674主窗口获取三键导航栏、状态栏的属性。 2675 2676**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2677 2678**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2679 2680**返回值:** 2681 2682| 类型 | 说明 | 2683| ------------------------------------- | ------------- | 2684| [SystemBarProperties](#systembarproperties) | 当前三键导航栏、状态栏属性。 | 2685 2686**错误码:** 2687 2688以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 2689 2690| 错误码ID | 错误信息 | 2691| ------- | ------------------------------ | 2692| 1300002 | This window state is abnormal. | 2693| 1300003 | This window manager service works abnormally. | 2694| 1300004 | Unauthorized operation. | 2695 2696 2697**示例:** 2698 2699```ts 2700// EntryAbility.ets 2701import { UIAbility } from '@kit.AbilityKit'; 2702import { BusinessError } from '@kit.BasicServicesKit'; 2703 2704export default class EntryAbility extends UIAbility { 2705 // ... 2706 2707 onWindowStageCreate(windowStage: window.WindowStage) { 2708 let windowClass: window.Window | undefined = undefined; 2709 windowStage.getMainWindow((err: BusinessError, data) => { 2710 const errCode: number = err.code; 2711 if (errCode) { 2712 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2713 return; 2714 } 2715 windowClass = data; 2716 try { 2717 let systemBarProperty = windowClass.getWindowSystemBarProperties(); 2718 console.info('Success in obtaining system bar properties. Property: ' + JSON.stringify(systemBarProperty)); 2719 } catch (err) { 2720 console.error(`Failed to get system bar properties. Code: ${err.code}, message: ${err.message}`); 2721 } 2722 }); 2723 } 2724}; 2725``` 2726 2727### setPreferredOrientation<sup>9+</sup> 2728 2729setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void 2730 2731设置主窗口的显示方向属性,使用callback异步回调。<!--RP9-->仅在支持跟随sensor旋转的设备上生效,2in1设备上调用不生效,子窗口调用后不生效。<!--RP9End--> 2732 2733**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2734 2735**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2736 2737**参数:** 2738 2739| 参数名 | 类型 | 必填 | 说明 | 2740| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2741| orientation | [Orientation](#orientation9) | 是 | 窗口显示方向的属性。 | 2742| callback | AsyncCallback<void> | 是 | 回调函数。该回调函数返回调用结果是否成功,非应用旋转动效结束。 | 2743 2744**错误码:** 2745 2746以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2747 2748| 错误码ID | 错误信息 | 2749| ------- | ------------------------------ | 2750| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2751| 1300002 | This window state is abnormal. | 2752 2753**示例:** 2754 2755```ts 2756// EntryAbility.ets 2757import { UIAbility } from '@kit.AbilityKit'; 2758import { BusinessError } from '@kit.BasicServicesKit'; 2759 2760export default class EntryAbility extends UIAbility { 2761 // ... 2762 onWindowStageCreate(windowStage: window.WindowStage): void { 2763 console.info('onWindowStageCreate'); 2764 let windowClass: window.Window | undefined = undefined; 2765 windowStage.getMainWindow((err: BusinessError, data) => { 2766 const errCode: number = err.code; 2767 if (errCode) { 2768 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2769 return; 2770 } 2771 windowClass = data; 2772 let orientation = window.Orientation.AUTO_ROTATION; 2773 try { 2774 windowClass.setPreferredOrientation(orientation, (err: BusinessError) => { 2775 const errCode: number = err.code; 2776 if (errCode) { 2777 console.error(`Failed to set window orientation. Cause code: ${err.code}, message: ${err.message}`); 2778 return; 2779 } 2780 console.info('Succeeded in setting window orientation.'); 2781 }); 2782 } catch (exception) { 2783 console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 2784 } 2785 }); 2786 } 2787} 2788``` 2789 2790### setPreferredOrientation<sup>9+</sup> 2791 2792setPreferredOrientation(orientation: Orientation): Promise<void> 2793 2794设置主窗口的显示方向属性,使用Promise异步回调。<!--RP9-->仅在支持跟随sensor旋转的设备上生效,2in1设备上调用不生效,子窗口调用后不生效。<!--RP9End--> 2795 2796**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2797 2798**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2799 2800**参数:** 2801 2802| 参数名 | 类型 | 必填 | 说明 | 2803| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2804| orientation | [Orientation](#orientation9) | 是 | 窗口显示方向的属性。 | 2805 2806**返回值:** 2807 2808| 类型 | 说明 | 2809| ------------------- | ------------------------- | 2810| Promise<void> | 无返回结果的Promise对象。 | 2811 2812**错误码:** 2813 2814以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2815 2816| 错误码ID | 错误信息 | 2817| ------- | ------------------------------ | 2818| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2819| 1300002 | This window state is abnormal. | 2820 2821**示例:** 2822 2823```ts 2824// EntryAbility.ets 2825import { UIAbility } from '@kit.AbilityKit'; 2826import { BusinessError } from '@kit.BasicServicesKit'; 2827 2828export default class EntryAbility extends UIAbility { 2829 // ... 2830 onWindowStageCreate(windowStage: window.WindowStage): void { 2831 console.info('onWindowStageCreate'); 2832 let windowClass: window.Window | undefined = undefined; 2833 windowStage.getMainWindow((err: BusinessError, data) => { 2834 const errCode: number = err.code; 2835 if (errCode) { 2836 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2837 return; 2838 } 2839 windowClass = data; 2840 let orientation = window.Orientation.AUTO_ROTATION; 2841 try { 2842 let promise = windowClass.setPreferredOrientation(orientation); 2843 promise.then(() => { 2844 console.info('Succeeded in setting the window orientation.'); 2845 }).catch((err: BusinessError) => { 2846 console.error(`Failed to set the window orientation. Cause code: ${err.code}, message: ${err.message}`); 2847 }); 2848 } catch (exception) { 2849 console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 2850 } 2851 }); 2852 } 2853} 2854``` 2855 2856### getPreferredOrientation<sup>12+</sup> 2857 2858getPreferredOrientation(): Orientation 2859 2860主窗口调用,获取窗口的显示方向属性。 2861 2862**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2863 2864**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2865 2866**返回值:** 2867 2868| 类型 | 说明 | 2869|------------------------------| ------------------ | 2870| [Orientation](#orientation9) | 窗口显示方向的属性。 | 2871 2872**错误码:** 2873 2874以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 2875 2876| 错误码ID | 错误信息 | 2877| ------- | ------------------------------ | 2878| 1300002 | This window state is abnormal. | 2879 2880**示例:** 2881 2882```ts 2883// EntryAbility.ets 2884import { UIAbility } from '@kit.AbilityKit'; 2885import { BusinessError } from '@kit.BasicServicesKit'; 2886export default class EntryAbility extends UIAbility { 2887 // ... 2888 2889 onWindowStageCreate(windowStage: window.WindowStage) { 2890 console.info('onWindowStageCreate'); 2891 let windowClass: window.Window | undefined = undefined; 2892 windowStage.getMainWindow((err: BusinessError, data) => { 2893 const errCode: number = err.code; 2894 if (errCode) { 2895 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2896 return; 2897 } 2898 windowClass = data; 2899 try { 2900 let orientation = windowClass.getPreferredOrientation(); 2901 } catch (exception) { 2902 console.error(`Failed to get window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 2903 } 2904 }); 2905 } 2906}; 2907``` 2908 2909### getUIContext<sup>10+</sup> 2910 2911getUIContext(): UIContext 2912 2913获取UIContext实例。 2914 2915**模型约束:** 此接口仅可在Stage模型下使用。 2916 2917**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2918 2919**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2920 2921**返回值:** 2922 2923| 类型 | 说明 | 2924| ---------- | ---------------------- | 2925| [UIContext](js-apis-arkui-UIContext.md#uicontext) | 返回UIContext实例对象。 | 2926 2927**错误码:** 2928 2929以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 2930 2931| 错误码ID | 错误信息 | 2932| ------- | ------------------------------ | 2933| 1300002 | This window state is abnormal. | 2934 2935**示例:** 2936 2937```ts 2938// EntryAbility.ets 2939import { UIAbility } from '@kit.AbilityKit'; 2940import { window, UIContext } from '@kit.ArkUI'; 2941import { BusinessError } from '@kit.BasicServicesKit'; 2942 2943export default class EntryAbility extends UIAbility { 2944 onWindowStageCreate(windowStage: window.WindowStage) { 2945 // 为主窗口加载对应的目标页面。 2946 windowStage.loadContent("pages/page2", (err: BusinessError) => { 2947 let errCode: number = err.code; 2948 if (errCode) { 2949 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2950 return; 2951 } 2952 console.info('Succeeded in loading the content.'); 2953 // 获取应用主窗口。 2954 let windowClass: window.Window | undefined = undefined; 2955 windowStage.getMainWindow((err: BusinessError, data) => { 2956 let errCode: number = err.code; 2957 if (errCode) { 2958 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2959 return; 2960 } 2961 windowClass = data; 2962 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 2963 // 获取UIContext实例。 2964 let uiContext: UIContext | null = null; 2965 uiContext = windowClass.getUIContext(); 2966 }); 2967 }); 2968 } 2969}; 2970``` 2971 2972### setUIContent<sup>9+</sup> 2973 2974setUIContent(path: string, callback: AsyncCallback<void>): void 2975 2976根据当前工程中某个页面的路径为窗口加载具体页面内容,使用callback异步回调。 2977 2978**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2979 2980**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2981 2982**参数:** 2983 2984| 参数名 | 类型 | 必填 | 说明 | 2985| -------- | ------------------------- | -- | -------------------- | 2986| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 2987| callback | AsyncCallback<void> | 是 | 回调函数。 | 2988 2989**错误码:** 2990 2991以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2992 2993| 错误码ID | 错误信息 | 2994| ------- | -------------------------------------------- | 2995| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2996| 1300002 | This window state is abnormal. | 2997| 1300003 | This window manager service works abnormally. | 2998 2999**示例:** 3000 3001```ts 3002import { BusinessError } from '@kit.BasicServicesKit'; 3003 3004try { 3005 windowClass.setUIContent('pages/page2/page3', (err: BusinessError) => { 3006 const errCode: number = err.code; 3007 if (errCode) { 3008 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3009 return; 3010 } 3011 console.info('Succeeded in loading the content.'); 3012 }); 3013} catch (exception) { 3014 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3015} 3016``` 3017 3018### setUIContent<sup>9+</sup> 3019 3020setUIContent(path: string): Promise<void> 3021 3022根据当前工程中某个页面的路径为窗口加载具体页面内容,使用Promise异步回调。 3023 3024**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3025 3026**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3027 3028**参数:** 3029 3030| 参数名 | 类型 | 必填 | 说明 | 3031| ---- | ------ | -- | ------------------ | 3032| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 3033 3034**返回值:** 3035 3036| 类型 | 说明 | 3037| ------------------- | ------------------------ | 3038| Promise<void> | 无返回结果的Promise对象。 | 3039 3040**错误码:** 3041 3042以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3043 3044| 错误码ID | 错误信息 | 3045| ------- | -------------------------------------------- | 3046| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3047| 1300002 | This window state is abnormal. | 3048| 1300003 | This window manager service works abnormally. | 3049 3050**示例:** 3051 3052```ts 3053import { BusinessError } from '@kit.BasicServicesKit'; 3054 3055try { 3056 let promise = windowClass.setUIContent('pages/page2/page3'); 3057 promise.then(() => { 3058 console.info('Succeeded in loading the content.'); 3059 }).catch((err: BusinessError) => { 3060 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3061 }); 3062} catch (exception) { 3063 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3064} 3065``` 3066 3067### loadContent<sup>9+</sup> 3068 3069loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 3070 3071根据当前工程中某个页面的路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 3072 3073**模型约束:** 此接口仅可在Stage模型下使用。 3074 3075**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3076 3077**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3078 3079**参数:** 3080 3081| 参数名 | 类型 | 必填 | 说明 | 3082| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 3083| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 3084| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 3085| callback | AsyncCallback<void> | 是 | 回调函数。 | 3086 3087**错误码:** 3088 3089以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3090 3091| 错误码ID | 错误信息 | 3092| ------- | -------------------------------------------- | 3093| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3094| 1300002 | This window state is abnormal. | 3095| 1300003 | This window manager service works abnormally. | 3096 3097**示例:** 3098 3099```ts 3100import { BusinessError } from '@kit.BasicServicesKit'; 3101 3102let storage: LocalStorage = new LocalStorage(); 3103storage.setOrCreate('storageSimpleProp', 121); 3104windowClass.loadContent('pages/page2', storage, (err: BusinessError) => { 3105 const errCode: number = err.code; 3106 if (errCode) { 3107 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3108 return; 3109 } 3110 console.info('Succeeded in loading the content.'); 3111}); 3112``` 3113 3114### loadContent<sup>9+</sup> 3115 3116loadContent(path: string, storage: LocalStorage): Promise<void> 3117 3118根据当前工程中某个页面的路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 3119 3120**模型约束:** 此接口仅可在Stage模型下使用。 3121 3122**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3123 3124**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3125 3126**参数:** 3127 3128| 参数名 | 类型 | 必填 | 说明 | 3129| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 3130| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 3131| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 3132 3133**返回值:** 3134 3135| 类型 | 说明 | 3136| ------------------- | ------------------------- | 3137| Promise<void> | 无返回结果的Promise对象。 | 3138 3139**错误码:** 3140 3141以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3142 3143| 错误码ID | 错误信息 | 3144| ------- | -------------------------------------------- | 3145| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3146| 1300002 | This window state is abnormal. | 3147| 1300003 | This window manager service works abnormally. | 3148 3149**示例:** 3150 3151```ts 3152import { BusinessError } from '@kit.BasicServicesKit'; 3153 3154let storage: LocalStorage = new LocalStorage(); 3155storage.setOrCreate('storageSimpleProp', 121); 3156let promise = windowClass.loadContent('pages/page2', storage); 3157promise.then(() => { 3158 console.info('Succeeded in loading the content.'); 3159}).catch((err: BusinessError) => { 3160 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3161}); 3162``` 3163 3164### loadContentByName<sup>11+</sup> 3165 3166loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback<void>): void 3167 3168为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 3169 3170**模型约束:** 此接口仅可在Stage模型下使用。 3171 3172**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3173 3174**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3175 3176**参数:** 3177 3178| 参数名 | 类型 | 必填 | 说明 | 3179| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3180| name | string | 是 | 命名路由页面的名称。 | 3181| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 3182| callback | AsyncCallback<void> | 是 | 回调函数。 | 3183 3184**错误码:** 3185 3186以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3187 3188| 错误码ID | 错误信息 | 3189| -------- | --------------------------------------------- | 3190| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3191| 1300002 | This window state is abnormal. | 3192| 1300003 | This window manager service works abnormally. | 3193 3194**示例:** 3195<!--code_no_check--> 3196```ts 3197import { BusinessError } from '@kit.BasicServicesKit'; 3198import * as Index from '../pages/Index'; // 导入命名路由页面 3199 3200console.info('onWindowStageCreate'); 3201let storage: LocalStorage = new LocalStorage(); 3202storage.setOrCreate('storageSimpleProp', 121); 3203try { 3204 (windowClass as window.Window).loadContentByName(Index.entryName, storage, (err: BusinessError) => { 3205 const errCode: number = err.code; 3206 if (errCode) { 3207 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3208 return; 3209 } 3210 console.info('Succeeded in loading the content.'); 3211 }); 3212} catch (exception) { 3213 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3214} 3215``` 3216<!--code_no_check--> 3217```ts 3218// ets/pages/Index.ets 3219export const entryName : string = 'Index'; 3220@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 3221@Component 3222export struct Index { 3223 @State message: string = 'Hello World' 3224 build() { 3225 Row() { 3226 Column() { 3227 Text(this.message) 3228 .fontSize(50) 3229 .fontWeight(FontWeight.Bold) 3230 } 3231 .width('100%') 3232 } 3233 .height('100%') 3234 } 3235} 3236``` 3237 3238### loadContentByName<sup>11+</sup> 3239 3240loadContentByName(name: string, callback: AsyncCallback<void>): void 3241 3242为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面内容,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 3243 3244**模型约束:** 此接口仅可在Stage模型下使用。 3245 3246**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3247 3248**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3249 3250**参数:** 3251 3252| 参数名 | 类型 | 必填 | 说明 | 3253| -------- | ------------------------- | ---- | ---------------- | 3254| name | string | 是 | 命名路由页面的名称。 | 3255| callback | AsyncCallback<void> | 是 | 回调函数。 | 3256 3257**错误码:** 3258 3259以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3260 3261| 错误码ID | 错误信息 | 3262| -------- | --------------------------------------------- | 3263| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3264| 1300002 | This window state is abnormal. | 3265| 1300003 | This window manager service works abnormally. | 3266 3267**示例:** 3268<!--code_no_check--> 3269```ts 3270import { BusinessError } from '@kit.BasicServicesKit'; 3271import * as Index from '../pages/Index'; // 导入命名路由页面 3272 3273try { 3274 (windowClass as window.Window).loadContentByName(Index.entryName, (err: BusinessError) => { 3275 const errCode: number = err.code; 3276 if (errCode) { 3277 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3278 return; 3279 } 3280 console.info('Succeeded in loading the content.'); 3281 }); 3282} catch (exception) { 3283 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3284} 3285``` 3286<!--code_no_check--> 3287```ts 3288// ets/pages/Index.ets 3289export const entryName : string = 'Index'; 3290@Entry({routeName: entryName}) 3291@Component 3292export struct Index { 3293 @State message: string = 'Hello World' 3294 build() { 3295 Row() { 3296 Column() { 3297 Text(this.message) 3298 .fontSize(50) 3299 .fontWeight(FontWeight.Bold) 3300 } 3301 .width('100%') 3302 } 3303 .height('100%') 3304 } 3305} 3306``` 3307 3308### loadContentByName<sup>11+</sup> 3309 3310loadContentByName(name: string, storage?: LocalStorage): Promise<void> 3311 3312为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 3313 3314**模型约束:** 此接口仅可在Stage模型下使用。 3315 3316**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3317 3318**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3319 3320**参数:** 3321 3322| 参数名 | 类型 | 必填 | 说明 | 3323| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3324| name | string | 是 | 命名路由页面的名称。 | 3325| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 否 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 3326 3327**返回值:** 3328 3329| 类型 | 说明 | 3330| ------------------- | ------------------------- | 3331| Promise<void> | 无返回结果的Promise对象。 | 3332 3333**错误码:** 3334 3335以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3336 3337| 错误码ID | 错误信息 | 3338| -------- | --------------------------------------------- | 3339| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3340| 1300002 | This window state is abnormal. | 3341| 1300003 | This window manager service works abnormally. | 3342 3343**示例:** 3344<!--code_no_check--> 3345```ts 3346import { BusinessError } from '@kit.BasicServicesKit'; 3347import * as Index from '../pages/Index'; // 导入命名路由页面 3348 3349let storage: LocalStorage = new LocalStorage(); 3350storage.setOrCreate('storageSimpleProp', 121); 3351try { 3352 let promise = (windowClass as window.Window).loadContentByName(Index.entryName, storage); 3353 promise.then(() => { 3354 console.info('Succeeded in loading the content.'); 3355 }).catch((err: BusinessError) => { 3356 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3357 }); 3358} catch (exception) { 3359 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3360} 3361``` 3362<!--code_no_check--> 3363```ts 3364// ets/pages/Index.ets 3365export const entryName : string = 'Index'; 3366@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 3367@Component 3368export struct Index { 3369 @State message: string = 'Hello World' 3370 build() { 3371 Row() { 3372 Column() { 3373 Text(this.message) 3374 .fontSize(50) 3375 .fontWeight(FontWeight.Bold) 3376 } 3377 .width('100%') 3378 } 3379 .height('100%') 3380 } 3381} 3382``` 3383 3384### isWindowShowing<sup>9+</sup> 3385 3386isWindowShowing(): boolean 3387 3388判断当前窗口是否已显示。 3389 3390**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3391 3392**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3393 3394**返回值:** 3395 3396| 类型 | 说明 | 3397| ------- | ------------------------------------------------------------------ | 3398| boolean | 当前窗口是否已显示。true表示当前窗口已显示,false则表示当前窗口未显示。 | 3399 3400**错误码:** 3401 3402以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 3403 3404| 错误码ID | 错误信息 | 3405| ------- | ------------------------------ | 3406| 1300002 | This window state is abnormal. | 3407 3408**示例:** 3409 3410```ts 3411try { 3412 let data = windowClass.isWindowShowing(); 3413 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 3414} catch (exception) { 3415 console.error(`Failed to check whether the window is showing. Cause code: ${exception.code}, message: ${exception.message}`); 3416} 3417``` 3418 3419### on('windowSizeChange')<sup>7+</sup> 3420 3421on(type: 'windowSizeChange', callback: Callback<Size>): void 3422 3423开启窗口尺寸变化的监听。 3424 3425**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3426 3427**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3428 3429**参数:** 3430 3431| 参数名 | 类型 | 必填 | 说明 | 3432| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 3433| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 | 3434| callback | Callback<[Size](#size7)> | 是 | 回调函数。返回当前的窗口尺寸。 | 3435 3436**错误码:** 3437 3438以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3439 3440| 错误码ID | 错误信息 | 3441| ------- | -------------------------------------------- | 3442| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3443 3444**示例:** 3445 3446```ts 3447try { 3448 windowClass.on('windowSizeChange', (data) => { 3449 console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data)); 3450 }); 3451} catch (exception) { 3452 console.error(`Failed to enable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`); 3453} 3454``` 3455 3456### off('windowSizeChange')<sup>7+</sup> 3457 3458off(type: 'windowSizeChange', callback?: Callback<Size>): void 3459 3460关闭窗口尺寸变化的监听。 3461 3462**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3463 3464**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3465 3466**参数:** 3467 3468| 参数名 | 类型 | 必填 | 说明 | 3469| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 3470| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 | 3471| callback | Callback<[Size](#size7)> | 否 | 回调函数。返回当前的窗口尺寸。如果传入参数,则关闭该监听。如果未传入参数,则关闭窗口尺寸变化的监听。 | 3472 3473**错误码:** 3474 3475以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3476 3477| 错误码ID | 错误信息 | 3478| ------- | -------------------------------------------- | 3479| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3480 3481**示例:** 3482 3483```ts 3484const callback = (size: window.Size) => { 3485 // ... 3486} 3487try { 3488 // 通过on接口开启监听 3489 windowClass.on('windowSizeChange', callback); 3490 // 关闭指定callback的监听 3491 windowClass.off('windowSizeChange', callback); 3492 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3493 windowClass.off('windowSizeChange'); 3494} catch (exception) { 3495 console.error(`Failed to disable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`); 3496} 3497``` 3498 3499### on('avoidAreaChange')<sup>9+</sup> 3500 3501on(type: 'avoidAreaChange', callback: Callback<AvoidAreaOptions>): void 3502 3503开启当前应用窗口系统规避区变化的监听。 3504<!--RP7-->常见的触发避让区回调的场景如下:应用窗口在全屏模式、悬浮模式、分屏模式之间的切换;应用窗口旋转;多折叠设备在屏幕折叠态和展开态之间的切换;应用窗口在多设备之间的流转。<!--RP7End--> 3505 3506**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3507 3508**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3509 3510**参数:** 3511 3512| 参数名 | 类型 | 必填 | 说明 | 3513| -------- |----------------------------------| ---- |--------------------------------------| 3514| type | string | 是 | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 | 3515| callback | Callback<[AvoidAreaOptions](#avoidareaoptions12)> | 是 | 回调函数。返回当前规避区以及规避区类型。| 3516 3517**错误码:** 3518 3519以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3520 3521| 错误码ID | 错误信息 | 3522| ------- | -------------------------------------------- | 3523| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3524 3525**示例:** 3526 3527```ts 3528try { 3529 windowClass.on('avoidAreaChange', (data) => { 3530 console.info('Succeeded in enabling the listener for system avoid area changes. type:' + 3531 JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area)); 3532 }); 3533} catch (exception) { 3534 console.error(`Failed to enable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`); 3535} 3536``` 3537 3538### off('avoidAreaChange')<sup>9+</sup> 3539 3540off(type: 'avoidAreaChange', callback?: Callback<AvoidAreaOptions>): void 3541 3542关闭当前窗口系统规避区变化的监听。 3543 3544**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3545 3546**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3547 3548**参数:** 3549 3550| 参数名 | 类型 | 必填 | 说明 | 3551| -------- |----------------------------------|------|------------------------------------| 3552| type | string | 是 | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 | 3553| callback | Callback<[AvoidAreaOptions](#avoidareaoptions12)> | 否 | 回调函数。返回当前规避区以及规避区类型。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有系统规避区变化的监听。| 3554 3555**错误码:** 3556 3557以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3558 3559| 错误码ID | 错误信息 | 3560| ------- | -------------------------------------------- | 3561| 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed. | 3562 3563**示例:** 3564 3565```ts 3566interface Param { 3567 type: window.AvoidAreaType, 3568 area: window.AvoidArea 3569} 3570const callback = (data: Param) => { 3571 // ... 3572} 3573try { 3574 windowClass.on('avoidAreaChange', callback); 3575 3576 windowClass.off('avoidAreaChange', callback); 3577 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3578 windowClass.off('avoidAreaChange'); 3579} catch (exception) { 3580 console.error(`Failed to enable or disable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`); 3581} 3582``` 3583 3584### on('keyboardHeightChange')<sup>7+</sup> 3585 3586on(type: 'keyboardHeightChange', callback: Callback<number>): void 3587 3588开启固定态软键盘高度变化的监听,当软键盘由本窗口唤出并存在重叠区域时通知键盘高度变化。从API version 10开始,改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。 3589 3590**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3591 3592**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3593 3594**参数:** 3595 3596| 参数名 | 类型 | 必填 | 说明 | 3597| -------- | ------------------- | ---- |-------------------------------------------| 3598| type | string | 是 | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 | 3599| callback | Callback<number> | 是 | 回调函数。返回当前的键盘高度,返回值为整数,单位为px。 | 3600 3601**错误码:** 3602 3603以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3604 3605| 错误码ID | 错误信息 | 3606| ------- | -------------------------------------------- | 3607| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3608 3609**示例:** 3610 3611```ts 3612import { BusinessError } from '@kit.BasicServicesKit'; 3613 3614try { 3615 windowClass.on('keyboardHeightChange', (data) => { 3616 console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); 3617 }); 3618} catch (exception) { 3619 console.error(`Failed to enable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`); 3620} 3621``` 3622 3623### off('keyboardHeightChange')<sup>7+</sup> 3624 3625off(type: 'keyboardHeightChange', callback?: Callback<number>): void 3626 3627关闭固定态软键盘高度变化的监听。从API version 10开始,改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。 3628 3629**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3630 3631**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3632 3633**参数:** 3634 3635| 参数名 | 类型 | 必填 | 说明 | 3636| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3637| type | string | 是 | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 | 3638| callback | Callback<number> | 否 | 回调函数。返回当前的键盘高度,返回值为整数,单位为px。若传入参数,则关闭该监听。如果未传入参数,则关闭所有固定态软键盘高度变化的监听。 | 3639 3640**错误码:** 3641 3642以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3643 3644| 错误码ID | 错误信息 | 3645| ------- | -------------------------------------------- | 3646| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3647 3648**示例:** 3649 3650```ts 3651import { BusinessError } from '@kit.BasicServicesKit'; 3652 3653const callback = (height: number) => { 3654 // ... 3655} 3656try { 3657 windowClass.on('keyboardHeightChange', callback); 3658 3659 windowClass.off('keyboardHeightChange', callback); 3660 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3661 windowClass.off('keyboardHeightChange'); 3662} catch (exception) { 3663 console.error(`Failed to disable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`); 3664} 3665``` 3666 3667### on('touchOutside')<sup>11+</sup> 3668 3669on(type: 'touchOutside', callback: Callback<void>): void 3670 3671开启本窗口区域范围外的点击事件的监听。 3672 3673**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3674 3675**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3676 3677**参数:** 3678 3679| 参数名 | 类型 | 必填 | 说明 | 3680| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3681| type | string | 是 | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 | 3682| callback | Callback<void> | 是 | 回调函数。当点击事件发生在本窗口范围之外的回调。 | 3683 3684**错误码:** 3685 3686以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3687 3688| 错误码ID | 错误信息 | 3689| ------- | -------------------------------------------- | 3690| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3691 3692**示例:** 3693 3694```ts 3695try { 3696 windowClass.on('touchOutside', () => { 3697 console.info('touch outside'); 3698 }); 3699} catch (exception) { 3700 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3701} 3702``` 3703 3704### off('touchOutside')<sup>11+</sup> 3705 3706off(type: 'touchOutside', callback?: Callback<void>): void 3707 3708关闭本窗口区域范围外的点击事件的监听。 3709 3710**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3711 3712**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3713 3714**参数:** 3715 3716| 参数名 | 类型 | 必填 | 说明 | 3717| -------- |----------------------| ---- |--------------------------------------| 3718| type | string | 是 | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 | 3719| callback | Callback<void> | 否 | 回调函数。当点击事件发生在本窗口范围之外的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口区域范围外的点击事件的监听。 | 3720 3721**错误码:** 3722 3723以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3724 3725| 错误码ID | 错误信息 | 3726| ------- | -------------------------------------------- | 3727| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3728 3729**示例:** 3730 3731```ts 3732const callback = () => { 3733 // ... 3734} 3735try { 3736 windowClass.on('touchOutside', callback); 3737 windowClass.off('touchOutside', callback); 3738 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3739 windowClass.off('touchOutside'); 3740} catch (exception) { 3741 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3742} 3743``` 3744 3745### on('screenshot')<sup>9+</sup> 3746 3747on(type: 'screenshot', callback: Callback<void>): void 3748 3749开启截屏事件的监听。 3750 3751**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3752 3753**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3754 3755**参数:** 3756 3757| 参数名 | 类型 | 必填 | 说明 | 3758| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3759| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件,对控制中心截屏、hdc命令截屏、整屏截屏接口生效。 | 3760| callback | Callback<void> | 是 | 回调函数。发生截屏事件时的回调。 | 3761 3762**错误码:** 3763 3764以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3765 3766| 错误码ID | 错误信息 | 3767| ------- | -------------------------------------------- | 3768| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3769 3770**示例:** 3771 3772```ts 3773try { 3774 windowClass.on('screenshot', () => { 3775 console.info('screenshot happened'); 3776 }); 3777} catch (exception) { 3778 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3779} 3780``` 3781 3782### off('screenshot')<sup>9+</sup> 3783 3784off(type: 'screenshot', callback?: Callback<void>): void 3785 3786关闭截屏事件的监听。 3787 3788**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3789 3790**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3791 3792**参数:** 3793 3794| 参数名 | 类型 | 必填 | 说明 | 3795| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3796| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件。 | 3797| callback | Callback<void> | 否 | 回调函数。发生截屏事件时的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有截屏事件的监听。 | 3798 3799**错误码:** 3800 3801以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3802 3803| 错误码ID | 错误信息 | 3804| ------- | -------------------------------------------- | 3805| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3806 3807**示例:** 3808 3809```ts 3810let callback = () => { 3811 console.info('screenshot happened'); 3812}; 3813try { 3814 windowClass.on('screenshot', callback); 3815 windowClass.off('screenshot', callback); 3816 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3817 windowClass.off('screenshot'); 3818} catch (exception) { 3819 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3820} 3821``` 3822 3823### on('dialogTargetTouch')<sup>10+</sup> 3824 3825on(type: 'dialogTargetTouch', callback: Callback<void>): void 3826 3827开启模态窗口所遮盖窗口的点击或触摸事件的监听,除模态窗口以外其他窗口调用此接口不生效。 3828 3829**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3830 3831**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3832 3833**参数:** 3834 3835| 参数名 | 类型 | 必填 | 说明 | 3836| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3837| type | string | 是 | 监听事件,固定为'dialogTargetTouch',即模态窗口所遮盖窗口的点击或触摸事件。 | 3838| callback | Callback<void>| 是 | 回调函数。当点击或触摸事件发生在模态窗口所遮盖窗口的回调。 | 3839 3840**错误码:** 3841 3842以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3843 3844| 错误码ID | 错误信息 | 3845| ------- | -------------------------------------------- | 3846| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3847 3848**示例:** 3849 3850```ts 3851try { 3852 windowClass.on('dialogTargetTouch', () => { 3853 console.info('touch dialog target'); 3854 }); 3855} catch (exception) { 3856 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3857} 3858``` 3859 3860### off('dialogTargetTouch')<sup>10+</sup> 3861 3862off(type: 'dialogTargetTouch', callback?: Callback<void>): void 3863 3864关闭模态窗口目标窗口的点击事件的监听。 3865 3866**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3867 3868**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3869 3870**参数:** 3871 3872| 参数名 | 类型 | 必填 | 说明 | 3873| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3874| type | string | 是 | 监听事件,固定为'dialogTargetTouch',即模态窗口目标窗口的点击事件。 | 3875| callback | Callback<void> | 否 | 回调函数。当点击事件发生在模态窗口目标窗口的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有模态窗口目标窗口的点击事件的监听。 | 3876 3877**错误码:** 3878 3879以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3880 3881| 错误码ID | 错误信息 | 3882| ------- | -------------------------------------------- | 3883| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3884 3885**示例:** 3886 3887```ts 3888const callback = () => { 3889 // ... 3890} 3891try { 3892 windowClass.on('dialogTargetTouch', callback); 3893 windowClass.off('dialogTargetTouch', callback); 3894 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3895 windowClass.off('dialogTargetTouch'); 3896} catch (exception) { 3897 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3898} 3899``` 3900 3901### on('windowEvent')<sup>10+</sup> 3902 3903on(type: 'windowEvent', callback: Callback<WindowEventType>): void 3904 3905开启窗口生命周期变化的监听。 3906 3907**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3908 3909**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3910 3911**参数:** 3912 3913| 参数名 | 类型 | 必填 | 说明 | 3914| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3915| type | string | 是 | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 | 3916| callback | Callback<[WindowEventType](#windoweventtype10)> | 是 | 回调函数。返回当前的窗口生命周期状态。 | 3917 3918**错误码:** 3919 3920以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3921 3922| 错误码ID | 错误信息 | 3923| ------- | -------------------------------------------- | 3924| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3925 3926**示例:** 3927 3928```ts 3929try { 3930 windowClass.on('windowEvent', (data) => { 3931 console.info('Window event happened. Event:' + JSON.stringify(data)); 3932 }); 3933} catch (exception) { 3934 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3935} 3936``` 3937 3938### off('windowEvent')<sup>10+</sup> 3939 3940off(type: 'windowEvent', callback?: Callback<WindowEventType>): void 3941 3942关闭窗口生命周期变化的监听。 3943 3944**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3945 3946**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3947 3948**参数:** 3949 3950| 参数名 | 类型 | 必填 | 说明 | 3951| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3952| type | string | 是 | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 | 3953| callback | Callback<[WindowEventType](#windoweventtype10)> | 否 | 回调函数。返回当前的窗口生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有窗口生命周期变化的监听。 | 3954 3955**错误码:** 3956 3957以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3958 3959| 错误码ID | 错误信息 | 3960| ------- | -------------------------------------------- | 3961| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3962 3963**示例:** 3964 3965```ts 3966const callback = (windowEventType: window.WindowEventType) => { 3967 // ... 3968} 3969try { 3970 // 通过on接口开启监听 3971 windowClass.on('windowEvent', callback); 3972 // 关闭指定callback的监听 3973 windowClass.off('windowEvent', callback); 3974 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3975 windowClass.off('windowEvent'); 3976} catch (exception) { 3977 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3978} 3979``` 3980 3981### on('displayIdChange')<sup>14+</sup> 3982 3983on(type: 'displayIdChange', callback: Callback<number>): void 3984 3985开启本窗口所处屏幕变化事件的监听。比如,当前窗口移动到其他屏幕时,可以从此接口监听到这个行为。 3986 3987**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 3988 3989**系统能力:** SystemCapability.Window.SessionManager 3990 3991**参数:** 3992 3993| 参数名 | 类型 | 必填 | 说明 | 3994| -------- | --------------------------| ---- | ------------------------------------------------------------ | 3995| type | string | 是 | 监听事件,固定为'displayIdChange',即本窗口所处屏幕变化的事件。 | 3996| callback | Callback<number> | 是 | 回调函数。当本窗口所处屏幕发生变化后的回调。回调函数返回number类型参数,表示窗口所处屏幕的displayId。 | 3997 3998**错误码:** 3999 4000以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4001 4002| 错误码ID | 错误信息 | 4003| ------- | ------------------------------ | 4004| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4005| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4006| 1300002 | This window state is abnormal. | 4007 4008**示例:** 4009 4010```ts 4011try { 4012 windowClass.on('displayIdChange', (data) => { 4013 console.info('Window displayId changed, displayId=' + JSON.stringify(data)); 4014 }); 4015} catch (exception) { 4016 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4017} 4018``` 4019### off('displayIdChange')<sup>14+</sup> 4020 4021off(type: 'displayIdChange', callback?: Callback<number>): void 4022 4023关闭本窗口所处屏幕变化事件的监听。 4024 4025**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 4026 4027**系统能力:** SystemCapability.Window.SessionManager 4028 4029**参数:** 4030 4031| 参数名 | 类型 | 必填 | 说明 | 4032| -------- |----------------------------| ---- |--------------------------------------| 4033| type | string | 是 | 监听事件,固定为'displayIdChange',即本窗口所处屏幕变化的事件。 | 4034| callback | Callback<number> | 否 | 回调函数。当本窗口所处屏幕发生变化时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口所处屏幕变化事件的回调。 | 4035 4036**错误码:** 4037 4038以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4039 4040| 错误码ID | 错误信息 | 4041| ------- | ------------------------------ | 4042| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4043| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4044| 1300002 | This window state is abnormal. | 4045 4046**示例:** 4047 4048```ts 4049const callback = (displayId: number) => { 4050 // ... 4051} 4052try { 4053 // 通过on接口开启监听 4054 windowClass.on('displayIdChange', callback); 4055 // 关闭指定callback的监听 4056 windowClass.off('displayIdChange', callback); 4057 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4058 windowClass.off('displayIdChange'); 4059} catch (exception) { 4060 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4061} 4062``` 4063 4064### on('windowVisibilityChange')<sup>11+</sup> 4065 4066on(type: 'windowVisibilityChange', callback: Callback<boolean>): void 4067 4068开启本窗口可见状态变化事件的监听。 4069 4070**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4071 4072**系统能力:** SystemCapability.Window.SessionManager 4073 4074**参数:** 4075 4076| 参数名 | 类型 | 必填 | 说明 | 4077| -------- | --------------------------| ---- | ------------------------------------------------------------ | 4078| type | string | 是 | 监听事件,固定为'windowVisibilityChange',即本窗口可见状态变化的事件。 | 4079| callback | Callback<boolean> | 是 | 回调函数。当本窗口可见状态发生变化后的回调。回调函数返回boolean类型参数,当返回参数为true时表示窗口可见,否则表示窗口不可见。 | 4080 4081**错误码:** 4082 4083以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4084 4085| 错误码ID | 错误信息 | 4086| ------- | ------------------------------ | 4087| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4088| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4089| 1300002 | This window state is abnormal. | 4090| 1300003 | This window manager service works abnormally. | 4091 4092**示例:** 4093 4094```ts 4095try { 4096 windowClass.on('windowVisibilityChange', (boolean) => { 4097 console.info('Window visibility changed, isVisible=' + boolean); 4098 }); 4099} catch (exception) { 4100 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4101} 4102``` 4103 4104### off('windowVisibilityChange')<sup>11+</sup> 4105 4106off(type: 'windowVisibilityChange', callback?: Callback<boolean>): void 4107 4108关闭本窗口可见状态变化事件的监听。 4109 4110**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4111 4112**系统能力:** SystemCapability.Window.SessionManager 4113 4114**参数:** 4115 4116| 参数名 | 类型 | 必填 | 说明 | 4117| -------- |----------------------------| ---- |--------------------------------------| 4118| type | string | 是 | 监听事件,固定为'windowVisibilityChange',即本窗口可见状态变化的事件。 | 4119| callback | Callback<boolean> | 否 | 回调函数。当本窗口可见状态发生变化时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口可见状态变化事件的回调。 | 4120 4121**错误码:** 4122 4123以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4124 4125| 错误码ID | 错误信息 | 4126| ------- | ------------------------------ | 4127| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4128| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4129| 1300002 | This window state is abnormal. | 4130| 1300003 | This window manager service works abnormally. | 4131 4132**示例:** 4133 4134```ts 4135const callback = (bool: boolean) => { 4136 // ... 4137} 4138try { 4139 // 通过on接口开启监听 4140 windowClass.on('windowVisibilityChange', callback); 4141 // 关闭指定callback的监听 4142 windowClass.off('windowVisibilityChange', callback); 4143 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4144 windowClass.off('windowVisibilityChange'); 4145} catch (exception) { 4146 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4147} 4148``` 4149 4150### on('systemDensityChange')<sup>15+</sup> 4151 4152on(type: 'systemDensityChange', callback: Callback<number>): void 4153 4154开启本窗口所处屏幕的系统显示大小缩放系数变化事件的监听。比如,当调整窗口所处屏幕的显示大小缩放系数时,可以从此接口监听到这个行为。 4155 4156**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 4157 4158**系统能力:** SystemCapability.Window.SessionManager 4159 4160**参数:** 4161 4162| 参数名 | 类型 | 必填 | 说明 | 4163| -------- | --------------------------| ---- | ------------------------------------------------------------ | 4164| type | string | 是 | 监听事件,固定为'systemDensityChange',即本窗口所处屏幕的系统显示大小缩放系数变化的事件。 | 4165| callback | Callback<number> | 是 | 回调函数。当本窗口所处屏幕的系统显示大小缩放系数发生变化后的回调。回调函数返回number类型参数,表示当前窗口所处屏幕的系统显示大小缩放系数。 | 4166 4167**错误码:** 4168 4169 4170以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4171 4172| 错误码ID | 错误信息 | 4173| ------- | ------------------------------ | 4174| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4175| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4176| 1300002 | This window state is abnormal. | 4177 4178**示例:** 4179 4180```ts 4181const callback = (density: number) => { 4182 console.info('System density changed, density=' + JSON.stringify(density)); 4183} 4184try { 4185 windowClass.on('systemDensityChange', callback); 4186} catch (exception) { 4187 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4188} 4189``` 4190### off('systemDensityChange')<sup>15+</sup> 4191 4192off(type: 'systemDensityChange', callback?: Callback<number>): void 4193 4194关闭本窗口所处屏幕的系统显示大小缩放系数变化事件的监听。 4195 4196**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 4197 4198**系统能力:** SystemCapability.Window.SessionManager 4199 4200**参数:** 4201 4202| 参数名 | 类型 | 必填 | 说明 | 4203| -------- |----------------------------| ---- |--------------------------------------| 4204| type | string | 是 | 监听事件,固定为'systemDensityChange',即本窗口所处屏幕的系统显示大小缩放系数变化的事件。 | 4205| callback | Callback<number> | 否 | 回调函数。当本窗口所处屏幕的系统显示大小缩放系数发生变化后的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口所处屏幕的系统显示大小缩放系数变化事件的回调。 | 4206 4207**错误码:** 4208 4209以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4210 4211| 错误码ID | 错误信息 | 4212| ------- | ------------------------------ | 4213| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4214| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4215| 1300002 | This window state is abnormal. | 4216 4217**示例:** 4218 4219```ts 4220const callback = (density: number) => { 4221 // ... 4222} 4223try { 4224 // 通过on接口开启监听 4225 windowClass.on('systemDensityChange', callback); 4226 // 关闭指定callback的监听 4227 windowClass.off('systemDensityChange', callback); 4228 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4229 windowClass.off('systemDensityChange'); 4230} catch (exception) { 4231 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4232} 4233``` 4234 4235### on('noInteractionDetected')<sup>12+</sup> 4236 4237on(type: 'noInteractionDetected', timeout: number, callback: Callback<void>): void 4238 4239开启本窗口在指定超时时间内无交互事件的监听,交互事件支持物理键盘输入事件和屏幕触控点击事件,不支持软键盘输入事件。 4240 4241**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4242 4243**系统能力:** SystemCapability.Window.SessionManager 4244 4245**参数:** 4246 4247| 参数名 | 类型 | 必填 | 说明 | 4248| -------- | --------------------------| ---- | ------------------------------------------------------------ | 4249| type | string | 是 | 监听事件,固定为'noInteractionDetected',即本窗口在指定超时时间内无交互的事件。 | 4250| timeout | number | 是 | 指定本窗口在多长时间内无交互即回调,单位为秒(s)。该参数仅支持整数输入,负数和小数为非法参数。 | 4251| callback | Callback<void> | 是 | 回调函数。当本窗口在指定超时时间内无交互事件时的回调。 | 4252 4253**错误码:** 4254 4255以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4256 4257| 错误码ID | 错误信息 | 4258| ------- | ------------------------------ | 4259| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4260| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4261| 1300002 | This window state is abnormal. | 4262| 1300003 | This window manager service works abnormally. | 4263 4264**示例:** 4265 4266```ts 4267try { 4268 windowClass.on('noInteractionDetected', 60, () => { 4269 console.info('no interaction in 60s'); 4270 }); 4271} catch (exception) { 4272 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4273} 4274``` 4275 4276### off('noInteractionDetected')<sup>12+</sup> 4277 4278off(type: 'noInteractionDetected', callback?: Callback<void>): void 4279 4280关闭本窗口在指定超时时间内无交互事件的监听,交互事件支持物理键盘输入事件和屏幕触控点击事件,不支持软键盘输入事件。 4281 4282**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4283 4284**系统能力:** SystemCapability.Window.SessionManager 4285 4286**参数:** 4287 4288| 参数名 | 类型 | 必填 | 说明 | 4289| -------- |----------------------------| ---- |--------------------------------------| 4290| type | string | 是 | 监听事件,固定为'noInteractionDetected',即本窗口在指定超时时间内无交互的事件。 | 4291| callback | Callback<void> | 否 | 回调函数,当本窗口在指定超时时间内无交互事件时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口在指定超时时间内无交互事件的监听。 | 4292 4293**错误码:** 4294 4295以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4296 4297| 错误码ID | 错误信息 | 4298| ------- | ------------------------------ | 4299| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4300| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4301| 1300002 | This window state is abnormal. | 4302| 1300003 | This window manager service works abnormally. | 4303 4304**示例:** 4305 4306```ts 4307const callback = () => { 4308 // ... 4309} 4310try { 4311 windowClass.on('noInteractionDetected', 60, callback); 4312 windowClass.off('noInteractionDetected', callback); 4313 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4314 windowClass.off('noInteractionDetected'); 4315} catch (exception) { 4316 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4317} 4318``` 4319 4320### on('windowStatusChange')<sup>11+</sup> 4321 4322on(type: 'windowStatusChange', callback: Callback<WindowStatusType>): void 4323 4324开启窗口模式变化的监听,当窗口windowStatus发生变化时进行通知(此时窗口属性可能还没有更新)。 4325 4326> **说明:** 4327> 4328> 在2in1设备上调用本接口时,在窗口最大化状态时返回值对应为WindowStatusType::FULL_SCREEN。 4329> 4330> 若想在2in1设备上区分当前窗口状态为最大化还是全屏,可在窗口状态为WindowStatusType::FULL_SCREEN的情况下,再调用[getImmersiveModeEnabledState()](#getimmersivemodeenabledstate12) 接口进行进一步判断,到底是最大化状态还是全屏状态。若接口返回true则表示当前窗口为全屏状态,若接口返回false则表示当前窗口为最大化状态。 4331 4332**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4333 4334**系统能力:** SystemCapability.Window.SessionManager 4335 4336**参数:** 4337 4338| 参数名 | 类型 | 必填 | 说明 | 4339| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4340| type | string | 是 | 监听事件,固定为'windowStatusChange',即窗口模式变化事件。 | 4341| callback | Callback<[WindowStatusType](#windowstatustype11)> | 是 | 回调函数。返回当前的窗口模式。 | 4342 4343**错误码:** 4344 4345以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4346 4347| 错误码ID | 错误信息 | 4348| ------- | ------------------------------ | 4349| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4350| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4351 4352**示例:** 4353 4354```ts 4355try { 4356 windowClass.on('windowStatusChange', (WindowStatusType) => { 4357 console.info('Succeeded in enabling the listener for window status changes. Data: ' + JSON.stringify(WindowStatusType)); 4358 }); 4359} catch (exception) { 4360 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4361} 4362``` 4363 4364### off('windowStatusChange')<sup>11+</sup> 4365 4366off(type: 'windowStatusChange', callback?: Callback<WindowStatusType>): void 4367 4368关闭窗口模式变化的监听。 4369 4370**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4371 4372**系统能力:** SystemCapability.Window.SessionManager 4373 4374**参数:** 4375 4376| 参数名 | 类型 | 必填 | 说明 | 4377| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 4378| type | string | 是 | 监听事件,固定为'windowStatusChange',即窗口模式变化事件。 | 4379| callback | Callback<[WindowStatusType](#windowstatustype11)> | 否 | 回调函数。返回当前的窗口模式。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有窗口模式变化的监听。 | 4380 4381**错误码:** 4382 4383以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4384 4385| 错误码ID | 错误信息 | 4386| ------- | ------------------------------ | 4387| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4388| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4389 4390**示例:** 4391 4392```ts 4393const callback = (windowStatusType: window.WindowStatusType) => { 4394 // ... 4395} 4396try { 4397 windowClass.on('windowStatusChange', callback); 4398 windowClass.off('windowStatusChange', callback); 4399 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4400 windowClass.off('windowStatusChange'); 4401} catch (exception) { 4402 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4403} 4404``` 4405 4406### setWindowGrayScale<sup>12+</sup> 4407 4408setWindowGrayScale(grayScale: number): Promise<void> 4409 4410设置窗口灰阶,使用Promise异步回调。该接口需要在调用[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)使窗口加载页面内容后调用。 4411 4412**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4413 4414**系统能力:** SystemCapability.Window.SessionManager 4415 4416**参数:** 4417 4418| 参数名 | 类型 | 必填 | 说明 | 4419| --------- | ------ | -- | ---------------------------------------- | 4420| grayScale | number | 是 | 窗口灰阶。该参数为浮点数,取值范围为[0.0, 1.0]。0.0表示窗口图像无变化,1.0表示窗口图像完全转为灰度图像,0.0至1.0之间时效果呈线性变化。 | 4421 4422**返回值:** 4423 4424| 类型 | 说明 | 4425| ------------------- | ------------------------ | 4426| Promise<void> | 无返回结果的Promise对象。 | 4427 4428**错误码:** 4429 4430以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4431 4432| 错误码ID | 错误信息 | 4433| ------- | --------------------------------------------- | 4434| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4435| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4436| 1300002 | This window state is abnormal. | 4437| 1300003 | This window manager service works abnormally. | 4438 4439**示例:** 4440 4441```ts 4442import { BusinessError } from '@kit.BasicServicesKit'; 4443 4444windowClass?.setUIContent('pages/Index', (error: BusinessError) => { 4445 if (error.code) { 4446 console.error(`Failed to set the content. Cause code: ${error.code}`); 4447 return; 4448 } 4449 console.info('Succeeded in setting the content.'); 4450 let grayScale: number = 0.5; 4451 try { 4452 if (canIUse("SystemCapability.Window.SessionManager")) { 4453 let promise = windowClass?.setWindowGrayScale(grayScale); 4454 promise?.then(() => { 4455 console.info('Succeeded in setting the grayScale.'); 4456 }).catch((err: BusinessError) => { 4457 console.error(`Failed to set the grayScale. Cause code: ${err.code}, message: ${err.message}`); 4458 }); 4459 } 4460 } catch (exception) { 4461 console.error(`Failed to set the grayScale. Cause code: ${exception.code}, message: ${exception.message}`); 4462 } 4463}); 4464``` 4465 4466### on('windowTitleButtonRectChange')<sup>11+</sup> 4467 4468on(type: 'windowTitleButtonRectChange', callback: Callback<TitleButtonRect>): void 4469 4470开启窗口标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 4471 4472<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 4473 4474**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4475 4476**系统能力:** SystemCapability.Window.SessionManager 4477 4478**参数:** 4479 4480| 参数名 | 类型 | 必填 | 说明 | 4481| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 4482| type | string | 是 | 监听事件,固定为'windowTitleButtonRectChange',即标题栏上的最小化、最大化、关闭按钮矩形区域变化事件。 | 4483| callback | Callback<[TitleButtonRect](#titlebuttonrect11)> | 是 | 回调函数。返回当前标题栏上的最小化、最大化、关闭按钮矩形区域。 | 4484 4485**错误码:** 4486 4487以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4488 4489| 错误码ID | 错误信息 | 4490| -------- | ------------------------------ | 4491| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4492| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4493| 1300002 | This window state is abnormal. | 4494 4495**示例:** 4496 4497```ts 4498windowClass.setUIContent('pages/WindowPage').then(() => { 4499 try { 4500 windowClass?.on('windowTitleButtonRectChange', (titleButtonRect) => { 4501 console.info('Succeeded in enabling the listener for window title buttons area changes. Data: ' + JSON.stringify(titleButtonRect)); 4502 }); 4503 } catch (exception) { 4504 console.error(`Failed to enable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`); 4505 } 4506}) 4507``` 4508 4509### off('windowTitleButtonRectChange')<sup>11+</sup> 4510 4511off(type: 'windowTitleButtonRectChange', callback?: Callback<TitleButtonRect>): void 4512 4513关闭窗口标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 4514 4515<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 4516 4517**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4518 4519**系统能力:** SystemCapability.Window.SessionManager 4520 4521**参数:** 4522 4523| 参数名 | 类型 | 必填 | 说明 | 4524| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 4525| type | string | 是 | 监听事件,固定为'windowTitleButtonRectChange',即标题栏上的最小化、最大化、关闭按钮矩形区域变化事件。 | 4526| callback | Callback<[TitleButtonRect](#titlebuttonrect11)> | 否 | 回调函数。返回当前标题栏上的最小化、最大化、关闭按钮矩形区域。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听。 | 4527 4528**错误码:** 4529 4530以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4531 4532| 错误码ID | 错误信息 | 4533| -------- | ------------------------------ | 4534| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4535| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4536| 1300002 | This window state is abnormal. | 4537 4538**示例:** 4539 4540```ts 4541windowClass.setUIContent('pages/WindowPage').then(() => { 4542 const callback = (titleButtonRect: window.TitleButtonRect) => { 4543 // ... 4544 } 4545 try { 4546 // 通过on接口开启监听 4547 windowClass?.on('windowTitleButtonRectChange', callback); 4548 // 关闭指定callback的监听 4549 windowClass?.off('windowTitleButtonRectChange', callback); 4550 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4551 windowClass?.off('windowTitleButtonRectChange'); 4552 } catch (exception) { 4553 console.error(`Failed to disable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`); 4554 } 4555}) 4556``` 4557 4558### on('windowRectChange')<sup>12+</sup> 4559 4560on(type: 'windowRectChange', callback: Callback<RectChangeOptions>): void 4561 4562开启窗口矩形(窗口位置及窗口大小)变化的监听。 4563 4564**系统能力:** SystemCapability.Window.SessionManager 4565 4566**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4567 4568**参数:** 4569 4570| 参数名 | 类型 | 必填 | 说明 | 4571| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4572| type | string | 是 | 监听事件,固定为'windowRectChange',即窗口矩形变化事件。 | 4573| callback | Callback<[RectChangeOptions](#rectchangeoptions12)> | 是 | 回调函数。返回当前窗口矩形变化值及变化原因。 | 4574 4575**错误码:** 4576 4577以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4578 4579| 错误码ID | 错误信息 | 4580| ------- | -------------------------------------------- | 4581| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4582| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4583| 1300002 | This window state is abnormal. | 4584| 1300003 | This window manager service works abnormally. | 4585 4586**示例:** 4587 4588```ts 4589windowClass.on('windowRectChange', (data: window.RectChangeOptions) => { 4590 console.info('Succeeded window rect changes. Data: ' + JSON.stringify(data)); 4591}); 4592``` 4593 4594### off('windowRectChange')<sup>12+</sup> 4595 4596off(type: 'windowRectChange', callback?: Callback<RectChangeOptions>): void 4597 4598关闭窗口矩形(窗口位置及窗口大小)变化的监听。 4599 4600**系统能力:** SystemCapability.Window.SessionManager 4601 4602**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4603 4604**参数:** 4605 4606| 参数名 | 类型 | 必填 | 说明 | 4607| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 4608| type | string | 是 | 监听事件,固定为'windowRectChange',即窗口矩形变化事件。 | 4609| callback | Callback<[RectChangeOptions](#rectchangeoptions12)> | 否 | 回调函数。返回当前的窗口矩形及变化原因。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有窗口矩形变化的监听。 | 4610 4611**错误码:** 4612 4613以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4614 4615| 错误码ID | 错误信息 | 4616| ------- | -------------------------------------------- | 4617| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4618| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4619| 1300002 | This window state is abnormal. | 4620| 1300003 | This window manager service works abnormally. | 4621 4622**示例:** 4623 4624```ts 4625const callback = (rectChangeOptions: window.RectChangeOptions) => { 4626 // ... 4627} 4628windowClass.on('windowRectChange', callback); 4629windowClass.off('windowRectChange', callback); 4630// 如果通过on开启多个callback进行监听,同时关闭所有监听: 4631windowClass.off('windowRectChange'); 4632``` 4633 4634### on('subWindowClose')<sup>12+</sup> 4635 4636on(type: 'subWindowClose', callback: Callback<void>): void 4637 4638开启子窗口关闭事件的监听。此监听仅在点击系统提供的右上角关闭按钮关闭子窗时触发,其余关闭方式不触发回调。 4639 4640当重复注册窗口关闭事件的监听时,最后一次注册成功的监听事件生效。 4641 4642该接口触发的窗口关闭事件监听回调函数是同步执行,子窗口的异步关闭事件监听参考[on('windowWillClose')](#onwindowwillclose15)方法。 4643 4644如果存在[on('windowWillClose')](#onwindowwillclose15)监听事件,只响应[on('windowWillClose')](#onwindowwillclose15)接口。 4645 4646**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4647 4648**系统能力:** SystemCapability.Window.SessionManager 4649 4650**参数:** 4651 4652| 参数名 | 类型 | 必填 | 说明 | 4653| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4654| type | string | 是 | 监听事件,固定为'subWindowClose',即子窗口关闭事件。 | 4655| callback | Callback<void> | 是 | 回调函数。当点击子窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前子窗是否继续关闭,true表示不关闭子窗,false表示关闭子窗。 | 4656 4657**错误码:** 4658 4659以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4660 4661| 错误码ID | 错误信息 | 4662| ------- | -------------------------------------------- | 4663| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4664| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4665| 1300002 | This window state is abnormal. | 4666| 1300004 | Unauthorized operation. | 4667 4668**示例:** 4669 4670```ts 4671const callback = () => { 4672 // ... 4673 return true; 4674} 4675try { 4676 windowClass.on('subWindowClose', callback); 4677} catch (exception) { 4678 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4679} 4680``` 4681 4682### off('subWindowClose')<sup>12+</sup> 4683 4684off(type: 'subWindowClose', callback?: Callback<void>): void 4685 4686关闭子窗口关闭事件的监听。 4687 4688**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4689 4690**系统能力:** SystemCapability.Window.SessionManager 4691 4692**参数:** 4693 4694| 参数名 | 类型 | 必填 | 说明 | 4695| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 4696| type | string | 是 | 监听事件,固定为'subWindowClose',即子窗口关闭事件。 | 4697| callback | Callback<void> | 否 | 回调函数。当点击子窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前子窗是否继续关闭,true表示不关闭子窗,false表示关闭子窗。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有子窗口关闭的监听。 | 4698 4699**错误码:** 4700 4701以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4702 4703| 错误码ID | 错误信息 | 4704| ------- | -------------------------------------------- | 4705| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4706| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4707| 1300002 | This window state is abnormal. | 4708| 1300004 | Unauthorized operation. | 4709 4710**示例:** 4711 4712```ts 4713const callback = () => { 4714 // ... 4715 return true; 4716} 4717try { 4718 windowClass.on('subWindowClose', callback); 4719 windowClass.off('subWindowClose', callback); 4720 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4721 windowClass.off('subWindowClose'); 4722} catch (exception) { 4723 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4724} 4725``` 4726 4727### on('windowWillClose')<sup>15+</sup> 4728 4729on(type: 'windowWillClose', callback: Callback<void, Promise<boolean>>): void 4730 4731开启主窗口或子窗口关闭事件的监听。此监听仅能通过系统提供的窗口标题栏关闭按键触发,其余关闭窗口的方式不触发回调。 4732 4733该接口触发的回调函数是异步执行。子窗口的同步关闭事件监听参考[on('subWindowClose')](#onsubwindowclose12)方法。主窗口的同步关闭事件监听参考[on('windowStageClose')](#onwindowstageclose14)方法。 4734 4735<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> </br> 4736 4737**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 4738 4739**系统能力:** SystemCapability.Window.SessionManager 4740 4741**参数:** 4742 4743| 参数名 | 类型 | 必填 | 说明 | 4744| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4745| type | string | 是 | 监听事件,固定为'windowWillClose',即窗口关闭事件。 | 4746| callback | Callback<void, Promise<boolean>> | 是 | 回调函数。当点击窗口系统提供的右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有Promise<boolean>类型的返回值。在返回的Promise函数里,执行resolve(true) 方法表示不关闭当前窗口,执行resolve(false) 方法或者reject方法均表示关闭当前窗口。| 4747 4748**错误码:** 4749 4750以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4751 4752| 错误码ID | 错误信息 | 4753| ------- | -------------------------------------------- | 4754| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4755| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4756| 1300002 | This window state is abnormal. | 4757| 1300004 | Unauthorized operation. | 4758 4759**示例:** 4760 4761```ts 4762// EntryAbility.ets 4763import { UIAbility } from '@kit.AbilityKit'; 4764import { window } from '@kit.ArkUI'; 4765 4766export default class EntryAbility extends UIAbility { 4767 4768 onWindowStageCreate(windowStage: window.WindowStage) { 4769 console.info('onWindowStageCreate'); 4770 const callback = () => { 4771 // ... 4772 return new Promise<boolean>((resolve, reject) => { 4773 // 是否关闭该窗口 4774 let result: boolean = true; 4775 resolve(result); 4776 }); 4777 } 4778 try { 4779 let windowClass = windowStage.getMainWindowSync(); 4780 windowClass.on('windowWillClose', callback); 4781 } catch (exception) { 4782 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4783 } 4784 } 4785} 4786``` 4787 4788### off('windowWillClose')<sup>15+</sup> 4789 4790off(type: 'windowWillClose', callback?: Callback<void, Promise<boolean>>): void 4791 4792关闭主窗口或子窗口关闭事件的监听。 4793 4794<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> </br> 4795 4796**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 4797 4798**系统能力:** SystemCapability.Window.SessionManager 4799 4800**参数:** 4801 4802| 参数名 | 类型 | 必填 | 说明 | 4803| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4804| type | string | 是 | 监听事件,固定为'windowWillClose',即窗口关闭事件。 | 4805| callback | Callback<void, Promise<boolean>> | 否 | 回调函数。当点击窗口系统提供的右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有Promise<boolean>类型的返回值。在返回的Promise函数里,执行resolve(true) 方法表示不关闭当前窗口,执行resolve(false) 方法或者reject方法均表示关闭当前窗口。| 4806 4807**错误码:** 4808 4809以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4810 4811| 错误码ID | 错误信息 | 4812| ------- | -------------------------------------------- | 4813| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4814| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4815| 1300002 | This window state is abnormal. | 4816| 1300004 | Unauthorized operation. | 4817 4818**示例:** 4819 4820```ts 4821// EntryAbility.ets 4822import { UIAbility } from '@kit.AbilityKit'; 4823import { window } from '@kit.ArkUI'; 4824 4825export default class EntryAbility extends UIAbility { 4826 4827 onWindowStageCreate(windowStage: window.WindowStage) { 4828 console.info('onWindowStageCreate'); 4829 try { 4830 const callback = () => { 4831 // ... 4832 return new Promise<boolean>((resolve, reject) => { 4833 // 是否关闭该窗口 4834 let result: boolean = true; 4835 resolve(result); 4836 }); 4837 } 4838 let windowClass = windowStage.getMainWindowSync(); 4839 windowClass.on('windowWillClose', callback); 4840 windowClass.off('windowWillClose', callback); 4841 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4842 windowClass.off('windowWillClose'); 4843 } catch (exception) { 4844 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4845 } 4846 } 4847} 4848``` 4849 4850### on('windowHighlightChange')<sup>15+</sup> 4851 4852on(type: 'windowHighlightChange', callback: Callback<boolean>): void 4853 4854开启窗口激活态变化事件的监听。 4855 4856**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 4857 4858**系统能力:** SystemCapability.Window.SessionManager 4859 4860**参数:** 4861 4862| 参数名 | 类型 | 必填 | 说明 | 4863| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4864| type | string | 是 | 监听事件,固定为'windowHighlightChange',即窗口激活态变化事件。 | 4865| callback | Callback<boolean> | 是 | 回调函数。当本窗口的激活态发生变化时的回调。回调函数返回boolean类型参数。当返回参数为true表示激活态;false表示非激活态。 | 4866 4867**错误码:** 4868 4869以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4870 4871| 错误码ID | 错误信息 | 4872| ------- | -------------------------------------------- | 4873| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4874| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4875| 1300002 | This window state is abnormal. | 4876| 1300003 | This window manager service works abnormally. | 4877 4878**示例:** 4879 4880```ts 4881try { 4882 windowClass.on('windowHighlightChange', (data: boolean) => { 4883 console.info(`Window highlight Change: ${data}`); 4884 }); 4885} catch (exception) { 4886 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4887} 4888``` 4889 4890### off('windowHighlightChange')<sup>15+</sup> 4891 4892off(type: 'windowHighlightChange', callback?: Callback<boolean>): void 4893 4894关闭窗口激活态变化事件的监听。 4895 4896**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 4897 4898**系统能力:** SystemCapability.Window.SessionManager 4899 4900**参数:** 4901 4902| 参数名 | 类型 | 必填 | 说明 | 4903| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 4904| type | string | 是 | 监听事件,固定为'windowHighlightChange',即窗口激活态变化事件。 | 4905| callback | Callback<boolean> | 否 | 回调函数。当本窗口的激活态发生变化时的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有窗口激活态变化的监听。 | 4906 4907**错误码:** 4908 4909以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4910 4911| 错误码ID | 错误信息 | 4912| ------- | -------------------------------------------- | 4913| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4914| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4915| 1300002 | This window state is abnormal. | 4916| 1300003 | This window manager service works abnormally. | 4917 4918**示例:** 4919 4920```ts 4921const callback = (data: boolean) => { 4922 // ... 4923} 4924try { 4925 // 通过on接口开启监听 4926 windowClass.on('windowHighlightChange', callback); 4927 // 关闭指定callback的监听 4928 windowClass.off('windowHighlightChange', callback); 4929 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4930 windowClass.off('windowHighlightChange'); 4931} catch (exception) { 4932 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4933} 4934``` 4935 4936### isWindowSupportWideGamut<sup>9+</sup> 4937 4938isWindowSupportWideGamut(callback: AsyncCallback<boolean>): void 4939 4940判断当前窗口是否支持广色域模式,使用callback异步回调。 4941 4942**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4943 4944**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4945 4946**参数:** 4947 4948| 参数名 | 类型 | 必填 | 说明 | 4949| -------- | ---------------------------- | -- | -------------------------------------------------------------------------------- | 4950| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 4951 4952**错误码:** 4953 4954以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 4955 4956| 错误码ID | 错误信息 | 4957| ------- | ------------------------------ | 4958| 1300002 | This window state is abnormal. | 4959 4960**示例:** 4961 4962```ts 4963import { BusinessError } from '@kit.BasicServicesKit'; 4964 4965windowClass.isWindowSupportWideGamut((err: BusinessError, data) => { 4966 const errCode: number = err.code; 4967 if (errCode) { 4968 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 4969 return; 4970 } 4971 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 4972}); 4973``` 4974 4975### isWindowSupportWideGamut<sup>9+</sup> 4976 4977isWindowSupportWideGamut(): Promise<boolean> 4978 4979判断当前窗口是否支持广色域模式,使用Promise异步回调。 4980 4981**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4982 4983**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4984 4985**返回值:** 4986 4987| 类型 | 说明 | 4988| ---------------------- | ------------------------------------------------------------------------------------ | 4989| Promise<boolean> | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 4990 4991**错误码:** 4992 4993以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 4994 4995| 错误码ID | 错误信息 | 4996| ------- | ------------------------------ | 4997| 1300002 | This window state is abnormal. | 4998 4999**示例:** 5000 5001```ts 5002import { BusinessError } from '@kit.BasicServicesKit'; 5003 5004let promise = windowClass.isWindowSupportWideGamut(); 5005promise.then((data) => { 5006 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 5007}).catch((err: BusinessError) => { 5008 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 5009}); 5010``` 5011 5012### setWindowColorSpace<sup>9+</sup> 5013 5014setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 5015 5016设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。 5017 5018**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5019 5020**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5021 5022**参数:** 5023 5024| 参数名 | 类型 | 必填 | 说明 | 5025| ---------- | ------------------------- | -- | ----------- | 5026| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 5027| callback | AsyncCallback<void> | 是 | 回调函数。 | 5028 5029**错误码:** 5030 5031以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5032 5033| 错误码ID | 错误信息 | 5034| ------- | ------------------------------ | 5035| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5036| 1300002 | This window state is abnormal. | 5037 5038**示例:** 5039 5040```ts 5041import { BusinessError } from '@kit.BasicServicesKit'; 5042 5043try { 5044 windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 5045 const errCode: number = err.code; 5046 if (errCode) { 5047 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 5048 return; 5049 } 5050 console.info('Succeeded in setting window colorspace.'); 5051 }); 5052} catch (exception) { 5053 console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`); 5054} 5055``` 5056 5057### setWindowColorSpace<sup>9+</sup> 5058 5059setWindowColorSpace(colorSpace:ColorSpace): Promise<void> 5060 5061设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。 5062 5063**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5064 5065**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5066 5067**参数:** 5068 5069| 参数名 | 类型 | 必填 | 说明 | 5070| ---------- | ------------------------- | -- | ------------- | 5071| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 5072 5073**返回值:** 5074 5075| 类型 | 说明 | 5076| ------------------- | ------------------------ | 5077| Promise<void> | 无返回结果的Promise对象。 | 5078 5079**错误码:** 5080 5081以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5082 5083| 错误码ID | 错误信息 | 5084| ------- | ------------------------------ | 5085| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5086| 1300002 | This window state is abnormal. | 5087 5088**示例:** 5089 5090```ts 5091import { BusinessError } from '@kit.BasicServicesKit'; 5092 5093try { 5094 let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT); 5095 promise.then(() => { 5096 console.info('Succeeded in setting window colorspace.'); 5097 }).catch((err: BusinessError) => { 5098 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 5099 }); 5100} catch (exception) { 5101 console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`); 5102} 5103``` 5104 5105### getWindowColorSpace<sup>9+</sup> 5106 5107getWindowColorSpace(): ColorSpace 5108 5109获取当前窗口色域模式。 5110 5111**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5112 5113**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5114 5115**返回值:** 5116 5117| 类型 | 说明 | 5118| ------------------------- | ------------- | 5119| [ColorSpace](#colorspace8) | 当前色域模式。 | 5120 5121**错误码:** 5122 5123以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 5124 5125| 错误码ID | 错误信息 | 5126| ------- | ------------------------------ | 5127| 1300002 | This window state is abnormal. | 5128 5129**示例:** 5130 5131```ts 5132let colorSpace = windowClass.getWindowColorSpace(); 5133``` 5134 5135### setWindowBackgroundColor<sup>9+</sup> 5136 5137setWindowBackgroundColor(color: string): void 5138 5139设置窗口的背景色。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 5140 5141**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5142 5143**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5144 5145**参数:** 5146 5147| 参数名 | 类型 | 必填 | 说明 | 5148| ----- | ------ | -- | ----------------------------------------------------------------------- | 5149| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 | 5150 5151**错误码:** 5152 5153以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5154 5155| 错误码ID | 错误信息 | 5156| ------- | ------------------------------ | 5157| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5158| 1300002 | This window state is abnormal. | 5159 5160**示例:** 5161 5162```ts 5163import { BusinessError } from '@kit.BasicServicesKit'; 5164 5165let storage: LocalStorage = new LocalStorage(); 5166storage.setOrCreate('storageSimpleProp', 121); 5167windowClass.loadContent("pages/page2", storage, (err: BusinessError) => { 5168 let errCode: number = err.code; 5169 if (errCode) { 5170 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 5171 return; 5172 } 5173 console.info('Succeeded in loading the content.'); 5174 let color: string = '#00ff33'; 5175 try { 5176 windowClass?.setWindowBackgroundColor(color); 5177 } catch (exception) { 5178 console.error(`Failed to set the background color. Cause code: ${exception.code}, message: ${exception.message}`); 5179 }; 5180}); 5181``` 5182 5183### setWindowBrightness<sup>9+</sup> 5184 5185setWindowBrightness(brightness: number, callback: AsyncCallback<void>): void 5186 5187允许应用主窗口设置屏幕亮度值,使用callback异步回调。 5188 5189当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 5190 5191**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5192 5193**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5194 5195**参数:** 5196 5197| 参数名 | 类型 | 必填 | 说明 | 5198| ---------- | ------------------------- | -- |-------------------------------------------| 5199| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 5200| callback | AsyncCallback<void> | 是 | 回调函数。 | 5201 5202**错误码:** 5203 5204以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5205 5206| 错误码ID | 错误信息 | 5207| ------- | -------------------------------------------- | 5208| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5209| 1300002 | This window state is abnormal. | 5210| 1300003 | This window manager service works abnormally. | 5211 5212**示例:** 5213 5214```ts 5215// EntryAbility.ets 5216import { UIAbility } from '@kit.AbilityKit'; 5217import { BusinessError } from '@kit.BasicServicesKit'; 5218 5219export default class EntryAbility extends UIAbility { 5220 // ... 5221 onWindowStageCreate(windowStage: window.WindowStage): void { 5222 console.info('onWindowStageCreate'); 5223 let windowClass: window.Window | undefined = undefined; 5224 windowStage.getMainWindow((err: BusinessError, data) => { 5225 const errCode: number = err.code; 5226 if (errCode) { 5227 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 5228 return; 5229 } 5230 windowClass = data; 5231 let brightness: number = 1; 5232 try { 5233 windowClass.setWindowBrightness(brightness, (err: BusinessError) => { 5234 const errCode: number = err.code; 5235 if (errCode) { 5236 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 5237 return; 5238 } 5239 console.info('Succeeded in setting the brightness.'); 5240 }); 5241 } catch (exception) { 5242 console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`); 5243 } 5244 }); 5245 } 5246} 5247``` 5248 5249### setWindowBrightness<sup>9+</sup> 5250 5251setWindowBrightness(brightness: number): Promise<void> 5252 5253允许应用主窗口设置屏幕亮度值,使用Promise异步回调。 5254 5255当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 5256 5257**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5258 5259**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5260 5261**参数:** 5262 5263| 参数名 | 类型 | 必填 | 说明 | 5264| ---------- | ------ | -- |----------------------------------------| 5265| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 5266 5267**返回值:** 5268 5269| 类型 | 说明 | 5270| ------------------- | ------------------------ | 5271| Promise<void> | 无返回结果的Promise对象。 | 5272 5273**错误码:** 5274 5275以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5276 5277| 错误码ID | 错误信息 | 5278| ------- | -------------------------------------------- | 5279| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5280| 1300002 | This window state is abnormal. | 5281| 1300003 | This window manager service works abnormally. | 5282 5283**示例:** 5284 5285```ts 5286// EntryAbility.ets 5287import { UIAbility } from '@kit.AbilityKit'; 5288import { BusinessError } from '@kit.BasicServicesKit'; 5289 5290export default class EntryAbility extends UIAbility { 5291 // ... 5292 onWindowStageCreate(windowStage: window.WindowStage): void { 5293 console.info('onWindowStageCreate'); 5294 let windowClass: window.Window | undefined = undefined; 5295 windowStage.getMainWindow((err: BusinessError, data) => { 5296 const errCode: number = err.code; 5297 if (errCode) { 5298 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 5299 return; 5300 } 5301 windowClass = data; 5302 let brightness: number = 1; 5303 try { 5304 let promise = windowClass.setWindowBrightness(brightness); 5305 promise.then(() => { 5306 console.info('Succeeded in setting the brightness.'); 5307 }).catch((err: BusinessError) => { 5308 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 5309 }); 5310 } catch (exception) { 5311 console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`); 5312 } 5313 }); 5314 } 5315} 5316``` 5317 5318### setWindowFocusable<sup>9+</sup> 5319 5320setWindowFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 5321 5322设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用callback异步回调。 5323 5324**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5325 5326**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5327 5328**参数:** 5329 5330| 参数名 | 类型 | 必填 | 说明 | 5331| ----------- | ------------------------- | -- | ------------------------------------------------------- | 5332| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 5333| callback | AsyncCallback<void> | 是 | 回调函数。 | 5334 5335**错误码:** 5336 5337以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5338 5339| 错误码ID | 错误信息 | 5340| ------- | -------------------------------------------- | 5341| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5342| 1300002 | This window state is abnormal. | 5343| 1300003 | This window manager service works abnormally. | 5344 5345**示例:** 5346 5347```ts 5348import { BusinessError } from '@kit.BasicServicesKit'; 5349 5350let isFocusable: boolean = true; 5351try { 5352 windowClass.setWindowFocusable(isFocusable, (err: BusinessError) => { 5353 const errCode: number = err.code; 5354 if (errCode) { 5355 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 5356 return; 5357 } 5358 console.info('Succeeded in setting the window to be focusable.'); 5359 }); 5360} catch (exception) { 5361 console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`); 5362} 5363``` 5364 5365### setWindowFocusable<sup>9+</sup> 5366 5367setWindowFocusable(isFocusable: boolean): Promise<void> 5368 5369设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用Promise异步回调。 5370 5371**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5372 5373**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5374 5375**参数:** 5376 5377| 参数名 | 类型 | 必填 | 说明 | 5378| ----------- | ------- | -- | -------------------------------------------------------- | 5379| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 5380 5381**返回值:** 5382 5383| 类型 | 说明 | 5384| ------------------- | ------------------------ | 5385| Promise<void> | 无返回结果的Promise对象。 | 5386 5387**错误码:** 5388 5389以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5390 5391| 错误码ID | 错误信息 | 5392| ------- | -------------------------------------------- | 5393| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5394| 1300002 | This window state is abnormal. | 5395| 1300003 | This window manager service works abnormally. | 5396 5397**示例:** 5398 5399```ts 5400import { BusinessError } from '@kit.BasicServicesKit'; 5401 5402let isFocusable: boolean = true; 5403try { 5404 let promise = windowClass.setWindowFocusable(isFocusable); 5405 promise.then(() => { 5406 console.info('Succeeded in setting the window to be focusable.'); 5407 }).catch((err: BusinessError) => { 5408 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 5409 }); 5410} catch (exception) { 5411 console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`); 5412} 5413``` 5414 5415### setWindowKeepScreenOn<sup>9+</sup> 5416 5417setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 5418 5419设置屏幕是否为常亮状态,使用callback异步回调。 5420 5421规范使用该接口:仅在必要场景(导航、视频播放、绘画、游戏等场景)下,设置该属性为true;退出上述场景后,应当重置该属性为false;其他场景(无屏幕互动、音频播放等)下,不使用该接口;系统检测到非规范使用该接口时,可能会恢复自动灭屏功能。 5422 5423**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5424 5425**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5426 5427**参数:** 5428 5429| 参数名 | 类型 | 必填 | 说明 | 5430| -------------- | ------------------------- | -- | ---------------------------------------------------- | 5431| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 5432| callback | AsyncCallback<void> | 是 | 回调函数。 | 5433 5434**错误码:** 5435 5436以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5437 5438| 错误码ID | 错误信息 | 5439| ------- | -------------------------------------------- | 5440| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5441| 1300002 | This window state is abnormal. | 5442| 1300003 | This window manager service works abnormally. | 5443 5444**示例:** 5445 5446```ts 5447import { BusinessError } from '@kit.BasicServicesKit'; 5448 5449let isKeepScreenOn: boolean = true; 5450try { 5451 windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 5452 const errCode: number = err.code; 5453 if (errCode) { 5454 console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 5455 return; 5456 } 5457 console.info('Succeeded in setting the screen to be always on.'); 5458 }); 5459} catch (exception) { 5460 console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`); 5461} 5462``` 5463 5464### setWindowKeepScreenOn<sup>9+</sup> 5465 5466setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 5467 5468设置屏幕是否为常亮状态,使用Promise异步回调。 5469 5470规范使用该接口:仅在必要场景(导航、视频播放、绘画、游戏等场景)下,设置该属性为true;退出上述场景后,应当重置该属性为false;其他场景(无屏幕互动、音频播放等)下,不使用该接口;系统检测到非规范使用该接口时,可能会恢复自动灭屏功能。 5471 5472**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5473 5474**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5475 5476**参数:** 5477 5478| 参数名 | 类型 | 必填 | 说明 | 5479| -------------- | ------- | -- | --------------------------------------------------- | 5480| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 5481 5482**返回值:** 5483 5484| 类型 | 说明 | 5485| ------------------- | ------------------------ | 5486| Promise<void> | 无返回结果的Promise对象。 | 5487 5488**错误码:** 5489 5490以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5491 5492| 错误码ID | 错误信息 | 5493| ------- | -------------------------------------------- | 5494| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5495| 1300002 | This window state is abnormal. | 5496| 1300003 | This window manager service works abnormally. | 5497 5498**示例:** 5499 5500```ts 5501import { BusinessError } from '@kit.BasicServicesKit'; 5502 5503let isKeepScreenOn: boolean = true; 5504try { 5505 let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn); 5506 promise.then(() => { 5507 console.info('Succeeded in setting the screen to be always on.'); 5508 }).catch((err: BusinessError) => { 5509 console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 5510 }); 5511} catch (exception) { 5512 console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`); 5513} 5514``` 5515 5516### setWindowPrivacyMode<sup>9+</sup> 5517 5518setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 5519 5520设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 5521 5522**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5523 5524**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5525 5526**需要权限:** ohos.permission.PRIVACY_WINDOW 5527 5528**参数:** 5529 5530| 参数名 | 类型 | 必填 | 说明 | 5531| ------------- | ------------------------- | -- | ------------------------------------------------------ | 5532| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 5533| callback | AsyncCallback<void> | 是 | 回调函数。 | 5534 5535**错误码:** 5536 5537以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5538 5539| 错误码ID | 错误信息 | 5540| ------- | ------------------------------ | 5541| 201 | Permission verification failed. The application does not have the permission required to call the API. | 5542| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5543| 1300002 | This window state is abnormal. | 5544 5545**示例:** 5546 5547```ts 5548import { BusinessError } from '@kit.BasicServicesKit'; 5549 5550let isPrivacyMode: boolean = true; 5551try { 5552 windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => { 5553 const errCode: number = err.code; 5554 if (errCode) { 5555 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 5556 return; 5557 } 5558 console.info('Succeeded in setting the window to privacy mode.'); 5559 }); 5560} catch (exception) { 5561 console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`); 5562} 5563``` 5564 5565### setWindowPrivacyMode<sup>9+</sup> 5566 5567setWindowPrivacyMode(isPrivacyMode: boolean): Promise<void> 5568 5569设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 5570 5571**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5572 5573**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5574 5575**需要权限:** ohos.permission.PRIVACY_WINDOW 5576 5577**参数:** 5578 5579| 参数名 | 类型 | 必填 | 说明 | 5580| ------------- | ------- | -- | ----------------------------------------------------- | 5581| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 5582 5583**返回值:** 5584 5585| 类型 | 说明 | 5586| ------------------- | ------------------------ | 5587| Promise<void> | 无返回结果的Promise对象。 | 5588 5589**错误码:** 5590 5591以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5592 5593| 错误码ID | 错误信息 | 5594| ------- | ------------------------------ | 5595| 201 | Permission verification failed. The application does not have the permission required to call the API. | 5596| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5597| 1300002 | This window state is abnormal. | 5598 5599**示例:** 5600 5601```ts 5602import { BusinessError } from '@kit.BasicServicesKit'; 5603 5604let isPrivacyMode: boolean = true; 5605try { 5606 let promise = windowClass.setWindowPrivacyMode(isPrivacyMode); 5607 promise.then(() => { 5608 console.info('Succeeded in setting the window to privacy mode.'); 5609 }).catch((err: BusinessError) => { 5610 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 5611 }); 5612} catch (exception) { 5613 console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`); 5614} 5615``` 5616 5617### setWindowTouchable<sup>9+</sup> 5618 5619setWindowTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 5620 5621设置窗口是否为可触状态,使用callback异步回调。 5622 5623**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5624 5625**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5626 5627**参数:** 5628 5629| 参数名 | 类型 | 必填 | 说明 | 5630| ----------- | ------------------------- | -- | ----------------------------------------------- | 5631| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 5632| callback | AsyncCallback<void> | 是 | 回调函数。 | 5633 5634**错误码:** 5635 5636以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5637 5638| 错误码ID | 错误信息 | 5639| ------- | -------------------------------------------- | 5640| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5641| 1300002 | This window state is abnormal. | 5642| 1300003 | This window manager service works abnormally. | 5643 5644**示例:** 5645 5646```ts 5647import { BusinessError } from '@kit.BasicServicesKit'; 5648 5649let isTouchable = true; 5650try { 5651 windowClass.setWindowTouchable(isTouchable, (err: BusinessError) => { 5652 const errCode: number = err.code; 5653 if (errCode) { 5654 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 5655 return; 5656 } 5657 console.info('Succeeded in setting the window to be touchable.'); 5658 }); 5659} catch (exception) { 5660 console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 5661} 5662``` 5663 5664### setWindowTouchable<sup>9+</sup> 5665 5666setWindowTouchable(isTouchable: boolean): Promise<void> 5667 5668设置窗口是否为可触状态,使用Promise异步回调。 5669 5670**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5671 5672**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5673 5674**参数:** 5675 5676| 参数名 | 类型 | 必填 | 说明 | 5677| ----------- | ------- | -- | ----------------------------------------------- | 5678| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 5679 5680**返回值:** 5681 5682| 类型 | 说明 | 5683| ------------------- | ------------------------- | 5684| Promise<void> | 无返回结果的Promise对象。 | 5685 5686**错误码:** 5687 5688以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5689 5690| 错误码ID | 错误信息 | 5691| ------- | -------------------------------------------- | 5692| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5693| 1300002 | This window state is abnormal. | 5694| 1300003 | This window manager service works abnormally. | 5695 5696**示例:** 5697 5698```ts 5699import { BusinessError } from '@kit.BasicServicesKit'; 5700 5701let isTouchable: boolean = true; 5702try { 5703 let promise = windowClass.setWindowTouchable(isTouchable); 5704 promise.then(() => { 5705 console.info('Succeeded in setting the window to be touchable.'); 5706 }).catch((err: BusinessError) => { 5707 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 5708 }); 5709} catch (exception) { 5710 console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 5711} 5712``` 5713 5714### snapshot<sup>9+</sup> 5715 5716snapshot(callback: AsyncCallback<image.PixelMap>): void 5717 5718获取窗口截图,使用callback异步回调。 5719 5720**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5721 5722**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5723 5724**参数:** 5725 5726| 参数名 | 类型 | 必填 | 说明 | 5727| ----------- | ------------------------- | ---- | -------------------- | 5728| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | 是 | 回调函数。 | 5729 5730**错误码:** 5731 5732以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 5733 5734| 错误码ID | 错误信息 | 5735| ------- | ------------------------------ | 5736| 1300002 | This window state is abnormal. | 5737 5738**示例:** 5739 5740```ts 5741import { BusinessError } from '@kit.BasicServicesKit'; 5742import { image } from '@kit.ImageKit'; 5743 5744windowClass.snapshot((err: BusinessError, pixelMap: image.PixelMap) => { 5745 const errCode: number = err.code; 5746 if (errCode) { 5747 console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`); 5748 return; 5749 } 5750 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 5751 pixelMap.release(); // PixelMap使用完后及时释放内存 5752}); 5753``` 5754 5755### snapshot<sup>9+</sup> 5756 5757snapshot(): Promise<image.PixelMap> 5758 5759获取窗口截图,使用Promise异步回调。 5760 5761**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5762 5763**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5764 5765**返回值:** 5766 5767| 类型 | 说明 | 5768| ------------------- | ------------------------- | 5769| Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise对象。返回当前窗口截图。 | 5770 5771**错误码:** 5772 5773以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 5774 5775| 错误码ID | 错误信息 | 5776| ------- | ------------------------------ | 5777| 1300002 | This window state is abnormal. | 5778 5779**示例:** 5780 5781```ts 5782import { BusinessError } from '@kit.BasicServicesKit'; 5783import { image } from '@kit.ImageKit'; 5784 5785let promise = windowClass.snapshot(); 5786promise.then((pixelMap: image.PixelMap) => { 5787 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 5788 pixelMap.release(); // PixelMap使用完后及时释放内存 5789}).catch((err: BusinessError) => { 5790 console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`); 5791}); 5792``` 5793 5794### setAspectRatio<sup>10+</sup> 5795 5796setAspectRatio(ratio: number): Promise<void> 5797 5798设置窗口内容布局的比例,使用Promise异步回调。 5799 5800通过其他接口如[resize](#resize9)、[resizeAsync](#resizeasync12)设置窗口大小时,不受ratio约束。 5801 5802仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。 5803 5804**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5805 5806**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5807 5808**参数:** 5809 5810| 参数名 | 类型 | 必填 | 说明 | 5811| ------------------ | ------- | ---- |-------------------------------------------| 5812| ratio | number | 是 | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,受窗口最大最小尺寸限制,比例值下限为最小宽度/最大高度,上限为最大宽度/最小高度。窗口最大最小尺寸由[WindowLimits](#windowlimits11)和系统限制的交集决定,系统限制优先级高于[WindowLimits](#windowlimits11)。ratio的有效范围会随[WindowLimits](#windowlimits11)变化而变化。如果先设置了[WindowLimits](#windowlimits11),后设置的ratio与其冲突,会返回错误码;如果先设置了ratio,后设置的[WindowLimits](#windowlimits11)与其冲突,窗口的宽高比可能会不跟随设置的宽高比(ratio)。 | 5813 5814**返回值:** 5815 5816| 类型 | 说明 | 5817| ------------------- | ------------------------- | 5818| Promise<void> | 无返回结果的Promise对象。 | 5819 5820**错误码:** 5821 5822以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5823 5824| 错误码ID | 错误信息 | 5825| ------- | -------------------------------------------- | 5826| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5827| 1300002 | This window state is abnormal. | 5828| 1300004 | Unauthorized operation. | 5829 5830**示例:** 5831<!--code_no_check--> 5832```ts 5833// EntryAbility.ets 5834import { UIAbility } from '@kit.AbilityKit'; 5835import { BusinessError } from '@kit.BasicServicesKit'; 5836 5837export default class EntryAbility extends UIAbility { 5838 5839 // ... 5840 onWindowStageCreate(windowStage: window.WindowStage) { 5841 console.info('onWindowStageCreate'); 5842 let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 5843 if (!windowClass) { 5844 console.info('windowClass is null'); 5845 } 5846 try { 5847 let ratio = 1.0; 5848 let promise = windowClass.setAspectRatio(ratio); 5849 promise.then(() => { 5850 console.info('Succeeded in setting aspect ratio of window.'); 5851 }).catch((err: BusinessError) => { 5852 console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 5853 }); 5854 } catch (exception) { 5855 console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 5856 } 5857 } 5858} 5859``` 5860 5861### setAspectRatio<sup>10+</sup> 5862 5863setAspectRatio(ratio: number, callback: AsyncCallback<void>): void 5864 5865设置窗口内容布局的比例,使用callback异步回调。 5866 5867通过其他接口如[resize](#resize9)、[resizeAsync](#resizeasync12)设置窗口大小时,不受ratio约束。 5868 5869仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。 5870 5871**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5872 5873**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5874 5875**参数:** 5876 5877| 参数名 | 类型 | 必填 | 说明 | 5878| ------------------ | ------- | ---- |--------------------------------------------| 5879| ratio | number | 是 | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,受窗口最大最小尺寸限制,比例值下限为最小宽度/最大高度,上限为最大宽度/最小高度。窗口最大最小尺寸由[WindowLimits](#windowlimits11)和系统限制的交集决定,系统限制优先级高于[WindowLimits](#windowlimits11)。ratio的有效范围会随[WindowLimits](#windowlimits11)变化而变化。如果先设置了[WindowLimits](#windowlimits11),后设置的ratio与其冲突,会返回错误码;如果先设置了ratio,后设置的[WindowLimits](#windowlimits11)与其冲突,窗口的宽高比可能会不跟随设置的宽高比(ratio)。 | 5880| callback | AsyncCallback<void> | 是 | 回调函数。 | 5881 5882**错误码:** 5883 5884以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5885 5886| 错误码ID | 错误信息 | 5887| ------- | -------------------------------------------- | 5888| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5889| 1300002 | This window state is abnormal. | 5890| 1300004 | Unauthorized operation. | 5891 5892**示例:** 5893<!--code_no_check--> 5894```ts 5895// EntryAbility.ets 5896import { UIAbility } from '@kit.AbilityKit'; 5897import { BusinessError } from '@kit.BasicServicesKit'; 5898 5899export default class EntryAbility extends UIAbility { 5900 5901 // ... 5902 onWindowStageCreate(windowStage: window.WindowStage) { 5903 console.info('onWindowStageCreate'); 5904 let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 5905 if (!windowClass) { 5906 console.info('Failed to load the content. Cause: windowClass is null'); 5907 } 5908 try { 5909 let ratio = 1.0; 5910 windowClass.setAspectRatio(ratio, (err: BusinessError) => { 5911 const errCode: number = err.code; 5912 if (errCode) { 5913 console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 5914 return; 5915 } 5916 console.info('Succeeded in setting the aspect ratio of window.'); 5917 }); 5918 } catch (exception) { 5919 console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 5920 } 5921 } 5922} 5923 5924``` 5925 5926### resetAspectRatio<sup>10+</sup> 5927 5928resetAspectRatio(): Promise<void> 5929 5930取消设置窗口内容布局的比例,使用Promise异步回调。 5931 5932仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,调用后将清除持久化储存的比例信息。 5933 5934**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5935 5936**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5937 5938**返回值:** 5939 5940| 类型 | 说明 | 5941| ------------------- | ------------------------- | 5942| Promise<void> | 无返回结果的Promise对象。 | 5943 5944**错误码:** 5945 5946以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 5947 5948| 错误码ID | 错误信息 | 5949| ------- | -------------------------------------------- | 5950| 1300002 | This window state is abnormal. | 5951| 1300004 | Unauthorized operation. | 5952 5953**示例:** 5954<!--code_no_check--> 5955```ts 5956// EntryAbility.ets 5957import { UIAbility } from '@kit.AbilityKit'; 5958import { BusinessError } from '@kit.BasicServicesKit'; 5959 5960export default class EntryAbility extends UIAbility { 5961 5962 // ... 5963 onWindowStageCreate(windowStage: window.WindowStage) { 5964 console.info('onWindowStageCreate'); 5965 let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 5966 if (!windowClass) { 5967 console.info('Failed to load the content. Cause: windowClass is null'); 5968 } 5969 try { 5970 let promise = windowClass.resetAspectRatio(); 5971 promise.then(() => { 5972 console.info('Succeeded in resetting aspect ratio of window.'); 5973 }).catch((err: BusinessError) => { 5974 console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 5975 }); 5976 } catch (exception) { 5977 console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 5978 } 5979 } 5980} 5981``` 5982 5983### resetAspectRatio<sup>10+</sup> 5984 5985resetAspectRatio(callback: AsyncCallback<void>): void 5986 5987取消设置窗口内容布局的比例,使用callback异步回调。 5988 5989仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,调用后将清除持久化储存的比例信息。 5990 5991**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5992 5993**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5994 5995**参数:** 5996 5997| 参数名 | 类型 | 必填 | 说明 | 5998| ------------------ | ------- | ---- | ------------------------------------------------------------ | 5999| callback | AsyncCallback<void> | 是 | 回调函数。 | 6000 6001**错误码:** 6002 6003以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 6004 6005| 错误码ID | 错误信息 | 6006| ------- | -------------------------------------------- | 6007| 1300002 | This window state is abnormal. | 6008| 1300004 | Unauthorized operation. | 6009 6010**示例:** 6011<!--code_no_check--> 6012```ts 6013// EntryAbility.ets 6014import { UIAbility } from '@kit.AbilityKit'; 6015import { BusinessError } from '@kit.BasicServicesKit'; 6016 6017export default class EntryAbility extends UIAbility { 6018 6019 // ... 6020 onWindowStageCreate(windowStage: window.WindowStage) { 6021 console.info('onWindowStageCreate'); 6022 let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 6023 if (!windowClass) { 6024 console.info('Failed to load the content. Cause: windowClass is null'); 6025 } 6026 try { 6027 windowClass.resetAspectRatio((err: BusinessError) => { 6028 const errCode: number = err.code; 6029 if (errCode) { 6030 console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 6031 return; 6032 } 6033 console.info('Succeeded in resetting aspect ratio of window.'); 6034 }); 6035 } catch (exception) { 6036 console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 6037 } 6038 } 6039} 6040``` 6041 6042### minimize<sup>11+</sup> 6043 6044minimize(callback: AsyncCallback<void>): void 6045 6046此接口根据调用对象不同,实现不同的功能: 6047 6048当调用对象为主窗口时,实现最小化功能,可在Dock栏中还原,2in1 设备上可以使用[restore()](#restore14)进行还原。 6049 6050当调用对象为子窗口或悬浮窗时,实现隐藏功能,不可在Dock栏中还原,可以使用[showWindow()](#showwindow9)进行还原。 6051 6052使用callback异步回调。 6053 6054**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6055 6056**系统能力:** SystemCapability.Window.SessionManager 6057 6058**参数:** 6059 6060| 参数名 | 类型 | 必填 | 说明 | 6061| -------- | ------------------------- | ---- | ---------- | 6062| callback | AsyncCallback<void> | 是 | 回调函数。 | 6063 6064**错误码:** 6065 6066以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6067 6068| 错误码ID | 错误信息 | 6069| ------- | ------------------------------ | 6070| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6071| 1300002 | This window state is abnormal. | 6072| 1300003 | This window manager service works abnormally. | 6073 6074**示例:** 6075 6076```ts 6077import { BusinessError } from '@kit.BasicServicesKit'; 6078 6079windowClass.minimize((err: BusinessError) => { 6080 const errCode: number = err.code; 6081 if (errCode) { 6082 console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`); 6083 return; 6084 } 6085 console.info('Succeeded in minimizing the window.'); 6086}); 6087``` 6088 6089### minimize<sup>11+</sup> 6090 6091minimize(): Promise<void> 6092 6093此接口根据调用对象不同,实现不同的功能: 6094 6095当调用对象为主窗口时,实现最小化功能,可在Dock栏中还原,2in1 设备上可以使用[restore()](#restore14)进行还原。 6096 6097当调用对象为子窗口或悬浮窗时,实现隐藏功能,不可在Dock栏中还原,可以使用[showWindow()](#showwindow9)进行还原。 6098 6099使用Promise异步回调。 6100 6101**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6102 6103**系统能力:** SystemCapability.Window.SessionManager 6104 6105**返回值:** 6106 6107| 类型 | 说明 | 6108| ------------------- | ------------------------- | 6109| Promise<void> | 无返回结果的Promise对象。 | 6110 6111**错误码:** 6112 6113以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6114 6115| 错误码ID | 错误信息 | 6116| ------- | ------------------------------ | 6117| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6118| 1300002 | This window state is abnormal. | 6119| 1300003 | This window manager service works abnormally. | 6120 6121**示例:** 6122 6123```ts 6124import { BusinessError } from '@kit.BasicServicesKit'; 6125 6126let promise = windowClass.minimize(); 6127promise.then(() => { 6128 console.info('Succeeded in minimizing the window.'); 6129}).catch((err: BusinessError) => { 6130 console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`); 6131}); 6132``` 6133 6134### maximize<sup>12+</sup> 6135maximize(presentation?: MaximizePresentation): Promise<void> 6136 6137主窗口调用,实现最大化功能,使用Promise异步回调。 6138 6139<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 6140 6141**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6142 6143**系统能力:** SystemCapability.Window.SessionManager 6144 6145**参数:** 6146 6147| 参数名 | 类型 | 必填 | 说明 | 6148| ----- | ---------------------------- | -- | --------------------------------- | 6149| presentation | [MaximizePresentation](#maximizepresentation12) | 否 | 主窗口最大化时候的布局枚举。默认值window.MaximizePresentation.ENTER_IMMERSIVE,即默认最大化时进入沉浸式布局。 | 6150 6151**返回值:** 6152 6153| 类型 | 说明 | 6154| ------------------- | ------------------------- | 6155| Promise<void> | 无返回结果的Promise对象。 | 6156 6157**错误码:** 6158 6159以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6160 6161| 错误码ID | 错误信息 | 6162| ------- | ------------------------------ | 6163| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6164| 1300002 | This window state is abnormal. | 6165| 1300003 | This window manager service works abnormally. | 6166| 1300004 | Unauthorized operation. | 6167| 1300005 | This window stage is abnormal. | 6168 6169**示例:** 6170 6171```ts 6172// EntryAbility.ets 6173import { UIAbility } from '@kit.AbilityKit'; 6174import { BusinessError } from '@kit.BasicServicesKit'; 6175export default class EntryAbility extends UIAbility { 6176 // ... 6177 6178 onWindowStageCreate(windowStage: window.WindowStage) { 6179 console.info('onWindowStageCreate'); 6180 let windowClass: window.Window | undefined = undefined; 6181 windowStage.getMainWindow((err: BusinessError, data) => { 6182 const errCode: number = err.code; 6183 if (errCode) { 6184 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 6185 return; 6186 } 6187 windowClass = data; 6188 let promise = windowClass.maximize(); 6189 // let promise = windowClass.maximize(window.MaximizePresentation.ENTER_IMMERSIVE); 6190 promise.then(() => { 6191 console.info('Succeeded in maximizing the window.'); 6192 }).catch((err: BusinessError) => { 6193 console.error(`Failed to maximize the window. Cause code: ${err.code}, message: ${err.message}`); 6194 }); 6195 }); 6196 } 6197}; 6198``` 6199 6200### setResizeByDragEnabled<sup>14+</sup> 6201setResizeByDragEnabled(enable: boolean, callback: AsyncCallback<void>): void 6202 6203禁止/使能通过拖拽方式缩放主窗口或启用装饰的子窗口的功能。使用callback异步回调。 6204 6205**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 6206 6207**系统能力:** SystemCapability.Window.SessionManager 6208 6209**参数:** 6210 6211| 参数名 | 类型 | 必填 | 说明 | 6212| ----- | ---------------------------- | -- | --------------------------------- | 6213| enable | boolean | 是 | 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。 | 6214| callback | AsyncCallback<void> | 是 | 回调函数。 | 6215 6216**错误码:** 6217 6218以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6219 6220| 错误码ID | 错误信息 | 6221| ------- | ------------------------------ | 6222| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6223| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6224| 1300002 | This window state is abnormal. | 6225| 1300003 | This window manager service works abnormally. | 6226 6227**示例:** 6228 6229```ts 6230import { BusinessError } from '@kit.BasicServicesKit'; 6231 6232let enabled = false; 6233windowClass.setResizeByDragEnabled(enabled, (err) => { 6234 if (err.code) { 6235 console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${err.code}, message: ${err.message}`); 6236 return; 6237 } 6238 console.info('Succeeded in setting the function of disabling the resize by drag window.'); 6239}); 6240``` 6241 6242### setResizeByDragEnabled<sup>14+</sup> 6243setResizeByDragEnabled(enable: boolean): Promise<void> 6244 6245禁止/使能通过拖拽方式缩放主窗口或启用装饰的子窗口的功能。使用Promise异步回调。 6246 6247**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 6248 6249**系统能力:** SystemCapability.Window.SessionManager 6250 6251**参数:** 6252 6253| 参数名 | 类型 | 必填 | 说明 | 6254| ----- | ---------------------------- | -- | --------------------------------- | 6255| enable | boolean | 是 | 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。 | 6256 6257**返回值:** 6258 6259| 类型 | 说明 | 6260| ------------------- | ------------------------ | 6261| Promise<void> | 无返回结果的Promise对象。 | 6262 6263**错误码:** 6264 6265以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6266 6267| 错误码ID | 错误信息 | 6268| ------- | ------------------------------ | 6269| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6270| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6271| 1300002 | This window state is abnormal. | 6272| 1300003 | This window manager service works abnormally. | 6273 6274**示例:** 6275 6276```ts 6277import { BusinessError } from '@kit.BasicServicesKit'; 6278 6279let enabled = false; 6280let promise = windowClass.setResizeByDragEnabled(enabled); 6281promise.then(() => { 6282 console.info('Succeeded in setting the function of disabling the resize by drag window.'); 6283}).catch((err: BusinessError) => { 6284 console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${err.code}, message: ${err.message}`); 6285}); 6286``` 6287 6288### recover<sup>11+</sup> 6289 6290recover(): Promise<void> 6291 6292将主窗口从全屏、最大化、分屏模式下还原为浮动窗口,并恢复到进入该模式之前的大小和位置,已经是浮动窗口模式不可再还原。使用Promise异步回调。此接口仅在多窗层叠布局效果下生效。 6293 6294<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 6295 6296**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6297 6298**系统能力:** SystemCapability.Window.SessionManager 6299 6300**返回值:** 6301 6302| 类型 | 说明 | 6303| ------------------- | ------------------------- | 6304| Promise<void> | 无返回结果的Promise对象。 | 6305 6306**错误码:** 6307 6308以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6309 6310| 错误码ID | 错误信息 | 6311| ------- | ------------------------------ | 6312| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6313| 1300001 | Repeated operation. | 6314| 1300002 | This window state is abnormal. | 6315 6316**示例:** 6317 6318```ts 6319// EntryAbility.ets 6320import { UIAbility } from '@kit.AbilityKit'; 6321import { BusinessError } from '@kit.BasicServicesKit'; 6322 6323export default class EntryAbility extends UIAbility { 6324 // ... 6325 onWindowStageCreate(windowStage: window.WindowStage): void { 6326 console.info('onWindowStageCreate'); 6327 let windowClass: window.Window | undefined = undefined; 6328 windowStage.getMainWindow((err: BusinessError, data) => { 6329 const errCode: number = err.code; 6330 if (errCode) { 6331 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 6332 return; 6333 } 6334 windowClass = data; 6335 let promise = windowClass.recover(); 6336 promise.then(() => { 6337 console.info('Succeeded in recovering the window.'); 6338 }).catch((err: BusinessError) => { 6339 console.error(`Failed to recover the window. Cause code: ${err.code}, message: ${err.message}`); 6340 }); 6341 }); 6342 } 6343} 6344``` 6345 6346### restore<sup>14+</sup> 6347 6348restore(): Promise<void> 6349 6350将主窗口从最小化状态,恢复到前台显示,并恢复到进入该模式之前的大小和位置。使用Promise异步回调。 6351此接口仅在多窗层叠布局效果下生效,仅在主窗口为最小化状态且UIAbility生命周期为onForeground时生效。 6352 6353<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 6354 6355**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 6356 6357**系统能力:** SystemCapability.Window.SessionManager 6358 6359**返回值:** 6360 6361| 类型 | 说明 | 6362| ------------------- | ------------------------- | 6363| Promise<void> | 无返回结果的Promise对象。 | 6364 6365**错误码:** 6366 6367以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6368 6369| **错误码ID** | **错误信息** | 6370| ------------ | ------------------------------------------------------------ | 6371| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6372| 1300002 | This window state is abnormal. | 6373| 1300003 | This window manager service works abnormally. | 6374| 1300004 | Unauthorized operation. | 6375 6376**示例** 6377 6378```ts 6379// EntryAbility.ets 6380import { UIAbility } from '@kit.AbilityKit'; 6381import { BusinessError } from '@kit.BasicServicesKit'; 6382import { window } from '@kit.ArkUI'; 6383import { BusinessError } from '@kit.BasicServicesKit'; 6384 6385export default class EntryAbility extends UIAbility { 6386 onWindowStageCreate(windowStage: window.WindowStage): void { 6387 // 加载主窗口对应的页面 6388 windowStage.loadContent('pages/Index', (err) => { 6389 let mainWindow: window.Window | undefined = undefined; 6390 // 获取应用主窗口。 6391 windowStage.getMainWindow().then( 6392 data => { 6393 mainWindow = data; 6394 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 6395 // 调用minimize, 使主窗缩小。 6396 mainWindow.minimize(); 6397 //设置延时函数延时5秒钟后对主窗进行恢复。 6398 setTimeout(()=>{ 6399 //调用restore()函数对主窗进行恢复。 6400 let promise = mainWindow.restore(); 6401 promise.then(() => { 6402 console.info('Succeeded in restoring the window.'); 6403 }).catch((err: BusinessError) => { 6404 console.error(`Failed to restore the window. Cause code: ${err.code}, 6405 message: ${err.message}`); 6406 }); 6407 },5000); 6408 } 6409 ).catch((err: BusinessError) => { 6410 if(err.code){ 6411 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 6412 } 6413 }); 6414 }); 6415 } 6416} 6417``` 6418 6419### getWindowLimits<sup>11+</sup> 6420 6421getWindowLimits(): WindowLimits 6422 6423获取当前应用窗口的尺寸限制。 6424 6425**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6426 6427**系统能力:** SystemCapability.Window.SessionManager 6428 6429**返回值:** 6430 6431| 类型 | 说明 | 6432| ----------------------------- | ------------------ | 6433| [WindowLimits](#windowlimits11) | 当前窗口尺寸限制。 | 6434 6435**错误码:** 6436 6437以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6438 6439| 错误码ID | 错误信息 | 6440| :------- | :----------------------------- | 6441| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6442| 1300002 | This window state is abnormal. | 6443 6444**示例:** 6445 6446```ts 6447try { 6448 let windowLimits = windowClass.getWindowLimits(); 6449} catch (exception) { 6450 console.error(`Failed to obtain the window limits of window. Cause code: ${exception.code}, message: ${exception.message}`); 6451} 6452``` 6453 6454### setWindowLimits<sup>11+</sup> 6455 6456setWindowLimits(windowLimits: WindowLimits): Promise<WindowLimits> 6457 6458设置当前应用窗口的尺寸限制,使用Promise异步回调。 6459默认存在一个系统尺寸限制,系统尺寸限制由产品配置决定,不可修改。未调用setWindowLimits配置过WindowLimits时,使用[getWindowLimits](#getwindowlimits11)可获取系统限制。 6460 6461**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6462 6463**系统能力:** SystemCapability.Window.SessionManager 6464 6465**参数:** 6466 6467| 参数名 | 类型 | 必填 | 说明 | 6468| :----------- | :---------------------------- | :--- | :----------------------------- | 6469| windowLimits | [WindowLimits](#windowlimits11) | 是 | 目标窗口的尺寸限制,单位为px。 | 6470 6471**返回值:** 6472 6473| 类型 | 说明 | 6474| :------------------------------------------- | :---------------------------------- | 6475| Promise<[WindowLimits](#windowlimits11)> | Promise对象。返回设置后的尺寸限制,为入参与系统尺寸限制的交集。 | 6476 6477**错误码:** 6478 6479以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6480 6481| 错误码ID | 错误信息 | 6482| :------- | :-------------------------------------------- | 6483| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6484| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6485| 1300002 | This window state is abnormal. | 6486| 1300003 | This window manager service works abnormally. | 6487| 1300004 | Unauthorized operation. | 6488 6489**示例:** 6490 6491```ts 6492import { BusinessError } from '@kit.BasicServicesKit'; 6493try { 6494 let windowLimits: window.WindowLimits = { 6495 maxWidth: 1500, 6496 maxHeight: 1000, 6497 minWidth: 500, 6498 minHeight: 400 6499 }; 6500 let promise = windowClass.setWindowLimits(windowLimits); 6501 promise.then((data) => { 6502 console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data)); 6503 }).catch((err: BusinessError) => { 6504 console.error(`Failed to change the window limits. Cause code: ${err.code}, message: ${err.message}`); 6505 }); 6506} catch (exception) { 6507 console.error(`Failed to change the window limits. Cause code: ${exception.code}, message: ${exception.message}`); 6508} 6509``` 6510 6511### setWindowLimits<sup>15+</sup> 6512 6513setWindowLimits(windowLimits: WindowLimits, isForcible: boolean): Promise<WindowLimits> 6514 6515设置当前应用窗口的尺寸限制,使用Promise异步回调。 6516默认存在一个系统尺寸限制,系统尺寸限制由产品配置决定,不可修改。未调用setWindowLimits配置过WindowLimits时,使用[getWindowLimits](#getwindowlimits11)可获取系统限制。 6517此接口仅支持2in1设备。 6518 6519**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 6520 6521**系统能力:** SystemCapability.Window.SessionManager 6522 6523**参数:** 6524 6525| 参数名 | 类型 | 必填 | 说明 | 6526| :----------- | :---------------------------- | :--- | :----------------------------- | 6527| windowLimits | [WindowLimits](#windowlimits11) | 是 | 目标窗口的尺寸限制,单位为px。 | 6528| isForcible | boolean | 是 | 是否强制设置窗口的尺寸限制。<br>设置为true,表示窗口宽高最小值以系统限制值和40vp两者中的低数值为准,窗口宽高的最大值仍取决于系统限制。<br>设置为false,表示窗口宽高的最小值和最大值都取决于系统限制。| 6529 6530**返回值:** 6531 6532| 类型 | 说明 | 6533| :------------------------------------------- | :---------------------------------- | 6534| Promise<[WindowLimits](#windowlimits11)> | Promise对象。返回设置后的窗口尺寸限制。根据isForcible判断为入参与系统默认窗口尺寸限制的交集。 | 6535 6536**错误码:** 6537 6538以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6539 6540| 错误码ID | 错误信息 | 6541| :------- | :-------------------------------------------- | 6542| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6543| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6544| 1300002 | This window state is abnormal. | 6545| 1300003 | This window manager service works abnormally. | 6546| 1300004 | Unauthorized operation. | 6547 6548**示例:** 6549 6550```ts 6551import { BusinessError } from '@kit.BasicServicesKit'; 6552try { 6553 let windowLimits: window.WindowLimits = { 6554 maxWidth: 1500, 6555 maxHeight: 1000, 6556 minWidth: 100, 6557 minHeight: 100 6558 }; 6559 let promise = windowClass.setWindowLimits(windowLimits, true); 6560 promise.then((data) => { 6561 console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data)); 6562 }).catch((err: BusinessError) => { 6563 console.error(`Failed to change the window limits. Cause code: ${err.code}, message: ${err.message}`); 6564 }); 6565} catch (exception) { 6566 console.error(`Failed to change the window limits. Cause code: ${exception.code}, message: ${exception.message}`); 6567} 6568``` 6569 6570### setWindowMask<sup>12+</sup> 6571 6572setWindowMask(windowMask: Array<Array<number>>): Promise<void>; 6573 6574设置异形窗口的掩码,使用Promise异步回调。异形窗口为非常规形状的窗口,掩码用于描述异形窗口的形状。此接口仅限子窗和全局悬浮窗可用。 6575当异形窗口大小发生变化时,实际的显示内容为掩码大小和窗口大小的交集部分。 6576 6577<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 6578 6579**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6580 6581**系统能力:** SystemCapability.Window.SessionManager 6582 6583**参数:** 6584 6585| 参数名 | 类型 | 必填 | 说明 | 6586| :----------- | :---------------------------- | :--- | :----------------------------- | 6587| windowMask | Array<Array<number>> | 是 | 异形窗口的掩码,该参数仅支持宽高为窗口宽高、取值为整数0和整数1的二维数组输入,整数0代表所在像素透明,整数1代表所在像素不透明,宽高不符合的二维数组或二维数组取值不为整数0和整数1的二维数组为非法参数。 | 6588 6589**返回值:** 6590 6591| 类型 | 说明 | 6592| :------------------------------------------- | :---------------------------------- | 6593| Promise<void> | 无返回结果的Promise对象。 | 6594 6595**错误码:** 6596 6597以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6598 6599| 错误码ID | 错误信息 | 6600| :------- | :-------------------------------------------- | 6601| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6602| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6603| 1300002 | This window state is abnormal. | 6604| 1300003 | This window manager service works abnormally. | 6605| 1300004 | Unauthorized operation. | 6606 6607**示例:** 6608 6609```ts 6610import { BusinessError } from '@kit.BasicServicesKit'; 6611try { 6612 let windowMask: Array<Array<number>> = [ 6613 [0, 0, 0, 1, 0, 0, 0], 6614 [0, 0, 1, 1, 1, 0, 0], 6615 [0, 1, 1, 0, 1, 1, 0], 6616 [1, 1, 0, 0, 0, 1, 1] 6617 ]; 6618 let promise = windowClass.setWindowMask(windowMask); 6619 promise.then(() => { 6620 console.info('Succeeded in setting the window mask.'); 6621 }).catch((err: BusinessError) => { 6622 console.error(`Failed to set the window mask. Cause code: ${err.code}, message: ${err.message}`); 6623 }); 6624} catch (exception) { 6625 console.error(`Failed to set the window mask. Cause code: ${exception.code}, message: ${exception.message}`); 6626} 6627``` 6628 6629### keepKeyboardOnFocus<sup>11+</sup> 6630 6631keepKeyboardOnFocus(keepKeyboardFlag: boolean): void 6632 6633窗口获焦时保留由其他窗口创建的软键盘,仅支持系统窗口与应用子窗口。 6634 6635**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6636 6637**系统能力:** SystemCapability.Window.SessionManager 6638 6639**参数:** 6640 6641| 参数名 | 类型 | 必填 | 说明 | 6642| ---------------- | ------- | ---- | ------------------------------------------------------------ | 6643| keepKeyboardFlag | boolean | 是 | 是否保留其他窗口创建的软键盘。true表示保留;false表示不保留。| 6644 6645**错误码:** 6646 6647以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6648 6649| 错误码ID | 错误信息 | 6650| ------- | ---------------------------------------- | 6651| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6652| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6653| 1300002 | This window state is abnormal. | 6654| 1300004 | Unauthorized operation. | 6655 6656**示例:** 6657 6658```ts 6659try { 6660 windowClass.keepKeyboardOnFocus(true); 6661} catch (exception) { 6662 console.error(`Failed to keep keyboard onFocus. Cause code: ${exception.code}, message: ${exception.message}`); 6663} 6664``` 6665 6666### setWindowDecorVisible<sup>11+</sup> 6667 6668setWindowDecorVisible(isVisible: boolean): void 6669 6670设置窗口标题栏是否可见,对存在标题栏和三键区的窗口形态生效。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 6671 6672设置窗口标题栏不可见后,当主窗口进入全屏沉浸状态时,此时鼠标Hover到上方窗口标题栏热区上会显示悬浮标题栏。若想禁用悬浮标题栏显示,请使用[setTitleAndDockHoverShown()](#settitleanddockhovershown14)接口。 6673 6674**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6675 6676**系统能力:** SystemCapability.Window.SessionManager 6677 6678**参数:** 6679 6680| 参数名 | 类型 | 必填 | 说明 | 6681| --------- | ------- | ---- | --------------------------------------------- | 6682| isVisible | boolean | 是 | 设置标题栏是否可见,true为可见,false为隐藏。 | 6683 6684**错误码:** 6685 6686以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6687 6688| 错误码ID | 错误信息 | 6689| -------- | ------------------------------ | 6690| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6691| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6692| 1300002 | This window state is abnormal. | 6693| 1300004 | Unauthorized operation. | 6694 6695**示例:** 6696 6697```ts 6698import { BusinessError } from '@kit.BasicServicesKit'; 6699let storage: LocalStorage = new LocalStorage(); 6700storage.setOrCreate('storageSimpleProp', 121); 6701windowClass.loadContent("pages/page2", storage, (err: BusinessError) => { 6702 let errCode: number = err.code; 6703 if (errCode) { 6704 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 6705 return; 6706 } 6707 console.info('Succeeded in loading the content.'); 6708 let isVisible = false; 6709 // 调用setWindowDecorVisible接口 6710 try { 6711 windowClass?.setWindowDecorVisible(isVisible); 6712 } catch (exception) { 6713 console.error(`Failed to set the visibility of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 6714 } 6715}); 6716``` 6717 6718### setWindowTitle<sup>15+</sup> 6719 6720setWindowTitle(titleName: string): Promise<void> 6721 6722设置窗口标题,存在标题栏的窗口形态生效,使用Promise异步回调。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 6723 6724此接口仅支持2in1设备和平板设备。 6725 6726**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 6727 6728**系统能力:** SystemCapability.Window.SessionManager 6729 6730**参数:** 6731 6732| 参数名 | 类型 | 必填 | 说明 | 6733| --------- | ------- | ---- | --------------------------------------------- | 6734| titleName | string | 是 | 窗口标题。标题显示区域最右端不超过系统三键区域最左端,超过部分以省略号表示。 | 6735 6736**返回值:** 6737 6738| 类型 | 说明 | 6739| ------------------- | ------------------------ | 6740| Promise<void> | 无返回结果的Promise对象。 | 6741 6742**错误码:** 6743 6744以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6745 6746| 错误码ID | 错误信息 | 6747| -------- | ------------------------------ | 6748| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6749| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6750| 1300002 | This window state is abnormal. | 6751 6752**示例:** 6753 6754```ts 6755import { window } from '@kit.ArkUI'; 6756import { BusinessError } from '@kit.BasicServicesKit'; 6757 6758let windowClass: window.Window | undefined = undefined; 6759try { 6760 let promise = window.getLastWindow(this.context); 6761 promise.then((data) => { 6762 windowClass = data; 6763 let title = "title"; 6764 windowClass.setWindowTitle(title).then(() => { 6765 console.info('Succeeded in setting the window title.'); 6766 }).catch((err: BusinessError) => { 6767 console.error(`Failed to set the window title. Cause code: ${err.code}, message: ${err.message}`); 6768 }); 6769 }).catch((err: BusinessError) => { 6770 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 6771 }); 6772} catch (exception) { 6773 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`); 6774} 6775``` 6776 6777### setWindowTitleMoveEnabled<sup>14+</sup> 6778 6779setWindowTitleMoveEnabled(enabled: boolean): void 6780 6781禁止/使能主窗或子窗标题栏默认移动窗口和双击最大化的功能,当禁用标题栏默认移动窗口和双击最大化的功能时,可使用[startMoving()](#startmoving14)在应用热区中发起拖拽移动,使用[maximize()](#maximize12)实现最大化功能。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 6782 6783<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 6784 6785**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 6786 6787**系统能力:** SystemCapability.Window.SessionManager 6788 6789**参数:** 6790 6791| 参数名 | 类型 | 必填 | 说明 | 6792| --------- | ------- | ---- | --------------------------------------------- | 6793| enabled | boolean | 是 | 是否使能标题栏默认移动窗口和双击最大化功能,true表示使能,false表示不使能。| 6794 6795**错误码:** 6796 6797以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6798 6799| 错误码ID | 错误信息 | 6800| -------- | ------------------------------ | 6801| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6802| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6803| 1300002 | This window state is abnormal. | 6804| 1300004 | Unauthorized operation. | 6805 6806**示例:** 6807 6808```ts 6809windowClass.setUIContent('pages/WindowPage').then(() => { 6810 try { 6811 let enabled = false; 6812 windowClass.setWindowTitleMoveEnabled(enabled); 6813 } catch (exception) { 6814 console.error(`Failed to set the window title move enabled. Cause code: ${exception.code}, message: ${exception.message}`); 6815 } 6816}) 6817``` 6818 6819### setSubWindowModal<sup>12+</sup> 6820 6821setSubWindowModal(isModal: boolean): Promise<void> 6822 6823设置子窗的模态属性是否启用,使用Promise异步回调。 6824 6825子窗口调用该接口时,设置子窗口模态属性是否启用。启用子窗口模态属性后,其父级窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态属性被禁用。 6826 6827子窗口之外的窗口调用该接口时,会报错。 6828 6829**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6830 6831**系统能力:** SystemCapability.Window.SessionManager 6832 6833**参数:** 6834 6835| 参数名 | 类型 | 必填 | 说明 | 6836| --------- | ------- | ---- | --------------------------------------------- | 6837| isModal | boolean | 是 | 设置子窗口模态属性是否启用,true为启用,false为不启用。 | 6838 6839 6840**返回值:** 6841 6842| 类型 | 说明 | 6843| ------------------- | ------------------------ | 6844| Promise<void> | 无返回结果的Promise对象。 | 6845 6846**错误码:** 6847 6848以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6849 6850| 错误码ID | 错误信息 | 6851| -------- | ------------------------------ | 6852| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6853| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6854| 1300002 | This window state is abnormal. | 6855| 1300004 | Unauthorized operation. | 6856 6857**示例:** 6858 6859```ts 6860// EntryAbility.ets 6861import { UIAbility } from '@kit.AbilityKit'; 6862import { BusinessError } from '@kit.BasicServicesKit'; 6863 6864export default class EntryAbility extends UIAbility { 6865 // ... 6866 onWindowStageCreate(windowStage: window.WindowStage): void { 6867 console.info('onWindowStageCreate'); 6868 let windowClass: window.Window | undefined = undefined; 6869 // 创建子窗 6870 try { 6871 let subWindow = windowStage.createSubWindow("testSubWindow"); 6872 subWindow.then((data) => { 6873 if (data == null) { 6874 console.error("Failed to create the subWindow. Cause: The data is empty"); 6875 return; 6876 } 6877 windowClass = data; 6878 let promise = windowClass.setSubWindowModal(true); 6879 promise.then(() => { 6880 console.info('Succeeded in setting subwindow modal'); 6881 }).catch((err: BusinessError) => { 6882 console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`); 6883 }); 6884 }); 6885 } catch (exception) { 6886 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 6887 } 6888 } 6889} 6890``` 6891 6892### setSubWindowModal<sup>14+</sup> 6893 6894setSubWindowModal(isModal: boolean, modalityType: ModalityType): Promise<void> 6895 6896设置子窗的模态类型,使用Promise异步回调。 6897 6898当子窗口模态类型为模窗口子窗时,其父级窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态类型被禁用。 6899 6900当子窗口模态类型为模应用子窗时,其父级窗口与该应用其他实例的窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态类型被禁用。 6901 6902此接口仅支持设置子窗口模态类型,当需要禁用子窗口模态属性时,建议使用[setSubWindowModal<sup>12+</sup>](#setsubwindowmodal12)。 6903 6904子窗口之外的窗口调用该接口时,会报错。 6905 6906**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 6907 6908**系统能力:** SystemCapability.Window.SessionManager 6909 6910**参数:** 6911 6912| 参数名 | 类型 | 必填 | 说明 | 6913| --------- | ------- | ---- | --------------------------------------------- | 6914| isModal | boolean | 是 | 设置子窗口模态属性是否启用,true为启用,false为不启用。当前仅支持设置为true。 | 6915| modalityType | [ModalityType](#modalitytype14) | 是 | 子窗口模态类型。 | 6916 6917**返回值:** 6918 6919| 类型 | 说明 | 6920| ------------------- | ------------------------ | 6921| Promise<void> | 无返回结果的Promise对象。 | 6922 6923**错误码:** 6924 6925以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6926 6927| 错误码ID | 错误信息 | 6928| -------- | ------------------------------ | 6929| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6930| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6931| 1300002 | This window state is abnormal. | 6932| 1300004 | Unauthorized operation. | 6933 6934**示例:** 6935 6936```ts 6937// EntryAbility.ets 6938import { UIAbility } from '@kit.AbilityKit'; 6939import { BusinessError } from '@kit.BasicServicesKit'; 6940import { window } from '@kit.ArkUI'; 6941 6942export default class EntryAbility extends UIAbility { 6943 // ... 6944 onWindowStageCreate(windowStage: window.WindowStage): void { 6945 console.info('onWindowStageCreate'); 6946 let windowClass: window.Window | undefined = undefined; 6947 // 创建子窗 6948 try { 6949 let subWindow = windowStage.createSubWindow("testSubWindow"); 6950 subWindow.then((data) => { 6951 if (data == null) { 6952 console.error("Failed to create the subWindow. Cause: The data is empty"); 6953 return; 6954 } 6955 windowClass = data; 6956 let promise = windowClass.setSubWindowModal(true, window.ModalityType.WINDOW_MODALITY); 6957 promise.then(() => { 6958 console.info('Succeeded in setting subwindow modal'); 6959 }).catch((err: BusinessError) => { 6960 console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`); 6961 }); 6962 }); 6963 } catch (exception) { 6964 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 6965 } 6966 } 6967} 6968``` 6969 6970### setWindowDecorHeight<sup>11+</sup> 6971 6972setWindowDecorHeight(height: number): void 6973 6974<!--RP1--> 6975设置窗口的标题栏高度,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 6976<!--RP1End--> 6977 6978当主窗口进入全屏沉浸状态时,此时鼠标Hover到窗口标题栏热区时,会显示悬浮标题栏,悬浮标题栏高度固定为37vp。 6979 6980**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6981 6982**系统能力:** SystemCapability.Window.SessionManager 6983 6984**参数:** 6985 6986| 参数名 | 类型 | 必填 | 说明 | 6987| ------ | ------ | ---- | ------------------------------------------------------------ | 6988| height | number | 是 |设置的窗口标题栏高度,仅支持具有窗口标题栏的窗口。该参数为整数,浮点数输入将向下取整,取值范围为[37,112],范围外为非法参数,单位为vp。 | 6989 6990**错误码:** 6991 6992以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6993 6994| 错误码ID | 错误信息 | 6995| -------- | ------------------------------ | 6996| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6997| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6998| 1300002 | This window state is abnormal. | 6999 7000**示例:** 7001 7002```ts 7003windowClass.setUIContent('pages/WindowPage').then(() => { 7004 let height: number = 50; 7005 try { 7006 windowClass?.setWindowDecorHeight(height); 7007 console.info(`Succeeded in setting the height of window decor: ${height}`); 7008 } catch (exception) { 7009 console.error(`Failed to set the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 7010 } 7011}) 7012``` 7013 7014### setDecorButtonStyle<sup>14+</sup> 7015 7016setDecorButtonStyle(dectorStyle: DecorButtonStyle): void 7017 7018设置装饰栏按钮样式,仅对主窗和使能窗口标题的子窗生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 7019 7020<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7021 7022**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 7023 7024**系统能力:** SystemCapability.Window.SessionManager 7025 7026**参数:** 7027 7028| 参数名 | 类型 | 必填 | 说明 | 7029| --------- | ------- | ---- | --------------------------------------------- | 7030| dectorStyle | [DecorButtonStyle](#decorbuttonstyle14) | 是 | 要设置的装饰栏按钮样式。 | 7031 7032**错误码:** 7033 7034以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7035 7036| 错误码ID | 错误信息 | 7037| -------- | ------------------------------ | 7038| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7039| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7040| 1300002 | This window state is abnormal. | 7041| 1300004 | Unauthorized operation. | 7042 7043**示例:** 7044 7045```ts 7046import { ConfigurationConstant } from '@kit.AbilityKit'; 7047 7048windowClass.setUIContent('pages/WindowPage').then(() => { 7049 try { 7050 let colorMode : ConfigurationConstant.ColorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT; 7051 let style: window.DecorButtonStyle = { 7052 colorMode: colorMode, 7053 buttonBackgroundSize: 24, 7054 spacingBetweenButtons: 12, 7055 closeButtonRightMargin: 20 7056 }; 7057 windowClass.setDecorButtonStyle(style); 7058 console.info('Succeeded in setting the style of button. Data: ' + JSON.stringify(style)); 7059 } catch (exception) { 7060 console.error(`Failed to set the style of button. Cause code: ${exception.code}, message: ${exception.message}`); 7061 } 7062}) 7063``` 7064 7065### getDecorButtonStyle<sup>14+</sup> 7066 7067getDecorButtonStyle(): DecorButtonStyle 7068 7069获取装饰栏按钮样式,仅对主窗和使能窗口标题的子窗生效。 7070 7071<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7072 7073**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 7074 7075**系统能力:** SystemCapability.Window.SessionManager 7076 7077**返回值:** 7078 7079| 类型 | 说明 | 7080| ------------------------------------- | ------------------------------------------------------------ | 7081| [DecorButtonStyle](#decorbuttonstyle14) | 返回当前窗口装饰栏上的按钮样式,窗口装饰按钮区域位于窗口的右上角。 | 7082 7083**错误码:** 7084 7085以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7086 7087| 错误码ID | 错误信息 | 7088| -------- | ------------------------------ | 7089| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7090| 1300002 | This window state is abnormal. | 7091| 1300003 | This window manager service works abnormally. | 7092| 1300004 | Unauthorized operation. | 7093 7094**示例:** 7095 7096```ts 7097try { 7098 let decorButtonStyle = windowClass.getDecorButtonStyle(); 7099 console.info('Succeeded in getting the style of button. Data: ' + JSON.stringify(decorButtonStyle)); 7100} catch (exception) { 7101 console.error(`Failed to get the style of button. Cause code: ${exception.code}, message: ${exception.message}`); 7102} 7103``` 7104 7105### getWindowDecorHeight<sup>11+</sup> 7106 7107getWindowDecorHeight(): number 7108 7109<!--RP2--> 7110获取窗口的标题栏高度,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 7111<!--RP2End--> 7112 7113**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7114 7115**系统能力:** SystemCapability.Window.SessionManager 7116 7117**返回值:** 7118 7119| 类型 | 说明 | 7120| ------ | ------------------------------------------------------------ | 7121| number | 返回的窗口标题栏高度。该参数为整数,取值范围为[37,112],单位为vp。 | 7122 7123**错误码:** 7124 7125以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7126 7127| 错误码ID | 错误信息 | 7128| -------- | ------------------------------ | 7129| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7130| 1300002 | This window state is abnormal. | 7131 7132**示例:** 7133 7134```ts 7135windowClass.setUIContent('pages/WindowPage').then(() => { 7136 try { 7137 let height = windowClass?.getWindowDecorHeight(); 7138 console.info(`Succeeded in getting the height of window decor: ${height}`); 7139 } catch (exception) { 7140 console.error(`Failed to get the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 7141 } 7142}) 7143``` 7144 7145### getTitleButtonRect<sup>11+</sup> 7146 7147getTitleButtonRect(): TitleButtonRect 7148 7149获取主窗口或启用装饰的子窗口的标题栏上的最小化、最大化、关闭按钮矩形区域。 7150 7151**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7152 7153**系统能力:** SystemCapability.Window.SessionManager 7154 7155**返回值:** 7156 7157| 类型 | 说明 | 7158| ------------------------------------- | ------------------------------------------------------------ | 7159| [TitleButtonRect](#titlebuttonrect11) | 标题栏上的最小化、最大化、关闭按钮矩形区域,该区域位置坐标相对窗口右上角。 | 7160 7161**错误码:** 7162 7163以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7164 7165| 错误码ID | 错误信息 | 7166| -------- | ------------------------------ | 7167| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7168| 1300002 | This window state is abnormal. | 7169 7170**示例:** 7171 7172```ts 7173// EntryAbility.ets 7174import { UIAbility } from '@kit.AbilityKit'; 7175import { BusinessError } from '@kit.BasicServicesKit'; 7176 7177export default class EntryAbility extends UIAbility { 7178 // ... 7179 onWindowStageCreate(windowStage: window.WindowStage): void { 7180 console.info('onWindowStageCreate'); 7181 let windowClass: window.Window | undefined = undefined; 7182 windowStage.getMainWindow((err: BusinessError, data) => { 7183 const errCode: number = err.code; 7184 if (errCode) { 7185 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7186 return; 7187 } 7188 windowClass = data; 7189 try { 7190 let titleButtonArea = windowClass.getTitleButtonRect(); 7191 console.info('Succeeded in obtaining the area of title buttons. Data: ' + JSON.stringify(titleButtonArea)); 7192 } catch (exception) { 7193 console.error(`Failed to get the area of title buttons. Cause code: ${exception.code}, message: ${exception.message}`); 7194 } 7195 }); 7196 } 7197} 7198``` 7199 7200### getWindowStatus<sup>12+</sup> 7201 7202getWindowStatus(): WindowStatusType 7203 7204获取当前应用窗口的模式。 7205 7206> **说明:** 7207> 7208> 在2in1设备上调用本接口时,在窗口最大化状态时返回值对应为WindowStatusType::FULL_SCREEN。 7209> 7210> 若想在2in1设备上区分当前窗口状态为最大化还是全屏,可在窗口状态为WindowStatusType::FULL_SCREEN的情况下,再调用[getImmersiveModeEnabledState()](#getimmersivemodeenabledstate12) 接口进行进一步判断,到底是最大化状态还是全屏状态。若接口返回true则表示当前窗口为全屏状态,若接口返回false则表示当前窗口为最大化状态。 7211 7212**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7213 7214**系统能力:** SystemCapability.Window.SessionManager 7215 7216**返回值:** 7217 7218| 类型 | 说明 | 7219| ------------------------------ | ----------------------------------------| 7220| [WindowStatusType](#windowstatustype11) | 当前窗口模式。 | 7221 7222**错误码:** 7223 7224以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7225 7226| 错误码ID | 错误信息 | 7227| ------- | ------------------------------ | 7228| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7229| 1300002 | This window state is abnormal. | 7230 7231**示例:** 7232 7233```ts 7234try { 7235 let windowStatusType = windowClass.getWindowStatus(); 7236} catch (exception) { 7237 console.error(`Failed to obtain the window status of window. Cause code: ${exception.code}, message: ${exception.message}`); 7238} 7239``` 7240 7241### isFocused<sup>12+</sup> 7242 7243isFocused(): boolean 7244 7245判断当前窗口是否已获焦。 7246 7247**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7248 7249**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7250 7251**返回值:** 7252 7253| 类型 | 说明 | 7254| ------- | ------------------------------------------------------------------ | 7255| boolean | 当前窗口是否已获焦。true表示当前窗口已获焦,false则表示当前窗口未获焦。 | 7256 7257**错误码:** 7258 7259以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 7260 7261| 错误码ID | 错误信息 | 7262| ------- | ------------------------------ | 7263| 1300002 | This window state is abnormal. | 7264 7265**示例:** 7266 7267```ts 7268try { 7269 let focus = windowClass.isFocused(); 7270 console.info('Succeeded in checking whether the window is focused. Data: ' + JSON.stringify(focus)); 7271} catch (exception) { 7272 console.error(`Failed to check whether the window is focused. Cause code: ${exception.code}, message: ${exception.message}`); 7273} 7274``` 7275 7276### createSubWindowWithOptions<sup>12+</sup> 7277 7278createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise<Window> 7279 7280创建主窗口、子窗口或悬浮窗下的子窗口,使用Promise异步回调。 7281 7282<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7283 7284**模型约束:** 此接口仅可在Stage模型下使用。 7285 7286**系统能力:** SystemCapability.Window.SessionManager 7287 7288**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7289 7290**参数:** 7291 7292| 参数名 | 类型 | 必填 | 说明 | 7293| ------ | ------ | ---- | -------------- | 7294| name | string | 是 | 子窗口的名字。 | 7295| options | [SubWindowOptions](#subwindowoptions11) | 是 | 子窗口参数。 | 7296 7297**返回值:** 7298 7299| 类型 | 说明 | 7300| -------------------------------- | ------------------------------------------------ | 7301| Promise<[Window](#window)> | Promise对象。返回当前Window下创建的子窗口对象。 | 7302 7303**错误码:** 7304 7305以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7306 7307| 错误码ID | 错误信息 | 7308| ------- | ------------------------------ | 7309| 401 | Parameter error. Possible cause: Incorrect parameter types. | 7310| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7311| 1300002 | This window state is abnormal. | 7312| 1300003 | This window manager service works abnormally. | 7313| 1300004 | Unauthorized operation. | 7314 7315**示例:** 7316 7317```ts 7318import { BusinessError } from '@kit.BasicServicesKit'; 7319 7320try { 7321 let options : window.SubWindowOptions = { 7322 title: 'title', 7323 decorEnabled: true, 7324 isModal: true 7325 }; 7326 let promise = windowClass.createSubWindowWithOptions('mySubWindow', options); 7327 promise.then((data) => { 7328 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 7329 }).catch((err: BusinessError) => { 7330 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 7331 }); 7332} catch (exception) { 7333 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 7334} 7335``` 7336 7337### setWindowTitleButtonVisible<sup>14+</sup> 7338 7339setWindowTitleButtonVisible(isMaximizeButtonVisible: boolean, isMinimizeButtonVisible: boolean, isCloseButtonVisible?: boolean): void 7340 7341设置主窗标题栏上的最大化、最小化、关闭按钮是否可见。 7342 7343<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7344 7345**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 7346 7347**系统能力:** SystemCapability.Window.SessionManager 7348 7349**参数:** 7350 7351| 参数名 | 类型 | 必填 | 说明 | 7352| --------- | ------- | ---- | --------------------------------------------- | 7353| isMaximizeButtonVisible | boolean | 是 | 设置最大化按钮是否可见,true为可见,false为隐藏。如果最大化按钮隐藏,那么在最大化场景下,也隐藏对应的还原按钮。 | 7354| isMinimizeButtonVisible | boolean | 是 | 设置最小化按钮是否可见,true为可见,false为隐藏。 | 7355| isCloseButtonVisible | boolean | 否 | 设置关闭按钮是否可见,true为可见,false为隐藏,默认值true。 | 7356 7357**错误码:** 7358 7359以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7360 7361| 错误码ID | 错误信息 | 7362| -------- | ------------------------------ | 7363| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7364| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7365| 1300002 | This window state is abnormal. | 7366| 1300004 | Unauthorized operation. | 7367 7368**示例:** 7369 7370```ts 7371// EntryAbility.ets 7372import { UIAbility } from '@kit.AbilityKit'; 7373import { BusinessError } from '@kit.BasicServicesKit'; 7374import { window } from '@kit.ArkUI'; 7375 7376export default class EntryAbility extends UIAbility { 7377 onWindowStageCreate(windowStage: window.WindowStage): void { 7378 // 加载主窗口对应的页面 7379 windowStage.loadContent('pages/Index', (err) => { 7380 let mainWindow: window.Window | undefined = undefined; 7381 // 获取应用主窗口。 7382 windowStage.getMainWindow().then( 7383 data => { 7384 mainWindow = data; 7385 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 7386 // 调用setWindowTitleButtonVisible接口,隐藏主窗标题栏最大化、最小化、关闭按钮。 7387 mainWindow.setWindowTitleButtonVisible(false, false, false); 7388 } 7389 ).catch((err: BusinessError) => { 7390 if(err.code){ 7391 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7392 } 7393 }); 7394 }); 7395 } 7396} 7397``` 7398 7399### setWindowTopmost<sup>14+</sup> 7400 7401setWindowTopmost(isWindowTopmost: boolean): Promise<void> 7402 7403应用主窗口调用,实现将窗口置于其他应用窗口之上不被遮挡,使用Promise异步回调。 7404 7405应用可通过自定义快捷键实现主窗口的置顶和取消置顶。 7406 7407<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7408 7409**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 7410 7411**系统能力:** SystemCapability.Window.SessionManager 7412 7413**需要权限:** ohos.permission.WINDOW_TOPMOST 7414 7415**参数:** 7416 7417| 参数名 | 类型 | 必填 | 说明 | 7418| --------- | ------- | ---- | --------------------------------------------- | 7419| isWindowTopmost | boolean | 是 | 设置主窗口置顶,true为置顶,false为取消置顶。 | 7420 7421 7422**错误码:** 7423 7424以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7425 7426| 错误码ID | 错误信息 | 7427| -------- | ------------------------------ | 7428| 201 | Permission verification failed. The application does not have the permission required to call the API. | 7429| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7430| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7431| 1300002 | This window state is abnormal. | 7432| 1300004 | Unauthorized operation. | 7433 7434**示例:** 7435 7436```ts 7437// ets/pages/Index.ets 7438import { window } from '@kit.ArkUI'; 7439import { common } from '@kit.AbilityKit'; 7440import { BusinessError } from '@kit.BasicServicesKit'; 7441 7442const context = (getContext(this) as common.UIAbilityContext); 7443let windowClass: window.Window | undefined; 7444let keyUpEventAry: string[] = []; 7445 7446@Entry 7447@Component 7448struct Index { 7449 build() { 7450 RelativeContainer() { 7451 Button("窗口置顶") 7452 .onClick(() => { 7453 try { 7454 let promiseCtx = window.getLastWindow(context); 7455 promiseCtx.then((data) => { 7456 windowClass = data; 7457 // true:窗口置顶,false:取消窗口置顶 7458 let isWindowTopmost: boolean = true; 7459 let promiseTopmost = windowClass.setWindowTopmost(isWindowTopmost); 7460 promiseTopmost.then(() => { 7461 console.info('Succeeded in setting the main window to be topmost.'); 7462 }).catch((err: BusinessError) => { 7463 console.error(`Failed to set the main window to be topmost. Cause code: ${err.code}, message: ${err.message}`); 7464 }); 7465 }) 7466 } catch (exception) { 7467 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`) 7468 } 7469 }) 7470 } 7471 .height('100%') 7472 .width('100%') 7473 .onKeyEvent((event) => { 7474 if(event) { 7475 if(event.type === KeyType.Down) { 7476 keyUpEventAry = []; 7477 } 7478 if(event.type === KeyType.Up) { 7479 keyUpEventAry.push(event.keyText); 7480 // 自定义快捷键 ctrl+T 执行主窗口置顶、取消置顶的操作 7481 if(windowClass && keyUpEventAry.includes('KEYCODE_CTRL_LEFT') && keyUpEventAry.includes('KEYCODE_T')) { 7482 let isWindowTopmost: boolean = false; 7483 windowClass.setWindowTopmost(isWindowTopmost); 7484 } 7485 } 7486 } 7487 }) 7488 } 7489} 7490``` 7491 7492### raiseToAppTop<sup>14+</sup> 7493 7494raiseToAppTop(): Promise<void> 7495 7496应用子窗口调用,提升应用子窗口到顶层,只在当前应用同一个父窗口下的相同类型子窗范围内生效。使用Promise异步回调。 7497 7498**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7499 7500**返回值:** 7501 7502| 类型 | 说明 | 7503| ------------------- | ------------------------- | 7504| Promise<void> | 无返回结果的Promise对象。 | 7505 7506**错误码:** 7507 7508以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7509 7510| 错误码ID | 错误信息 | 7511| ------- | ------------------------------ | 7512| 1300002 | This window state is abnormal. | 7513| 1300003 | This window manager service works abnormally. | 7514| 1300004 | Unauthorized operation. | 7515| 1300009 | The parent window is invalid. | 7516 7517**示例:** 7518 7519```ts 7520import { BusinessError } from '@kit.BasicServicesKit'; 7521 7522let promise = windowClass.raiseToAppTop(); 7523promise.then(() => { 7524 console.info('Succeeded in raising the window to app top.'); 7525}).catch((err: BusinessError) => { 7526 console.error(`Failed to raise the window to app top. Cause code: ${err.code}, message: ${err.message}`); 7527}); 7528``` 7529 7530### setRaiseByClickEnabled<sup>14+</sup> 7531 7532setRaiseByClickEnabled(enable: boolean): Promise<void> 7533 7534禁止/使能子窗点击抬升功能。使用Promise异步回调。 7535 7536通常来说,点击一个子窗口,会将该子窗口显示抬升到应用内同一个父窗口下同类型子窗口的最上方,如果设置为false,那么点击子窗口的时候,不会将该子窗口进行抬升,而是保持不变。 7537 7538**系统能力:** SystemCapability.Window.SessionManager 7539 7540**参数:** 7541 7542| 参数名 | 类型 | 必填 | 说明 | 7543| -------- | ------------------------- | ---- | ---------- | 7544| enable | boolean | 是 | 设置子窗口点击抬升功能是否使能,true表示使能,false表示禁止。 | 7545 7546**返回值:** 7547 7548| 类型 | 说明 | 7549| ------------------- | ------------------------- | 7550| Promise<void> | 无返回结果的Promise对象。 | 7551 7552**错误码:** 7553 7554以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7555 7556| 错误码ID | 错误信息 | 7557| ------- | ------------------------------ | 7558| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7559| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7560| 1300002 | This window state is abnormal. | 7561| 1300003 | This window manager service works abnormally. | 7562| 1300004 | Unauthorized operation. | 7563| 1300009 | The parent window is invalid. | 7564 7565**示例:** 7566 7567```ts 7568// EntryAbility.ets 7569import { UIAbility } from '@kit.AbilityKit'; 7570import { BusinessError } from '@kit.BasicServicesKit'; 7571 7572export default class EntryAbility extends UIAbility { 7573 // ... 7574 onWindowStageCreate(windowStage: window.WindowStage): void { 7575 console.info('onWindowStageCreate'); 7576 let windowClass: window.Window | undefined = undefined; 7577 // 创建子窗 7578 try { 7579 let subWindow = windowStage.createSubWindow("testSubWindow"); 7580 subWindow.then((data) => { 7581 if (data == null) { 7582 console.error("Failed to create the subWindow. Cause: The data is empty"); 7583 return; 7584 } 7585 windowClass = data; 7586 let enabled = false; 7587 let promise = windowClass.setRaiseByClickEnabled(enabled); 7588 promise.then(()=> { 7589 console.info('Succeeded in disabling the raise-by-click function.'); 7590 }).catch((err: BusinessError)=>{ 7591 console.error(`Failed to disable the raise-by-click function. Cause code: ${err.code}, message: ${err.message}`); 7592 }); 7593 }); 7594 } catch (exception) { 7595 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 7596 } 7597 } 7598} 7599``` 7600 7601### enableLandscapeMultiWindow<sup>12+</sup> 7602 7603enableLandscapeMultiWindow(): Promise<void> 7604 7605应用部分界面支持横向布局时,在进入该界面时使能,使能后可支持进入横向多窗。不建议竖向布局界面使用。 7606 7607此接口只对应用主窗口生效,且需要在module.json5配置文件中[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中配置preferMultiWindowOrientation属性为"landscape_auto"。 7608 7609**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7610 7611**系统能力:** SystemCapability.Window.SessionManager 7612 7613**返回值:** 7614 7615| 类型 | 说明 | 7616| ------------------- | ------------------------- | 7617| Promise<void> | 无返回结果的Promise对象。 | 7618 7619**错误码:** 7620 7621以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 7622 7623| 错误码ID | 错误信息 | 7624| ------- | -------------------------------------------- | 7625| 1300002 | This window state is abnormal. | 7626| 1300003 | This window manager service works abnormally. | 7627 7628**示例:** 7629 7630```ts 7631// EntryAbility.ets 7632import { UIAbility } from '@kit.AbilityKit'; 7633import { BusinessError } from '@kit.BasicServicesKit'; 7634import { window } from '@kit.ArkUI'; 7635 7636export default class EntryAbility extends UIAbility { 7637 // ... 7638 onWindowStageCreate(windowStage: window.WindowStage): void { 7639 console.info('onWindowStageCreate'); 7640 let windowClass: window.Window | undefined = undefined; 7641 windowStage.getMainWindow((err: BusinessError, data) => { 7642 const errCode: number = err.code; 7643 if (errCode) { 7644 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7645 return; 7646 } 7647 windowClass = data; 7648 let promise = windowClass.enableLandscapeMultiWindow(); 7649 promise.then(() => { 7650 console.info('Succeeded in making multi-window become landscape.'); 7651 }).catch((err: BusinessError) => { 7652 console.error(`Failed to make multi-window become landscape. Cause code: ${err.code}, message: ${err.message}`); 7653 }); 7654 }); 7655 } 7656} 7657``` 7658 7659### disableLandscapeMultiWindow<sup>12+</sup> 7660 7661disableLandscapeMultiWindow(): Promise<void> 7662 7663应用部分界面支持横向布局时,在退出该界面时去使能,去使能后不支持进入横向多窗。 7664 7665此接口只对应用主窗口生效,且需要在module.json5配置文件中[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中配置preferMultiWindowOrientation属性为"landscape_auto"。 7666 7667**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7668 7669**系统能力:** SystemCapability.Window.SessionManager 7670 7671**返回值:** 7672 7673| 类型 | 说明 | 7674| ------------------- | ------------------------- | 7675| Promise<void> | 无返回结果的Promise对象。 | 7676 7677**错误码:** 7678 7679以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 7680 7681| 错误码ID | 错误信息 | 7682| ------- | -------------------------------------------- | 7683| 1300002 | This window state is abnormal. | 7684| 1300003 | This window manager service works abnormally. | 7685 7686**示例:** 7687 7688```ts 7689// EntryAbility.ets 7690import { UIAbility } from '@kit.AbilityKit'; 7691import { BusinessError } from '@kit.BasicServicesKit'; 7692import { window } from '@kit.ArkUI'; 7693 7694export default class EntryAbility extends UIAbility { 7695 // ... 7696 onWindowStageCreate(windowStage: window.WindowStage): void { 7697 console.info('onWindowStageCreate'); 7698 let windowClass: window.Window | undefined = undefined; 7699 windowStage.getMainWindow((err: BusinessError, data) => { 7700 const errCode: number = err.code; 7701 if (errCode) { 7702 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7703 return; 7704 } 7705 windowClass = data; 7706 let promise = windowClass.disableLandscapeMultiWindow(); 7707 promise.then(() => { 7708 console.info('Succeeded in making multi-window become not landscape.'); 7709 }).catch((err: BusinessError) => { 7710 console.error(`Failed to make multi-window become not landscape. Cause code: ${err.code}, message: ${err.message}`); 7711 }); 7712 }); 7713 } 7714} 7715``` 7716 7717### setDialogBackGestureEnabled<sup>12+</sup> 7718 7719setDialogBackGestureEnabled(enabled: boolean): Promise<void> 7720 7721设置模态窗口是否响应手势返回事件,非模态窗口调用返回错误码。 7722 7723**系统能力**:SystemCapability.Window.SessionManager 7724 7725**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7726 7727**参数:** 7728 7729| 参数名 | 类型 | 必填 | 说明 | 7730| ---------- | ------- | ---- | ------------------------------------------------------------ | 7731| enabled | boolean | 是 | 是否响应手势返回事件。<br>true表示响应手势返回事件,触发onBackPress回调;false表示不响应手势返回事件,不触发onBackPress回调。</br> | 7732 7733**返回值:** 7734 7735| 类型 | 说明 | 7736| ------------------- | ------------------------- | 7737| Promise<void> | 无返回结果的Promise对象。 | 7738 7739**错误码:** 7740 7741以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7742 7743| 错误码ID | 错误信息 | 7744| ------- | -------------------------------------------- | 7745| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7746| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7747| 1300002 | This window state is abnormal. | 7748| 1300003 | This window manager service works abnormally. | 7749| 1300004 | Unauthorized operation. | 7750 7751**示例:** 7752 7753```ts 7754// EntryAbility.ets 7755import { UIAbility } from '@kit.AbilityKit'; 7756import { BusinessError } from '@kit.BasicServicesKit'; 7757 7758export default class EntryAbility extends UIAbility { 7759 onWindowStageCreate(windowStage: window.WindowStage): void { 7760 console.info('onWindowStageCreate'); 7761 let windowClass: window.Window | undefined = undefined; 7762 let config: window.Configuration = { 7763 name: "test", 7764 windowType: window.WindowType.TYPE_DIALOG, 7765 ctx: this.context 7766 }; 7767 try { 7768 window.createWindow(config, (err: BusinessError, data) => { 7769 const errCode: number = err.code; 7770 if (errCode) { 7771 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 7772 return; 7773 } 7774 windowClass = data; 7775 windowClass.setUIContent("pages/Index"); 7776 let enabled = true; 7777 let promise = windowClass.setDialogBackGestureEnabled(enabled); 7778 promise.then(() => { 7779 console.info('Succeeded in setting dialog window to respond back gesture.'); 7780 }).catch((err: BusinessError) => { 7781 console.error(`Failed to set dialog window to respond back gesture. Cause code: ${err.code}, message: ${err.message}`); 7782 }); 7783 }); 7784 } catch (exception) { 7785 console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`); 7786 } 7787 } 7788} 7789``` 7790 7791```ts 7792// ets/pages/Index.ets 7793@Entry 7794@Component 7795struct Index { 7796 @State message: string = 'Hello World' 7797 build() { 7798 RelativeContainer() { 7799 Text(this.message) 7800 .id('HelloWorld') 7801 .fontSize(50) 7802 .fontWeight(FontWeight.Bold) 7803 } 7804 .height('100%') 7805 .width('100%') 7806 } 7807 7808 onBackPress(): boolean | void { 7809 console.info('Succeeded in setting dialog window to respond back gesture.'); 7810 return true; 7811 } 7812} 7813``` 7814 7815### startMoving<sup>14+</sup> 7816 7817startMoving(): Promise<void> 7818 7819开始移动窗口,使用Promise异步回调。 7820 7821仅在[onTouch](./arkui-ts/ts-universal-events-touch.md#touchevent)事件(其中,事件类型必须为TouchType.Down)的回调方法中调用此接口才会有移动效果,成功调用此接口后,窗口将跟随鼠标移动。 7822 7823<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7824 7825仅对主窗、子窗、系统窗口生效,其它设备类型和窗口类型调用此接口会报错。 7826 7827**系统能力:** SystemCapability.Window.SessionManager 7828 7829**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 7830 7831**返回值:** 7832 7833| 类型 | 说明 | 7834| ------------------- | ------------------------- | 7835| Promise<void> | 无返回结果的Promise对象。 | 7836 7837**错误码:** 7838 7839以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7840 7841| 错误码ID | 错误信息 | 7842| -------- | -------------------------------------------- | 7843| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7844| 1300001 | Repeated operation. | 7845| 1300002 | This window state is abnormal. | 7846| 1300003 | This window manager service works abnormally. | 7847| 1300004 | Unauthorized operation. | 7848 7849**示例:** 7850 7851```ts 7852// ets/pages/Index.ets 7853import { BusinessError } from '@kit.BasicServicesKit'; 7854 7855@Entry 7856@Component 7857struct Index { 7858 build() { 7859 Row() { 7860 Column() { 7861 Blank('160') 7862 .color(Color.Blue) 7863 .onTouch((event: TouchEvent) => { 7864 if (event.type === TouchType.Down) { 7865 try { 7866 windowClass.startMoving().then(() => { 7867 console.info('Succeeded in starting moving window.') 7868 }).catch((err: BusinessError) => { 7869 console.error(`Failed to start moving. Cause code: ${err.code}, message: ${err.message}`); 7870 }); 7871 } catch (exception) { 7872 console.error(`Failed to start moving window. Cause code: ${exception.code}, message: ${exception.message}`); 7873 } 7874 } 7875 }) 7876 }.width('100%') 7877 }.height('100%').width('100%') 7878 } 7879} 7880``` 7881 7882### startMoving<sup>15+</sup> 7883 7884startMoving(offsetX: number, offsetY: number): Promise<void> 7885 7886指定鼠标在窗口内的位置并移动窗口,使用Promise异步回调。 7887 7888在同应用内窗口分合后,且鼠标保持按下状态直接移动新窗口,如果此时鼠标快速移动,窗口移动时鼠标可能会在窗口外。可以使用本接口指定窗口移动时鼠标在窗口内的位置,先移动窗口到鼠标位置,再开始移动窗口。 7889 7890仅在[onTouch](./arkui-ts/ts-universal-events-touch.md#touchevent)事件(其中,事件类型必须为TouchType.Down)的回调方法中调用此接口才会有移动效果,成功调用此接口后,窗口将跟随鼠标移动。 7891 7892<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7893 7894**系统能力:** SystemCapability.Window.SessionManager 7895 7896**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 7897 7898**参数:** 7899 7900| 参数名 | 类型 | 必填 | 说明 | 7901| --------- | --------- | ------- |----------------------------------------------------| 7902| offsetX | number | 是 | 窗口移动时预期鼠标位置相对窗口左上角的x轴偏移量,单位为px,该参数仅支持整数输入,浮点数向下取整。负值为非法参数,大于窗口宽度为非法参数,窗口宽度可以在窗口属性[WindowProperties](#windowproperties)中获取。 | 7903| offsetY | number | 是 | 窗口移动时预期鼠标位置相对窗口左上角的y轴偏移量,单位为px,该参数仅支持整数输入,浮点数向下取整。负值为非法参数,大于窗口高度为非法参数,窗口高度可以在窗口属性[WindowProperties](#windowproperties)中获取。 | 7904 7905**返回值:** 7906 7907| 类型 | 说明 | 7908| ------------------- |----------------------------| 7909| Promise<void> | 无返回结果的Promise对象。 | 7910 7911**错误码:** 7912 7913以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7914 7915| 错误码ID | 错误信息 | 7916| ---- | -------------------------------------------- | 7917| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7918| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7919| 1300001 | Repeated operation. | 7920| 1300002 | This window state is abnormal. | 7921| 1300003 | This window manager service works abnormally. | 7922| 1300004 | Unauthorized operation. | 7923 7924**示例:** 7925 7926```ts 7927// ets/pages/Index.ets 7928import { BusinessError } from '@kit.BasicServicesKit'; 7929 7930@Entry 7931@Component 7932struct Index { 7933 build() { 7934 Row() { 7935 Column() { 7936 Blank('160') 7937 .color(Color.Blue) 7938 .onTouch((event: TouchEvent) => { 7939 if (event.type === TouchType.Down) { 7940 try { 7941 windowClass.startMoving(100, 50).then(() => { 7942 console.info('Succeeded in starting moving window.') 7943 }).catch((err: BusinessError) => { 7944 console.error(`Failed to start moving. Cause code: ${err.code}, message: ${err.message}`); 7945 }); 7946 } catch (exception) { 7947 console.error(`Failed to start moving window. Cause code: ${exception.code}, message: ${exception.message}`); 7948 } 7949 } 7950 }) 7951 }.width('100%') 7952 }.height('100%').width('100%') 7953 } 7954} 7955``` 7956 7957### stopMoving<sup>15+</sup> 7958 7959stopMoving(): Promise<void> 7960 7961在窗口拖拽移动过程中,通过此接口来停止窗口移动,使用Promise异步回调。 7962 7963<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7964 7965**系统能力:** SystemCapability.Window.SessionManager 7966 7967**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 7968 7969**返回值:** 7970 7971| 类型 | 说明 | 7972| ------------------- | -------------------------| 7973| Promise<void> | 无返回结果的Promise对象。 | 7974 7975**错误码:** 7976 7977以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7978 7979| 错误码ID | 错误信息 | 7980| -------- | -------------------------------------------- | 7981| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7982| 1300002 | This window state is abnormal. | 7983| 1300003 | This window manager service works abnormally. | 7984| 1300004 | Unauthorized operation. | 7985 7986**示例:** 7987 7988```ts 7989// EntryAbility.ets 7990import { UIAbility } from '@kit.AbilityKit'; 7991import { window } from '@kit.ArkUI'; 7992import { BusinessError } from '@kit.BasicServicesKit'; 7993 7994export default class EntryAbility extends UIAbility { 7995 7996 onWindowStageCreate(windowStage: window.WindowStage) { 7997 try { 7998 let windowClass = windowStage.getMainWindowSync(); 7999 windowClass.on('windowRectChange', (data: window.RectChangeOptions) => { 8000 if (data.reason === window.RectChangeReason.MOVE) { 8001 windowClass.stopMoving().then(() => { 8002 console.info('Succeeded in stopping moving window.') 8003 }).catch((err: BusinessError) => { 8004 console.error(`Failed to stop moving. Cause code: ${err.code}, message: ${err.message}`); 8005 }); 8006 } 8007 }); 8008 } catch (exception) { 8009 console.error(`Failed to stop moving window. Cause code: ${exception.code}, message: ${exception.message}`); 8010 } 8011 } 8012} 8013``` 8014 8015### setGestureBackEnabled<sup>13+<sup> 8016 8017setGestureBackEnabled(enabled: boolean): Promise<void> 8018 8019设置当前窗口是否禁用返回手势功能,仅主窗全屏模式下生效,2in1设备下不生效。 8020禁用返回手势功能后,当前应用会禁用手势热区,侧滑返回功能失效;切换到其他应用或者回到桌面后,手势热区恢复,侧滑返回功能正常。 8021开启返回手势功能后,当前应用会恢复手势热区,侧滑返回功能正常。 8022 8023**系统能力:** SystemCapability.Window.SessionManager 8024 8025**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 8026 8027**参数:** 8028 8029| 参数名 | 类型 | 必填 | 说明 | 8030| ---------- | --------- | -------- | --------------------------------------------- | 8031| enabled | boolean | 是 | true时开启返回手势功能,false时禁用返回手势功能。 | 8032 8033**返回值:** 8034 8035| 类型 | 说明 | 8036| ------------------- | ------------------------- | 8037| Promise<void> | 无返回结果的Promise对象。 | 8038 8039**错误码:** 8040 8041以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8042 8043| 错误码ID | 错误信息 | 8044| -------- | ------------------------------------------------------------------------------------------------------------ | 8045| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8046| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8047| 1300002 | This window state is abnormal. | 8048| 1300003 | This window manager service works abnormally. | 8049| 1300004 | Unauthorized operation. | 8050 8051**示例:** 8052 8053```ts 8054// EntryAbility.ets 8055import { UIAbility } from '@kit.AbilityKit'; 8056import { BusinessError } from '@kit.BasicServicesKit'; 8057import { window } from '@kit.ArkUI'; 8058 8059export default class EntryAbility extends UIAbility { 8060 // ... 8061 onWindowStageCreate(windowStage: window.WindowStage): void { 8062 console.info('onWindowStageCreate'); 8063 let windowClass: window.Window | undefined = undefined; 8064 windowStage.getMainWindow((err: BusinessError, data) => { 8065 const errCode: number = err.code; 8066 if (errCode) { 8067 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8068 return; 8069 } 8070 windowClass = data; 8071 8072 // 设置当前窗口禁用返回手势功能 8073 try { 8074 let gestureBackEnabled: boolean = false; 8075 let promise = windowClass.setGestureBackEnabled(gestureBackEnabled); 8076 promise.then(() => { 8077 console.info(`Succeeded in setting gesture back disabled`); 8078 }).catch((err: BusinessError) => { 8079 console.error(`Failed to set gesture back disabled, Cause code: ${err.code}, message: ${err.message}`); 8080 }); 8081 } catch(exception) { 8082 console.error(`Failed to set gesture back disabled, Cause code: ${exception.code}, message: ${exception.message}`); 8083 } 8084 }); 8085 } 8086} 8087``` 8088 8089### isGestureBackEnabled<sup>13+<sup> 8090 8091isGestureBackEnabled(): boolean 8092 8093获取当前窗口是否禁用返回手势功能,仅主窗全屏模式下生效,2in1设备不生效。 8094 8095**系统能力:** SystemCapability.Window.SessionManager 8096 8097**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 8098 8099**返回值:** 8100 8101| 类型 | 说明 | 8102| ------------------- | --------------------------------------------- | 8103| boolean | 是否已经禁用返回手势。true表示未禁用返回手势功能,false表示已禁用返回手势功能。 | 8104 8105**错误码:** 8106 8107以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8108 8109| 错误码ID | 错误信息 | 8110| -------- | ------------------------------------------------------------------------------------------------------------ | 8111| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8112| 1300002 | This window state is abnormal. | 8113| 1300003 | This window manager service works abnormally. | 8114| 1300004 | Unauthorized operation. | 8115 8116**示例:** 8117 8118```ts 8119// EntryAbility.ets 8120import { UIAbility } from '@kit.AbilityKit'; 8121import { BusinessError } from '@kit.BasicServicesKit'; 8122import { window } from '@kit.ArkUI'; 8123 8124export default class EntryAbility extends UIAbility { 8125 // ... 8126 onWindowStageCreate(windowStage: window.WindowStage): void { 8127 console.info('onWindowStageCreate'); 8128 let windowClass: window.Window | undefined = undefined; 8129 windowStage.getMainWindow((err: BusinessError, data) => { 8130 const errCode: number = err.code; 8131 if (errCode) { 8132 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8133 return; 8134 } 8135 windowClass = data; 8136 8137 // 获取当前窗口是否禁用返回手势功能 8138 try { 8139 let gestureBackEnabled: boolean = windowClass.isGestureBackEnabled(); 8140 console.info(`Succeeded in obtaining gesture back enabled status: ${gestureBackEnabled}`); 8141 } catch (exception) { 8142 console.error(`Failed to get gesture back enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 8143 } 8144 }); 8145 } 8146} 8147``` 8148 8149### setExclusivelyHighlighted<sup>15+<sup> 8150 8151setExclusivelyHighlighted(exclusivelyHighlighted: boolean): Promise<void> 8152 8153设置窗口独占激活态属性。独占激活态表示窗口获焦时,会导致当前父子窗口链中处于激活态的其他窗口失去激活态。使用Promise异步回调。 8154 8155此接口对主窗、模态窗、dialog窗口不生效。 8156 8157**系统能力:** SystemCapability.Window.SessionManager 8158 8159**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 8160 8161**参数:** 8162 8163| 参数名 | 类型 | 必填 | 说明 | 8164| ----------- | ------- | -- | -------------------------------------------------------- | 8165| exclusivelyHighlighted | boolean | 是 | 窗口是否独占激活态。true表示独占激活态;false表示不独占激活态。 | 8166 8167**返回值:** 8168 8169| 类型 | 说明 | 8170| ---------------------- | ------------------------------------------------------------------------------------ | 8171| Promise<void> | 无返回结果的Promise对象。 | 8172 8173**错误码:** 8174 8175以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8176 8177| 错误码ID | 错误信息 | 8178| -------- | ------------------------------------------------------------------------------------------------------------ | 8179| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8180| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8181| 1300002 | This window state is abnormal. | 8182| 1300003 | This window manager service works abnormally. | 8183| 1300004 | Unauthorized operation. | 8184 8185**示例:** 8186 8187```ts 8188import { BusinessError } from '@kit.BasicServicesKit'; 8189 8190let exclusivelyHighlighted: boolean = true; 8191try { 8192 let promise = windowClass.setExclusivelyHighlighted(exclusivelyHighlighted); 8193 promise.then(() => { 8194 console.info('Succeeded in setting the window to be exclusively highlight.'); 8195 }).catch((err: BusinessError) => { 8196 console.error(`Failed to set the window to be exclusively highlight. Cause code: ${err.code}, message: ${err.message}`); 8197 }); 8198} catch (exception) { 8199 console.error(`Failed to set the window to be exclusively highlight. Cause code: ${exception.code}, message: ${exception.message}`); 8200} 8201``` 8202 8203### setWindowSystemBarProperties<sup>(deprecated)</sup> 8204 8205setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 8206 8207设置主窗口三键导航栏、状态栏的属性,使用callback异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 8208 8209子窗口调用后不生效。 8210 8211> **说明:** 8212> 8213> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowSystemBarProperties](#setwindowsystembarproperties9)。 8214 8215**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8216 8217**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8218 8219**参数:** 8220 8221| 参数名 | 类型 | 必填 | 说明 | 8222| ------------------- | ------------------------------------------- | ---- | ---------------------- | 8223| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 三键导航栏、状态栏的属性。 | 8224| callback | AsyncCallback<void> | 是 | 回调函数。 | 8225 8226**错误码:** 8227 8228以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8229 8230| 错误码ID | 错误信息 | 8231| -------- | ------------------------------------------------------------------------------------------------------------ | 8232| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8233| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8234| 1300002 | This window state is abnormal. | 8235| 1300003 | This window manager service works abnormally. | 8236 8237**示例:** 8238 8239```ts 8240// EntryAbility.ets 8241import { UIAbility } from '@kit.AbilityKit'; 8242import { BusinessError } from '@kit.BasicServicesKit'; 8243 8244export default class EntryAbility extends UIAbility { 8245 // ... 8246 onWindowStageCreate(windowStage: window.WindowStage): void { 8247 console.info('onWindowStageCreate'); 8248 let windowClass: window.Window | undefined = undefined; 8249 windowStage.getMainWindow((err: BusinessError, data) => { 8250 const errCode: number = err.code; 8251 if (errCode) { 8252 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8253 return; 8254 } 8255 windowClass = data; 8256 let SystemBarProperties: window.SystemBarProperties = { 8257 statusBarColor: '#ff00ff', 8258 navigationBarColor: '#00ff00', 8259 //以下两个属性从API Version8开始支持 8260 statusBarContentColor: '#ffffff', 8261 navigationBarContentColor: '#00ffff' 8262 }; 8263 try { 8264 windowClass.setWindowSystemBarProperties(SystemBarProperties, (err: BusinessError) => { 8265 const errCode: number = err.code; 8266 if (errCode) { 8267 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 8268 return; 8269 } 8270 console.info('Succeeded in setting the system bar properties.'); 8271 }); 8272 } catch (exception) { 8273 console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); 8274 } 8275 }); 8276 } 8277} 8278``` 8279 8280### setWindowSystemBarEnable<sup>(deprecated)</sup> 8281 8282setWindowSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 8283 8284设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用callback异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 8285 8286调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。 8287 8288> **说明:** 8289> 8290> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowSystemBarEnable](#setwindowsystembarenable9)。 8291 8292**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8293 8294**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8295 8296**参数:** 8297 8298| 参数名 | 类型 | 必填 | 说明 | 8299| -------- | ----------------------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------- | 8300| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 8301| callback | AsyncCallback<void> | 是 | 回调函数。 | 8302 8303**错误码:** 8304 8305以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8306 8307| 错误码ID | 错误信息 | 8308| -------- | ------------------------------------------------------------------------------------------------------------ | 8309| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8310| 1300002 | This window state is abnormal. | 8311| 1300003 | This window manager service works abnormally. | 8312 8313**示例:** 8314 8315```ts 8316// 此处以不显示三键导航栏、状态栏、底部导航条为例 8317// EntryAbility.ets 8318import { UIAbility } from '@kit.AbilityKit'; 8319import { BusinessError } from '@kit.BasicServicesKit'; 8320 8321export default class EntryAbility extends UIAbility { 8322 // ... 8323 onWindowStageCreate(windowStage: window.WindowStage): void { 8324 console.info('onWindowStageCreate'); 8325 let windowClass: window.Window | undefined = undefined; 8326 windowStage.getMainWindow((err: BusinessError, data) => { 8327 const errCode: number = err.code; 8328 if (errCode) { 8329 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8330 return; 8331 } 8332 windowClass = data; 8333 let names: Array<'status' | 'navigation'> = []; 8334 try { 8335 windowClass.setWindowSystemBarEnable(names, (err: BusinessError) => { 8336 const errCode: number = err.code; 8337 if (errCode) { 8338 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 8339 return; 8340 } 8341 console.info('Succeeded in setting the system bar to be invisible.'); 8342 }); 8343 } catch (exception) { 8344 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 8345 } 8346 }); 8347 } 8348} 8349``` 8350 8351### setWindowLayoutFullScreen<sup>(deprecated)</sup> 8352 8353setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 8354 8355设置主窗口或子窗口的布局是否为沉浸式布局,使用callback异步回调。 8356沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 8357非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 8358 8359> **说明:** 8360> 8361> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowLayoutFullScreen](#setwindowlayoutfullscreen9)。 8362 8363**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8364 8365**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8366 8367**参数:** 8368 8369| 参数名 | 类型 | 必填 | 说明 | 8370| ------------------ | ------------------------- | ---- | ------------------------------------------------------------------------------------------------------------- | 8371| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 8372| callback | AsyncCallback<void> | 是 | 回调函数。 | 8373 8374**错误码:** 8375 8376以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8377 8378| 错误码ID | 错误信息 | 8379| -------- | ------------------------------------------------------------------------------------------------------------ | 8380| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8381| 1300002 | This window state is abnormal. | 8382| 1300003 | This window manager service works abnormally. | 8383 8384**示例:** 8385 8386```ts 8387// EntryAbility.ets 8388import { UIAbility } from '@kit.AbilityKit'; 8389import { BusinessError } from '@kit.BasicServicesKit'; 8390 8391export default class EntryAbility extends UIAbility { 8392 // ... 8393 onWindowStageCreate(windowStage: window.WindowStage): void { 8394 console.info('onWindowStageCreate'); 8395 let windowClass: window.Window | undefined = undefined; 8396 windowStage.getMainWindow((err: BusinessError, data) => { 8397 const errCode: number = err.code; 8398 if (errCode) { 8399 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8400 return; 8401 } 8402 windowClass = data; 8403 let isLayoutFullScreen = true; 8404 try { 8405 windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 8406 const errCode: number = err.code; 8407 if (errCode) { 8408 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 8409 return; 8410 } 8411 console.info('Succeeded in setting the window layout to full-screen mode.'); 8412 }); 8413 } catch (exception) { 8414 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`); 8415 } 8416 }); 8417 } 8418} 8419``` 8420 8421### show<sup>(deprecated)</sup> 8422 8423show(callback: AsyncCallback<void>): void 8424 8425显示当前窗口,使用callback异步回调。 8426 8427> **说明:** 8428> 8429> 从API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9)。 8430 8431**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8432 8433**参数:** 8434 8435| 参数名 | 类型 | 必填 | 说明 | 8436| -------- | ------------------------- | ---- | ---------- | 8437| callback | AsyncCallback<void> | 是 | 回调函数。 | 8438 8439**示例:** 8440 8441```ts 8442import { BusinessError } from '@kit.BasicServicesKit'; 8443 8444windowClass.show((err: BusinessError) => { 8445 const errCode: number = err.code; 8446 if (errCode) { 8447 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 8448 return; 8449 } 8450 console.info('Succeeded in showing the window.'); 8451}); 8452``` 8453 8454### show<sup>(deprecated)</sup> 8455 8456show(): Promise<void> 8457 8458显示当前窗口,使用Promise异步回调。 8459 8460> **说明:** 8461> 8462> 从API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9-1)。 8463 8464**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8465 8466**返回值:** 8467 8468| 类型 | 说明 | 8469| ------------------- | ------------------------- | 8470| Promise<void> | 无返回结果的Promise对象。 | 8471 8472**示例:** 8473 8474```ts 8475import { BusinessError } from '@kit.BasicServicesKit'; 8476 8477let promise = windowClass.show(); 8478promise.then(() => { 8479 console.info('Succeeded in showing the window.'); 8480}).catch((err: BusinessError) => { 8481 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 8482}); 8483``` 8484 8485### destroy<sup>(deprecated)</sup> 8486 8487destroy(callback: AsyncCallback<void>): void 8488 8489销毁当前窗口,使用callback异步回调。 8490 8491> **说明:** 8492> 8493> 从API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9)。 8494 8495**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8496 8497**参数:** 8498 8499| 参数名 | 类型 | 必填 | 说明 | 8500| -------- | ------------------------- | ---- | ---------- | 8501| callback | AsyncCallback<void> | 是 | 回调函数。 | 8502 8503**示例:** 8504 8505```ts 8506import { BusinessError } from '@kit.BasicServicesKit'; 8507 8508windowClass.destroy((err: BusinessError) => { 8509 const errCode: number = err.code; 8510 if (err.code) { 8511 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 8512 return; 8513 } 8514 console.info('Succeeded in destroying the window.'); 8515}); 8516``` 8517 8518### destroy<sup>(deprecated)</sup> 8519 8520destroy(): Promise<void> 8521 8522销毁当前窗口,使用Promise异步回调。 8523 8524> **说明:** 8525> 8526> 从API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9-1)。 8527 8528**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8529 8530**返回值:** 8531 8532| 类型 | 说明 | 8533| ------------------- | ------------------------- | 8534| Promise<void> | 无返回结果的Promise对象。 | 8535 8536**示例:** 8537 8538```ts 8539import { BusinessError } from '@kit.BasicServicesKit'; 8540 8541let promise = windowClass.destroy(); 8542promise.then(() => { 8543 console.info('Succeeded in destroying the window.'); 8544}).catch((err: BusinessError) => { 8545 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 8546}); 8547``` 8548 8549### moveTo<sup>(deprecated)</sup> 8550 8551moveTo(x: number, y: number, callback: AsyncCallback<void>): void 8552 8553移动窗口位置,使用callback异步回调。 8554 8555全屏模式窗口不支持该操作。 8556 8557> **说明:** 8558> 8559> 从API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9)。 8560 8561**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8562 8563**参数:** 8564 8565| 参数名 | 类型 | 必填 | 说明 | 8566| -------- | ------------------------- | ---- | ------------------------------------------------- | 8567| x | number | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 8568| y | number | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 8569| callback | AsyncCallback<void> | 是 | 回调函数。 | 8570 8571**示例:** 8572 8573```ts 8574import { BusinessError } from '@kit.BasicServicesKit'; 8575 8576windowClass.moveTo(300, 300, (err: BusinessError) => { 8577 const errCode: number = err.code; 8578 if (errCode) { 8579 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 8580 return; 8581 } 8582 console.info('Succeeded in moving the window.'); 8583}); 8584``` 8585 8586### moveTo<sup>(deprecated)</sup> 8587 8588moveTo(x: number, y: number): Promise<void> 8589 8590移动窗口位置,使用Promise异步回调。 8591 8592全屏模式窗口不支持该操作。 8593 8594> **说明:** 8595> 8596> 从API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9-1)。 8597 8598**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8599 8600**参数:** 8601 8602| 参数名 | 类型 | 必填 | 说明 | 8603| ------ | ------ | ---- | ------------------------------------------------- | 8604| x | number | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 8605| y | number | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在y轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 8606 8607**返回值:** 8608 8609| 类型 | 说明 | 8610| ------------------- | ------------------------- | 8611| Promise<void> | 无返回结果的Promise对象。 | 8612 8613**示例:** 8614 8615```ts 8616import { BusinessError } from '@kit.BasicServicesKit'; 8617 8618let promise = windowClass.moveTo(300, 300); 8619promise.then(() => { 8620 console.info('Succeeded in moving the window.'); 8621}).catch((err: BusinessError) => { 8622 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 8623}); 8624``` 8625 8626### resetSize<sup>(deprecated)</sup> 8627 8628resetSize(width: number, height: number, callback: AsyncCallback<void>): void 8629 8630改变当前窗口大小,使用callback异步回调。 8631 8632应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 8633应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 8634 8635系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 8636 8637设置的宽度与高度受到此约束限制,规则: 8638若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 8639若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 8640 8641全屏模式窗口不支持该操作。 8642 8643> **说明:** 8644> 8645> 从API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9)。 8646 8647**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8648 8649**参数:** 8650 8651| 参数名 | 类型 | 必填 | 说明 | 8652| -------- | ------------------------- | ---- | -------------------------- | 8653| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 8654| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 8655| callback | AsyncCallback<void> | 是 | 回调函数。 | 8656 8657**示例:** 8658 8659```ts 8660import { BusinessError } from '@kit.BasicServicesKit'; 8661 8662windowClass.resetSize(500, 1000, (err: BusinessError) => { 8663 const errCode: number = err.code; 8664 if (errCode) { 8665 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 8666 return; 8667 } 8668 console.info('Succeeded in changing the window size.'); 8669}); 8670``` 8671 8672### resetSize<sup>(deprecated)</sup> 8673 8674resetSize(width: number, height: number): Promise<void> 8675 8676改变当前窗口大小,使用Promise异步回调。 8677 8678应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 8679应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 8680 8681系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 8682 8683设置的宽度与高度受到此约束限制,规则: 8684若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 8685若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 8686 8687全屏模式窗口不支持该操作。 8688 8689> **说明:** 8690> 8691> 从API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9-1)。 8692 8693**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8694 8695**参数:** 8696 8697| 参数名 | 类型 | 必填 | 说明 | 8698| ------ | ------ | ---- | -------------------------- | 8699| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 8700| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 8701 8702**返回值:** 8703 8704| 类型 | 说明 | 8705| ------------------- | ------------------------- | 8706| Promise<void> | 无返回结果的Promise对象。 | 8707 8708**示例:** 8709 8710```ts 8711import { BusinessError } from '@kit.BasicServicesKit'; 8712 8713let promise = windowClass.resetSize(500, 1000); 8714promise.then(() => { 8715 console.info('Succeeded in changing the window size.'); 8716}).catch((err: BusinessError) => { 8717 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 8718}); 8719``` 8720 8721### getProperties<sup>(deprecated)</sup> 8722 8723getProperties(callback: AsyncCallback<WindowProperties>): void 8724 8725获取当前窗口的属性,使用callback异步回调,返回WindowProperties。 8726 8727> **说明:** 8728> 8729> 从API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。 8730 8731**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8732 8733**参数:** 8734 8735| 参数名 | 类型 | 必填 | 说明 | 8736| -------- | ---------------------------------------------------------- | ---- | ---------------------------- | 8737| callback | AsyncCallback<[WindowProperties](#windowproperties)> | 是 | 回调函数。返回当前窗口属性。 | 8738 8739**示例:** 8740 8741```ts 8742import { BusinessError } from '@kit.BasicServicesKit'; 8743 8744windowClass.getProperties((err: BusinessError, data) => { 8745 const errCode: number = err.code; 8746 if (errCode) { 8747 console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`); 8748 return; 8749 } 8750 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 8751}); 8752``` 8753 8754### getProperties<sup>(deprecated)</sup> 8755 8756getProperties(): Promise<WindowProperties> 8757 8758获取当前窗口的属性,使用Promise异步回调,返回WindowProperties。 8759 8760> **说明:** 8761> 8762> 从API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。 8763 8764**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8765 8766**返回值:** 8767 8768| 类型 | 说明 | 8769| ---------------------------------------------------- | ------------------------------- | 8770| Promise<[WindowProperties](#windowproperties)> | Promise对象。返回当前窗口属性。 | 8771 8772**示例:** 8773 8774```ts 8775import { BusinessError } from '@kit.BasicServicesKit'; 8776 8777let promise = windowClass.getProperties(); 8778promise.then((data) => { 8779 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 8780}).catch((err: BusinessError) => { 8781 console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`); 8782}); 8783``` 8784 8785### getAvoidArea<sup>(deprecated)</sup> 8786 8787getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback<[AvoidArea](#avoidarea7)>): void 8788 8789获取当前窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 8790 8791> **说明:** 8792> 8793> 从API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。 8794 8795**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8796 8797**参数:** 8798 8799| 参数名 | 类型 | 必填 | 说明 | 8800| -------- |-----------------------------------------------| ---- | ------------------------------------------------------------ | 8801| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。| 8802| callback | AsyncCallback<[AvoidArea](#avoidarea7)> | 是 | 回调函数。返回窗口内容规避区域。 | 8803 8804**示例:** 8805 8806```ts 8807import { BusinessError } from '@kit.BasicServicesKit'; 8808 8809let type = window.AvoidAreaType.TYPE_SYSTEM; 8810windowClass.getAvoidArea(type, (err: BusinessError, data) => { 8811 const errCode: number = err.code; 8812 if (errCode) { 8813 console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`); 8814 return; 8815 } 8816 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 8817}); 8818``` 8819 8820### getAvoidArea<sup>(deprecated)</sup> 8821 8822getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise<[AvoidArea](#avoidarea7)> 8823 8824获取当前窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 8825 8826> **说明:** 8827> 8828> 从API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。 8829 8830**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8831 8832**参数:** 8833 8834| 参数名 | 类型 | 必填 | 说明 | 8835| ------ |----------------------------------| ---- | ------------------------------------------------------------ | 8836| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。 | 8837 8838**返回值:** 8839 8840| 类型 | 说明 | 8841|-----------------------------------------| ----------------------------------- | 8842| Promise<[AvoidArea](#avoidarea7)> | Promise对象。返回窗口内容规避区域。 | 8843 8844**示例:** 8845 8846```ts 8847import { BusinessError } from '@kit.BasicServicesKit'; 8848 8849let type = window.AvoidAreaType.TYPE_SYSTEM; 8850let promise = windowClass.getAvoidArea(type); 8851promise.then((data) => { 8852 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 8853}).catch((err: BusinessError) => { 8854 console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`); 8855}); 8856``` 8857 8858### setFullScreen<sup>(deprecated)</sup> 8859 8860setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void 8861 8862设置主窗口或子窗口的布局是否为全屏布局,使用callback异步回调。 8863全屏布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 8864非全屏布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 8865 8866> **说明:** 8867> 8868> 从API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)实现全屏。 8869 8870**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8871 8872**参数:** 8873 8874| 参数名 | 类型 | 必填 | 说明 | 8875| ------------ | ------------------------- | ---- | ---------------------------------------------- | 8876| isFullScreen | boolean | 是 | 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。 | 8877| callback | AsyncCallback<void> | 是 | 回调函数。 | 8878 8879**示例:** 8880 8881```ts 8882// EntryAbility.ets 8883import { UIAbility } from '@kit.AbilityKit'; 8884import { BusinessError } from '@kit.BasicServicesKit'; 8885 8886export default class EntryAbility extends UIAbility { 8887 // ... 8888 onWindowStageCreate(windowStage: window.WindowStage): void { 8889 console.info('onWindowStageCreate'); 8890 let windowClass: window.Window | undefined = undefined; 8891 windowStage.getMainWindow((err: BusinessError, data) => { 8892 const errCode: number = err.code; 8893 if (errCode) { 8894 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8895 return; 8896 } 8897 windowClass = data; 8898 let isFullScreen: boolean = true; 8899 windowClass.setFullScreen(isFullScreen, (err: BusinessError) => { 8900 const errCode: number = err.code; 8901 if (errCode) { 8902 console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 8903 return; 8904 } 8905 console.info('Succeeded in enabling the full-screen mode.'); 8906 }); 8907 }); 8908 } 8909} 8910``` 8911 8912### setFullScreen<sup>(deprecated)</sup> 8913 8914setFullScreen(isFullScreen: boolean): Promise<void> 8915 8916设置主窗口或子窗口的布局是否为全屏布局,使用Promise异步回调。 8917全屏布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 8918非全屏布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 8919 8920> **说明:** 8921> 8922> 从API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)实现全屏。 8923 8924**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8925 8926**参数:** 8927 8928| 参数名 | 类型 | 必填 | 说明 | 8929| ------------ | ------- | ---- | ---------------------------------------------- | 8930| isFullScreen | boolean | 是 | 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。 | 8931 8932**返回值:** 8933 8934| 类型 | 说明 | 8935| ------------------- | ------------------------- | 8936| Promise<void> | 无返回结果的Promise对象。 | 8937 8938**示例:** 8939 8940```ts 8941// EntryAbility.ets 8942import { UIAbility } from '@kit.AbilityKit'; 8943import { BusinessError } from '@kit.BasicServicesKit'; 8944 8945export default class EntryAbility extends UIAbility { 8946 // ... 8947 onWindowStageCreate(windowStage: window.WindowStage): void { 8948 console.info('onWindowStageCreate'); 8949 let windowClass: window.Window | undefined = undefined; 8950 windowStage.getMainWindow((err: BusinessError, data) => { 8951 const errCode: number = err.code; 8952 if (errCode) { 8953 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8954 return; 8955 } 8956 windowClass = data; 8957 let isFullScreen: boolean = true; 8958 let promise = windowClass.setFullScreen(isFullScreen); 8959 promise.then(() => { 8960 console.info('Succeeded in enabling the full-screen mode.'); 8961 }).catch((err: BusinessError) => { 8962 console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 8963 }); 8964 }); 8965 } 8966} 8967``` 8968 8969### setLayoutFullScreen<sup>(deprecated)</sup> 8970 8971setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 8972 8973设置主窗口或子窗口的布局是否为沉浸式布局,使用callback异步回调。 8974沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 8975非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 8976 8977> **说明:** 8978> 8979> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)。 8980 8981**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8982 8983**参数:** 8984 8985| 参数名 | 类型 | 必填 | 说明 | 8986| ------------------ | ------------------------- | ---- | ------------------------------------------------------------ | 8987| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 8988| callback | AsyncCallback<void> | 是 | 回调函数。 | 8989 8990**示例:** 8991 8992```ts 8993// EntryAbility.ets 8994import { UIAbility } from '@kit.AbilityKit'; 8995import { BusinessError } from '@kit.BasicServicesKit'; 8996 8997export default class EntryAbility extends UIAbility { 8998 // ... 8999 onWindowStageCreate(windowStage: window.WindowStage): void { 9000 console.info('onWindowStageCreate'); 9001 let windowClass: window.Window | undefined = undefined; 9002 windowStage.getMainWindow((err: BusinessError, data) => { 9003 const errCode: number = err.code; 9004 if (errCode) { 9005 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9006 return; 9007 } 9008 windowClass = data; 9009 let isLayoutFullScreen: boolean = true; 9010 windowClass.setLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 9011 const errCode: number = err.code; 9012 if (errCode) { 9013 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 9014 return; 9015 } 9016 console.info('Succeeded in setting the window layout to full-screen mode.'); 9017 }); 9018 }); 9019 } 9020} 9021``` 9022 9023### setLayoutFullScreen<sup>(deprecated)</sup> 9024 9025setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 9026 9027设置主窗口或子窗口的布局是否为沉浸式布局,使用Promise异步回调。 9028沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 9029非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 9030 9031> **说明:** 9032> 9033> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)。 9034 9035**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9036 9037**参数:** 9038 9039| 参数名 | 类型 | 必填 | 说明 | 9040| ------------------ | ------- | ---- | ------------------------------------------------------------ | 9041| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 9042 9043**返回值:** 9044 9045| 类型 | 说明 | 9046| ------------------- | ------------------------- | 9047| Promise<void> | 无返回结果的Promise对象。 | 9048 9049**示例:** 9050 9051```ts 9052// EntryAbility.ets 9053import { UIAbility } from '@kit.AbilityKit'; 9054import { BusinessError } from '@kit.BasicServicesKit'; 9055 9056export default class EntryAbility extends UIAbility { 9057 // ... 9058 onWindowStageCreate(windowStage: window.WindowStage): void { 9059 console.info('onWindowStageCreate'); 9060 let windowClass: window.Window | undefined = undefined; 9061 windowStage.getMainWindow((err: BusinessError, data) => { 9062 const errCode: number = err.code; 9063 if (errCode) { 9064 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9065 return; 9066 } 9067 windowClass = data; 9068 let isLayoutFullScreen: boolean = true; 9069 let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen); 9070 promise.then(() => { 9071 console.info('Succeeded in setting the window layout to full-screen mode.'); 9072 }).catch((err: BusinessError) => { 9073 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 9074 }); 9075 }); 9076 } 9077} 9078``` 9079 9080### setSystemBarEnable<sup>(deprecated)</sup> 9081 9082setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 9083 9084设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用callback异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 9085 9086调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。 9087 9088> **说明:** 9089> 9090> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)。 9091 9092**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9093 9094**参数:** 9095 9096| 参数名 | 类型 | 必填 | 说明 | 9097| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 9098| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 9099| callback | AsyncCallback<void> | 是 | 回调函数。 | 9100 9101 9102**示例:** 9103 9104```ts 9105// 此处以不显示三键导航栏、状态栏、底部导航条为例 9106// EntryAbility.ets 9107import { UIAbility } from '@kit.AbilityKit'; 9108import { BusinessError } from '@kit.BasicServicesKit'; 9109 9110export default class EntryAbility extends UIAbility { 9111 // ... 9112 onWindowStageCreate(windowStage: window.WindowStage): void { 9113 console.info('onWindowStageCreate'); 9114 let windowClass: window.Window | undefined = undefined; 9115 windowStage.getMainWindow((err: BusinessError, data) => { 9116 const errCode: number = err.code; 9117 if (errCode) { 9118 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9119 return; 9120 } 9121 windowClass = data; 9122 let names: Array<'status' | 'navigation'> = []; 9123 windowClass.setSystemBarEnable(names, (err: BusinessError) => { 9124 const errCode: number = err.code; 9125 if (errCode) { 9126 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 9127 return; 9128 } 9129 console.info('Succeeded in setting the system bar to be invisible.'); 9130 }); 9131 }); 9132 } 9133} 9134``` 9135 9136### setSystemBarEnable<sup>(deprecated)</sup> 9137 9138setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 9139 9140设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 9141 9142调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。 9143 9144> **说明:** 9145> 9146> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)。 9147 9148**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9149 9150**参数:** 9151 9152| 参数名 | 类型 | 必填 | 说明 | 9153| ------ | ---------------------------- | ---- | ------------------------ | 9154| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏、底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 9155 9156**返回值:** 9157 9158| 类型 | 说明 | 9159| ------------------- | ------------------------- | 9160| Promise<void> | 无返回结果的Promise对象。 | 9161 9162 9163**示例:** 9164 9165```ts 9166// 此处以不显示三键导航栏、状态栏、底部导航条为例 9167// EntryAbility.ets 9168import { UIAbility } from '@kit.AbilityKit'; 9169import { BusinessError } from '@kit.BasicServicesKit'; 9170 9171export default class EntryAbility extends UIAbility { 9172 // ... 9173 onWindowStageCreate(windowStage: window.WindowStage): void { 9174 console.info('onWindowStageCreate'); 9175 let windowClass: window.Window | undefined = undefined; 9176 windowStage.getMainWindow((err: BusinessError, data) => { 9177 const errCode: number = err.code; 9178 if (errCode) { 9179 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9180 return; 9181 } 9182 windowClass = data; 9183 let names: Array<'status' | 'navigation'> = []; 9184 let promise = windowClass.setSystemBarEnable(names); 9185 promise.then(() => { 9186 console.info('Succeeded in setting the system bar to be invisible.'); 9187 }).catch((err: BusinessError) => { 9188 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 9189 }); 9190 }); 9191 } 9192} 9193``` 9194 9195### setSystemBarProperties<sup>(deprecated)</sup> 9196 9197setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 9198 9199设置主窗口三键导航栏、状态栏的属性,使用callback异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 9200 9201子窗口调用后不生效。 9202 9203> **说明:** 9204> 9205> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9)。 9206 9207**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9208 9209**参数:** 9210 9211| 参数名 | 类型 | 必填 | 说明 | 9212| ------------------- | ------------------------------------------- | ---- | ---------------------- | 9213| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 三键导航栏、状态栏的属性。 | 9214| callback | AsyncCallback<void> | 是 | 回调函数。 | 9215 9216**示例:** 9217 9218```ts 9219// EntryAbility.ets 9220import { UIAbility } from '@kit.AbilityKit'; 9221import { BusinessError } from '@kit.BasicServicesKit'; 9222 9223export default class EntryAbility extends UIAbility { 9224 // ... 9225 onWindowStageCreate(windowStage: window.WindowStage): void { 9226 console.info('onWindowStageCreate'); 9227 let windowClass: window.Window | undefined = undefined; 9228 windowStage.getMainWindow((err: BusinessError, data) => { 9229 const errCode: number = err.code; 9230 if (errCode) { 9231 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9232 return; 9233 } 9234 windowClass = data; 9235 let SystemBarProperties: window.SystemBarProperties = { 9236 statusBarColor: '#ff00ff', 9237 navigationBarColor: '#00ff00', 9238 //以下两个属性从API Version8开始支持 9239 statusBarContentColor: '#ffffff', 9240 navigationBarContentColor: '#00ffff' 9241 }; 9242 windowClass.setSystemBarProperties(SystemBarProperties, (err) => { 9243 const errCode: number = err.code; 9244 if (errCode) { 9245 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 9246 return; 9247 } 9248 console.info('Succeeded in setting the system bar properties.'); 9249 }); 9250 }); 9251 } 9252} 9253``` 9254 9255### setSystemBarProperties<sup>(deprecated)</sup> 9256 9257setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 9258 9259设置主窗口三键导航栏、状态栏的属性,使用Promise异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 9260 9261子窗口调用后不生效。 9262 9263> **说明:** 9264> 9265> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9-1)。 9266 9267**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9268 9269**参数:** 9270 9271| 参数名 | 类型 | 必填 | 说明 | 9272| ------------------- | ------------------------------------------- | ---- | ---------------------- | 9273| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 三键导航栏、状态栏的属性。 | 9274 9275**返回值:** 9276 9277| 类型 | 说明 | 9278| ------------------- | ------------------------- | 9279| Promise<void> | 无返回结果的Promise对象。 | 9280 9281**示例:** 9282 9283```ts 9284// EntryAbility.ets 9285import { UIAbility } from '@kit.AbilityKit'; 9286import { BusinessError } from '@kit.BasicServicesKit'; 9287 9288export default class EntryAbility extends UIAbility { 9289 // ... 9290 onWindowStageCreate(windowStage: window.WindowStage): void { 9291 console.info('onWindowStageCreate'); 9292 let windowClass: window.Window | undefined = undefined; 9293 windowStage.getMainWindow((err: BusinessError, data) => { 9294 const errCode: number = err.code; 9295 if (errCode) { 9296 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9297 return; 9298 } 9299 windowClass = data; 9300 let SystemBarProperties: window.SystemBarProperties = { 9301 statusBarColor: '#ff00ff', 9302 navigationBarColor: '#00ff00', 9303 //以下两个属性从API Version8开始支持 9304 statusBarContentColor: '#ffffff', 9305 navigationBarContentColor: '#00ffff' 9306 }; 9307 let promise = windowClass.setSystemBarProperties(SystemBarProperties); 9308 promise.then(() => { 9309 console.info('Succeeded in setting the system bar properties.'); 9310 }).catch((err: BusinessError) => { 9311 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 9312 }); 9313 }); 9314 } 9315} 9316``` 9317 9318### loadContent<sup>(deprecated)</sup> 9319 9320loadContent(path: string, callback: AsyncCallback<void>): void 9321 9322为当前窗口加载具体页面内容,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 9323 9324> **说明:** 9325> 9326> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9)。 9327 9328**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9329 9330**参数:** 9331 9332| 参数名 | 类型 | 必填 | 说明 | 9333| -------- | ------------------------- | ---- | -------------------- | 9334| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 9335| callback | AsyncCallback<void> | 是 | 回调函数。 | 9336 9337**示例:** 9338 9339```ts 9340import { BusinessError } from '@kit.BasicServicesKit'; 9341 9342windowClass.loadContent('pages/page2/page3', (err: BusinessError) => { 9343 const errCode: number = err.code; 9344 if (errCode) { 9345 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 9346 return; 9347 } 9348 console.info('Succeeded in loading the content.'); 9349}); 9350``` 9351 9352### loadContent<sup>(deprecated)</sup> 9353 9354loadContent(path: string): Promise<void> 9355 9356为当前窗口加载具体页面内容,使用Promise异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 9357 9358> **说明:** 9359> 9360> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9-1)。 9361 9362**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9363 9364**参数:** 9365 9366| 参数名 | 类型 | 必填 | 说明 | 9367| ------ | ------ | ---- | -------------------- | 9368| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 9369 9370**返回值:** 9371 9372| 类型 | 说明 | 9373| ------------------- | ------------------------- | 9374| Promise<void> | 无返回结果的Promise对象。 | 9375 9376**示例:** 9377 9378```ts 9379import { BusinessError } from '@kit.BasicServicesKit'; 9380 9381let promise = windowClass.loadContent('pages/page2/page3'); 9382promise.then(() => { 9383 console.info('Succeeded in loading the content.'); 9384}).catch((err: BusinessError) => { 9385 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 9386}); 9387``` 9388 9389### isShowing<sup>(deprecated)</sup> 9390 9391isShowing(callback: AsyncCallback<boolean>): void 9392 9393判断当前窗口是否已显示,使用callback异步回调。 9394 9395> **说明:** 9396> 9397> 从API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。 9398 9399**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9400 9401**参数:** 9402 9403| 参数名 | 类型 | 必填 | 说明 | 9404| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 9405| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 | 9406 9407**示例:** 9408 9409```ts 9410import { BusinessError } from '@kit.BasicServicesKit'; 9411 9412windowClass.isShowing((err: BusinessError, data) => { 9413 const errCode: number = err.code; 9414 if (errCode) { 9415 console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`); 9416 return; 9417 } 9418 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 9419}); 9420``` 9421 9422### isShowing<sup>(deprecated)</sup> 9423 9424isShowing(): Promise<boolean> 9425 9426判断当前窗口是否已显示,使用Promise异步回调。 9427 9428> **说明:** 9429> 9430> 从API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。 9431 9432**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9433 9434**返回值:** 9435 9436| 类型 | 说明 | 9437| ---------------------- | ------------------------------------------------------------ | 9438| Promise<boolean> | Promise对象。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 | 9439 9440**示例:** 9441 9442```ts 9443import { BusinessError } from '@kit.BasicServicesKit'; 9444 9445let promise = windowClass.isShowing(); 9446promise.then((data) => { 9447 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 9448}).catch((err: BusinessError) => { 9449 console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`); 9450}); 9451``` 9452 9453### on('systemAvoidAreaChange')<sup>(deprecated)</sup> 9454 9455on(type: 'systemAvoidAreaChange', callback: Callback<AvoidArea>): void 9456 9457开启当前窗口系统规避区变化的监听。 9458 9459> **说明:** 9460> 9461> 从API version 7开始支持,从API version 9开始废弃,推荐使用[on('avoidAreaChange')](#onavoidareachange9)。 9462 9463**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9464 9465**参数:** 9466 9467| 参数名 | 类型 | 必填 | 说明 | 9468| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 9469| type | string | 是 | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 | 9470| callback | Callback<[AvoidArea](#avoidarea7)> | 是 | 回调函数。返回当前规避区。 | 9471 9472 9473**示例:** 9474 9475```ts 9476windowClass.on('systemAvoidAreaChange', (data) => { 9477 console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data)); 9478}); 9479``` 9480 9481### off('systemAvoidAreaChange')<sup>(deprecated)</sup> 9482 9483off(type: 'systemAvoidAreaChange', callback?: Callback<AvoidArea>): void 9484 9485关闭当前窗口系统规避区变化的监听。 9486 9487> **说明:** 9488> 9489> 从API version 7开始支持,从API version 9开始废弃,推荐使用[off('avoidAreaChange')](#offavoidareachange9)。 9490 9491**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9492 9493**参数:** 9494 9495| 参数名 | 类型 | 必填 | 说明 | 9496| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 9497| type | string | 是 | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 | 9498| callback | Callback<[AvoidArea](#avoidarea7)> | 否 | 回调函数。返回当前规避区。若传入参数,则关闭该监听。若未传入参数,则关闭所有系统规避区变化的监听。 | 9499 9500**示例:** 9501 9502```ts 9503const callback = (avoidArea: window.AvoidArea) => { 9504 // ... 9505} 9506windowClass.on('systemAvoidAreaChange', callback); 9507windowClass.off('systemAvoidAreaChange', callback); 9508// 如果通过on开启多个callback进行监听,同时关闭所有监听: 9509windowClass.off('systemAvoidAreaChange'); 9510``` 9511 9512### isSupportWideGamut<sup>(deprecated)</sup> 9513 9514isSupportWideGamut(callback: AsyncCallback<boolean>): void 9515 9516判断当前窗口是否支持广色域模式,使用callback异步回调。 9517 9518> **说明:** 9519> 9520> 从API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9)。 9521 9522**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9523 9524**参数:** 9525 9526| 参数名 | 类型 | 必填 | 说明 | 9527| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 9528| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 9529 9530**示例:** 9531 9532```ts 9533import { BusinessError } from '@kit.BasicServicesKit'; 9534 9535windowClass.isSupportWideGamut((err: BusinessError, data) => { 9536 const errCode: number = err.code; 9537 if (errCode) { 9538 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 9539 return; 9540 } 9541 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 9542}); 9543``` 9544 9545### isSupportWideGamut<sup>(deprecated)</sup> 9546 9547isSupportWideGamut(): Promise<boolean> 9548 9549判断当前窗口是否支持广色域模式,使用Promise异步回调。 9550 9551> **说明:** 9552> 9553> 从API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9-1)。 9554 9555**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9556 9557**返回值:** 9558 9559| 类型 | 说明 | 9560| ---------------------- | ------------------------------------------------------------ | 9561| Promise<boolean> | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 9562 9563**示例:** 9564 9565```ts 9566import { BusinessError } from '@kit.BasicServicesKit'; 9567 9568let promise = windowClass.isSupportWideGamut(); 9569promise.then((data) => { 9570 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 9571}).catch((err: BusinessError) => { 9572 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 9573}); 9574``` 9575 9576### setColorSpace<sup>(deprecated)</sup> 9577 9578setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 9579 9580设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。 9581 9582> **说明:** 9583> 9584> 从API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9)。 9585 9586**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9587 9588**参数:** 9589 9590| 参数名 | 类型 | 必填 | 说明 | 9591| ---------- | ------------------------- | ---- | ------------ | 9592| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 9593| callback | AsyncCallback<void> | 是 | 回调函数。 | 9594 9595 9596**示例:** 9597 9598```ts 9599import { BusinessError } from '@kit.BasicServicesKit'; 9600 9601windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 9602 const errCode: number = err.code; 9603 if (errCode) { 9604 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 9605 return; 9606 } 9607 console.info('Succeeded in setting window colorspace.'); 9608}); 9609``` 9610 9611### setColorSpace<sup>(deprecated)</sup> 9612 9613setColorSpace(colorSpace:ColorSpace): Promise<void> 9614 9615设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。 9616 9617> **说明:** 9618> 9619> 从API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9-1)。 9620 9621**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9622 9623**参数:** 9624 9625| 参数名 | 类型 | 必填 | 说明 | 9626| ---------- | ------------------------- | ---- | -------------- | 9627| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 9628 9629**返回值:** 9630 9631| 类型 | 说明 | 9632| ------------------- | ------------------------- | 9633| Promise<void> | 无返回结果的Promise对象。 | 9634 9635 9636**示例:** 9637 9638```ts 9639import { BusinessError } from '@kit.BasicServicesKit'; 9640 9641let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT); 9642promise.then(() => { 9643 console.info('Succeeded in setting window colorspace.'); 9644}).catch((err: BusinessError) => { 9645 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 9646}); 9647``` 9648 9649### getColorSpace<sup>(deprecated)</sup> 9650 9651getColorSpace(callback: AsyncCallback<ColorSpace>): void 9652 9653获取当前窗口色域模式,使用callback异步回调。 9654 9655> **说明:** 9656> 9657> 从API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。 9658 9659**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9660 9661**参数:** 9662 9663| 参数名 | 类型 | 必填 | 说明 | 9664| -------- | ---------------------------------------------- | ---- | ---------------------------------------------------------- | 9665| callback | AsyncCallback<[ColorSpace](#colorspace8)> | 是 | 回调函数。当获取成功,err为undefined,data为当前色域模式。 | 9666 9667**示例:** 9668 9669```ts 9670import { BusinessError } from '@kit.BasicServicesKit'; 9671 9672windowClass.getColorSpace((err: BusinessError, data) => { 9673 const errCode: number = err.code; 9674 if (errCode) { 9675 console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`); 9676 return; 9677 } 9678 console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data)); 9679}); 9680``` 9681 9682### getColorSpace<sup>(deprecated)</sup> 9683 9684getColorSpace(): Promise<ColorSpace> 9685 9686获取当前窗口色域模式,使用Promise异步回调。 9687 9688> **说明:** 9689> 9690> 从API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。 9691 9692**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9693 9694**返回值:** 9695 9696| 类型 | 说明 | 9697| ---------------------------------------- | ------------------------------- | 9698| Promise<[ColorSpace](#colorspace8)> | Promise对象。返回当前色域模式。 | 9699 9700**示例:** 9701 9702```ts 9703import { BusinessError } from '@kit.BasicServicesKit'; 9704 9705let promise = windowClass.getColorSpace(); 9706promise.then((data) => { 9707 console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data)); 9708}).catch((err: BusinessError) => { 9709 console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`); 9710}); 9711``` 9712 9713### setBackgroundColor<sup>(deprecated)</sup> 9714 9715setBackgroundColor(color: string, callback: AsyncCallback<void>): void 9716 9717设置窗口的背景色,使用callback异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 9718 9719> **说明:** 9720> 9721> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。 9722 9723**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9724 9725**参数:** 9726 9727| 参数名 | 类型 | 必填 | 说明 | 9728| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 9729| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 | 9730| callback | AsyncCallback<void> | 是 | 回调函数。 | 9731 9732 9733**示例:** 9734 9735```ts 9736import { BusinessError } from '@kit.BasicServicesKit'; 9737 9738let color: string = '#00ff33'; 9739windowClass.setBackgroundColor(color, (err: BusinessError) => { 9740 const errCode: number = err.code; 9741 if (errCode) { 9742 console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`); 9743 return; 9744 } 9745 console.info('Succeeded in setting the background color.'); 9746}); 9747``` 9748 9749### setBackgroundColor<sup>(deprecated)</sup> 9750 9751setBackgroundColor(color: string): Promise<void> 9752 9753设置窗口的背景色,使用Promise异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 9754 9755> **说明:** 9756> 9757> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。 9758 9759**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9760 9761**参数:** 9762 9763| 参数名 | 类型 | 必填 | 说明 | 9764| ------ | ------ | ---- | ------------------------------------------------------------ | 9765| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 | 9766 9767**返回值:** 9768 9769| 类型 | 说明 | 9770| ------------------- | ------------------------- | 9771| Promise<void> | 无返回结果的Promise对象。 | 9772 9773 9774**示例:** 9775 9776```ts 9777import { BusinessError } from '@kit.BasicServicesKit'; 9778 9779let color: string = '#00ff33'; 9780let promise = windowClass.setBackgroundColor(color); 9781promise.then(() => { 9782 console.info('Succeeded in setting the background color.'); 9783}).catch((err: BusinessError) => { 9784 console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`); 9785}); 9786``` 9787 9788### setBrightness<sup>(deprecated)</sup> 9789 9790setBrightness(brightness: number, callback: AsyncCallback<void>): void 9791 9792允许应用窗口设置屏幕亮度值,使用callback异步回调。 9793 9794当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 9795 9796> **说明:** 9797> 9798> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9)。 9799 9800**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9801 9802**参数:** 9803 9804| 参数名 | 类型 | 必填 | 说明 | 9805| ---------- | ------------------------- | ---- |---------------------------------------| 9806| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 9807| callback | AsyncCallback<void> | 是 | 回调函数。 | 9808 9809 9810**示例:** 9811 9812```ts 9813import { BusinessError } from '@kit.BasicServicesKit'; 9814 9815let brightness: number = 1; 9816windowClass.setBrightness(brightness, (err: BusinessError) => { 9817 const errCode: number = err.code; 9818 if (errCode) { 9819 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 9820 return; 9821 } 9822 console.info('Succeeded in setting the brightness.'); 9823}); 9824``` 9825 9826### setBrightness<sup>(deprecated)</sup> 9827 9828setBrightness(brightness: number): Promise<void> 9829 9830允许应用窗口设置屏幕亮度值,使用Promise异步回调。 9831 9832当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 9833 9834> **说明:** 9835> 9836> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9-1)。 9837 9838**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9839 9840**参数:** 9841 9842| 参数名 | 类型 | 必填 | 说明 | 9843| ---------- | ------ | ---- |------------------------------------------| 9844| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 9845 9846**返回值:** 9847 9848| 类型 | 说明 | 9849| ------------------- | ------------------------- | 9850| Promise<void> | 无返回结果的Promise对象。 | 9851 9852 9853**示例:** 9854 9855```ts 9856import { BusinessError } from '@kit.BasicServicesKit'; 9857 9858let brightness: number = 1; 9859let promise = windowClass.setBrightness(brightness); 9860promise.then(() => { 9861 console.info('Succeeded in setting the brightness.'); 9862}).catch((err: BusinessError) => { 9863 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 9864}); 9865``` 9866 9867### setDimBehind<sup>(deprecated)</sup> 9868 9869setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void 9870 9871窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用callback异步回调。 9872 9873> **说明:** 9874> 9875> 该接口不支持使用。从API version 7开始支持,从API version 9开始废弃。 9876 9877**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9878 9879**参数:** 9880 9881| 参数名 | 类型 | 必填 | 说明 | 9882| -------------- | ------------------------- | ---- |----------------------------------------| 9883| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为[0.0, 1.0],取1.0时表示最暗。 | 9884| callback | AsyncCallback<void> | 是 | 回调函数。 | 9885 9886**示例:** 9887 9888```ts 9889import { BusinessError } from '@kit.BasicServicesKit'; 9890 9891windowClass.setDimBehind(0.5, (err: BusinessError) => { 9892 const errCode: number = err.code; 9893 if (errCode) { 9894 console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`); 9895 return; 9896 } 9897 console.info('Succeeded in setting the dimness.'); 9898}); 9899``` 9900 9901### setDimBehind<sup>(deprecated)</sup> 9902 9903setDimBehind(dimBehindValue: number): Promise<void> 9904 9905窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用Promise异步回调。 9906 9907> **说明:** 9908> 9909> 该接口不支持使用。从API version 7开始支持,从API version 9开始废弃。 9910 9911**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9912 9913**参数:** 9914 9915| 参数名 | 类型 | 必填 | 说明 | 9916| -------------- | ------ | ---- | -------------------------------------------------- | 9917| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 | 9918 9919**返回值:** 9920 9921| 类型 | 说明 | 9922| ------------------- | ------------------------- | 9923| Promise<void> | 无返回结果的Promise对象。 | 9924 9925**示例:** 9926 9927```ts 9928import { BusinessError } from '@kit.BasicServicesKit'; 9929 9930let promise = windowClass.setDimBehind(0.5); 9931promise.then(() => { 9932 console.info('Succeeded in setting the dimness.'); 9933}).catch((err: BusinessError) => { 9934 console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`); 9935}); 9936``` 9937 9938### setFocusable<sup>(deprecated)</sup> 9939 9940setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 9941 9942设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从操作前的获焦窗口切换到该窗口,使用callback异步回调。 9943 9944> **说明:** 9945> 9946> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9)。 9947 9948**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9949 9950**参数:** 9951 9952| 参数名 | 类型 | 必填 | 说明 | 9953| ----------- | ------------------------- | ---- | ---------------------------- | 9954| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 9955| callback | AsyncCallback<void> | 是 | 回调函数。 | 9956 9957 9958**示例:** 9959 9960```ts 9961import { BusinessError } from '@kit.BasicServicesKit'; 9962 9963let isFocusable: boolean = true; 9964windowClass.setFocusable(isFocusable, (err: BusinessError) => { 9965 const errCode: number = err.code; 9966 if (errCode) { 9967 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 9968 return; 9969 } 9970 console.info('Succeeded in setting the window to be focusable.'); 9971}); 9972``` 9973 9974### setFocusable<sup>(deprecated)</sup> 9975 9976setFocusable(isFocusable: boolean): Promise<void> 9977 9978设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用Promise异步回调。 9979 9980> **说明:** 9981> 9982> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9-1)。 9983 9984**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9985 9986**参数:** 9987 9988| 参数名 | 类型 | 必填 | 说明 | 9989| ----------- | ------- | ---- | ---------------------------- | 9990| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 9991 9992**返回值:** 9993 9994| 类型 | 说明 | 9995| ------------------- | ------------------------- | 9996| Promise<void> | 无返回结果的Promise对象。 | 9997 9998 9999**示例:** 10000 10001```ts 10002import { BusinessError } from '@kit.BasicServicesKit'; 10003 10004let isFocusable: boolean = true; 10005let promise = windowClass.setFocusable(isFocusable); 10006promise.then(() => { 10007 console.info('Succeeded in setting the window to be focusable.'); 10008}).catch((err: BusinessError) => { 10009 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 10010}); 10011``` 10012 10013### setKeepScreenOn<sup>(deprecated)</sup> 10014 10015setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 10016 10017设置屏幕是否为常亮状态,使用callback异步回调。 10018 10019> **说明:** 10020> 10021> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9)。 10022 10023**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10024 10025**参数:** 10026 10027| 参数名 | 类型 | 必填 | 说明 | 10028| -------------- | ------------------------- | ---- | ------------------------ | 10029| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 10030| callback | AsyncCallback<void> | 是 | 回调函数。 | 10031 10032 10033**示例:** 10034 10035```ts 10036import { BusinessError } from '@kit.BasicServicesKit'; 10037 10038let isKeepScreenOn: boolean = true; 10039windowClass.setKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 10040 const errCode: number = err.code; 10041 if (errCode) { 10042 console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 10043 return; 10044 } 10045 console.info('Succeeded in setting the screen to be always on.'); 10046}); 10047``` 10048 10049### setKeepScreenOn<sup>(deprecated)</sup> 10050 10051setKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 10052 10053设置屏幕是否为常亮状态,使用Promise异步回调。 10054 10055> **说明:** 10056> 10057> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9-1)。 10058 10059**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10060 10061**参数:** 10062 10063| 参数名 | 类型 | 必填 | 说明 | 10064| -------------- | ------- | ---- | ------------------------ | 10065| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 10066 10067**返回值:** 10068 10069| 类型 | 说明 | 10070| ------------------- | ------------------------- | 10071| Promise<void> | 无返回结果的Promise对象。 | 10072 10073**示例:** 10074 10075```ts 10076import { BusinessError } from '@kit.BasicServicesKit'; 10077 10078let isKeepScreenOn: boolean = true; 10079let promise = windowClass.setKeepScreenOn(isKeepScreenOn); 10080promise.then(() => { 10081 console.info('Succeeded in setting the screen to be always on.'); 10082}).catch((err: BusinessError) => { 10083 console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 10084}); 10085``` 10086 10087### setOutsideTouchable<sup>(deprecated)</sup> 10088 10089setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void 10090 10091设置是否允许可点击子窗口之外的区域,使用callback异步回调。 10092 10093> **说明:** 10094> 10095> 从API version 7开始支持,从API version 9开始废弃。 10096> 10097> 从API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。 10098 10099**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10100 10101**参数:** 10102 10103| 参数名 | 类型 | 必填 | 说明 | 10104| --------- | ------------------------- | ---- | ---------------- | 10105| touchable | boolean | 是 | 设置是否可点击。true表示可点击;false表示不可点击。 | 10106| callback | AsyncCallback<void> | 是 | 回调函数。 | 10107 10108**示例:** 10109 10110```ts 10111import { BusinessError } from '@kit.BasicServicesKit'; 10112 10113windowClass.setOutsideTouchable(true, (err: BusinessError) => { 10114 const errCode: number = err.code; 10115 if (errCode) { 10116 console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`); 10117 return; 10118 } 10119 console.info('Succeeded in setting the area to be touchable.'); 10120}); 10121``` 10122 10123### setOutsideTouchable<sup>(deprecated)</sup> 10124 10125setOutsideTouchable(touchable: boolean): Promise<void> 10126 10127设置是否允许可点击子窗口之外的区域,使用Promise异步回调。 10128 10129> **说明:** 10130> 10131> 从API version 7开始支持,从API version 9开始废弃。 10132> 10133> 从API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。 10134 10135**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10136 10137**参数:** 10138 10139| 参数名 | 类型 | 必填 | 说明 | 10140| --------- | ------- | ---- | ---------------- | 10141| touchable | boolean | 是 | 设置是否可点击。true表示可点击;false表示不可点击。 | 10142 10143**返回值:** 10144 10145| 类型 | 说明 | 10146| ------------------- | ------------------------- | 10147| Promise<void> | 无返回结果的Promise对象。 | 10148 10149**示例:** 10150 10151```ts 10152import { BusinessError } from '@kit.BasicServicesKit'; 10153 10154let promise = windowClass.setOutsideTouchable(true); 10155promise.then(() => { 10156 console.info('Succeeded in setting the area to be touchable.'); 10157}).catch((err: BusinessError) => { 10158 console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`); 10159}); 10160``` 10161 10162### setPrivacyMode<sup>(deprecated)</sup> 10163 10164setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 10165 10166设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 10167 10168> **说明:** 10169> 10170> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9)。 10171 10172**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10173 10174**参数:** 10175 10176| 参数名 | 类型 | 必填 | 说明 | 10177| ------------- | ------------------------- | ---- | -------------------- | 10178| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 10179| callback | AsyncCallback<void> | 是 | 回调函数。 | 10180 10181**示例:** 10182 10183```ts 10184import { BusinessError } from '@kit.BasicServicesKit'; 10185 10186let isPrivacyMode: boolean = true; 10187windowClass.setPrivacyMode(isPrivacyMode, (err: BusinessError) => { 10188 const errCode: number = err.code; 10189 if (errCode) { 10190 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 10191 return; 10192 } 10193 console.info('Succeeded in setting the window to privacy mode.'); 10194}); 10195``` 10196 10197### setPrivacyMode<sup>(deprecated)</sup> 10198 10199setPrivacyMode(isPrivacyMode: boolean): Promise<void> 10200 10201设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 10202 10203> **说明:** 10204> 10205> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9-1)。 10206 10207**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10208 10209**参数:** 10210 10211| 参数名 | 类型 | 必填 | 说明 | 10212| ------------- | ------- | ---- | -------------------- | 10213| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 10214 10215**返回值:** 10216 10217| 类型 | 说明 | 10218| ------------------- | ------------------------- | 10219| Promise<void> | 无返回结果的Promise对象。 | 10220 10221**示例:** 10222 10223```ts 10224import { BusinessError } from '@kit.BasicServicesKit'; 10225 10226let isPrivacyMode: boolean = true; 10227let promise = windowClass.setPrivacyMode(isPrivacyMode); 10228promise.then(() => { 10229 console.info('Succeeded in setting the window to privacy mode.'); 10230}).catch((err: BusinessError) => { 10231 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 10232}); 10233``` 10234 10235### setTouchable<sup>(deprecated)</sup> 10236 10237setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 10238 10239设置窗口是否为可触状态,使用callback异步回调。 10240 10241> **说明:** 10242> 10243> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9)。 10244 10245**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10246 10247**参数:** 10248 10249| 参数名 | 类型 | 必填 | 说明 | 10250| ----------- | ------------------------- | ---- | -------------------- | 10251| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 10252| callback | AsyncCallback<void> | 是 | 回调函数。 | 10253 10254 10255**示例:** 10256 10257```ts 10258import { BusinessError } from '@kit.BasicServicesKit'; 10259 10260let isTouchable = true; 10261windowClass.setTouchable(isTouchable, (err: BusinessError) => { 10262 const errCode: number = err.code; 10263 if (errCode) { 10264 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 10265 return; 10266 } 10267 console.info('Succeeded in setting the window to be touchable.'); 10268}); 10269``` 10270 10271### setTouchable<sup>(deprecated)</sup> 10272 10273setTouchable(isTouchable: boolean): Promise<void> 10274 10275设置窗口是否为可触状态,使用Promise异步回调。 10276 10277> **说明:** 10278> 10279> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9-1)。 10280 10281**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10282 10283**参数:** 10284 10285| 参数名 | 类型 | 必填 | 说明 | 10286| ----------- | ------- | ---- | -------------------- | 10287| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 10288 10289**返回值:** 10290 10291| 类型 | 说明 | 10292| ------------------- | ------------------------- | 10293| Promise<void> | 无返回结果的Promise对象。 | 10294 10295 10296**示例:** 10297 10298```ts 10299import { BusinessError } from '@kit.BasicServicesKit'; 10300 10301let isTouchable = true; 10302let promise = windowClass.setTouchable(isTouchable); 10303promise.then(() => { 10304 console.info('Succeeded in setting the window to be touchable.'); 10305}).catch((err: BusinessError) => { 10306 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 10307}); 10308``` 10309 10310## WindowStageEventType<sup>9+</sup> 10311 10312WindowStage生命周期。 10313 10314**模型约束:** 此接口仅可在Stage模型下使用。 10315 10316**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10317 10318**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10319 10320| 名称 | 值 | 说明 | 10321| ---------- | ------ | ---------- | 10322| SHOWN | 1 | 切到前台,例如点击应用图标启动,无论是首次启动还是从后台启动均会触发。 | 10323| ACTIVE | 2 | 获焦状态,例如应用窗口处理点击事件后的状态、应用启动后的状态。 | 10324| INACTIVE | 3 | 失焦状态,例如打开新应用或点击其他窗口后,原获焦窗口的状态。 | 10325| HIDDEN | 4 | 切到后台,例如应用上滑退出、应用窗口关闭。 | 10326| RESUMED<sup>11+</sup> | 5 | 前台可交互状态,例如应用打开后,可以与用户交互的状态。 | 10327| PAUSED<sup>11+</sup> | 6 | 前台不可交互状态,例如从屏幕底部上划,应用进入到多任务界面后的状态。 | 10328 10329## ModalityType<sup>14+</sup> 10330 10331子窗口模态类型枚举。 10332 10333**系统能力:** SystemCapability.Window.SessionManager 10334 10335**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 10336 10337| 名称 | 值 | 说明 | 10338| -------------------- | ------ | ---------- | 10339| WINDOW_MODALITY | 0 | 模态子窗类型为模窗口子窗,当仅需要其父级窗口不响应用户操作时,可选此参数。 | 10340| APPLICATION_MODALITY | 1 | 模态子窗类型为模应用子窗,除其父级窗口外还需要该应用其他实例的窗口不响应用户操作时,可选此参数。<br> 此接口仅支持在2in1设备下使用。 | 10341 10342## SubWindowOptions<sup>11+</sup> 10343 10344子窗口创建参数。 10345 10346**系统能力:** SystemCapability.Window.SessionManager 10347 10348| 名称 | 类型 | 只读 | 可选 | 说明 | 10349| ---------- | ---- | ---- | ---- | ----------- | 10350| title<sup>11+</sup> | string | 否 | 否 | 子窗口标题。标题显示区域最右端不超过系统三键区域最左端,超过部分以省略号表示。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 10351| decorEnabled<sup>11+</sup> | boolean | 否 | 否 | 子窗口是否显示装饰。true表示子窗口显示装饰,false表示子窗口不显示装饰。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 10352| isModal<sup>12+</sup> | boolean | 否 | 是 | 子窗口是否启用模态属性。true表示子窗口启用模态属性,false表示子窗口禁用模态属性。不设置,则默认为false。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 10353| modalityType<sup>14+</sup> | [ModalityType](#modalitytype14) | 否 | 是 | 子窗口模态类型,仅当子窗口启用模态属性时生效。WINDOW_MODALITY表示子窗口模态类型为模窗口子窗,APPLICATION_MODALITY表示子窗口模态类型为模应用子窗。不设置,则默认为WINDOW_MODALITY。<br>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 | 10354 10355## WindowStage<sup>9+</sup> 10356 10357窗口管理器。管理各个基本窗口单元,即[Window](#window)实例。 10358 10359下列API示例中都需在[onWindowStageCreate()](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate)函数中使用WindowStage的实例调用对应方法。 10360 10361### getMainWindow<sup>9+</sup> 10362 10363getMainWindow(callback: AsyncCallback<Window>): void 10364 10365获取该WindowStage实例下的主窗口,使用callback异步回调。 10366 10367**模型约束:** 此接口仅可在Stage模型下使用。 10368 10369**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10370 10371**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10372 10373**参数:** 10374 10375| 参数名 | 类型 | 必填 | 说明 | 10376| -------- | -------------------------------------- | ---- | --------------------------------------------- | 10377| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前WindowStage下的主窗口对象。 | 10378 10379**错误码:** 10380 10381以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 10382 10383| 错误码ID | 错误信息 | 10384| ------- | ------------------------------ | 10385| 1300002 | This window state is abnormal. | 10386| 1300005 | This window stage is abnormal. | 10387 10388**示例:** 10389 10390```ts 10391// EntryAbility.ets 10392import { UIAbility } from '@kit.AbilityKit'; 10393import { BusinessError } from '@kit.BasicServicesKit'; 10394 10395export default class EntryAbility extends UIAbility { 10396 // ... 10397 10398 onWindowStageCreate(windowStage: window.WindowStage) { 10399 console.info('onWindowStageCreate'); 10400 let windowClass: window.Window | undefined = undefined; 10401 windowStage.getMainWindow((err: BusinessError, data) => { 10402 const errCode: number = err.code; 10403 if (errCode) { 10404 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10405 return; 10406 } 10407 windowClass = data; 10408 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 10409 }); 10410 } 10411}; 10412``` 10413 10414### getMainWindow<sup>9+</sup> 10415 10416getMainWindow(): Promise<Window> 10417 10418获取该WindowStage实例下的主窗口,使用Promise异步回调。 10419 10420**模型约束:** 此接口仅可在Stage模型下使用。 10421 10422**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10423 10424**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10425 10426**返回值:** 10427 10428| 类型 | 说明 | 10429| -------------------------------- | ------------------------------------------------ | 10430| Promise<[Window](#window)> | Promise对象。返回当前WindowStage下的主窗口对象。 | 10431 10432**错误码:** 10433 10434以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 10435 10436| 错误码ID | 错误信息 | 10437| ------- | ------------------------------ | 10438| 1300002 | This window state is abnormal. | 10439| 1300005 | This window stage is abnormal. | 10440 10441**示例:** 10442 10443```ts 10444// EntryAbility.ets 10445import { UIAbility } from '@kit.AbilityKit'; 10446import { BusinessError } from '@kit.BasicServicesKit'; 10447 10448export default class EntryAbility extends UIAbility { 10449 // ... 10450 10451 onWindowStageCreate(windowStage: window.WindowStage) { 10452 console.info('onWindowStageCreate'); 10453 let windowClass: window.Window | undefined = undefined; 10454 let promise = windowStage.getMainWindow(); 10455 promise.then((data) => { 10456 windowClass = data; 10457 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 10458 }).catch((err: BusinessError) => { 10459 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10460 }); 10461 } 10462}; 10463``` 10464 10465### getMainWindowSync<sup>9+</sup> 10466 10467getMainWindowSync(): Window 10468 10469获取该WindowStage实例下的主窗口。 10470 10471**模型约束:** 此接口仅可在Stage模型下使用。 10472 10473**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10474 10475**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10476 10477**返回值:** 10478 10479| 类型 | 说明 | 10480| ----------------- | --------------------------------- | 10481| [Window](#window) | 返回当前WindowStage下的主窗口对象。 | 10482 10483**错误码:** 10484 10485以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 10486 10487| 错误码ID | 错误信息 | 10488| ------- | ------------------------------ | 10489| 1300002 | This window state is abnormal. | 10490| 1300005 | This window stage is abnormal. | 10491 10492**示例:** 10493<!--code_no_check--> 10494```ts 10495// EntryAbility.ets 10496import { UIAbility } from '@kit.AbilityKit'; 10497 10498export default class EntryAbility extends UIAbility { 10499 // ... 10500 10501 onWindowStageCreate(windowStage: window.WindowStage) { 10502 console.info('onWindowStageCreate'); 10503 try { 10504 let windowClass = windowStage.getMainWindowSync(); 10505 } catch (exception) { 10506 console.error(`Failed to obtain the main window. Cause code: ${exception.code}, message: ${exception.message}`); 10507 } 10508 } 10509}; 10510``` 10511 10512### createSubWindow<sup>9+</sup> 10513 10514createSubWindow(name: string, callback: AsyncCallback<Window>): void 10515 10516创建该WindowStage实例下的子窗口,使用callback异步回调。 10517 10518**模型约束:** 此接口仅可在Stage模型下使用。 10519 10520**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10521 10522**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10523 10524**参数:** 10525 10526| 参数名 | 类型 | 必填 | 说明 | 10527| -------- | -------------------------------------- | ---- | --------------------------------------------- | 10528| name | string | 是 | 子窗口的名字。 | 10529| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前WindowStage下的子窗口对象。 | 10530 10531**错误码:** 10532 10533以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10534 10535| 错误码ID | 错误信息 | 10536| ------- | ------------------------------ | 10537| 401 | Parameter error. Possible cause: Incorrect parameter types. | 10538| 1300002 | This window state is abnormal. | 10539| 1300005 | This window stage is abnormal. | 10540 10541**示例:** 10542 10543```ts 10544// EntryAbility.ets 10545import { UIAbility } from '@kit.AbilityKit'; 10546import { BusinessError } from '@kit.BasicServicesKit'; 10547 10548export default class EntryAbility extends UIAbility { 10549 // ... 10550 10551 onWindowStageCreate(windowStage: window.WindowStage) { 10552 console.info('onWindowStageCreate'); 10553 let windowClass: window.Window | undefined = undefined; 10554 try { 10555 windowStage.createSubWindow('mySubWindow', (err: BusinessError, data) => { 10556 const errCode: number = err.code; 10557 if (errCode) { 10558 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 10559 return; 10560 } 10561 windowClass = data; 10562 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 10563 if (!windowClass) { 10564 console.info('Failed to load the content. Cause: windowClass is null'); 10565 } 10566 else { 10567 (windowClass as window.Window).resize(500, 1000); 10568 } 10569 }); 10570 } catch (exception) { 10571 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 10572 } 10573 } 10574}; 10575``` 10576 10577### createSubWindow<sup>9+</sup> 10578 10579createSubWindow(name: string): Promise<Window> 10580 10581创建该WindowStage实例下的子窗口,使用Promise异步回调。 10582 10583**模型约束:** 此接口仅可在Stage模型下使用。 10584 10585**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10586 10587**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10588 10589**参数:** 10590 10591| 参数名 | 类型 | 必填 | 说明 | 10592| ------ | ------ | ---- | -------------- | 10593| name | string | 是 | 子窗口的名字。 | 10594 10595**返回值:** 10596 10597| 类型 | 说明 | 10598| -------------------------------- | ------------------------------------------------ | 10599| Promise<[Window](#window)> | Promise对象。返回当前WindowStage下的子窗口对象。 | 10600 10601**错误码:** 10602 10603以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10604 10605| 错误码ID | 错误信息 | 10606| ------- | ------------------------------ | 10607| 401 | Parameter error. Possible cause: Incorrect parameter types. | 10608| 1300002 | This window state is abnormal. | 10609| 1300005 | This window stage is abnormal. | 10610 10611**示例:** 10612 10613```ts 10614// EntryAbility.ets 10615import { UIAbility } from '@kit.AbilityKit'; 10616import { BusinessError } from '@kit.BasicServicesKit'; 10617 10618export default class EntryAbility extends UIAbility { 10619 // ... 10620 10621 onWindowStageCreate(windowStage: window.WindowStage) { 10622 console.info('onWindowStageCreate'); 10623 let windowClass: window.Window | undefined = undefined; 10624 try { 10625 let promise = windowStage.createSubWindow('mySubWindow'); 10626 promise.then((data) => { 10627 windowClass = data; 10628 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 10629 }).catch((err: BusinessError) => { 10630 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 10631 }); 10632 } catch (exception) { 10633 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 10634 } 10635 } 10636}; 10637``` 10638 10639### createSubWindowWithOptions<sup>11+</sup> 10640 10641createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise<Window> 10642 10643创建该WindowStage实例下的子窗口,使用Promise异步回调。 10644 10645**模型约束:** 此接口仅可在Stage模型下使用。 10646 10647**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 10648 10649**系统能力:** SystemCapability.Window.SessionManager 10650 10651**参数:** 10652 10653| 参数名 | 类型 | 必填 | 说明 | 10654| ------ | ------ | ---- | -------------- | 10655| name | string | 是 | 子窗口的名字。 | 10656| options | [SubWindowOptions](#subwindowoptions11) | 是 | 子窗口参数。 | 10657 10658**返回值:** 10659 10660| 类型 | 说明 | 10661| -------------------------------- | ------------------------------------------------ | 10662| Promise<[Window](#window)> | Promise对象。返回当前WindowStage下创建的子窗口对象。 | 10663 10664**错误码:** 10665 10666以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10667 10668| 错误码ID | 错误信息 | 10669| ------- | ------------------------------ | 10670| 401 | Parameter error. Possible cause: Incorrect parameter types. | 10671| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 10672| 1300002 | This window state is abnormal. | 10673| 1300005 | This window stage is abnormal. | 10674 10675**示例:** 10676 10677```ts 10678// EntryAbility.ets 10679import { UIAbility } from '@kit.AbilityKit'; 10680import { BusinessError } from '@kit.BasicServicesKit'; 10681 10682export default class EntryAbility extends UIAbility { 10683 // ... 10684 10685 onWindowStageCreate(windowStage: window.WindowStage) { 10686 console.info('onWindowStageCreate'); 10687 let windowClass: window.Window | undefined = undefined; 10688 try { 10689 let options : window.SubWindowOptions = { 10690 title: 'title', 10691 decorEnabled: true 10692 }; 10693 let promise = windowStage.createSubWindowWithOptions('mySubWindow', options); 10694 promise.then((data) => { 10695 windowClass = data; 10696 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 10697 }).catch((err: BusinessError) => { 10698 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 10699 }); 10700 } catch (exception) { 10701 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 10702 } 10703 } 10704}; 10705``` 10706 10707### getSubWindow<sup>9+</sup> 10708 10709getSubWindow(callback: AsyncCallback<Array<Window>>): void 10710 10711获取该WindowStage实例下的所有子窗口,使用callback异步回调。 10712 10713**模型约束:** 此接口仅可在Stage模型下使用。 10714 10715**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10716 10717**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10718 10719**参数:** 10720 10721| 参数名 | 类型 | 必填 | 说明 | 10722| -------- | --------------------------------------------------- | ---- | ------------------------------------------------- | 10723| callback | AsyncCallback<Array<[Window](#window)>> | 是 | 回调函数。返回当前WindowStage下的所有子窗口对象。 | 10724 10725**错误码:** 10726 10727以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 10728 10729| 错误码ID | 错误信息 | 10730| ------- | ------------------------------ | 10731| 1300005 | This window stage is abnormal. | 10732 10733**示例:** 10734<!--code_no_check--> 10735```ts 10736// EntryAbility.ets 10737import { UIAbility } from '@kit.AbilityKit'; 10738import { BusinessError } from '@kit.BasicServicesKit'; 10739 10740export default class EntryAbility extends UIAbility { 10741 // ... 10742 10743 onWindowStageCreate(windowStage: window.WindowStage) { 10744 console.info('onWindowStageCreate'); 10745 let windowClass: window.Window[] = []; 10746 windowStage.getSubWindow((err: BusinessError, data) => { 10747 const errCode: number = err.code; 10748 if (errCode) { 10749 console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`); 10750 return; 10751 } 10752 windowClass = data; 10753 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 10754 }); 10755 } 10756}; 10757``` 10758 10759### getSubWindow<sup>9+</sup> 10760 10761getSubWindow(): Promise<Array<Window>> 10762 10763获取该WindowStage实例下的所有子窗口,使用Promise异步回调。 10764 10765**模型约束:** 此接口仅可在Stage模型下使用。 10766 10767**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10768 10769**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10770 10771**返回值:** 10772 10773| 类型 | 说明 | 10774| --------------------------------------------- | ---------------------------------------------------- | 10775| Promise<Array<[Window](#window)>> | Promise对象。返回当前WindowStage下的所有子窗口对象。 | 10776 10777**错误码:** 10778 10779以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 10780 10781| 错误码ID | 错误信息 | 10782| ------- | ------------------------------ | 10783| 1300005 | This window stage is abnormal. | 10784 10785**示例:** 10786<!--code_no_check--> 10787```ts 10788// EntryAbility.ets 10789import { UIAbility } from '@kit.AbilityKit'; 10790import { BusinessError } from '@kit.BasicServicesKit'; 10791 10792export default class EntryAbility extends UIAbility { 10793 // ... 10794 10795 onWindowStageCreate(windowStage: window.WindowStage) { 10796 console.info('onWindowStageCreate'); 10797 let windowClass: window.Window[] = []; 10798 let promise = windowStage.getSubWindow(); 10799 promise.then((data) => { 10800 windowClass = data; 10801 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 10802 }).catch((err: BusinessError) => { 10803 console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`); 10804 }); 10805 } 10806}; 10807``` 10808 10809### loadContent<sup>9+</sup> 10810 10811loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 10812 10813为当前WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 10814 10815**模型约束:** 此接口仅可在Stage模型下使用。 10816 10817**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10818 10819**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10820 10821**参数:** 10822 10823| 参数名 | 类型 | 必填 | 说明 | 10824| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 10825| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 10826| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 10827| callback | AsyncCallback<void> | 是 | 回调函数。 | 10828 10829**错误码:** 10830 10831以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10832 10833| 错误码ID | 错误信息 | 10834| ------- | ------------------------------ | 10835| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10836| 1300002 | This window state is abnormal. | 10837| 1300005 | This window stage is abnormal. | 10838 10839**示例:** 10840 10841```ts 10842// EntryAbility.ets 10843import { UIAbility } from '@kit.AbilityKit'; 10844import { BusinessError } from '@kit.BasicServicesKit'; 10845 10846export default class EntryAbility extends UIAbility { 10847 // ... 10848 10849 storage: LocalStorage = new LocalStorage(); 10850 10851 onWindowStageCreate(windowStage: window.WindowStage) { 10852 this.storage.setOrCreate('storageSimpleProp', 121); 10853 console.info('onWindowStageCreate'); 10854 try { 10855 windowStage.loadContent('pages/page2', this.storage, (err: BusinessError) => { 10856 const errCode: number = err.code; 10857 if (errCode) { 10858 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 10859 return; 10860 } 10861 console.info('Succeeded in loading the content.'); 10862 }); 10863 } catch (exception) { 10864 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 10865 } 10866 } 10867}; 10868``` 10869 10870### loadContent<sup>9+</sup> 10871 10872loadContent(path: string, storage?: LocalStorage): Promise<void> 10873 10874为当前WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 10875 10876**模型约束:** 此接口仅可在Stage模型下使用。 10877 10878**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10879 10880**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10881 10882**参数:** 10883 10884| 参数名 | 类型 | 必填 | 说明 | 10885| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 10886| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 10887| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 否 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 10888 10889**返回值:** 10890 10891| 类型 | 说明 | 10892| ------------------- | ------------------------- | 10893| Promise<void> | 无返回结果的Promise对象。 | 10894 10895**错误码:** 10896 10897以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10898 10899| 错误码ID | 错误信息 | 10900| ------- | ------------------------------ | 10901| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10902| 1300002 | This window state is abnormal. | 10903| 1300005 | This window stage is abnormal. | 10904 10905**示例:** 10906 10907```ts 10908// EntryAbility.ets 10909import { UIAbility } from '@kit.AbilityKit'; 10910import { BusinessError } from '@kit.BasicServicesKit'; 10911 10912export default class EntryAbility extends UIAbility { 10913 // ... 10914 10915 storage: LocalStorage = new LocalStorage(); 10916 10917 onWindowStageCreate(windowStage: window.WindowStage) { 10918 this.storage.setOrCreate('storageSimpleProp', 121); 10919 console.info('onWindowStageCreate'); 10920 try { 10921 let promise = windowStage.loadContent('pages/page2', this.storage); 10922 promise.then(() => { 10923 console.info('Succeeded in loading the content.'); 10924 }).catch((err: BusinessError) => { 10925 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 10926 }); 10927 } catch (exception) { 10928 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 10929 } 10930 ; 10931 } 10932}; 10933``` 10934 10935### loadContent<sup>9+</sup> 10936 10937loadContent(path: string, callback: AsyncCallback<void>): void 10938 10939为当前WindowStage的主窗口加载具体页面内容,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 10940 10941**模型约束:** 此接口仅可在Stage模型下使用。 10942 10943**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10944 10945**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10946 10947**参数:** 10948 10949| 参数名 | 类型 | 必填 | 说明 | 10950| -------- | ------------------------- | ---- | -------------------- | 10951| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 10952| callback | AsyncCallback<void> | 是 | 回调函数。 | 10953 10954**错误码:** 10955 10956以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10957 10958| 错误码ID | 错误信息 | 10959| ------- | ------------------------------ | 10960| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10961| 1300002 | This window state is abnormal. | 10962| 1300005 | This window stage is abnormal. | 10963 10964**示例:** 10965 10966```ts 10967// EntryAbility.ets 10968import { UIAbility } from '@kit.AbilityKit'; 10969import { BusinessError } from '@kit.BasicServicesKit'; 10970 10971export default class EntryAbility extends UIAbility { 10972 // ... 10973 10974 onWindowStageCreate(windowStage: window.WindowStage) { 10975 console.info('onWindowStageCreate'); 10976 try { 10977 windowStage.loadContent('pages/page2', (err: BusinessError) => { 10978 const errCode: number = err.code; 10979 if (errCode) { 10980 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 10981 return; 10982 } 10983 console.info('Succeeded in loading the content.'); 10984 }); 10985 } catch (exception) { 10986 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 10987 } 10988 } 10989}; 10990``` 10991 10992### loadContentByName<sup>11+</sup> 10993 10994loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback<void>): void 10995 10996为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 10997 10998**模型约束:** 此接口仅可在Stage模型下使用。 10999 11000**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11001 11002**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11003 11004**参数:** 11005 11006| 参数名 | 类型 | 必填 | 说明 | 11007| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 11008| name | string | 是 | 命名路由页面的名称。 | 11009| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 11010| callback | AsyncCallback<void> | 是 | 回调函数。 | 11011 11012**错误码:** 11013 11014以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11015 11016| 错误码ID | 错误信息 | 11017| -------- | --------------------------------------------- | 11018| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11019| 1300002 | This window state is abnormal. | 11020| 1300003 | This window manager service works abnormally. | 11021 11022**示例:** 11023 11024<!--code_no_check--> 11025```ts 11026// EntryAbility.ets 11027import { UIAbility } from '@kit.AbilityKit'; 11028import { BusinessError } from '@kit.BasicServicesKit'; 11029import * as Index from '../pages/Index'; // 导入命名路由页面 11030 11031export default class EntryAbility extends UIAbility { 11032 // ... 11033 11034 storage: LocalStorage = new LocalStorage(); 11035 11036 onWindowStageCreate(windowStage: window.WindowStage) { 11037 console.info('onWindowStageCreate'); 11038 this.storage.setOrCreate('storageSimpleProp', 121); 11039 try { 11040 windowStage.loadContentByName(Index.entryName, this.storage, (err: BusinessError) => { 11041 const errCode: number = err.code; 11042 if (errCode) { 11043 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 11044 return; 11045 } 11046 console.info('Succeeded in loading the content.'); 11047 }); 11048 } catch (exception) { 11049 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 11050 } 11051 } 11052}; 11053``` 11054<!--code_no_check--> 11055```ts 11056// ets/pages/Index.ets 11057export const entryName : string = 'Index'; 11058@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 11059@Component 11060export struct Index { 11061 @State message: string = 'Hello World' 11062 build() { 11063 Row() { 11064 Column() { 11065 Text(this.message) 11066 .fontSize(50) 11067 .fontWeight(FontWeight.Bold) 11068 } 11069 .width('100%') 11070 } 11071 .height('100%') 11072 } 11073} 11074``` 11075 11076### loadContentByName<sup>11+</sup> 11077 11078loadContentByName(name: string, callback: AsyncCallback<void>): void 11079 11080为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 11081 11082**模型约束:** 此接口仅可在Stage模型下使用。 11083 11084**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11085 11086**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11087 11088**参数:** 11089 11090| 参数名 | 类型 | 必填 | 说明 | 11091| -------- | ------------------------- | ---- | ---------------- | 11092| name | string | 是 | 命名路由页面的名称。 | 11093| callback | AsyncCallback<void> | 是 | 回调函数。 | 11094 11095**错误码:** 11096 11097以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11098 11099| 错误码ID | 错误信息 | 11100| -------- | --------------------------------------------- | 11101| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11102| 1300002 | This window state is abnormal. | 11103| 1300003 | This window manager service works abnormally. | 11104 11105**示例:** 11106 11107<!--code_no_check--> 11108```ts 11109// EntryAbility.ets 11110import { UIAbility } from '@kit.AbilityKit'; 11111import { BusinessError } from '@kit.BasicServicesKit'; 11112import * as Index from '../pages/Index'; // 导入命名路由页面 11113 11114export default class EntryAbility extends UIAbility { 11115 // ... 11116 11117 onWindowStageCreate(windowStage: window.WindowStage) { 11118 console.info('onWindowStageCreate'); 11119 try { 11120 windowStage.loadContentByName(Index.entryName, (err: BusinessError) => { 11121 const errCode: number = err.code; 11122 if (errCode) { 11123 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 11124 return; 11125 } 11126 console.info('Succeeded in loading the content.'); 11127 }); 11128 } catch (exception) { 11129 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 11130 } 11131 } 11132}; 11133``` 11134<!--code_no_check--> 11135```ts 11136// ets/pages/Index.ets 11137export const entryName : string = 'Index'; 11138@Entry({routeName: entryName}) 11139@Component 11140export struct Index { 11141 @State message: string = 'Hello World' 11142 build() { 11143 Row() { 11144 Column() { 11145 Text(this.message) 11146 .fontSize(50) 11147 .fontWeight(FontWeight.Bold) 11148 } 11149 .width('100%') 11150 } 11151 .height('100%') 11152 } 11153} 11154``` 11155 11156### loadContentByName<sup>11+</sup> 11157 11158loadContentByName(name: string, storage?: LocalStorage): Promise<void>; 11159 11160为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用promise异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 11161 11162**模型约束:** 此接口仅可在Stage模型下使用。 11163 11164**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11165 11166**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11167 11168**参数:** 11169 11170| 参数名 | 类型 | 必填 | 说明 | 11171| ------- | ------------ | ---- | ------------------------------------------------------------ | 11172| name | string | 是 | 命名路由页面的名称。 | 11173| storage | LocalStorage | 否 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 11174 11175**错误码:** 11176 11177以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11178 11179| 错误码ID | 错误信息 | 11180| -------- | --------------------------------------------- | 11181| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11182| 1300002 | This window state is abnormal. | 11183| 1300003 | This window manager service works abnormally. | 11184 11185**示例:** 11186 11187<!--code_no_check--> 11188```ts 11189// EntryAbility.ets 11190import { UIAbility } from '@kit.AbilityKit'; 11191import { BusinessError } from '@kit.BasicServicesKit'; 11192import * as Index from '../pages/Index'; // 导入命名路由页面 11193 11194export default class EntryAbility extends UIAbility { 11195 // ... 11196 11197 storage: LocalStorage = new LocalStorage(); 11198 11199 onWindowStageCreate(windowStage: window.WindowStage) { 11200 console.info('onWindowStageCreate'); 11201 this.storage.setOrCreate('storageSimpleProp', 121); 11202 try { 11203 let promise = windowStage.loadContentByName(Index.entryName, this.storage); 11204 promise.then(() => { 11205 console.info('Succeeded in loading the content.'); 11206 }).catch((err: BusinessError) => { 11207 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 11208 }); 11209 } catch (exception) { 11210 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 11211 } 11212 } 11213}; 11214``` 11215<!--code_no_check--> 11216```ts 11217// ets/pages/Index.ets 11218export const entryName : string = 'Index'; 11219@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 11220@Component 11221export struct Index { 11222 @State message: string = 'Hello World' 11223 build() { 11224 Row() { 11225 Column() { 11226 Text(this.message) 11227 .fontSize(50) 11228 .fontWeight(FontWeight.Bold) 11229 } 11230 .width('100%') 11231 } 11232 .height('100%') 11233 } 11234} 11235``` 11236 11237### on('windowStageEvent')<sup>9+</sup> 11238 11239on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void 11240 11241开启WindowStage生命周期变化的监听。 11242 11243**模型约束:** 此接口仅可在Stage模型下使用。 11244 11245**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11246 11247**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11248 11249**参数:** 11250 11251| 参数名 | 类型 | 必填 | 说明 | 11252| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 11253| eventType | string | 是 | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 | 11254| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | 是 | 回调函数。返回当前的WindowStage生命周期状态。 | 11255 11256**错误码:** 11257 11258以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11259 11260| 错误码ID | 错误信息 | 11261| ------- | ------------------------------ | 11262| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 11263| 1300002 | This window state is abnormal. | 11264| 1300005 | This window stage is abnormal. | 11265 11266**示例:** 11267 11268```ts 11269// EntryAbility.ets 11270import { UIAbility } from '@kit.AbilityKit'; 11271 11272export default class EntryAbility extends UIAbility { 11273 // ... 11274 11275 onWindowStageCreate(windowStage: window.WindowStage) { 11276 console.info('onWindowStageCreate'); 11277 try { 11278 windowStage.on('windowStageEvent', (data) => { 11279 console.info('Succeeded in enabling the listener for window stage event changes. Data: ' + 11280 JSON.stringify(data)); 11281 }); 11282 } catch (exception) { 11283 console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`); 11284 } 11285 } 11286}; 11287``` 11288 11289### off('windowStageEvent')<sup>9+</sup> 11290 11291off(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType>): void 11292 11293关闭WindowStage生命周期变化的监听。 11294 11295**模型约束:** 此接口仅可在Stage模型下使用。 11296 11297**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11298 11299**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11300 11301**参数:** 11302 11303| 参数名 | 类型 | 必填 | 说明 | 11304| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 11305| eventType | string | 是 | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 | 11306| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | 否 | 回调函数。返回当前的WindowStage生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有WindowStage生命周期变化的监听。 | 11307 11308**错误码:** 11309 11310以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11311 11312| 错误码ID | 错误信息 | 11313| ------- | ------------------------------ | 11314| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 11315| 1300002 | This window state is abnormal. | 11316| 1300005 | This window stage is abnormal. | 11317 11318**示例:** 11319 11320```ts 11321// EntryAbility.ets 11322import { UIAbility } from '@kit.AbilityKit'; 11323 11324export default class EntryAbility extends UIAbility { 11325 // ... 11326 11327 onWindowStageCreate(windowStage: window.WindowStage) { 11328 console.info('onWindowStageCreate'); 11329 const callback = (windowStageEventType: window.WindowStageEventType) => { 11330 // ... 11331 } 11332 try { 11333 windowStage.on('windowStageEvent', callback); 11334 } catch (exception) { 11335 console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`); 11336 } 11337 try { 11338 windowStage.off('windowStageEvent', callback); 11339 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 11340 windowStage.off('windowStageEvent'); 11341 } catch (exception) { 11342 console.error(`Failed to disable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`); 11343 } 11344 } 11345}; 11346``` 11347 11348### on('windowStageClose')<sup>14+</sup> 11349 11350on(eventType: 'windowStageClose', callback: Callback<void>): void 11351 11352开启点击主窗三键区的关闭按钮监听事件。点击主窗口的三键区域的关闭键时触发该回调函数,将不执行注册的[UIAbility.onPrepareToTerminate](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonpreparetoterminate10)生命周期回调函数。 11353 11354当重复注册窗口关闭事件的监听时,最后一次注册成功的监听事件生效。 11355 11356触发的回调函数是同步执行,主窗口的异步关闭事件监听参考[on('windowWillClose')](#onwindowwillclose15)方法。 11357 11358如果存在[on('windowWillClose')](#onwindowwillclose15)监听事件,只响应[on('windowWillClose')](#onwindowwillclose15)接口。 11359 11360<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 11361 11362**模型约束:** 此接口仅可在Stage模型下使用。 11363 11364**系统能力:** SystemCapability.Window.SessionManager 11365 11366**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 11367 11368**参数:** 11369 11370| 参数名 | 类型 | 必填 | 说明 | 11371| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 11372| eventType | string | 是 | 监听事件,固定为'windowStageClose',即开启主窗三键区的关闭按钮监听。| 11373| callback | Callback<void> | 是 | 回调函数。当点击主窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前主窗是否继续关闭,true表示不关闭,false表示关闭。| 11374 11375**错误码:** 11376 11377以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11378 11379| 错误码ID | 错误信息 | 11380| ------- | ------------------------------ | 11381| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 11382| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11383| 1300002 | This window state is abnormal. | 11384 11385**示例:** 11386 11387```ts 11388// EntryAbility.ets 11389import { UIAbility } from '@kit.AbilityKit'; 11390import { window } from '@kit.ArkUI'; 11391 11392export default class EntryAbility extends UIAbility { 11393 // ... 11394 11395 onWindowStageCreate(windowStage: window.WindowStage) { 11396 console.info('onWindowStageCreate'); 11397 try { 11398 windowStage.on('windowStageClose', () => { 11399 console.info('Succeeded in enabling the listener for window stage close event.'); 11400 return false; 11401 }); 11402 } catch (exception) { 11403 console.error(`Failed to enable the listener for window stage close event. Cause code: ${exception.code}, message: ${exception.message}`); 11404 } 11405 } 11406}; 11407``` 11408 11409### off('windowStageClose')<sup>14+</sup> 11410 11411off(eventType: 'windowStageClose', callback?: Callback<void>): void 11412 11413关闭主窗口关闭事件的监听。 11414 11415<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 11416 11417**模型约束:** 此接口仅可在Stage模型下使用。 11418 11419**系统能力:** SystemCapability.Window.SessionManager 11420 11421**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 11422 11423**参数:** 11424 11425| 参数名 | 类型 | 必填 | 说明 | 11426| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 11427| eventType | string | 是 | 监听事件,固定为'windowStageClose',即关闭主窗口关闭事件的监听。 | 11428| callback | Callback<void> | 否 | 回调函数。当点击主窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前主窗是否继续关闭,true表示不关闭,false表示关闭。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有主窗口关闭的监听。 | 11429 11430**错误码:** 11431 11432以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11433 11434| 错误码ID | 错误信息 | 11435| ------- | ------------------------------ | 11436| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 11437| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11438| 1300002 | This window state is abnormal. | 11439 11440**示例:** 11441 11442```ts 11443// EntryAbility.ets 11444import { UIAbility } from '@kit.AbilityKit'; 11445import { window } from '@kit.ArkUI'; 11446 11447export default class EntryAbility extends UIAbility { 11448 // ... 11449 11450 onWindowStageCreate(windowStage: window.WindowStage) { 11451 console.info('onWindowStageCreate'); 11452 const callback = () => { 11453 // ... 11454 return false; 11455 } 11456 try { 11457 windowStage.on('windowStageClose', callback); 11458 windowStage.off('windowStageClose', callback); 11459 windowStage.off('windowStageClose'); 11460 } catch (exception) { 11461 console.error(`Failed to disable the listener for window stage close changes. Cause code: ${exception.code}, message: ${exception.message}`); 11462 } 11463 } 11464}; 11465``` 11466 11467### setDefaultDensityEnabled<sup>12+</sup> 11468 11469setDefaultDensityEnabled(enabled: boolean): void 11470 11471设置应用是否使用系统默认Density。 11472 11473不调用此接口进行设置,则表示不使用系统默认Density,即窗口会跟随系统显示大小变化重新布局。 11474 11475**模型约束:** 此接口仅可在Stage模型下使用。 11476 11477**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 11478 11479**系统能力:** SystemCapability.Window.SessionManager 11480 11481**参数:** 11482 11483| 参数名 | 类型 | 必填 | 说明 | 11484| ---------------- | ------- | ---- | ---------------------------- | 11485| enabled | boolean | 是 | 是否设置应用使用系统默认Density。true表示使用系统默认Density,窗口不跟随系统显示大小变化重新布局;false表示不使用系统默认Density,窗口跟随系统显示大小变化重新布局。 | 11486 11487**错误码:** 11488 11489以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11490 11491| 错误码ID | 错误信息 | 11492| ------- | ------------------------------ | 11493| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11494| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11495| 1300002 | This window state is abnormal. | 11496| 1300005 | This window stage is abnormal. | 11497 11498**示例:** 11499 11500```ts 11501// EntryAbility.ets 11502import { UIAbility } from '@kit.AbilityKit'; 11503 11504export default class EntryAbility extends UIAbility { 11505 // ... 11506 11507 onWindowStageCreate(windowStage: window.WindowStage) { 11508 console.info('onWindowStageCreate'); 11509 try { 11510 windowStage.setDefaultDensityEnabled(true); 11511 } catch (exception) { 11512 console.error(`Failed to set default density enabled. Cause code: ${exception.code}, message: ${exception.message}`); 11513 } 11514 } 11515}; 11516``` 11517 11518### setCustomDensity<sup>15+</sup> 11519 11520setCustomDensity(density: number): void 11521 11522支持应用主窗口自定义其显示大小缩放系数,子窗会跟随主窗生效。当存在同时使用该接口和[setDefaultDensityEnabled(true)](#setdefaultdensityenabled12)时,以最终调用的结果设置效果为准。 11523 11524**模型约束:** 此接口仅可在Stage模型下使用。 11525 11526**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 11527 11528**系统能力:** SystemCapability.Window.SessionManager 11529 11530**参数:** 11531 11532| 参数名 | 类型 | 必填 | 说明 | 11533| ---------------- | ------- | ---- | ---------------------------- | 11534| density | number | 是 | 自定义显示大小缩放系数。该参数为浮点数,取值范围为[0.5, 4.0]或-1.0。4.0表示窗口可显示的最大显示大小缩放系数,-1.0表示窗口使用系统显示大小缩放系数。 | 11535 11536**错误码:** 11537 11538以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11539 11540| 错误码ID | 错误信息 | 11541| ------- | ------------------------------ | 11542| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11543| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11544| 1300002 | This window state is abnormal. | 11545| 1300005 | This window stage is abnormal. | 11546 11547**示例:** 11548 11549```ts 11550// EntryAbility.ets 11551import { UIAbility } from '@kit.AbilityKit'; 11552 11553export default class EntryAbility extends UIAbility { 11554 // ... 11555 11556 onWindowStageCreate(windowStage: window.WindowStage) { 11557 console.info('onWindowStageCreate'); 11558 try { 11559 windowStage.setCustomDensity(-1.0); 11560 } catch (exception) { 11561 console.error(`Failed to set custom density. Cause code: ${exception.code}, message: ${exception.message}`); 11562 } 11563 } 11564}; 11565``` 11566 11567### setWindowModal<sup>14+</sup> 11568 11569setWindowModal(isModal: boolean): Promise<void> 11570 11571设置主窗的模态属性是否启用,使用Promise异步回调。 11572 11573主窗口调用该接口时,设置主窗口模态属性是否启用。启用主窗口模态属性后,其相同应用进程下的其他主窗口以及其他主窗口的子窗口不能响应用户操作,直到该主窗口关闭或者主窗口的模态属性被禁用。 11574 11575<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 11576 11577**模型约束:** 此接口仅可在Stage模型下使用。 11578 11579**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 11580 11581**系统能力:** SystemCapability.Window.SessionManager 11582 11583**参数:** 11584 11585| 参数名 | 类型 | 必填 | 说明 | 11586| --------- | ------- | ---- | --------------------------------------------- | 11587| isModal | boolean | 是 | 设置主窗口模态属性是否启用,true为启用,false为不启用。 | 11588 11589 11590**返回值:** 11591 11592| 类型 | 说明 | 11593| ------------------- | ------------------------ | 11594| Promise<void> | 无返回结果的Promise对象。 | 11595 11596**错误码:** 11597 11598以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11599 11600| 错误码ID | 错误信息 | 11601| -------- | ------------------------------ | 11602| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11603| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11604| 1300002 | This window state is abnormal. | 11605| 1300003 | This window manager service works abnormally. | 11606 11607**示例:** 11608 11609```ts 11610// EntryAbility.ets 11611import { UIAbility } from '@kit.AbilityKit'; 11612import { BusinessError } from '@kit.BasicServicesKit'; 11613 11614export default class EntryAbility extends UIAbility { 11615 // ... 11616 onWindowStageCreate(windowStage: window.WindowStage): void { 11617 console.info('onWindowStageCreate'); 11618 try { 11619 let promise = windowStage.setWindowModal(true); 11620 promise.then(() => { 11621 console.info('Succeeded in setting window modal'); 11622 }).catch((err: BusinessError) => { 11623 console.error(`Failed to set window modal. Cause code: ${err.code}, message: ${err.message}`); 11624 }); 11625 } catch (exception) { 11626 console.error(`Failed to set window modal. Cause code: ${exception.code}, message: ${exception.message}`); 11627 } 11628 } 11629} 11630``` 11631 11632### removeStartingWindow<sup>14+</sup> 11633 11634removeStartingWindow(): Promise<void> 11635 11636支持应用控制启动页消失时机。 11637 11638此接口只对应用主窗口生效,且需要在module.json5配置文件[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中的metadata标签下配置"enable.remove.starting.window"为"true"才会生效。 11639 11640在标签配置为"true"的情况下,系统提供了启动页超时保护机制,若5s内未调用此接口,系统将自动移除启动页。 11641 11642若标签配置为"false"或未配置标签,则此接口不生效,启动页将会在应用首帧渲染完成后自动移除。 11643 11644**模型约束:** 此接口仅可在Stage模型下使用。 11645 11646**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 11647 11648**系统能力:** SystemCapability.Window.SessionManager 11649 11650**返回值:** 11651 11652| 类型 | 说明 | 11653| ------------------- | ------------------------- | 11654| Promise<void> | 无返回结果的Promise对象。 | 11655 11656**错误码:** 11657 11658以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11659 11660| 错误码ID | 错误信息 | 11661| ------- | ------------------------------ | 11662| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11663| 1300002 | This window state is abnormal. | 11664| 1300003 | This window manager service works abnormally. | 11665 11666**示例:** 11667 11668```ts 11669// EntryAbility.ets 11670import { UIAbility } from '@kit.AbilityKit'; 11671import { BusinessError } from '@kit.BasicServicesKit'; 11672 11673export default class EntryAbility extends UIAbility { 11674 // ... 11675 11676 onWindowStageCreate(windowStage: window.WindowStage) { 11677 console.info('onWindowStageCreate'); 11678 windowStage.removeStartingWindow().then(() => { 11679 console.info('Succeeded in removing starting window.'); 11680 }).catch((err: BusinessError) => { 11681 console.error(`Failed to remove starting window. Cause code: ${err.code}, message: ${err.message}`); 11682 }); 11683 } 11684}; 11685``` 11686 11687### setWindowRectAutoSave<sup>14+</sup> 11688 11689setWindowRectAutoSave(enabled: boolean): Promise<void> 11690 11691设置主窗的尺寸记忆是否启用,使用Promise异步回调,仅对2in1设备生效。 11692 11693主窗口调用该接口时,设置主窗口的尺寸记忆是否启用。启用主窗口尺寸记忆功能后,在同一个UIAbility下,记忆最后关闭的窗口的尺寸和模式。 11694 11695窗口再次启动时,以记忆的尺寸和模式按照规则进行打开。 11696 11697层叠规则: 116981、当前实例是自由窗口时,打开下一实例窗口层叠时,大小要跟随。 116992、当前实例是最大化或全屏窗口时,打开下一个实例窗口层叠时,保持最大化。 11700 11701记忆规则: 11702|上一次窗口状态|记忆规则| 11703|-------------|-------| 11704|自由窗口|保留自由窗口的大小/位置,超出工作区回弹| 11705|二分屏窗口|保留二分屏之前自由窗口的大小/位置| 11706|最大化窗口|保留最大化| 11707|沉浸式窗口|保留沉浸式之前自由窗口的大小/位置| 11708|最小化窗口|保留最小化之前自由窗口的大小/位置| 11709 11710**模型约束:** 此接口仅可在Stage模型下使用。 11711 11712**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 11713 11714**系统能力:** SystemCapability.Window.SessionManager 11715 11716**参数:** 11717 11718| 参数名 | 类型 | 必填 | 说明 | 11719| --------- | ------- | ---- | --------------------------------------------- | 11720| enabled | boolean | 是 | 设置主窗口的尺寸记忆是否启用,true为启用,false为不启用。 | 11721 11722 11723**返回值:** 11724 11725| 类型 | 说明 | 11726| ------------------- | ------------------------ | 11727| Promise<void> | 无返回结果的Promise对象。 | 11728 11729**错误码:** 11730 11731以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11732 11733| 错误码ID | 错误信息 | 11734| -------- | ------------------------------ | 11735| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11736| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11737| 1300002 | This window state is abnormal. | 11738| 1300003 | This window manager service works abnormally. | 11739 11740**示例:** 11741 11742```ts 11743// EntryAbility.ets 11744import { UIAbility } from '@kit.AbilityKit'; 11745import { BusinessError } from '@kit.BasicServicesKit'; 11746 11747export default class EntryAbility extends UIAbility { 11748 // ... 11749 onWindowStageCreate(windowStage: window.WindowStage): void { 11750 console.info('onWindowStageCreate'); 11751 try { 11752 let promise = windowStage.setWindowRectAutoSave(true); 11753 promise.then(() => { 11754 console.info('Succeeded in setting window rect auto-save'); 11755 }).catch((err: BusinessError) => { 11756 console.error(`Failed to set window rect auto-save. Cause code: ${err.code}, message: ${err.message}`); 11757 }); 11758 } catch (exception) { 11759 console.error(`Failed to set window rect auto-save. Cause code: ${exception.code}, message: ${exception.message}`); 11760 } 11761 } 11762} 11763``` 11764 11765### isWindowRectAutoSave<sup>14+</sup> 11766 11767isWindowRectAutoSave(): Promise<boolean> 11768 11769判断当前主窗口是否已经启用尺寸记忆,使用Promise异步回调,仅对2in1设备生效。 11770 11771**模型约束:** 此接口仅可在Stage模型下使用。 11772 11773**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 11774 11775**系统能力:** SystemCapability.Window.SessionManager 11776 11777**返回值:** 11778 11779| 类型 | 说明 | 11780| ---------------------- | ------------------------------------------------------------------------------------ | 11781| Promise<boolean> | Promise对象。返回true表示当前窗口启用尺寸记忆,返回false表示当前窗口禁用尺寸记忆。 | 11782 11783**错误码:** 11784 11785以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 11786 11787| 错误码ID | 错误信息 | 11788| ------- | ------------------------------ | 11789| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11790| 1300002 | This window state is abnormal. | 11791 11792**示例:** 11793 11794```ts 11795// EntryAbility.ets 11796import { UIAbility } from '@kit.AbilityKit'; 11797import { BusinessError } from '@kit.BasicServicesKit'; 11798 11799export default class EntryAbility extends UIAbility { 11800 // ... 11801 onWindowStageCreate(windowStage: window.WindowStage): void { 11802 console.info('onWindowStageCreate'); 11803 try { 11804 let promise = windowStage.isWindowRectAutoSave(); 11805 promise.then((data) => { 11806 console.info('Succeeded in checking whether the window support the rect auto-save. Data: ' + JSON.stringify(data)); 11807 }).catch((err: BusinessError) => { 11808 console.error(`Failed to check whether the window support the rect auto-save. Cause code: ${err.code}, message: ${err.message}`); 11809 }); 11810 } catch (exception) { 11811 console.error(`Failed to check whether the window support the rect auto-save. Cause code: ${exception.code}, message: ${exception.message}`); 11812 } 11813 } 11814} 11815``` 11816 11817### setSupportedWindowModes<sup>15+</sup> 11818 11819setSupportedWindowModes(supportedWindowModes: Array<bundleManager.SupportWindowMode>): Promise<void> 11820 11821设置主窗的窗口支持模式,使用Promise异步回调。 11822 11823<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 11824 11825**模型约束:** 此接口仅可在Stage模型下使用。 11826 11827**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 11828 11829**系统能力:** SystemCapability.Window.SessionManager 11830 11831**参数:** 11832 11833| 参数名 | 类型 | 必填 | 说明 | 11834| --------- | ------- | ---- | --------------------------------------------- | 11835| supportedWindowModes | Array<[bundleManager.SupportWindowMode](../apis-ability-kit/js-apis-bundleManager.md#supportwindowmode)> | 是 | 设置主窗的窗口支持模式。<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#属性)的supportWindowModes字段取值冲突。当取值冲突时,最终以该参数设置的窗口支持模式为准。| 11836 11837**返回值:** 11838 11839| 类型 | 说明 | 11840| ------------------- | ------------------------ | 11841| Promise<void> | 无返回结果的Promise对象。 | 11842 11843**错误码:** 11844 11845以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11846 11847| 错误码ID | 错误信息 | 11848| -------- | ------------------------------ | 11849| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11850| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11851| 1300002 | This window state is abnormal. | 11852| 1300003 | This window manager service works abnormally. | 11853 11854**示例:** 11855 11856```ts 11857// EntryAbility.ets 11858import { UIAbility, bundleManager } from '@kit.AbilityKit'; 11859import { BusinessError } from '@kit.BasicServicesKit'; 11860 11861export default class EntryAbility extends UIAbility { 11862 // ... 11863 onWindowStageCreate(windowStage: window.WindowStage): void { 11864 console.info('onWindowStageCreate'); 11865 try { 11866 let promise = windowStage.setSupportedWindowModes([ 11867 bundleManager.SupportWindowMode.FULL_SCREEN, 11868 bundleManager.SupportWindowMode.SPLIT, 11869 bundleManager.SupportWindowMode.FLOATING 11870 ]); 11871 promise.then(() => { 11872 console.info('Succeeded in setting window support modes'); 11873 }).catch((err: BusinessError) => { 11874 console.error(`Failed to set window support modes. Cause code: ${err.code}, message: ${err.message}`); 11875 }); 11876 } catch (exception) { 11877 console.error(`Failed to set window support modes. Cause code: ${exception.code}, message: ${exception.message}`); 11878 } 11879 } 11880} 11881``` 11882