1# @ohos.window (窗口) 2 3窗口提供管理窗口的一些基础能力,包括对当前窗口的创建、销毁、各属性设置,以及对各窗口间的管理调度。 4 5该模块提供以下窗口相关的常用功能: 6 7- [Window](#window):当前窗口实例,窗口管理器管理的基本单元。 8- [WindowStage](#windowstage9):窗口管理器。管理各个基本窗口单元。 9 10> **说明:** 11> 12> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 13 14## 导入模块 15 16```ts 17import { window } from '@kit.ArkUI'; 18``` 19 20## WindowType<sup>7+</sup> 21 22窗口类型枚举。 23 24**系统能力:** SystemCapability.WindowManager.WindowManager.Core 25 26| 名称 | 值 | 说明 | 27|-------------------------------------| ------ |----------------------------------------------------------------------------------------| 28| TYPE_APP | 0 | 表示应用子窗口。<br>**模型约束:** 此接口仅可在FA模型下使用。 | 29| TYPE_SYSTEM_ALERT | 1 | 表示系统告警窗口。<br>- **说明:** 从API version 11开始废弃。<br>- 从 API version 7开始支持。 | 30| TYPE_FLOAT<sup>9+</sup> | 8 | 表示悬浮窗。<br>**模型约束:** 此接口仅可在Stage模型下使用。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 31| TYPE_DIALOG<sup>10+</sup> | 16 | 表示模态窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 32 33## Configuration<sup>9+</sup> 34 35创建子窗口或系统窗口时的参数。 36 37**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 38 39**系统能力:** SystemCapability.WindowManager.WindowManager.Core 40 41| 名称 | 类型 | 必填 | 说明 | 42| ---------- | -------------------------- | -- |-----------------------------------------------------------------------------| 43| name | string | 是 | 窗口名字。 | 44| windowType | [WindowType](#windowtype7) | 是 | 窗口类型。 | 45| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 否 | 当前应用上下文信息。不设置,则默认为空。<br>FA模型下不需要使用该参数,即可创建子窗口,使用该参数时会报错。<br>Stage模型必须使用该参数,用于创建悬浮窗、模态窗或系统窗口。 | 46| displayId | number | 否 | 当前物理屏幕id。不设置,则默认为-1,该参数应为整数。 | 47| parentId | number | 否 | 父窗口id。不设置,则默认为-1,该参数应为整数。 | 48| decorEnabled<sup>12+</sup> | boolean | 否 | 是否显示窗口装饰,仅在windowType为TYPE_DIALOG时生效。true表示显示,false表示不显示。此参数默认值为false。<br>**系统能力:** SystemCapability.Window.SessionManager | 49| title<sup>12+</sup> | string| 否 | `decorEnabled`属性设置为true时,窗口的标题内容。不设置,则默认为空字符串。 <br>**系统能力:** SystemCapability.Window.SessionManager | 50 51## AvoidAreaType<sup>7+</sup> 52 53窗口内容需要规避区域的类型枚举。 54 55**系统能力:** SystemCapability.WindowManager.WindowManager.Core 56 57**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 58 59| 名称 | 值 | 说明 | 60| -------------------------------- | ---- | ------------------------------------------------------------ | 61| TYPE_SYSTEM | 0 | 表示系统默认区域。一般包括状态栏、导航栏,各设备系统定义可能不同。 | 62| TYPE_CUTOUT | 1 | 表示刘海屏区域。 | 63| TYPE_SYSTEM_GESTURE<sup>9+</sup> | 2 | 表示手势区域。 | 64| TYPE_KEYBOARD<sup>9+</sup> | 3 | 表示软键盘区域。 | 65| TYPE_NAVIGATION_INDICATOR<sup>11+</sup> | 4 | 表示导航条区域。 | 66 67 68## SystemBarProperties 69 70状态栏、导航栏的属性。在设置窗口级状态栏、导航栏属性时使用。 71 72**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 73 74| 名称 | 类型 | 必填 | 说明 | 75| -------------------------------------- | -------- | ---- | ------------------------------------------------------------ | 76| statusBarColor | string | 否 | 状态栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。默认值:`'#0x66000000'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。| 77| isStatusBarLightIcon<sup>7+</sup> | boolean | 否 | 状态栏图标是否为高亮状态。true表示高亮;false表示不高亮。默认值:false。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。| 78| statusBarContentColor<sup>8+</sup> | string | 否 | 状态栏文字颜色。当设置此属性后, `isStatusBarLightIcon`属性设置无效。默认值:`'#0xE5FFFFFF'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。| 79| navigationBarColor | string | 否 | 导航栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。默认值:`'#0x66000000'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。| 80| isNavigationBarLightIcon<sup>7+</sup> | boolean | 否 | 导航栏图标是否为高亮状态。true表示高亮;false表示不高亮。默认值:false。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。| 81| navigationBarContentColor<sup>8+</sup> | string | 否 | 导航栏文字颜色。当设置此属性后, `isNavigationBarLightIcon`属性设置无效。默认值:`'#0xE5FFFFFF'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。| 82| enableStatusBarAnimation<sup>12+</sup> | boolean | 否 | 是否使能状态栏属性变化时动画效果。true表示变化时使能动画效果;false表示没有使能动画效果。默认值:false。 <br> **系统能力:** SystemCapability.Window.SessionManager。| 83| enableNavigationBarAnimation<sup>12+</sup> | boolean | 否 | 是否使能导航栏属性变化时动画效果。true表示变化时使能动画效果;false表示没有使能动画效果。默认值:false。 <br> **系统能力:** SystemCapability.Window.SessionManager。| 84 85## SystemBarStyle<sup>12+</sup> 86 87状态栏的属性。在设置页面级状态栏属性时使用。 88 89**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 90 91**系统能力:** SystemCapability.WindowManager.WindowManager.Core 92 93| 名称 | 类型 | 只读 | 可选 | 说明 | 94| ------ | -------- | ---- | ---- | ------------------ | 95| statusBarContentColor | string | 是 | 是 | 状态栏文字颜色。默认值:`'#0xE5FFFFFF'`。| 96 97## Orientation<sup>9+</sup> 98 99窗口显示方向类型枚举。 100 101| 名称 | 值 | 说明 | 102| ------------------------------------- | ---- | ----------------------------- | 103| UNSPECIFIED | 0 | 表示未定义方向模式,由系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。| 104| PORTRAIT | 1 | 表示竖屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。| 105| LANDSCAPE | 2 | 表示横屏显示模式。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。| 106| PORTRAIT_INVERTED | 3 | 表示反向竖屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 107| LANDSCAPE_INVERTED | 4 | 表示反向横屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 108| AUTO_ROTATION | 5 | 跟随传感器自动旋转,可以旋转到竖屏、横屏、反向竖屏、反向横屏四个方向。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。| 109| AUTO_ROTATION_PORTRAIT | 6 | 跟随传感器自动竖向旋转,可以旋转到竖屏、反向竖屏,无法旋转到横屏、反向横屏。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。| 110| AUTO_ROTATION_LANDSCAPE | 7 | 跟随传感器自动横向旋转,可以旋转到横屏、反向横屏,无法旋转到竖屏、反向竖屏。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 111| AUTO_ROTATION_RESTRICTED | 8 | 跟随传感器自动旋转,可以旋转到竖屏、横屏、反向竖屏、反向横屏四个方向,且受控制中心的旋转开关控制。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 112| AUTO_ROTATION_PORTRAIT_RESTRICTED | 9 | 跟随传感器自动竖向旋转,可以旋转到竖屏、反向竖屏,无法旋转到横屏、反向横屏,且受控制中心的旋转开关控制。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。| 113| AUTO_ROTATION_LANDSCAPE_RESTRICTED | 10 | 跟随传感器自动横向旋转,可以旋转到横屏、反向横屏,无法旋转到竖屏、反向竖屏,且受控制中心的旋转开关控制。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。| 114| LOCKED | 11 | 表示锁定模式。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core。| 115| AUTO_ROTATION_UNSPECIFIED<sup>12+</sup> | 12 | 跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定(如在某种设备,可以旋转到竖屏、横屏、反向横屏三个方向,无法旋转到反向竖屏)。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager。| 116| USER_ROTATION_PORTRAIT<sup>12+</sup> | 13 | 调用时临时旋转到竖屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager。| 117| USER_ROTATION_LANDSCAPE<sup>12+</sup> | 14 | 调用时临时旋转到横屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager。| 118| USER_ROTATION_PORTRAIT_INVERTED<sup>12+</sup> | 15 | 调用时临时旋转到反向竖屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager。| 119| USER_ROTATION_LANDSCAPE_INVERTED<sup>12+</sup> | 16 | 调用时临时旋转到反向横屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager。| 120| FOLLOW_DESKTOP<sup>12+</sup> | 17 | 表示跟随桌面的旋转模式。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager。| 121 122## Rect<sup>7+</sup> 123 124窗口矩形区域。 125 126**系统能力:** SystemCapability.WindowManager.WindowManager.Core 127 128**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 129 130| 名称 | 类型 | 可读 | 可写 | 说明 | 131| ------ | -------- | ---- | ---- | ------------------ | 132| left | number | 是 | 是 | 矩形区域的左边界,单位为px,该参数为整数。 | 133| top | number | 是 | 是 | 矩形区域的上边界,单位为px,该参数应为整数。 | 134| width | number | 是 | 是 | 矩形区域的宽度,单位为px,该参数应为整数。 | 135| height | number | 是 | 是 | 矩形区域的高度,单位为px,该参数应为整数。 | 136 137## AvoidArea<sup>7+</sup> 138 139窗口内容规避区域。如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。在规避区无法响应用户点击事件。 140 141除此之外还需注意规避区域的如下约束,具体为: 142 143- 底部手势区域中非导航条区域支持点击、长按事件透传,不支持拖入。 144 145- 左右侧边手势区域支持点击、长按以及上下滑动事件透传,不支持拖入。 146 147- 导航条区域支持长按、点击、拖入事件响应,不支持事件向下透传。 148 149**系统能力:** SystemCapability.WindowManager.WindowManager.Core 150 151**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 152 153| 名称 | 类型 | 可读 | 可写 | 说明 | 154| ---------- | ------------- | ---- | ---- | ------------------ | 155| visible<sup>9+</sup> | boolean | 是 | 是 | 规避区域是否可见。true表示可见;false表示不可见。 | 156| leftRect | [Rect](#rect7) | 是 | 是 | 屏幕左侧的矩形区。 | 157| topRect | [Rect](#rect7) | 是 | 是 | 屏幕顶部的矩形区。 | 158| rightRect | [Rect](#rect7) | 是 | 是 | 屏幕右侧的矩形区。 | 159| bottomRect | [Rect](#rect7) | 是 | 是 | 屏幕底部的矩形区。 | 160 161## Size<sup>7+</sup> 162 163窗口大小。 164 165**系统能力:** SystemCapability.WindowManager.WindowManager.Core 166 167**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 168 169| 名称 | 类型 | 可读 | 可写 | 说明 | 170| ------ | -------- | ---- | ---- | ---------- | 171| width | number | 是 | 是 | 窗口宽度,单位为px,该参数应为整数。 | 172| height | number | 是 | 是 | 窗口高度,单位为px,该参数应为整数。 | 173 174## RectChangeReason<sup>12+</sup> 175 176窗口矩形(窗口位置及窗口大小)变化的原因。 177 178**系统能力:** SystemCapability.Window.SessionManager 179 180**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 181 182| 名称 | 值 | 说明 | 183| --------------------- | ---- | ------------------------------------------------------------ | 184| UNDEFINED | 0 | 默认值。 | 185| MAXIMIZE | 1 | 窗口最大化。 | 186| RECOVER | 2 | 窗口恢复到上一次的状态。 | 187| MOVE | 3 | 窗口拖拽移动。 | 188| DRAG | 4 | 窗口拖拽缩放。 | 189| DRAG_START | 5 | 窗口开始拖拽缩放。 | 190| DRAG_END | 6 | 窗口结束拖拽缩放。 | 191 192## RectChangeOptions<sup>12+</sup> 193 194窗口矩形(窗口位置及窗口大小)变化返回的值及变化原因。 195 196**系统能力:** SystemCapability.Window.SessionManager 197 198**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 199 200| 名称 | 类型 | 可读 | 可写 | 说明 | 201| ---------- | ------------- | ---- | ---- | ------------------ | 202| rect | [Rect](#rect7) | 是 | 是 | 窗口矩形变化后的值。 | 203| reason | [RectChangeReason](#rectchangereason12) | 是 | 是 | 窗口矩形变化的原因。 | 204 205## AvoidAreaOptions<sup>12+</sup> 206 207系统规避区变化后返回当前规避区域以及规避区域类型。 208 209**系统能力:** SystemCapability.WindowManager.WindowManager.Core 210 211**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 212 213| 名称 | 类型 | 可读 | 可写 | 说明 | 214| ---------- | ------------- | ---- | ---- | ------------------ | 215| type | [AvoidAreaType](#avoidareatype7) | 是 | 是 | 系统规避区变化后返回的规避区域类型。 | 216| area | [AvoidArea](#avoidarea7) | 是 | 是 | 系统规避区变化后返回的规避区域。 | 217 218## WindowProperties 219 220窗口属性。 221 222**系统能力:** SystemCapability.WindowManager.WindowManager.Core 223 224| 名称 | 类型 | 只读 | 可选 | 说明 | 225| ------------------------------------- | ------------------------- | ---- | ---- |--------------------------------------------------------------------------------------------------------| 226| windowRect<sup>7+</sup> | [Rect](#rect7) | 否 | 否 | 窗口尺寸,可在页面生命周期[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## window.createWindow<sup>9+</sup> 345 346createWindow(config: Configuration, callback: AsyncCallback<Window>): void 347 348创建子窗口或者系统窗口,使用callback异步回调。 349 350**需要权限:** 当创建窗口类型为window.WindowType.TYPE_FLOAT时,需要ohos.permission.SYSTEM_FLOAT_WINDOW权限 351 352**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 353 354**系统能力:** SystemCapability.WindowManager.WindowManager.Core 355 356**参数:** 357 358| 参数名 | 类型 | 必填 | 说明 | 359| -------- | -------------------------------------- | -- | --------------------------------- | 360| config | [Configuration](#configuration9) | 是 | 创建窗口时的参数。 | 361| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的窗口对象。 | 362 363**错误码:** 364 365以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 366 367| 错误码ID | 错误信息 | 368| ------- | -------------------------------- | 369| 201 | Permission verification failed. The application does not have the permission required to call the API. | 370| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 371| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 372| 1300001 | Repeated operation. | 373| 1300002 | This window state is abnormal. | 374| 1300004 | Unauthorized operation. | 375| 1300006 | This window context is abnormal. | 376| 1300008 | The display device is abnormal. | 377| 1300009 | The parent window is invalid. | 378 379**示例:** 380 381```ts 382import { BusinessError } from '@kit.BasicServicesKit'; 383 384let windowClass: window.Window | undefined = undefined; 385let config: window.Configuration = { 386 name: "test", 387 windowType: window.WindowType.TYPE_DIALOG, 388 ctx: this.context 389}; 390try { 391 window.createWindow(config, (err: BusinessError, data) => { 392 const errCode: number = err.code; 393 if (errCode) { 394 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 395 return; 396 } 397 windowClass = data; 398 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 399 windowClass.resize(500, 1000); 400 }); 401} catch (exception) { 402 console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`); 403} 404``` 405 406## window.createWindow<sup>9+</sup> 407 408createWindow(config: Configuration): Promise<Window> 409 410创建子窗口或者系统窗口,使用Promise异步回调。 411 412**需要权限:** 当创建窗口类型为window.WindowType.TYPE_FLOAT时,需要ohos.permission.SYSTEM_FLOAT_WINDOW权限 413 414**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 415 416**系统能力:** SystemCapability.WindowManager.WindowManager.Core 417 418**参数:** 419 420| 参数名 | 类型 | 必填 | 说明 | 421| ------ | -------------------------------- | -- | ------------------ | 422| config | [Configuration](#configuration9) | 是 | 创建窗口时的参数。 | 423 424**返回值:** 425 426| 类型 | 说明 | 427| -------------------------------- | ------------------------------------ | 428| Promise<[Window](#window)> | Promise对象。返回当前创建的窗口对象。 | 429 430**错误码:** 431 432以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 433 434| 错误码ID | 错误信息 | 435| ------- | -------------------------------- | 436| 201 | Permission verification failed. The application does not have the permission required to call the API. | 437| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 438| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 439| 1300001 | Repeated operation. | 440| 1300002 | This window state is abnormal. | 441| 1300004 | Unauthorized operation. | 442| 1300006 | This window context is abnormal. | 443| 1300008 | The display device is abnormal. | 444| 1300009 | The parent window is invalid. | 445 446**示例:** 447 448```ts 449import { BusinessError } from '@kit.BasicServicesKit'; 450 451let windowClass: window.Window | undefined = undefined; 452let config: window.Configuration = { 453 name: "test", 454 windowType: window.WindowType.TYPE_DIALOG, 455 ctx: this.context 456}; 457try { 458 let promise = window.createWindow(config); 459 promise.then((data) => { 460 windowClass = data; 461 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 462 }).catch((err: BusinessError) => { 463 console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`); 464 }); 465} catch (exception) { 466 console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`); 467} 468``` 469 470## window.findWindow<sup>9+</sup> 471 472findWindow(name: string): Window 473 474查找name所对应的窗口。 475 476**系统能力:** SystemCapability.WindowManager.WindowManager.Core 477 478**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 479 480**参数:** 481 482| 参数名 | 类型 | 必填 | 说明 | 483| ------ | ------ | ---- | -------- | 484| name | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 485 486**返回值:** 487 488| 类型 | 说明 | 489| ----------------- | ------------------- | 490| [Window](#window) | 当前查找的窗口对象。 | 491 492**错误码:** 493 494以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 495 496| 错误码ID | 错误信息 | 497| ------- | -------------------------------- | 498| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 499| 1300002 | This window state is abnormal. | 500 501**示例:** 502 503```ts 504let windowClass: window.Window | undefined = undefined; 505try { 506 windowClass = window.findWindow('test'); 507} catch (exception) { 508 console.error(`Failed to find the Window. Cause code: ${exception.code}, message: ${exception.message}`); 509} 510``` 511 512## window.getLastWindow<sup>9+</sup> 513 514getLastWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 515 516获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口,使用callback异步回调。 517 518**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 519 520**系统能力:** SystemCapability.WindowManager.WindowManager.Core 521 522**参数:** 523 524| 参数名 | 类型 | 必填 | 说明 | 525| -------- | -------------------------------------- | -- | ---------------------------------------- | 526| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 527| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 528 529**错误码:** 530 531以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 532 533| 错误码ID | 错误信息 | 534| ------- | -------------------------------- | 535| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 536| 1300002 | This window state is abnormal. | 537| 1300006 | This window context is abnormal. | 538 539**示例:** 540 541```ts 542// EntryAbility.ets 543import { UIAbility } from '@kit.AbilityKit'; 544import { BusinessError } from '@kit.BasicServicesKit'; 545 546export default class EntryAbility extends UIAbility { 547 // ... 548 onWindowStageCreate(windowStage: window.WindowStage) { 549 console.info('onWindowStageCreate'); 550 let windowClass: window.Window | undefined = undefined; 551 try { 552 window.getLastWindow(this.context, (err: BusinessError, data) => { 553 const errCode: number = err.code; 554 if (errCode) { 555 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 556 return; 557 } 558 windowClass = data; 559 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 560 }); 561 } catch (exception) { 562 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`); 563 } 564 } 565} 566``` 567 568## window.getLastWindow<sup>9+</sup> 569 570getLastWindow(ctx: BaseContext): Promise<Window> 571 572获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口,使用Promise异步回调。 573 574**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 575 576**系统能力:** SystemCapability.WindowManager.WindowManager.Core 577 578**参数:** 579 580| 参数名 | 类型 | 必填 | 说明 | 581| ------ | ----------- | ---- | ------------------------------------------------------------ | 582| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 583 584**返回值:** 585 586| 类型 | 说明 | 587| -------------------------------- | ------------------------------------------- | 588| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 589 590**错误码:** 591 592以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 593 594| 错误码ID | 错误信息 | 595| ------- | -------------------------------- | 596| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 597| 1300002 | This window state is abnormal. | 598| 1300006 | This window context is abnormal. | 599 600**示例:** 601 602```ts 603// EntryAbility.ets 604import { UIAbility } from '@kit.AbilityKit'; 605import { BusinessError } from '@kit.BasicServicesKit'; 606 607export default class EntryAbility extends UIAbility { 608 // ... 609 onWindowStageCreate(windowStage: window.WindowStage) { 610 console.info('onWindowStageCreate'); 611 let windowClass: window.Window | undefined = undefined; 612 try { 613 let promise = window.getLastWindow(this.context); 614 promise.then((data) => { 615 windowClass = data; 616 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 617 }).catch((err: BusinessError) => { 618 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 619 }); 620 } catch (exception) { 621 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`); 622 } 623 } 624} 625``` 626 627## window.shiftAppWindowFocus<sup>11+</sup> 628shiftAppWindowFocus(sourceWindowId: number, targetWindowId: number): Promise<void> 629 630在同应用内将窗口焦点从源窗口转移到目标窗口,仅支持应用主窗和子窗的焦点转移。 631 632**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 633 634**系统能力:** SystemCapability.Window.SessionManager 635 636**参数:** 637 638| 参数名 | 类型 | 必填 | 说明 | 639| -------------- | ------ | ----- | ----------------------- | 640| sourceWindowId | number | 是 | 源窗口id,必须是获焦状态。| 641| targetWindowId | number | 是 | 目标窗口id。 | 642 643**返回值:** 644 645| 类型 | 说明 | 646| ------------------- | ------------------------- | 647| Promise<void> | 无返回结果的Promise对象。 | 648 649**错误码:** 650 651以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 652 653| 错误码ID | 错误信息 | 654| ------- | --------------------------------------------- | 655| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 656| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 657| 1300002 | This window state is abnormal. | 658| 1300003 | This window manager service works abnormally. | 659| 1300004 | Unauthorized operation. | 660 661**示例:** 662 663```ts 664// EntryAbility.ets 665import { UIAbility } from '@kit.AbilityKit'; 666import { BusinessError } from '@kit.BasicServicesKit'; 667 668export default class EntryAbility extends UIAbility { 669 onWindowStageCreate(windowStage: window.WindowStage) { 670 // ... 671 console.info('onWindowStageCreate'); 672 let windowClass: window.Window | undefined = undefined; 673 let subWindowClass: window.Window | undefined = undefined; 674 let windowClassId: number = -1; 675 let subWindowClassId: number = -1; 676 677 try { 678 // 获取应用主窗及ID 679 let promise = windowStage.getMainWindow(); 680 promise.then((data) => { 681 if (data == null) { 682 console.error("Failed to obtaining the window. Cause: The data is empty"); 683 return; 684 } 685 windowClass = data; 686 windowClass.setUIContent("pages/Index"); 687 windowClassId = windowClass.getWindowProperties().id; 688 console.info('Succeeded in obtaining the window') 689 }).catch((err: BusinessError) => { 690 console.error(`Failed to obtaining the window. Cause code: ${err.code}, message: ${err.message}`); 691 }); 692 693 // 创建或获取子窗及ID,此时子窗口获焦 694 let promiseSub = windowStage.createSubWindow("testSubWindow"); 695 promiseSub.then((data) => { 696 if (data == null) { 697 console.error("Failed to obtaining the window. Cause: The data is empty"); 698 return; 699 } 700 subWindowClass = data; 701 subWindowClassId = subWindowClass.getWindowProperties().id; 702 subWindowClass.resize(500, 500); 703 subWindowClass.setUIContent("pages/Index2"); 704 subWindowClass.showWindow(); 705 706 // 监听Window状态,确保已经就绪 707 subWindowClass.on("windowEvent", (windowEvent) => { 708 if (windowEvent == window.WindowEventType.WINDOW_ACTIVE) { 709 // 切换焦点 710 let promise = window.shiftAppWindowFocus(subWindowClassId, windowClassId); 711 promise.then(() => { 712 console.info('Succeeded in shifting app window focus'); 713 }).catch((err: BusinessError) => { 714 console.error(`Failed to shift app window focus. Cause code: ${err.code}, message: ${err.message}`); 715 }); 716 } 717 }); 718 }); 719 } catch (exception) { 720 console.error(`Failed to shift app focus. Cause code: ${exception.code}, message: ${exception.message}`); 721 } 722 } 723} 724``` 725 726## window.getWindowsByCoordinate<sup>14+</sup> 727 728getWindowsByCoordinate(displayId: number, windowNumber?: number, x?: number, y?: number): Promise<Array<Window>> 729 730查询本应用指定坐标下的可见窗口,使用Promise异步回调。 731 732**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 733 734**系统能力:** SystemCapability.Window.SessionManager 735 736**参数:** 737 738| 参数名 | 类型 | 必填 | 说明 | 739| ------ | ---------- |----|---------------------------------------------------------------------------| 740| displayId | number| 是 | 查询窗口所在的displayId,该参数应为整数,可以在窗口属性[WindowProperties](#windowproperties)中获取。 | 741| windowNumber | number| 否 | 查询的窗口数量,该参数应为大于0整数,未设置或小于等于0返回所有满足条件的窗口。 | 742| x | number | 否 | 查询的x坐标,该参数应为非负整数,未设置或小于0返回所有可见窗口。 | 743| y | number| 否 | 查询的y坐标,该参数应为非负整数,未设置或小于0返回所有可见窗口。 | 744 745**返回值:** 746 747| 类型 | 说明 | 748| -------------------------------- |-------------------------| 749| Promise<Array<[Window](#window)>> | Promise对象。返回获取到的窗口对象数组。 | 750 751**错误码:** 752 753以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 754 755| 错误码ID | 错误信息 | 756|----------| ------------------------------ | 757| 401 | Parameter error. Possible cause: Incorrect parameter types. | 758| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 759| 1300003 | This window manager service works abnormally. | 760 761```ts 762import { window } from '@kit.ArkUI'; 763import { BusinessError } from '@kit.BasicServicesKit'; 764 765try { 766 let properties = windowClass.getWindowProperties(); 767 window.getWindowsByCoordinate(properties.displayId).then((data) => { 768 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 769 for (let window of data) { 770 // do something with window 771 } 772 }).catch((err: BusinessError) => { 773 console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`); 774 }); 775 776 window.getWindowsByCoordinate(properties.displayId, 2, 500, 500).then((data) => { 777 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 778 for (let window of data) { 779 // do something with window 780 } 781 }).catch((err: BusinessError) => { 782 console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`); 783 }); 784} catch (exception) { 785 console.error(`Failed to get window from point. Cause code: ${exception.code}, message: ${exception.message}`); 786} 787``` 788 789## window.create<sup>(deprecated)</sup> 790 791create(id: string, type: WindowType, callback: AsyncCallback<Window>): void 792 793创建子窗口,使用callback异步回调。 794 795> **说明:** 796> 797> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。 798 799**模型约束:** 此接口仅可在FA模型下使用。 800 801**系统能力:** SystemCapability.WindowManager.WindowManager.Core 802 803**参数:** 804 805| 参数名 | 类型 | 必填 | 说明 | 806| -------- | -------------------------------------- | ---- | ------------------------------------ | 807| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。| 808| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 809| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的子窗口对象。 | 810 811 812**示例:** 813 814```ts 815import { BusinessError } from '@kit.BasicServicesKit'; 816 817let windowClass: window.Window | undefined = undefined; 818window.create('test', window.WindowType.TYPE_APP, (err: BusinessError, data) => { 819 const errCode: number = err.code; 820 if (errCode) { 821 console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`); 822 return; 823 } 824 windowClass = data; 825 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 826}); 827``` 828 829## window.create<sup>(deprecated)</sup> 830 831create(id: string, type: WindowType): Promise<Window> 832 833创建子窗口,使用Promise异步回调。 834 835> **说明:** 836> 837> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。 838 839**模型约束:** 此接口仅可在FA模型下使用。 840 841**系统能力:** SystemCapability.WindowManager.WindowManager.Core 842 843**参数:** 844 845| 参数名 | 类型 | 必填 | 说明 | 846| ------ | ------------------------- | ---- | ---------- | 847| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 848| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 849 850**返回值:** 851 852| 类型 | 说明 | 853| -------------------------------- | --------------------------------------- | 854| Promise<[Window](#window)> | Promise对象。返回当前创建的子窗口对象。 | 855 856 857**示例:** 858 859```ts 860import { BusinessError } from '@kit.BasicServicesKit'; 861 862let windowClass: window.Window | undefined = undefined; 863let promise = window.create('test', window.WindowType.TYPE_APP); 864promise.then((data) => { 865 windowClass = data; 866 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 867}).catch((err: BusinessError) => { 868 console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`); 869}); 870``` 871 872## window.create<sup>(deprecated)</sup> 873 874create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback<Window>): void 875 876创建系统窗口,使用callback异步回调。 877 878> **说明:** 879> 880> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。 881 882**系统能力:** SystemCapability.WindowManager.WindowManager.Core 883 884**参数:** 885 886| 参数名 | 类型 | 必填 | 说明 | 887| -------- | ------------------------------------------------------- | ---- | ------------------------------------ | 888| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 889| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 890| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 891| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的子窗口对象。 | 892 893 894**示例:** 895 896```ts 897import { BusinessError } from '@kit.BasicServicesKit'; 898 899let windowClass: window.Window | undefined = undefined; 900window.create('test', window.WindowType.TYPE_SYSTEM_ALERT, (err: BusinessError, data) => { 901 const errCode: number = err.code; 902 if (errCode) { 903 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 904 return; 905 } 906 windowClass = data; 907 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 908 windowClass.resetSize(500, 1000); 909}); 910``` 911 912## window.create<sup>(deprecated)</sup> 913 914create(ctx: BaseContext, id: string, type: WindowType): Promise<Window> 915 916创建系统窗口,使用Promise异步回调。 917 918> **说明:** 919> 920> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。 921 922**系统能力:** SystemCapability.WindowManager.WindowManager.Core 923 924**参数:** 925 926| 参数名 | 类型 | 必填 | 说明 | 927| ------ | ------------------------- | ---- | ------------------------------------------------------------ | 928| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 929| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 930| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 931 932**返回值:** 933 934| 类型 | 说明 | 935| -------------------------------- | --------------------------------------- | 936| Promise<[Window](#window)> | Promise对象。返回当前创建的子窗口对象。 | 937 938 939**示例:** 940 941```ts 942import { BusinessError } from '@kit.BasicServicesKit'; 943 944let windowClass: window.Window | undefined = undefined; 945let promise = window.create('test', window.WindowType.TYPE_SYSTEM_ALERT); 946promise.then((data) => { 947 windowClass = data; 948 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 949}).catch((err: BusinessError) => { 950 console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`); 951}); 952``` 953 954## window.find<sup>(deprecated)</sup> 955 956find(id: string, callback: AsyncCallback<Window>): void 957 958查找id所对应的窗口,使用callback异步回调。 959 960> **说明:** 961> 962> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。 963 964**系统能力:** SystemCapability.WindowManager.WindowManager.Core 965 966**参数:** 967 968| 参数名 | 类型 | 必填 | 说明 | 969| -------- | -------------------------------------- | ---- | ------------------------------------ | 970| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 971| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前查找到的窗口对象。 | 972 973**示例:** 974 975```ts 976import { BusinessError } from '@kit.BasicServicesKit'; 977 978let windowClass: window.Window | undefined = undefined; 979window.find('test', (err: BusinessError, data) => { 980 const errCode: number = err.code; 981 if (errCode) { 982 console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`); 983 return; 984 } 985 windowClass = data; 986 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 987}); 988``` 989 990## window.find<sup>(deprecated)</sup> 991 992find(id: string): Promise<Window> 993 994查找id所对应的窗口,使用Promise异步回调。 995 996> **说明:** 997> 998> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。 999 1000**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1001 1002**参数:** 1003 1004| 参数名 | 类型 | 必填 | 说明 | 1005| ------ | ------ | ---- | -------- | 1006| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 1007 1008**返回值:** 1009 1010| 类型 | 说明 | 1011| -------------------------------- | ------------------------------------- | 1012| Promise<[Window](#window)> | Promise对象。返回当前查找的窗口对象。 | 1013 1014**示例:** 1015 1016```ts 1017import { BusinessError } from '@kit.BasicServicesKit'; 1018 1019let windowClass: window.Window | undefined = undefined; 1020let promise = window.find('test'); 1021promise.then((data) => { 1022 windowClass = data; 1023 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 1024}).catch((err: BusinessError) => { 1025 console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`); 1026}); 1027``` 1028 1029## window.getTopWindow<sup>(deprecated)</sup> 1030 1031getTopWindow(callback: AsyncCallback<Window>): void 1032 1033获取当前应用内最后显示的窗口,使用callback异步回调。 1034 1035> **说明:** 1036> 1037> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。 1038 1039**模型约束:** 此接口仅可在FA模型下使用。 1040 1041**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1042 1043**参数:** 1044 1045| 参数名 | 类型 | 必填 | 说明 | 1046| -------- | -------------------------------------- | ---- | -------------------------------------------- | 1047| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 1048 1049**示例:** 1050 1051```ts 1052import { BusinessError } from '@kit.BasicServicesKit'; 1053 1054let windowClass: window.Window | undefined = undefined; 1055window.getTopWindow((err: BusinessError, data) => { 1056 const errCode: number = err.code; 1057 if (errCode) { 1058 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 1059 return; 1060 } 1061 windowClass = data; 1062 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1063}); 1064``` 1065 1066## window.getTopWindow<sup>(deprecated)</sup> 1067 1068getTopWindow(): Promise<Window> 1069 1070获取当前应用内最后显示的窗口,使用Promise异步回调。 1071 1072> **说明:** 1073> 1074> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。 1075 1076**模型约束:** 此接口仅可在FA模型下使用。 1077 1078**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1079 1080**返回值:** 1081 1082| 类型 | 说明 | 1083| -------------------------------- | ----------------------------------------------- | 1084| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 1085 1086**示例:** 1087 1088```ts 1089import { BusinessError } from '@kit.BasicServicesKit'; 1090 1091let windowClass: window.Window | undefined = undefined; 1092let promise = window.getTopWindow(); 1093promise.then((data)=> { 1094 windowClass = data; 1095 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1096}).catch((err: BusinessError)=>{ 1097 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 1098}); 1099``` 1100 1101## window.getTopWindow<sup>(deprecated)</sup> 1102 1103getTopWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 1104 1105获取当前应用内最后显示的窗口,使用callback异步回调。 1106 1107> **说明:** 1108> 1109> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。 1110 1111**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1112 1113**参数:** 1114 1115| 参数名 | 类型 | 必填 | 说明 | 1116| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 1117| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1118| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 1119 1120**示例:** 1121 1122```ts 1123// EntryAbility.ets 1124import { UIAbility } from '@kit.AbilityKit'; 1125import { BusinessError } from '@kit.BasicServicesKit'; 1126 1127export default class EntryAbility extends UIAbility { 1128 onWindowStageCreate(windowStage:window.WindowStage){ 1129 console.info('onWindowStageCreate'); 1130 let windowClass: window.Window | undefined = undefined; 1131 try { 1132 window.getTopWindow(this.context, (err: BusinessError, data) => { 1133 const errCode: number = err.code; 1134 if(errCode){ 1135 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 1136 return ; 1137 } 1138 windowClass = data; 1139 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1140 }); 1141 } catch(error){ 1142 console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`); 1143 } 1144 } 1145} 1146``` 1147 1148## window.getTopWindow<sup>(deprecated)</sup> 1149 1150getTopWindow(ctx: BaseContext): Promise<Window> 1151 1152获取当前应用内最后显示的窗口,使用Promise异步回调。 1153 1154> **说明:** 1155> 1156> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。 1157 1158**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1159 1160**参数:** 1161 1162| 参数名 | 类型 | 必填 | 说明 | 1163| ------ | ----------- | ---- | ------------------------------------------------------------ | 1164| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1165 1166**返回值:** 1167 1168| 类型 | 说明 | 1169| -------------------------------- | ----------------------------------------------- | 1170| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 1171 1172**示例:** 1173 1174```ts 1175// EntryAbility.ets 1176import { UIAbility } from '@kit.AbilityKit'; 1177import { BusinessError } from '@kit.BasicServicesKit'; 1178 1179export default class EntryAbility extends UIAbility { 1180 onWindowStageCreate(windowStage:window.WindowStage) { 1181 console.info('onWindowStageCreate'); 1182 let windowClass: window.Window | undefined = undefined; 1183 let promise = window.getTopWindow(this.context); 1184 promise.then((data) => { 1185 windowClass = data; 1186 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1187 }).catch((error: BusinessError) => { 1188 console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`); 1189 }); 1190 } 1191} 1192``` 1193 1194## SpecificSystemBar<sup>11+</sup> 1195 1196type SpecificSystemBar = 'status' \| 'navigation' \| 'navigationIndicator' 1197 1198当前支持显示或隐藏的系统栏类型。 1199 1200**系统能力:** SystemCapability.Window.SessionManager 1201 1202**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1203 1204| 类型 | 说明 | 1205|------------|--------| 1206| 'status' | 状态栏。 | 1207| 'navigation' | 三键导航栏。 | 1208| 'navigationIndicator' | 底部导航条。 | 1209 1210## Window 1211 1212当前窗口实例,窗口管理器管理的基本单元。 1213 1214下列API示例中都需先使用[getLastWindow()](#windowgetlastwindow9)、[createWindow()](#windowcreatewindow9)、[findWindow()](#windowfindwindow9)中的任一方法获取到Window实例(windowClass),再通过此实例调用对应方法。 1215 1216### showWindow<sup>9+</sup> 1217 1218showWindow(callback: AsyncCallback<void>): void 1219 1220显示当前窗口,使用callback异步回调,仅支持系统窗口及应用子窗口,或将已显示的应用主窗口的层级提升至顶部。 1221 1222**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1223 1224**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1225 1226**参数:** 1227 1228| 参数名 | 类型 | 必填 | 说明 | 1229| -------- | ------------------------- | -- | --------- | 1230| callback | AsyncCallback<void> | 是 | 回调函数。 | 1231 1232**错误码:** 1233 1234以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1235 1236| 错误码ID | 错误信息 | 1237| ------- | ------------------------------ | 1238| 1300002 | This window state is abnormal. | 1239 1240**示例:** 1241 1242```ts 1243import { BusinessError } from '@kit.BasicServicesKit'; 1244 1245windowClass.showWindow((err: BusinessError) => { 1246 const errCode: number = err.code; 1247 if (errCode) { 1248 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 1249 return; 1250 } 1251 console.info('Succeeded in showing the window.'); 1252}); 1253``` 1254 1255### showWindow<sup>9+</sup> 1256 1257showWindow(): Promise<void> 1258 1259显示当前窗口,使用Promise异步回调,仅支持系统窗口及应用子窗口,或将已显示的应用主窗口的层级提升至顶部。 1260 1261**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1262 1263**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1264 1265**返回值:** 1266 1267| 类型 | 说明 | 1268| ------------------- | ----------------------- | 1269| Promise<void> | 无返回结果的Promise对象。 | 1270 1271**错误码:** 1272 1273以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1274 1275| 错误码ID | 错误信息 | 1276| ------- | ------------------------------ | 1277| 1300002 | This window state is abnormal. | 1278 1279**示例:** 1280 1281```ts 1282import { BusinessError } from '@kit.BasicServicesKit'; 1283 1284let promise = windowClass.showWindow(); 1285promise.then(() => { 1286 console.info('Succeeded in showing the window.'); 1287}).catch((err: BusinessError) => { 1288 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 1289}); 1290``` 1291 1292### destroyWindow<sup>9+</sup> 1293 1294destroyWindow(callback: AsyncCallback<void>): void 1295 1296销毁当前窗口,使用callback异步回调,仅支持系统窗口及应用子窗口。 1297 1298**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1299 1300**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1301 1302**参数:** 1303 1304| 参数名 | 类型 | 必填 | 说明 | 1305| -------- | ------------------------- | -- | --------- | 1306| callback | AsyncCallback<void> | 是 | 回调函数。 | 1307 1308**错误码:** 1309 1310以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1311 1312| 错误码ID | 错误信息 | 1313| ------- | -------------------------------------------- | 1314| 1300002 | This window state is abnormal. | 1315| 1300003 | This window manager service works abnormally. | 1316 1317**示例:** 1318 1319```ts 1320import { BusinessError } from '@kit.BasicServicesKit'; 1321 1322windowClass.destroyWindow((err) => { 1323 const errCode: number = err.code; 1324 if (errCode) { 1325 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 1326 return; 1327 } 1328 console.info('Succeeded in destroying the window.'); 1329}); 1330``` 1331 1332### destroyWindow<sup>9+</sup> 1333 1334destroyWindow(): Promise<void> 1335 1336销毁当前窗口,使用Promise异步回调,仅支持系统窗口及应用子窗口。 1337 1338**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1339 1340**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1341 1342**返回值:** 1343 1344| 类型 | 说明 | 1345| ------------------- | ------------------------ | 1346| Promise<void> | 无返回结果的Promise对象。 | 1347 1348**错误码:** 1349 1350以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1351 1352| 错误码ID | 错误信息 | 1353| ------- | -------------------------------------------- | 1354| 1300002 | This window state is abnormal. | 1355| 1300003 | This window manager service works abnormally. | 1356 1357**示例:** 1358 1359```ts 1360import { BusinessError } from '@kit.BasicServicesKit'; 1361 1362let promise = windowClass.destroyWindow(); 1363promise.then(() => { 1364 console.info('Succeeded in destroying the window.'); 1365}).catch((err: BusinessError) => { 1366 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 1367}); 1368``` 1369 1370### moveWindowTo<sup>9+</sup> 1371 1372moveWindowTo(x: number, y: number, callback: AsyncCallback<void>): void 1373 1374移动窗口位置,使用callback异步回调。 1375 1376<!--RP4--> 1377全屏模式下,本接口仅在2in1设备上生效。<!--RP4End--> 1378在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。 1379 1380**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1381 1382**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1383 1384**参数:** 1385 1386| 参数名 | 类型 | 必填 | 说明 | 1387| -------- | ------------------------- | -- | --------------------------------------------- | 1388| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 | 1389| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 | 1390| callback | AsyncCallback<void> | 是 | 回调函数。 | 1391 1392**错误码:** 1393 1394以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1395 1396| 错误码ID | 错误信息 | 1397| ------- | -------------------------------------------- | 1398| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1399| 1300002 | This window state is abnormal. | 1400| 1300003 | This window manager service works abnormally. | 1401 1402**示例:** 1403 1404```ts 1405import { BusinessError } from '@kit.BasicServicesKit'; 1406 1407try { 1408 windowClass.moveWindowTo(300, 300, (err: BusinessError) => { 1409 const errCode: number = err.code; 1410 if (errCode) { 1411 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1412 return; 1413 } 1414 console.info('Succeeded in moving the window.'); 1415 }); 1416} catch (exception) { 1417 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1418} 1419``` 1420 1421### moveWindowTo<sup>9+</sup> 1422 1423moveWindowTo(x: number, y: number): Promise<void> 1424 1425移动窗口位置,使用Promise异步回调。调用成功即返回,该接口返回后无法立即获取最终生效结果,如需立即获取,建议使用接口[moveWindowToAsync()](#movewindowtoasync12)。 1426 1427<!--RP4--> 1428全屏模式下,本接口仅在2in1设备上生效。<!--RP4End--> 1429在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。 1430 1431**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1432 1433**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1434 1435**参数:** 1436 1437| 参数名 | 类型 | 必填 | 说明 | 1438| -- | ----- | -- | --------------------------------------------- | 1439| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 | 1440| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 | 1441 1442**返回值:** 1443 1444| 类型 | 说明 | 1445| ------------------- | ------------------------ | 1446| Promise<void> | 无返回结果的Promise对象。 | 1447 1448**错误码:** 1449 1450以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1451 1452| 错误码ID | 错误信息 | 1453| ------- | -------------------------------------------- | 1454| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1455| 1300002 | This window state is abnormal. | 1456| 1300003 | This window manager service works abnormally. | 1457 1458**示例:** 1459 1460```ts 1461import { BusinessError } from '@kit.BasicServicesKit'; 1462 1463try { 1464 let promise = windowClass.moveWindowTo(300, 300); 1465 promise.then(() => { 1466 console.info('Succeeded in moving the window.'); 1467 }).catch((err: BusinessError) => { 1468 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1469 }); 1470} catch (exception) { 1471 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1472} 1473``` 1474 1475### moveWindowToAsync<sup>12+</sup> 1476 1477moveWindowToAsync(x: number, y: number): Promise<void> 1478 1479移动窗口位置,使用Promise异步回调。调用生效后返回,回调中可使用getWindowProperties(见示例)立即获取最终生效结果。 1480 1481仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效。 1482在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。 1483 1484**系统能力:** SystemCapability.Window.SessionManager 1485 1486**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1487 1488**参数:** 1489 1490| 参数名 | 类型 | 必填 | 说明 | 1491| -- | ----- | -- | --------------------------------------------- | 1492| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 | 1493| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 | 1494 1495**返回值:** 1496 1497| 类型 | 说明 | 1498| ------------------- | ------------------------ | 1499| Promise<void> | 无返回结果的Promise对象。 | 1500 1501**错误码:** 1502 1503以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1504 1505| 错误码ID | 错误信息 | 1506| ------- | -------------------------------------------- | 1507| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1508| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1509| 1300002 | This window state is abnormal. | 1510| 1300003 | This window manager service works abnormally. | 1511| 1300010 | The operation in the current window status is invalid. | 1512 1513**示例:** 1514 1515```ts 1516import { BusinessError } from '@kit.BasicServicesKit'; 1517 1518try { 1519 let promise = windowClass.moveWindowToAsync(300, 300); 1520 promise.then(() => { 1521 console.info('Succeeded in moving the window.'); 1522 let rect = windowClass?.getWindowProperties().windowRect; 1523 console.info(`Get window rect: ` + JSON.stringify(rect)); 1524 }).catch((err: BusinessError) => { 1525 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1526 }); 1527} catch (exception) { 1528 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1529} 1530``` 1531 1532### moveWindowToGlobal<sup>13+</sup> 1533 1534moveWindowToGlobal(x: number, y: number): Promise<void> 1535 1536基于屏幕坐标移动窗口位置,使用Promise异步回调。调用生效后返回。 1537 1538全屏模式窗口不支持该操作。 1539 1540在非2in1设备下,子窗会跟随主窗移动。 1541 1542**系统能力:** SystemCapability.Window.SessionManager 1543 1544**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 1545 1546**参数:** 1547 1548| 参数名 | 类型 | 必填 | 说明 | 1549| -- | ----- | -- | --------------------------------------------- | 1550| x | number | 是 | 表示以屏幕左上角为起点,窗口在x轴方向移动的值,单位为px。值为正表示右移,值为负表示左移。该参数仅支持整数输入,浮点数输入将向下取整。 | 1551| y | number | 是 | 表示以屏幕左上角为起点,窗口在y轴方向移动的值,单位为px。值为正表示下移,值为负表示上移。该参数仅支持整数输入,浮点数输入将向下取整。 | 1552 1553**返回值:** 1554 1555| 类型 | 说明 | 1556| ------------------- | ------------------------ | 1557| Promise<void> | 无返回结果的Promise对象。 | 1558 1559**错误码:** 1560 1561以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1562 1563| 错误码ID | 错误信息 | 1564| ------- | -------------------------------------------- | 1565| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1566| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1567| 1300002 | This window state is abnormal. | 1568| 1300003 | This window manager service works abnormally. | 1569| 1300010 | The operation in the current window status is invalid. | 1570 1571**示例:** 1572 1573```ts 1574import { BusinessError } from '@kit.BasicServicesKit'; 1575 1576try { 1577 let promise = windowClass.moveWindowToGlobal(300, 300); 1578 promise.then(() => { 1579 console.info('Succeeded in moving the window.'); 1580 }).catch((err: BusinessError) => { 1581 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1582 }); 1583} catch (exception) { 1584 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1585} 1586``` 1587 1588### resize<sup>9+</sup> 1589 1590resize(width: number, height: number, callback: AsyncCallback<void>): void 1591 1592改变当前窗口大小,使用callback异步回调。 1593 1594应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 1595应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 1596 1597系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 1598 1599设置的宽度与高度受到此约束限制,规则: 1600若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 1601若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 1602 1603全屏模式窗口不支持该操作。 1604 1605**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1606 1607**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1608 1609**参数:** 1610 1611| 参数名 | 类型 | 必填 | 说明 | 1612| -------- | ------------------------- | -- | ------------------------ | 1613| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 1614| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 1615| callback | AsyncCallback<void> | 是 | 回调函数。 | 1616 1617**错误码:** 1618 1619以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1620 1621| 错误码ID | 错误信息 | 1622| ------- | -------------------------------------------- | 1623| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1624| 1300002 | This window state is abnormal. | 1625| 1300003 | This window manager service works abnormally. | 1626 1627**示例:** 1628 1629```ts 1630import { BusinessError } from '@kit.BasicServicesKit'; 1631 1632try { 1633 windowClass.resize(500, 1000, (err: BusinessError) => { 1634 const errCode: number = err.code; 1635 if (errCode) { 1636 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 1637 return; 1638 } 1639 console.info('Succeeded in changing the window size.'); 1640 }); 1641} catch (exception) { 1642 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 1643} 1644``` 1645 1646### resize<sup>9+</sup> 1647 1648resize(width: number, height: number): Promise<void> 1649 1650改变当前窗口大小,使用Promise异步回调。调用成功即返回,该接口返回后无法立即获取最终生效结果,如需立即获取,建议使用接口[resizeAsync()](#resizeasync12)。 1651 1652应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 1653应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 1654 1655系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 1656 1657设置的宽度与高度受到此约束限制,规则: 1658若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 1659若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 1660 1661全屏模式窗口不支持该操作。 1662 1663**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1664 1665**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1666 1667**参数:** 1668 1669| 参数名 | 类型 | 必填 | 说明 | 1670| ------ | ------ | -- | ------------------------ | 1671| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 1672| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 1673 1674**返回值:** 1675 1676| 类型 | 说明 | 1677| ------------------- | ------------------------ | 1678| Promise<void> | 无返回结果的Promise对象。 | 1679 1680**错误码:** 1681 1682以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1683 1684| 错误码ID | 错误信息 | 1685| ------- | -------------------------------------------- | 1686| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1687| 1300002 | This window state is abnormal. | 1688| 1300003 | This window manager service works abnormally. | 1689 1690**示例:** 1691 1692```ts 1693import { BusinessError } from '@kit.BasicServicesKit'; 1694 1695try { 1696 let promise = windowClass.resize(500, 1000); 1697 promise.then(() => { 1698 console.info('Succeeded in changing the window size.'); 1699 }).catch((err: BusinessError) => { 1700 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 1701 }); 1702} catch (exception) { 1703 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 1704} 1705``` 1706 1707### resizeAsync<sup>12+</sup> 1708 1709resizeAsync(width: number, height: number): Promise<void> 1710 1711改变当前窗口大小,使用Promise异步回调。调用生效后返回,回调中可使用getWindowProperties(见示例)立即获取最终生效结果。 1712 1713应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 1714应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 1715 1716系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 1717 1718设置的宽度与高度受到此约束限制,规则: 1719若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 1720若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 1721 1722全屏模式窗口不支持该操作。 1723 1724**系统能力:** SystemCapability.Window.SessionManager 1725 1726**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1727 1728**参数:** 1729 1730| 参数名 | 类型 | 必填 | 说明 | 1731| ------ | ------ | -- | ------------------------ | 1732| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 1733| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 1734 1735**返回值:** 1736 1737| 类型 | 说明 | 1738| ------------------- | ------------------------ | 1739| Promise<void> | 无返回结果的Promise对象。 | 1740 1741**错误码:** 1742 1743以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1744 1745| 错误码ID | 错误信息 | 1746| ------- | -------------------------------------------- | 1747| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1748| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1749| 1300002 | This window state is abnormal. | 1750| 1300003 | This window manager service works abnormally. | 1751| 1300010 | The operation in the current window status is invalid. | 1752 1753**示例:** 1754 1755```ts 1756import { BusinessError } from '@kit.BasicServicesKit'; 1757 1758try { 1759 let promise = windowClass.resizeAsync(500, 1000); 1760 promise.then(() => { 1761 console.info('Succeeded in changing the window size.'); 1762 let rect = windowClass?.getWindowProperties().windowRect; 1763 console.info(`Get window rect: ` + JSON.stringify(rect)); 1764 }).catch((err: BusinessError) => { 1765 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 1766 }); 1767} catch (exception) { 1768 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 1769} 1770``` 1771 1772### getWindowProperties<sup>9+</sup> 1773 1774getWindowProperties(): WindowProperties 1775 1776获取当前窗口的属性,返回WindowProperties。 1777 1778**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1779 1780**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1781 1782**返回值:** 1783 1784| 类型 | 说明 | 1785| ------------------------------------- | ------------- | 1786| [WindowProperties](#windowproperties) | 当前窗口属性。 | 1787 1788**错误码:** 1789 1790以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1791 1792| 错误码ID | 错误信息 | 1793| ------- | ------------------------------ | 1794| 1300002 | This window state is abnormal. | 1795 1796**示例:** 1797 1798```ts 1799try { 1800 let properties = windowClass.getWindowProperties(); 1801} catch (exception) { 1802 console.error(`Failed to obtain the window properties. Cause code: ${exception.code}, message: ${exception.message}`); 1803} 1804``` 1805 1806### getGlobalRect<sup>13+</sup> 1807 1808getGlobalRect(): Rect 1809 1810获取窗口在屏幕上的真实显示区域,同步接口。 1811 1812在某些设备上,窗口显示时可能经过了缩放,此接口可以获取缩放后窗口在屏幕上的真实位置和大小。 1813 1814**系统能力:** SystemCapability.Window.SessionManager 1815 1816**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 1817 1818**返回值:** 1819 1820| 类型 | 说明 | 1821| ------------------- | ------------------------ | 1822| [Rect](#rect7) | 四元组分别表示距离屏幕左上角的x坐标、距离屏幕左上角的y坐标、缩放后的窗口宽度和缩放后的窗口高度。 | 1823 1824**错误码:** 1825 1826以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1827 1828| 错误码ID | 错误信息 | 1829| ------- | -------------------------------------------- | 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 1834**示例:** 1835 1836```ts 1837try { 1838 let rect = windowClass.getGlobalRect(); 1839 console.info(`Succeeded in getting window rect: ` + JSON.stringify(rect)); 1840} catch (exception) { 1841 console.error(`Failed to get window rect. Cause code: ${exception.code}, message: ${exception.message}`); 1842} 1843``` 1844 1845### getWindowAvoidArea<sup>9+</sup> 1846 1847getWindowAvoidArea(type: AvoidAreaType): AvoidArea 1848 1849获取当前应用窗口内容规避的区域。如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 1850 1851该接口一般适用于两种场景:1、在onWindowStageCreate方法中,获取应用启动时的初始布局避让区域时可调用该接口;2、当应用内子窗需要临时显示,对显示内容做布局避让时可调用该接口。 1852 1853**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1854 1855**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1856 1857**参数:** 1858 1859| 参数名 | 类型 | 必填 | 说明 | 1860| ---- |----------------------------------| -- | ------------------------------------------------------------ | 1861| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。 | 1862 1863**返回值:** 1864 1865| 类型 | 说明 | 1866|--------------------------| ----------------- | 1867| [AvoidArea](#avoidarea7) | 窗口内容规避区域。 | 1868 1869**错误码:** 1870 1871以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1872 1873| 错误码ID | 错误信息 | 1874| ------- | ------------------------------ | 1875| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1876| 1300002 | This window state is abnormal. | 1877 1878**示例:** 1879 1880```ts 1881let type = window.AvoidAreaType.TYPE_SYSTEM; 1882try { 1883 let avoidArea = windowClass.getWindowAvoidArea(type); 1884} catch (exception) { 1885 console.error(`Failed to obtain the area. Cause code: ${exception.code}, message: ${exception.message}`); 1886} 1887``` 1888 1889### setTitleAndDockHoverShown<sup>14+</sup> 1890 1891setTitleAndDockHoverShown(isTitleHoverShown?: boolean, isDockHoverShown?: boolean): Promise<void> 1892 1893设置主窗口进入全屏沉浸式时鼠标Hover到热区上是否显示窗口标题栏和dock栏,使用Promise异步回调,仅2in1设备可用。 1894 1895**系统能力**:SystemCapability.Window.SessionManager 1896 1897**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 1898 1899**参数:** 1900 1901| 参数名 | 类型 | 必填 | 说明 | 1902| ---------- | ------- | ---- | ------------------------------------------------------------ | 1903| isTitleHoverShown | boolean | 否 | 是否显示窗口标题栏。<br>true表示显示窗口标题栏;false表示不显示窗口标题栏。默认值是true。</br> | 1904| isDockHoverShown | boolean | 否 | 是否显示dock栏。<br>true表示显示dock栏;false表示不显示dock栏。默认值是true。</br> | 1905 1906**错误码:** 1907 1908以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1909 1910| 错误码ID | 错误信息 | 1911| ------- | -------------------------------------------- | 1912| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1913| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1914| 1300002 | This window state is abnormal. | 1915| 1300004 | Unauthorized operation. | 1916 1917**示例:** 1918 1919```ts 1920// EntryAbility.ets 1921import { UIAbility } from '@kit.AbilityKit'; 1922import { BusinessError } from '@kit.BasicServicesKit'; 1923import { window } from '@kit.ArkUI'; 1924 1925export default class EntryAbility extends UIAbility { 1926 // ... 1927 onWindowStageCreate(windowStage: window.WindowStage): void { 1928 // 加载主窗口对应的页面。 1929 windowStage.loadContent('pages/Index', (err) => { 1930 let mainWindow: window.Window | undefined = undefined; 1931 // 获取应用主窗口。 1932 windowStage.getMainWindow().then( 1933 data => { 1934 mainWindow = data; 1935 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 1936 // 调用maximize接口,设置窗口进入全屏沉浸式。 1937 mainWindow.maximize(window.MaximizePresentation.ENTER_IMMERSIVE); 1938 // 调用setTitleAndDockHoverShown接口,隐藏标题栏和dock栏。 1939 mainWindow.setTitleAndDockHoverShown(false, false); 1940 } 1941 ).catch((err: BusinessError) => { 1942 if(err.code){ 1943 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 1944 } 1945 }); 1946 }); 1947 } 1948} 1949``` 1950 1951### setWindowLayoutFullScreen<sup>9+</sup> 1952 1953setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 1954 1955设置主窗口或子窗口的布局是否为沉浸式布局,使用Promise异步回调。<!--RP8-->从API version 14开始,该接口在2in1设备上调用不生效。<!--RP8End--> 1956沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 1957非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 1958 1959**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1960 1961**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1962 1963**参数:** 1964 1965| 参数名 | 类型 | 必填 | 说明 | 1966| ------------------ | ------- | -- | ------------------------------------------------------------------------------------------------ | 1967| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 1968 1969**返回值:** 1970 1971| 类型 | 说明 | 1972| ------------------- | ------------------------ | 1973| Promise<void> | 无返回结果的Promise对象。 | 1974 1975**错误码:** 1976 1977以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1978 1979| 错误码ID | 错误信息 | 1980| ------- | -------------------------------------------- | 1981| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1982| 1300002 | This window state is abnormal. | 1983| 1300003 | This window manager service works abnormally. | 1984 1985**示例:** 1986 1987```ts 1988// EntryAbility.ets 1989import { UIAbility } from '@kit.AbilityKit'; 1990import { BusinessError } from '@kit.BasicServicesKit'; 1991 1992export default class EntryAbility extends UIAbility { 1993 // ... 1994 onWindowStageCreate(windowStage: window.WindowStage): void { 1995 console.info('onWindowStageCreate'); 1996 let windowClass: window.Window | undefined = undefined; 1997 windowStage.getMainWindow((err: BusinessError, data) => { 1998 const errCode: number = err.code; 1999 if (errCode) { 2000 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2001 return; 2002 } 2003 windowClass = data; 2004 let isLayoutFullScreen = true; 2005 try { 2006 let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); 2007 promise.then(() => { 2008 console.info('Succeeded in setting the window layout to full-screen mode.'); 2009 }).catch((err: BusinessError) => { 2010 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 2011 }); 2012 } catch (exception) { 2013 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`); 2014 } 2015 }); 2016 } 2017} 2018``` 2019 2020### setImmersiveModeEnabledState<sup>12+</sup> 2021 2022setImmersiveModeEnabledState(enabled: boolean): void 2023 2024设置当前窗口是否开启沉浸式布局,该调用不会改变窗口模式和窗口大小。<!--RP8-->从API version 14开始,该接口在2in1设备上调用不生效。<!--RP8End--> 2025 2026**系统能力**:SystemCapability.WindowManager.WindowManager.Core 2027 2028**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2029 2030**参数:** 2031 2032| 参数名 | 类型 | 必填 | 说明 | 2033| ---------- | ------- | ---- | ------------------------------------------------------------ | 2034| enabled | boolean | 是 | 是否开启沉浸式布局。<br>true表示开启,false表示关闭。</br> | 2035 2036**错误码:** 2037 2038以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2039 2040| 错误码ID | 错误信息 | 2041| ------- | -------------------------------------------- | 2042| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2043| 1300002 | This window state is abnormal. | 2044| 1300003 | This window manager service works abnormally. | 2045| 1300004 | Unauthorized operation. | 2046 2047**示例:** 2048 2049```ts 2050try { 2051 let enabled = false; 2052 windowClass.setImmersiveModeEnabledState(enabled); 2053} catch (exception) { 2054 console.error(`Failed to set the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 2055} 2056``` 2057 2058### getImmersiveModeEnabledState<sup>12+</sup> 2059 2060getImmersiveModeEnabledState(): boolean 2061 2062查询当前窗口是否已经开启沉浸式布局。 2063 2064**系统能力**:SystemCapability.WindowManager.WindowManager.Core 2065 2066**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2067 2068**返回值:** 2069| 类型 | 说明 | 2070| ------- | ------------------------------------------------------------------------------------ | 2071| boolean | 是否已经开启沉浸式布局。<br>true表示开启,false表示关闭。</br> | 2072 2073**错误码:** 2074 2075以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2076 2077| 错误码ID | 错误信息 | 2078| -------- | -------------------------------------------- | 2079| 1300002 | This window state is abnormal. | 2080| 1300003 | This window manager service works abnormally. | 2081| 1300004 | Unauthorized operation. | 2082 2083**示例:** 2084 2085```ts 2086try { 2087 let isEnabled = windowClass.getImmersiveModeEnabledState(); 2088} catch (exception) { 2089 console.error(`Failed to get the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 2090} 2091``` 2092 2093### setWindowSystemBarEnable<sup>9+</sup> 2094 2095setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 2096 2097设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 2098 2099调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。 2100 2101**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2102 2103**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2104 2105**参数:** 2106 2107| 参数名 | 类型 | 必填 | 说明 | 2108| ----- | ---------------------------- | -- | --------------------------------- | 2109| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 2110 2111**返回值:** 2112 2113| 类型 | 说明 | 2114| ------------------- | ------------------------ | 2115| Promise<void> | 无返回结果的Promise对象。 | 2116 2117**错误码:** 2118 2119以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2120 2121| 错误码ID | 错误信息 | 2122| ------- | -------------------------------------------- | 2123| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2124| 1300002 | This window state is abnormal. | 2125| 1300003 | This window manager service works abnormally. | 2126 2127**示例:** 2128 2129```ts 2130// 此处以不显示三键导航栏、状态栏、底部导航条为例 2131// EntryAbility.ets 2132import { UIAbility } from '@kit.AbilityKit'; 2133import { BusinessError } from '@kit.BasicServicesKit'; 2134 2135export default class EntryAbility extends UIAbility { 2136 // ... 2137 onWindowStageCreate(windowStage: window.WindowStage): void { 2138 console.info('onWindowStageCreate'); 2139 let windowClass: window.Window | undefined = undefined; 2140 windowStage.getMainWindow((err: BusinessError, data) => { 2141 const errCode: number = err.code; 2142 if (errCode) { 2143 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2144 return; 2145 } 2146 windowClass = data; 2147 let names: Array<'status' | 'navigation'> = []; 2148 try { 2149 let promise = windowClass.setWindowSystemBarEnable(names); 2150 promise.then(() => { 2151 console.info('Succeeded in setting the system bar to be invisible.'); 2152 }).catch((err: BusinessError) => { 2153 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 2154 }); 2155 } catch (exception) { 2156 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 2157 } 2158 }); 2159 } 2160} 2161``` 2162 2163### setSpecificSystemBarEnabled<sup>11+</sup> 2164 2165setSpecificSystemBarEnabled(name: SpecificSystemBar, enable: boolean, enableAnimation?: boolean): Promise<void> 2166 2167设置主窗口三键导航栏、状态栏、底部导航条的显示和隐藏,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 2168 2169调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。 2170 2171**系统能力:** SystemCapability.Window.SessionManager 2172 2173**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2174 2175**参数:** 2176 2177| 参数名 | 类型 | 必填 | 说明 | 2178| ----- | ---------------------------- | -- | --------------------------------- | 2179| name | [SpecificSystemBar](#specificsystembar11) | 是 | 设置窗口全屏模式时,显示或隐藏的系统栏类型。 | 2180| enable | boolean | 是 | 设置窗口全屏模式时状态栏、三键导航栏或底部导航条是否显示,true表示显示, false表示隐藏。| 2181| enableAnimation<sup>12+</sup> | boolean | 否 | 设置状态栏、三键导航栏或底部导航条显示状态变化时是否使用动画,true表示使用, false表示不使用,默认值为false。| 2182 2183**返回值:** 2184 2185| 类型 | 说明 | 2186| ------------------- | ------------------------ | 2187| Promise<void> | 无返回结果的Promise对象。 | 2188 2189**错误码:** 2190 2191以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2192 2193| 错误码ID | 错误信息 | 2194| ------- | -------------------------------------------- | 2195| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2196| 1300002 | This window state is abnormal. | 2197| 1300003 | This window manager service works abnormally. | 2198 2199**示例:** 2200 2201```ts 2202// 此处以隐藏底部导航条为例 2203// EntryAbility.ets 2204import { UIAbility } from '@kit.AbilityKit'; 2205import { BusinessError } from '@kit.BasicServicesKit'; 2206 2207export default class EntryAbility extends UIAbility { 2208 // ... 2209 onWindowStageCreate(windowStage: window.WindowStage): void { 2210 console.info('onWindowStageCreate'); 2211 let windowClass: window.Window | undefined = undefined; 2212 windowStage.getMainWindow((err: BusinessError, data) => { 2213 const errCode: number = err.code; 2214 if (errCode) { 2215 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2216 return; 2217 } 2218 windowClass = data; 2219 try { 2220 let promise = windowClass.setSpecificSystemBarEnabled('navigationIndicator', false); 2221 promise.then(() => { 2222 console.info('Succeeded in setting the system bar to be invisible.'); 2223 }).catch((err: BusinessError) => { 2224 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 2225 }); 2226 } catch (exception) { 2227 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 2228 } 2229 }); 2230 } 2231} 2232``` 2233 2234### setWindowSystemBarProperties<sup>9+</sup> 2235 2236setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 2237 2238设置主窗口三键导航栏、状态栏的属性,使用Promise异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 2239 2240子窗口调用后不生效。 2241 2242**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2243 2244**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2245 2246**参数:** 2247 2248| 参数名 | 类型 | 必填 | 说明 | 2249| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2250| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 三键导航栏、状态栏的属性。 | 2251 2252**返回值:** 2253 2254| 类型 | 说明 | 2255| ------------------- | ------------------------- | 2256| Promise<void> | 无返回结果的Promise对象。 | 2257 2258**错误码:** 2259 2260以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2261 2262| 错误码ID | 错误信息 | 2263| ------- | -------------------------------------------- | 2264| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2265| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2266| 1300002 | This window state is abnormal. | 2267| 1300003 | This window manager service works abnormally. | 2268 2269**示例:** 2270 2271```ts 2272// EntryAbility.ets 2273import { UIAbility } from '@kit.AbilityKit'; 2274import { BusinessError } from '@kit.BasicServicesKit'; 2275 2276export default class EntryAbility extends UIAbility { 2277 // ... 2278 onWindowStageCreate(windowStage: window.WindowStage): void { 2279 console.info('onWindowStageCreate'); 2280 let windowClass: window.Window | undefined = undefined; 2281 windowStage.getMainWindow((err: BusinessError, data) => { 2282 const errCode: number = err.code; 2283 if (errCode) { 2284 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2285 return; 2286 } 2287 windowClass = data; 2288 let SystemBarProperties: window.SystemBarProperties = { 2289 statusBarColor: '#ff00ff', 2290 navigationBarColor: '#00ff00', 2291 //以下两个属性从API Version8开始支持 2292 statusBarContentColor: '#ffffff', 2293 navigationBarContentColor: '#00ffff' 2294 }; 2295 try { 2296 let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties); 2297 promise.then(() => { 2298 console.info('Succeeded in setting the system bar properties.'); 2299 }).catch((err: BusinessError) => { 2300 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 2301 }); 2302 } catch (exception) { 2303 console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); 2304 } 2305 }); 2306 } 2307} 2308``` 2309 2310### getWindowSystemBarProperties<sup>12+</sup> 2311 2312getWindowSystemBarProperties(): SystemBarProperties 2313 2314主窗口获取三键导航栏、状态栏的属性。 2315 2316**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2317 2318**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2319 2320**返回值:** 2321 2322| 类型 | 说明 | 2323| ------------------------------------- | ------------- | 2324| [SystemBarProperties](#systembarproperties) | 当前三键导航栏、状态栏属性。 | 2325 2326**错误码:** 2327 2328以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 2329 2330| 错误码ID | 错误信息 | 2331| ------- | ------------------------------ | 2332| 1300002 | This window state is abnormal. | 2333| 1300003 | This window manager service works abnormally. | 2334| 1300004 | Unauthorized operation. | 2335 2336 2337**示例:** 2338 2339```ts 2340// EntryAbility.ets 2341import { UIAbility } from '@kit.AbilityKit'; 2342import { BusinessError } from '@kit.BasicServicesKit'; 2343 2344export default class EntryAbility extends UIAbility { 2345 // ... 2346 2347 onWindowStageCreate(windowStage: window.WindowStage) { 2348 let windowClass: window.Window | undefined = undefined; 2349 windowStage.getMainWindow((err: BusinessError, data) => { 2350 const errCode: number = err.code; 2351 if (errCode) { 2352 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2353 return; 2354 } 2355 windowClass = data; 2356 try { 2357 let systemBarProperty = windowClass.getWindowSystemBarProperties(); 2358 console.info('Success in obtaining system bar properties. Property: ' + JSON.stringify(systemBarProperty)); 2359 } catch (err) { 2360 console.error(`Failed to get system bar properties. Code: ${err.code}, message: ${err.message}`); 2361 } 2362 }); 2363 } 2364}; 2365``` 2366 2367### setPreferredOrientation<sup>9+</sup> 2368 2369setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void 2370 2371设置主窗口的显示方向属性,使用callback异步回调。<!--RP9-->仅在支持跟随sensor旋转的设备上生效,2in1设备上调用不生效,子窗口调用后不生效。<!--RP9End--> 2372 2373**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2374 2375**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2376 2377**参数:** 2378 2379| 参数名 | 类型 | 必填 | 说明 | 2380| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2381| orientation | [Orientation](#orientation9) | 是 | 窗口显示方向的属性。 | 2382| callback | AsyncCallback<void> | 是 | 回调函数。该回调函数返回调用结果是否成功,非应用旋转动效结束。 | 2383 2384**错误码:** 2385 2386以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2387 2388| 错误码ID | 错误信息 | 2389| ------- | ------------------------------ | 2390| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2391| 1300002 | This window state is abnormal. | 2392 2393**示例:** 2394 2395```ts 2396// EntryAbility.ets 2397import { UIAbility } from '@kit.AbilityKit'; 2398import { BusinessError } from '@kit.BasicServicesKit'; 2399 2400export default class EntryAbility extends UIAbility { 2401 // ... 2402 onWindowStageCreate(windowStage: window.WindowStage): void { 2403 console.info('onWindowStageCreate'); 2404 let windowClass: window.Window | undefined = undefined; 2405 windowStage.getMainWindow((err: BusinessError, data) => { 2406 const errCode: number = err.code; 2407 if (errCode) { 2408 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2409 return; 2410 } 2411 windowClass = data; 2412 let orientation = window.Orientation.AUTO_ROTATION; 2413 try { 2414 windowClass.setPreferredOrientation(orientation, (err: BusinessError) => { 2415 const errCode: number = err.code; 2416 if (errCode) { 2417 console.error(`Failed to set window orientation. Cause code: ${err.code}, message: ${err.message}`); 2418 return; 2419 } 2420 console.info('Succeeded in setting window orientation.'); 2421 }); 2422 } catch (exception) { 2423 console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 2424 } 2425 }); 2426 } 2427} 2428``` 2429 2430### setPreferredOrientation<sup>9+</sup> 2431 2432setPreferredOrientation(orientation: Orientation): Promise<void> 2433 2434设置主窗口的显示方向属性,使用Promise异步回调。<!--RP9-->仅在支持跟随sensor旋转的设备上生效,2in1设备上调用不生效,子窗口调用后不生效。<!--RP9End--> 2435 2436**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2437 2438**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2439 2440**参数:** 2441 2442| 参数名 | 类型 | 必填 | 说明 | 2443| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2444| orientation | [Orientation](#orientation9) | 是 | 窗口显示方向的属性。 | 2445 2446**返回值:** 2447 2448| 类型 | 说明 | 2449| ------------------- | ------------------------- | 2450| Promise<void> | 无返回结果的Promise对象。 | 2451 2452**错误码:** 2453 2454以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2455 2456| 错误码ID | 错误信息 | 2457| ------- | ------------------------------ | 2458| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2459| 1300002 | This window state is abnormal. | 2460 2461**示例:** 2462 2463```ts 2464// EntryAbility.ets 2465import { UIAbility } from '@kit.AbilityKit'; 2466import { BusinessError } from '@kit.BasicServicesKit'; 2467 2468export default class EntryAbility extends UIAbility { 2469 // ... 2470 onWindowStageCreate(windowStage: window.WindowStage): void { 2471 console.info('onWindowStageCreate'); 2472 let windowClass: window.Window | undefined = undefined; 2473 windowStage.getMainWindow((err: BusinessError, data) => { 2474 const errCode: number = err.code; 2475 if (errCode) { 2476 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2477 return; 2478 } 2479 windowClass = data; 2480 let orientation = window.Orientation.AUTO_ROTATION; 2481 try { 2482 let promise = windowClass.setPreferredOrientation(orientation); 2483 promise.then(() => { 2484 console.info('Succeeded in setting the window orientation.'); 2485 }).catch((err: BusinessError) => { 2486 console.error(`Failed to set the window orientation. Cause code: ${err.code}, message: ${err.message}`); 2487 }); 2488 } catch (exception) { 2489 console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 2490 } 2491 }); 2492 } 2493} 2494``` 2495 2496### getPreferredOrientation<sup>12+</sup> 2497 2498getPreferredOrientation(): Orientation 2499 2500主窗口调用,获取窗口的显示方向属性。 2501 2502**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2503 2504**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2505 2506**返回值:** 2507 2508| 类型 | 说明 | 2509|------------------------------| ------------------ | 2510| [Orientation](#orientation9) | 窗口显示方向的属性。 | 2511 2512**错误码:** 2513 2514以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 2515 2516| 错误码ID | 错误信息 | 2517| ------- | ------------------------------ | 2518| 1300002 | This window state is abnormal. | 2519 2520**示例:** 2521 2522```ts 2523// EntryAbility.ets 2524import { UIAbility } from '@kit.AbilityKit'; 2525import { BusinessError } from '@kit.BasicServicesKit'; 2526export default class EntryAbility extends UIAbility { 2527 // ... 2528 2529 onWindowStageCreate(windowStage: window.WindowStage) { 2530 console.info('onWindowStageCreate'); 2531 let windowClass: window.Window | undefined = undefined; 2532 windowStage.getMainWindow((err: BusinessError, data) => { 2533 const errCode: number = err.code; 2534 if (errCode) { 2535 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2536 return; 2537 } 2538 windowClass = data; 2539 try { 2540 let orientation = windowClass.getPreferredOrientation(); 2541 } catch (exception) { 2542 console.error(`Failed to get window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 2543 } 2544 }); 2545 } 2546}; 2547``` 2548 2549### getUIContext<sup>10+</sup> 2550 2551getUIContext(): UIContext 2552 2553获取UIContext实例。 2554 2555**模型约束:** 此接口仅可在Stage模型下使用。 2556 2557**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2558 2559**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2560 2561**返回值:** 2562 2563| 类型 | 说明 | 2564| ---------- | ---------------------- | 2565| [UIContext](js-apis-arkui-UIContext.md#uicontext) | 返回UIContext实例对象。 | 2566 2567**错误码:** 2568 2569以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 2570 2571| 错误码ID | 错误信息 | 2572| ------- | ------------------------------ | 2573| 1300002 | This window state is abnormal. | 2574 2575**示例:** 2576 2577```ts 2578// EntryAbility.ets 2579import { UIAbility } from '@kit.AbilityKit'; 2580import { window, UIContext } from '@kit.ArkUI'; 2581import { BusinessError } from '@kit.BasicServicesKit'; 2582 2583export default class EntryAbility extends UIAbility { 2584 onWindowStageCreate(windowStage: window.WindowStage) { 2585 // 为主窗口加载对应的目标页面。 2586 windowStage.loadContent("pages/page2", (err: BusinessError) => { 2587 let errCode: number = err.code; 2588 if (errCode) { 2589 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2590 return; 2591 } 2592 console.info('Succeeded in loading the content.'); 2593 // 获取应用主窗口。 2594 let windowClass: window.Window | undefined = undefined; 2595 windowStage.getMainWindow((err: BusinessError, data) => { 2596 let errCode: number = err.code; 2597 if (errCode) { 2598 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2599 return; 2600 } 2601 windowClass = data; 2602 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 2603 // 获取UIContext实例。 2604 let uiContext: UIContext | null = null; 2605 uiContext = windowClass.getUIContext(); 2606 }); 2607 }); 2608 } 2609}; 2610``` 2611 2612### setUIContent<sup>9+</sup> 2613 2614setUIContent(path: string, callback: AsyncCallback<void>): void 2615 2616根据当前工程中某个页面的路径为窗口加载具体页面内容,使用callback异步回调。 2617 2618**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2619 2620**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2621 2622**参数:** 2623 2624| 参数名 | 类型 | 必填 | 说明 | 2625| -------- | ------------------------- | -- | -------------------- | 2626| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 2627| callback | AsyncCallback<void> | 是 | 回调函数。 | 2628 2629**错误码:** 2630 2631以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2632 2633| 错误码ID | 错误信息 | 2634| ------- | -------------------------------------------- | 2635| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2636| 1300002 | This window state is abnormal. | 2637| 1300003 | This window manager service works abnormally. | 2638 2639**示例:** 2640 2641```ts 2642import { BusinessError } from '@kit.BasicServicesKit'; 2643 2644try { 2645 windowClass.setUIContent('pages/page2/page3', (err: BusinessError) => { 2646 const errCode: number = err.code; 2647 if (errCode) { 2648 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2649 return; 2650 } 2651 console.info('Succeeded in loading the content.'); 2652 }); 2653} catch (exception) { 2654 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 2655} 2656``` 2657 2658### setUIContent<sup>9+</sup> 2659 2660setUIContent(path: string): Promise<void> 2661 2662根据当前工程中某个页面的路径为窗口加载具体页面内容,使用Promise异步回调。 2663 2664**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2665 2666**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2667 2668**参数:** 2669 2670| 参数名 | 类型 | 必填 | 说明 | 2671| ---- | ------ | -- | ------------------ | 2672| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 2673 2674**返回值:** 2675 2676| 类型 | 说明 | 2677| ------------------- | ------------------------ | 2678| Promise<void> | 无返回结果的Promise对象。 | 2679 2680**错误码:** 2681 2682以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2683 2684| 错误码ID | 错误信息 | 2685| ------- | -------------------------------------------- | 2686| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2687| 1300002 | This window state is abnormal. | 2688| 1300003 | This window manager service works abnormally. | 2689 2690**示例:** 2691 2692```ts 2693import { BusinessError } from '@kit.BasicServicesKit'; 2694 2695try { 2696 let promise = windowClass.setUIContent('pages/page2/page3'); 2697 promise.then(() => { 2698 console.info('Succeeded in loading the content.'); 2699 }).catch((err: BusinessError) => { 2700 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2701 }); 2702} catch (exception) { 2703 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 2704} 2705``` 2706 2707### loadContent<sup>9+</sup> 2708 2709loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 2710 2711根据当前工程中某个页面的路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。 2712 2713**模型约束:** 此接口仅可在Stage模型下使用。 2714 2715**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2716 2717**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2718 2719**参数:** 2720 2721| 参数名 | 类型 | 必填 | 说明 | 2722| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 2723| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 2724| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 2725| callback | AsyncCallback<void> | 是 | 回调函数。 | 2726 2727**错误码:** 2728 2729以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2730 2731| 错误码ID | 错误信息 | 2732| ------- | -------------------------------------------- | 2733| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2734| 1300002 | This window state is abnormal. | 2735| 1300003 | This window manager service works abnormally. | 2736 2737**示例:** 2738 2739```ts 2740import { BusinessError } from '@kit.BasicServicesKit'; 2741 2742let storage: LocalStorage = new LocalStorage(); 2743storage.setOrCreate('storageSimpleProp', 121); 2744windowClass.loadContent('pages/page2', storage, (err: BusinessError) => { 2745 const errCode: number = err.code; 2746 if (errCode) { 2747 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2748 return; 2749 } 2750 console.info('Succeeded in loading the content.'); 2751}); 2752``` 2753 2754### loadContent<sup>9+</sup> 2755 2756loadContent(path: string, storage: LocalStorage): Promise<void> 2757 2758根据当前工程中某个页面的路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。 2759 2760**模型约束:** 此接口仅可在Stage模型下使用。 2761 2762**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2763 2764**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2765 2766**参数:** 2767 2768| 参数名 | 类型 | 必填 | 说明 | 2769| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 2770| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 2771| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 2772 2773**返回值:** 2774 2775| 类型 | 说明 | 2776| ------------------- | ------------------------- | 2777| Promise<void> | 无返回结果的Promise对象。 | 2778 2779**错误码:** 2780 2781以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2782 2783| 错误码ID | 错误信息 | 2784| ------- | -------------------------------------------- | 2785| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2786| 1300002 | This window state is abnormal. | 2787| 1300003 | This window manager service works abnormally. | 2788 2789**示例:** 2790 2791```ts 2792import { BusinessError } from '@kit.BasicServicesKit'; 2793 2794let storage: LocalStorage = new LocalStorage(); 2795storage.setOrCreate('storageSimpleProp', 121); 2796let promise = windowClass.loadContent('pages/page2', storage); 2797promise.then(() => { 2798 console.info('Succeeded in loading the content.'); 2799}).catch((err: BusinessError) => { 2800 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2801}); 2802``` 2803 2804### loadContentByName<sup>11+</sup> 2805 2806loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback<void>): void 2807 2808为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。 2809 2810**模型约束:** 此接口仅可在Stage模型下使用。 2811 2812**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2813 2814**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2815 2816**参数:** 2817 2818| 参数名 | 类型 | 必填 | 说明 | 2819| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2820| name | string | 是 | 命名路由页面的名称。 | 2821| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 2822| callback | AsyncCallback<void> | 是 | 回调函数。 | 2823 2824**错误码:** 2825 2826以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2827 2828| 错误码ID | 错误信息 | 2829| -------- | --------------------------------------------- | 2830| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2831| 1300002 | This window state is abnormal. | 2832| 1300003 | This window manager service works abnormally. | 2833 2834**示例:** 2835<!--code_no_check--> 2836```ts 2837import { BusinessError } from '@kit.BasicServicesKit'; 2838import * as Index from '../pages/Index'; // 导入命名路由页面 2839 2840console.info('onWindowStageCreate'); 2841let storage: LocalStorage = new LocalStorage(); 2842storage.setOrCreate('storageSimpleProp', 121); 2843try { 2844 (windowClass as window.Window).loadContentByName(Index.entryName, storage, (err: BusinessError) => { 2845 const errCode: number = err.code; 2846 if (errCode) { 2847 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2848 return; 2849 } 2850 console.info('Succeeded in loading the content.'); 2851 }); 2852} catch (exception) { 2853 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 2854} 2855``` 2856<!--code_no_check--> 2857```ts 2858// ets/pages/Index.ets 2859export const entryName : string = 'Index'; 2860@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 2861@Component 2862export struct Index { 2863 @State message: string = 'Hello World' 2864 build() { 2865 Row() { 2866 Column() { 2867 Text(this.message) 2868 .fontSize(50) 2869 .fontWeight(FontWeight.Bold) 2870 } 2871 .width('100%') 2872 } 2873 .height('100%') 2874 } 2875} 2876``` 2877 2878### loadContentByName<sup>11+</sup> 2879 2880loadContentByName(name: string, callback: AsyncCallback<void>): void 2881 2882为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面内容,使用callback异步回调。 2883 2884**模型约束:** 此接口仅可在Stage模型下使用。 2885 2886**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2887 2888**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2889 2890**参数:** 2891 2892| 参数名 | 类型 | 必填 | 说明 | 2893| -------- | ------------------------- | ---- | ---------------- | 2894| name | string | 是 | 命名路由页面的名称。 | 2895| callback | AsyncCallback<void> | 是 | 回调函数。 | 2896 2897**错误码:** 2898 2899以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2900 2901| 错误码ID | 错误信息 | 2902| -------- | --------------------------------------------- | 2903| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2904| 1300002 | This window state is abnormal. | 2905| 1300003 | This window manager service works abnormally. | 2906 2907**示例:** 2908<!--code_no_check--> 2909```ts 2910import { BusinessError } from '@kit.BasicServicesKit'; 2911import * as Index from '../pages/Index'; // 导入命名路由页面 2912 2913try { 2914 (windowClass as window.Window).loadContentByName(Index.entryName, (err: BusinessError) => { 2915 const errCode: number = err.code; 2916 if (errCode) { 2917 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2918 return; 2919 } 2920 console.info('Succeeded in loading the content.'); 2921 }); 2922} catch (exception) { 2923 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 2924} 2925``` 2926<!--code_no_check--> 2927```ts 2928// ets/pages/Index.ets 2929export const entryName : string = 'Index'; 2930@Entry({routeName: entryName}) 2931@Component 2932export struct Index { 2933 @State message: string = 'Hello World' 2934 build() { 2935 Row() { 2936 Column() { 2937 Text(this.message) 2938 .fontSize(50) 2939 .fontWeight(FontWeight.Bold) 2940 } 2941 .width('100%') 2942 } 2943 .height('100%') 2944 } 2945} 2946``` 2947 2948### loadContentByName<sup>11+</sup> 2949 2950loadContentByName(name: string, storage?: LocalStorage): Promise<void> 2951 2952为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。 2953 2954**模型约束:** 此接口仅可在Stage模型下使用。 2955 2956**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2957 2958**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2959 2960**参数:** 2961 2962| 参数名 | 类型 | 必填 | 说明 | 2963| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2964| name | string | 是 | 命名路由页面的名称。 | 2965| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 否 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 2966 2967**返回值:** 2968 2969| 类型 | 说明 | 2970| ------------------- | ------------------------- | 2971| Promise<void> | 无返回结果的Promise对象。 | 2972 2973**错误码:** 2974 2975以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2976 2977| 错误码ID | 错误信息 | 2978| -------- | --------------------------------------------- | 2979| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2980| 1300002 | This window state is abnormal. | 2981| 1300003 | This window manager service works abnormally. | 2982 2983**示例:** 2984<!--code_no_check--> 2985```ts 2986import { BusinessError } from '@kit.BasicServicesKit'; 2987import * as Index from '../pages/Index'; // 导入命名路由页面 2988 2989let storage: LocalStorage = new LocalStorage(); 2990storage.setOrCreate('storageSimpleProp', 121); 2991try { 2992 let promise = (windowClass as window.Window).loadContentByName(Index.entryName, storage); 2993 promise.then(() => { 2994 console.info('Succeeded in loading the content.'); 2995 }).catch((err: BusinessError) => { 2996 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2997 }); 2998} catch (exception) { 2999 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3000} 3001``` 3002<!--code_no_check--> 3003```ts 3004// ets/pages/Index.ets 3005export const entryName : string = 'Index'; 3006@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 3007@Component 3008export struct Index { 3009 @State message: string = 'Hello World' 3010 build() { 3011 Row() { 3012 Column() { 3013 Text(this.message) 3014 .fontSize(50) 3015 .fontWeight(FontWeight.Bold) 3016 } 3017 .width('100%') 3018 } 3019 .height('100%') 3020 } 3021} 3022``` 3023 3024### isWindowShowing<sup>9+</sup> 3025 3026isWindowShowing(): boolean 3027 3028判断当前窗口是否已显示。 3029 3030**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3031 3032**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3033 3034**返回值:** 3035 3036| 类型 | 说明 | 3037| ------- | ------------------------------------------------------------------ | 3038| boolean | 当前窗口是否已显示。true表示当前窗口已显示,false则表示当前窗口未显示。 | 3039 3040**错误码:** 3041 3042以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 3043 3044| 错误码ID | 错误信息 | 3045| ------- | ------------------------------ | 3046| 1300002 | This window state is abnormal. | 3047 3048**示例:** 3049 3050```ts 3051try { 3052 let data = windowClass.isWindowShowing(); 3053 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 3054} catch (exception) { 3055 console.error(`Failed to check whether the window is showing. Cause code: ${exception.code}, message: ${exception.message}`); 3056} 3057``` 3058 3059### on('windowSizeChange')<sup>7+</sup> 3060 3061on(type: 'windowSizeChange', callback: Callback<Size>): void 3062 3063开启窗口尺寸变化的监听。 3064 3065**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3066 3067**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3068 3069**参数:** 3070 3071| 参数名 | 类型 | 必填 | 说明 | 3072| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 3073| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 | 3074| callback | Callback<[Size](#size7)> | 是 | 回调函数。返回当前的窗口尺寸。 | 3075 3076**错误码:** 3077 3078以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3079 3080| 错误码ID | 错误信息 | 3081| ------- | -------------------------------------------- | 3082| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3083 3084**示例:** 3085 3086```ts 3087try { 3088 windowClass.on('windowSizeChange', (data) => { 3089 console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data)); 3090 }); 3091} catch (exception) { 3092 console.error(`Failed to enable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`); 3093} 3094``` 3095 3096### off('windowSizeChange')<sup>7+</sup> 3097 3098off(type: 'windowSizeChange', callback?: Callback<Size>): void 3099 3100关闭窗口尺寸变化的监听。 3101 3102**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3103 3104**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3105 3106**参数:** 3107 3108| 参数名 | 类型 | 必填 | 说明 | 3109| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 3110| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 | 3111| callback | Callback<[Size](#size7)> | 否 | 回调函数。返回当前的窗口尺寸。如果传入参数,则关闭该监听。如果未传入参数,则关闭窗口尺寸变化的监听。 | 3112 3113**错误码:** 3114 3115以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3116 3117| 错误码ID | 错误信息 | 3118| ------- | -------------------------------------------- | 3119| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3120 3121**示例:** 3122 3123```ts 3124const callback = (size: window.Size) => { 3125 // ... 3126} 3127try { 3128 // 通过on接口开启监听 3129 windowClass.on('windowSizeChange', callback); 3130 // 关闭指定callback的监听 3131 windowClass.off('windowSizeChange', callback); 3132 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3133 windowClass.off('windowSizeChange'); 3134} catch (exception) { 3135 console.error(`Failed to disable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`); 3136} 3137``` 3138 3139### on('avoidAreaChange')<sup>9+</sup> 3140 3141on(type: 'avoidAreaChange', callback: Callback<AvoidAreaOptions>): void 3142 3143开启当前应用窗口系统规避区变化的监听。 3144<!--RP7-->常见的触发避让区回调的场景如下:应用窗口在全屏模式、悬浮模式、分屏模式之间的切换;应用窗口旋转;多折叠设备在屏幕折叠态和展开态之间的切换;应用窗口在多设备之间的流转。<!--RP7End--> 3145 3146**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3147 3148**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3149 3150**参数:** 3151 3152| 参数名 | 类型 | 必填 | 说明 | 3153| -------- |----------------------------------| ---- |--------------------------------------| 3154| type | string | 是 | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 | 3155| callback | Callback<[AvoidAreaOptions](#avoidareaoptions12)> | 是 | 回调函数。返回当前规避区以及规避区类型。| 3156 3157**错误码:** 3158 3159以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3160 3161| 错误码ID | 错误信息 | 3162| ------- | -------------------------------------------- | 3163| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3164 3165**示例:** 3166 3167```ts 3168try { 3169 windowClass.on('avoidAreaChange', (data) => { 3170 console.info('Succeeded in enabling the listener for system avoid area changes. type:' + 3171 JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area)); 3172 }); 3173} catch (exception) { 3174 console.error(`Failed to enable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`); 3175} 3176``` 3177 3178### off('avoidAreaChange')<sup>9+</sup> 3179 3180off(type: 'avoidAreaChange', callback?: Callback<AvoidAreaOptions>): void 3181 3182关闭当前窗口系统规避区变化的监听。 3183 3184**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3185 3186**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3187 3188**参数:** 3189 3190| 参数名 | 类型 | 必填 | 说明 | 3191| -------- |----------------------------------|------|------------------------------------| 3192| type | string | 是 | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 | 3193| callback | Callback<[AvoidAreaOptions](#avoidareaoptions12)> | 否 | 回调函数。返回当前规避区以及规避区类型。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有系统规避区变化的监听。| 3194 3195**错误码:** 3196 3197以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3198 3199| 错误码ID | 错误信息 | 3200| ------- | -------------------------------------------- | 3201| 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed. | 3202 3203**示例:** 3204 3205```ts 3206interface Param { 3207 type: window.AvoidAreaType, 3208 area: window.AvoidArea 3209} 3210const callback = (data: Param) => { 3211 // ... 3212} 3213try { 3214 windowClass.on('avoidAreaChange', callback); 3215 3216 windowClass.off('avoidAreaChange', callback); 3217 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3218 windowClass.off('avoidAreaChange'); 3219} catch (exception) { 3220 console.error(`Failed to enable or disable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`); 3221} 3222``` 3223 3224### on('keyboardHeightChange')<sup>7+</sup> 3225 3226on(type: 'keyboardHeightChange', callback: Callback<number>): void 3227 3228开启固定态软键盘高度变化的监听,当软键盘由本窗口唤出并存在重叠区域时通知键盘高度变化。从API version 10开始,改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。 3229 3230**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3231 3232**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3233 3234**参数:** 3235 3236| 参数名 | 类型 | 必填 | 说明 | 3237| -------- | ------------------- | ---- |-------------------------------------------| 3238| type | string | 是 | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 | 3239| callback | Callback<number> | 是 | 回调函数。返回当前的键盘高度,返回值为整数,单位为px。 | 3240 3241**错误码:** 3242 3243以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3244 3245| 错误码ID | 错误信息 | 3246| ------- | -------------------------------------------- | 3247| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3248 3249**示例:** 3250 3251```ts 3252import { BusinessError } from '@kit.BasicServicesKit'; 3253 3254try { 3255 windowClass.on('keyboardHeightChange', (data) => { 3256 console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); 3257 }); 3258} catch (exception) { 3259 console.error(`Failed to enable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`); 3260} 3261``` 3262 3263### off('keyboardHeightChange')<sup>7+</sup> 3264 3265off(type: 'keyboardHeightChange', callback?: Callback<number>): void 3266 3267关闭固定态软键盘高度变化的监听。从API version 10开始,改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。 3268 3269**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3270 3271**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3272 3273**参数:** 3274 3275| 参数名 | 类型 | 必填 | 说明 | 3276| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3277| type | string | 是 | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 | 3278| callback | Callback<number> | 否 | 回调函数。返回当前的键盘高度,返回值为整数,单位为px。若传入参数,则关闭该监听。如果未传入参数,则关闭所有固定态软键盘高度变化的监听。 | 3279 3280**错误码:** 3281 3282以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3283 3284| 错误码ID | 错误信息 | 3285| ------- | -------------------------------------------- | 3286| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3287 3288**示例:** 3289 3290```ts 3291import { BusinessError } from '@kit.BasicServicesKit'; 3292 3293const callback = (height: number) => { 3294 // ... 3295} 3296try { 3297 windowClass.on('keyboardHeightChange', callback); 3298 3299 windowClass.off('keyboardHeightChange', callback); 3300 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3301 windowClass.off('keyboardHeightChange'); 3302} catch (exception) { 3303 console.error(`Failed to disable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`); 3304} 3305``` 3306 3307### on('touchOutside')<sup>11+</sup> 3308 3309on(type: 'touchOutside', callback: Callback<void>): void 3310 3311开启本窗口区域范围外的点击事件的监听。 3312 3313**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3314 3315**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3316 3317**参数:** 3318 3319| 参数名 | 类型 | 必填 | 说明 | 3320| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3321| type | string | 是 | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 | 3322| callback | Callback<void> | 是 | 回调函数。当点击事件发生在本窗口范围之外的回调。 | 3323 3324**错误码:** 3325 3326以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3327 3328| 错误码ID | 错误信息 | 3329| ------- | -------------------------------------------- | 3330| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3331 3332**示例:** 3333 3334```ts 3335try { 3336 windowClass.on('touchOutside', () => { 3337 console.info('touch outside'); 3338 }); 3339} catch (exception) { 3340 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3341} 3342``` 3343 3344### off('touchOutside')<sup>11+</sup> 3345 3346off(type: 'touchOutside', callback?: Callback<void>): void 3347 3348关闭本窗口区域范围外的点击事件的监听。 3349 3350**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3351 3352**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3353 3354**参数:** 3355 3356| 参数名 | 类型 | 必填 | 说明 | 3357| -------- |----------------------| ---- |--------------------------------------| 3358| type | string | 是 | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 | 3359| callback | Callback<void> | 否 | 回调函数。当点击事件发生在本窗口范围之外的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口区域范围外的点击事件的监听。 | 3360 3361**错误码:** 3362 3363以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3364 3365| 错误码ID | 错误信息 | 3366| ------- | -------------------------------------------- | 3367| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3368 3369**示例:** 3370 3371```ts 3372const callback = () => { 3373 // ... 3374} 3375try { 3376 windowClass.on('touchOutside', callback); 3377 windowClass.off('touchOutside', callback); 3378 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3379 windowClass.off('touchOutside'); 3380} catch (exception) { 3381 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3382} 3383``` 3384 3385### on('screenshot')<sup>9+</sup> 3386 3387on(type: 'screenshot', callback: Callback<void>): void 3388 3389开启截屏事件的监听。 3390 3391**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3392 3393**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3394 3395**参数:** 3396 3397| 参数名 | 类型 | 必填 | 说明 | 3398| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3399| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件,对控制中心截屏、hdc命令截屏、整屏截屏接口生效。 | 3400| callback | Callback<void> | 是 | 回调函数。发生截屏事件时的回调。 | 3401 3402**错误码:** 3403 3404以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3405 3406| 错误码ID | 错误信息 | 3407| ------- | -------------------------------------------- | 3408| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3409 3410**示例:** 3411 3412```ts 3413try { 3414 windowClass.on('screenshot', () => { 3415 console.info('screenshot happened'); 3416 }); 3417} catch (exception) { 3418 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3419} 3420``` 3421 3422### off('screenshot')<sup>9+</sup> 3423 3424off(type: 'screenshot', callback?: Callback<void>): void 3425 3426关闭截屏事件的监听。 3427 3428**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3429 3430**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3431 3432**参数:** 3433 3434| 参数名 | 类型 | 必填 | 说明 | 3435| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3436| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件。 | 3437| callback | Callback<void> | 否 | 回调函数。发生截屏事件时的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有截屏事件的监听。 | 3438 3439**错误码:** 3440 3441以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3442 3443| 错误码ID | 错误信息 | 3444| ------- | -------------------------------------------- | 3445| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3446 3447**示例:** 3448 3449```ts 3450let callback = () => { 3451 console.info('screenshot happened'); 3452}; 3453try { 3454 windowClass.on('screenshot', callback); 3455 windowClass.off('screenshot', callback); 3456 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3457 windowClass.off('screenshot'); 3458} catch (exception) { 3459 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3460} 3461``` 3462 3463### on('dialogTargetTouch')<sup>10+</sup> 3464 3465on(type: 'dialogTargetTouch', callback: Callback<void>): void 3466 3467开启模态窗口所遮盖窗口的点击或触摸事件的监听,除模态窗口以外其他窗口调用此接口不生效。 3468 3469**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3470 3471**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3472 3473**参数:** 3474 3475| 参数名 | 类型 | 必填 | 说明 | 3476| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3477| type | string | 是 | 监听事件,固定为'dialogTargetTouch',即模态窗口所遮盖窗口的点击或触摸事件。 | 3478| callback | Callback<void>| 是 | 回调函数。当点击或触摸事件发生在模态窗口所遮盖窗口的回调。 | 3479 3480**错误码:** 3481 3482以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3483 3484| 错误码ID | 错误信息 | 3485| ------- | -------------------------------------------- | 3486| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3487 3488**示例:** 3489 3490```ts 3491try { 3492 windowClass.on('dialogTargetTouch', () => { 3493 console.info('touch dialog target'); 3494 }); 3495} catch (exception) { 3496 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3497} 3498``` 3499 3500### off('dialogTargetTouch')<sup>10+</sup> 3501 3502off(type: 'dialogTargetTouch', callback?: Callback<void>): void 3503 3504关闭模态窗口目标窗口的点击事件的监听。 3505 3506**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3507 3508**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3509 3510**参数:** 3511 3512| 参数名 | 类型 | 必填 | 说明 | 3513| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3514| type | string | 是 | 监听事件,固定为'dialogTargetTouch',即模态窗口目标窗口的点击事件。 | 3515| callback | Callback<void> | 否 | 回调函数。当点击事件发生在模态窗口目标窗口的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有模态窗口目标窗口的点击事件的监听。 | 3516 3517**错误码:** 3518 3519以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3520 3521| 错误码ID | 错误信息 | 3522| ------- | -------------------------------------------- | 3523| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3524 3525**示例:** 3526 3527```ts 3528const callback = () => { 3529 // ... 3530} 3531try { 3532 windowClass.on('dialogTargetTouch', callback); 3533 windowClass.off('dialogTargetTouch', callback); 3534 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3535 windowClass.off('dialogTargetTouch'); 3536} catch (exception) { 3537 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3538} 3539``` 3540 3541### on('windowEvent')<sup>10+</sup> 3542 3543on(type: 'windowEvent', callback: Callback<WindowEventType>): void 3544 3545开启窗口生命周期变化的监听。 3546 3547**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3548 3549**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3550 3551**参数:** 3552 3553| 参数名 | 类型 | 必填 | 说明 | 3554| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3555| type | string | 是 | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 | 3556| callback | Callback<[WindowEventType](#windoweventtype10)> | 是 | 回调函数。返回当前的窗口生命周期状态。 | 3557 3558**错误码:** 3559 3560以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3561 3562| 错误码ID | 错误信息 | 3563| ------- | -------------------------------------------- | 3564| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3565 3566**示例:** 3567 3568```ts 3569try { 3570 windowClass.on('windowEvent', (data) => { 3571 console.info('Window event happened. Event:' + JSON.stringify(data)); 3572 }); 3573} catch (exception) { 3574 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3575} 3576``` 3577 3578### off('windowEvent')<sup>10+</sup> 3579 3580off(type: 'windowEvent', callback?: Callback<WindowEventType>): void 3581 3582关闭窗口生命周期变化的监听。 3583 3584**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3585 3586**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3587 3588**参数:** 3589 3590| 参数名 | 类型 | 必填 | 说明 | 3591| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3592| type | string | 是 | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 | 3593| callback | Callback<[WindowEventType](#windoweventtype10)> | 否 | 回调函数。返回当前的窗口生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有窗口生命周期变化的监听。 | 3594 3595**错误码:** 3596 3597以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3598 3599| 错误码ID | 错误信息 | 3600| ------- | -------------------------------------------- | 3601| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3602 3603**示例:** 3604 3605```ts 3606const callback = (windowEventType: window.WindowEventType) => { 3607 // ... 3608} 3609try { 3610 // 通过on接口开启监听 3611 windowClass.on('windowEvent', callback); 3612 // 关闭指定callback的监听 3613 windowClass.off('windowEvent', callback); 3614 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3615 windowClass.off('windowEvent'); 3616} catch (exception) { 3617 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3618} 3619``` 3620 3621### on('displayIdChange')<sup>14+</sup> 3622 3623on(type: 'displayIdChange', callback: Callback<number>): void 3624 3625开启本窗口所处屏幕变化事件的监听。比如,当前窗口移动到其他屏幕时,可以从此接口监听到这个行为。 3626 3627**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 3628 3629**系统能力:** SystemCapability.Window.SessionManager 3630 3631**参数:** 3632 3633| 参数名 | 类型 | 必填 | 说明 | 3634| -------- | --------------------------| ---- | ------------------------------------------------------------ | 3635| type | string | 是 | 监听事件,固定为'displayIdChange',即本窗口所处屏幕变化的事件。 | 3636| callback | Callback<number> | 是 | 回调函数。当本窗口所处屏幕发生变化后的回调。回调函数返回number类型参数,表示窗口所处屏幕的displayId。 | 3637 3638**错误码:** 3639 3640以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3641 3642| 错误码ID | 错误信息 | 3643| ------- | ------------------------------ | 3644| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3645| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3646| 1300002 | This window state is abnormal. | 3647 3648**示例:** 3649 3650```ts 3651try { 3652 windowClass.on('displayIdChange', (data) => { 3653 console.info('Window displayId changed, displayId=' + JSON.stringify(data)); 3654 }); 3655} catch (exception) { 3656 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3657} 3658``` 3659### off('displayIdChange')<sup>14+</sup> 3660 3661off(type: 'displayIdChange', callback?: Callback<number>): void 3662 3663关闭本窗口所处屏幕变化事件的监听。 3664 3665**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 3666 3667**系统能力:** SystemCapability.Window.SessionManager 3668 3669**参数:** 3670 3671| 参数名 | 类型 | 必填 | 说明 | 3672| -------- |----------------------------| ---- |--------------------------------------| 3673| type | string | 是 | 监听事件,固定为'displayIdChange',即本窗口所处屏幕变化的事件。 | 3674| callback | Callback<number> | 否 | 回调函数。当本窗口所处屏幕发生变化时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口所处屏幕变化事件的回调。 | 3675 3676**错误码:** 3677 3678以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3679 3680| 错误码ID | 错误信息 | 3681| ------- | ------------------------------ | 3682| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3683| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3684| 1300002 | This window state is abnormal. | 3685 3686**示例:** 3687 3688```ts 3689const callback = (displayId: number) => { 3690 // ... 3691} 3692try { 3693 // 通过on接口开启监听 3694 windowClass.on('displayIdChange', callback); 3695 // 关闭指定callback的监听 3696 windowClass.off('displayIdChange', callback); 3697 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3698 windowClass.off('displayIdChange'); 3699} catch (exception) { 3700 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3701} 3702``` 3703 3704### on('windowVisibilityChange')<sup>11+</sup> 3705 3706on(type: 'windowVisibilityChange', callback: Callback<boolean>): void 3707 3708开启本窗口可见状态变化事件的监听。 3709 3710**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3711 3712**系统能力:** SystemCapability.Window.SessionManager 3713 3714**参数:** 3715 3716| 参数名 | 类型 | 必填 | 说明 | 3717| -------- | --------------------------| ---- | ------------------------------------------------------------ | 3718| type | string | 是 | 监听事件,固定为'windowVisibilityChange',即本窗口可见状态变化的事件。 | 3719| callback | Callback<boolean> | 是 | 回调函数。当本窗口可见状态发生变化后的回调。回调函数返回boolean类型参数,当返回参数为true时表示窗口可见,否则表示窗口不可见。 | 3720 3721**错误码:** 3722 3723以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3724 3725| 错误码ID | 错误信息 | 3726| ------- | ------------------------------ | 3727| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3728| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3729| 1300002 | This window state is abnormal. | 3730| 1300003 | This window manager service works abnormally. | 3731 3732**示例:** 3733 3734```ts 3735try { 3736 windowClass.on('windowVisibilityChange', (boolean) => { 3737 console.info('Window visibility changed, isVisible=' + boolean); 3738 }); 3739} catch (exception) { 3740 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3741} 3742``` 3743 3744### off('windowVisibilityChange')<sup>11+</sup> 3745 3746off(type: 'windowVisibilityChange', callback?: Callback<boolean>): void 3747 3748关闭本窗口可见状态变化事件的监听。 3749 3750**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3751 3752**系统能力:** SystemCapability.Window.SessionManager 3753 3754**参数:** 3755 3756| 参数名 | 类型 | 必填 | 说明 | 3757| -------- |----------------------------| ---- |--------------------------------------| 3758| type | string | 是 | 监听事件,固定为'windowVisibilityChange',即本窗口可见状态变化的事件。 | 3759| callback | Callback<boolean> | 否 | 回调函数。当本窗口可见状态发生变化时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口可见状态变化事件的回调。 | 3760 3761**错误码:** 3762 3763以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3764 3765| 错误码ID | 错误信息 | 3766| ------- | ------------------------------ | 3767| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3768| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3769| 1300002 | This window state is abnormal. | 3770| 1300003 | This window manager service works abnormally. | 3771 3772**示例:** 3773 3774```ts 3775const callback = (bool: boolean) => { 3776 // ... 3777} 3778try { 3779 // 通过on接口开启监听 3780 windowClass.on('windowVisibilityChange', callback); 3781 // 关闭指定callback的监听 3782 windowClass.off('windowVisibilityChange', callback); 3783 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3784 windowClass.off('windowVisibilityChange'); 3785} catch (exception) { 3786 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3787} 3788``` 3789 3790### on('noInteractionDetected')<sup>12+</sup> 3791 3792on(type: 'noInteractionDetected', timeout: number, callback: Callback<void>): void 3793 3794开启本窗口在指定超时时间内无交互事件的监听,交互事件支持物理键盘输入事件和屏幕触控点击事件,不支持软键盘输入事件。 3795 3796**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3797 3798**系统能力:** SystemCapability.Window.SessionManager 3799 3800**参数:** 3801 3802| 参数名 | 类型 | 必填 | 说明 | 3803| -------- | --------------------------| ---- | ------------------------------------------------------------ | 3804| type | string | 是 | 监听事件,固定为'noInteractionDetected',即本窗口在指定超时时间内无交互的事件。 | 3805| timeout | number | 是 | 指定本窗口在多长时间内无交互即回调,单位为秒(s)。该参数仅支持整数输入,负数和小数为非法参数。 | 3806| callback | Callback<void> | 是 | 回调函数。当本窗口在指定超时时间内无交互事件时的回调。 | 3807 3808**错误码:** 3809 3810以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3811 3812| 错误码ID | 错误信息 | 3813| ------- | ------------------------------ | 3814| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3815| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3816| 1300002 | This window state is abnormal. | 3817| 1300003 | This window manager service works abnormally. | 3818 3819**示例:** 3820 3821```ts 3822try { 3823 windowClass.on('noInteractionDetected', 60, () => { 3824 console.info('no interaction in 60s'); 3825 }); 3826} catch (exception) { 3827 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 3828} 3829``` 3830 3831### off('noInteractionDetected')<sup>12+</sup> 3832 3833off(type: 'noInteractionDetected', callback?: Callback<void>): void 3834 3835关闭本窗口在指定超时时间内无交互事件的监听,交互事件支持物理键盘输入事件和屏幕触控点击事件,不支持软键盘输入事件。 3836 3837**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3838 3839**系统能力:** SystemCapability.Window.SessionManager 3840 3841**参数:** 3842 3843| 参数名 | 类型 | 必填 | 说明 | 3844| -------- |----------------------------| ---- |--------------------------------------| 3845| type | string | 是 | 监听事件,固定为'noInteractionDetected',即本窗口在指定超时时间内无交互的事件。 | 3846| callback | Callback<void> | 否 | 回调函数,当本窗口在指定超时时间内无交互事件时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口在指定超时时间内无交互事件的监听。 | 3847 3848**错误码:** 3849 3850以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3851 3852| 错误码ID | 错误信息 | 3853| ------- | ------------------------------ | 3854| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3855| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3856| 1300002 | This window state is abnormal. | 3857| 1300003 | This window manager service works abnormally. | 3858 3859**示例:** 3860 3861```ts 3862const callback = () => { 3863 // ... 3864} 3865try { 3866 windowClass.on('noInteractionDetected', 60, callback); 3867 windowClass.off('noInteractionDetected', callback); 3868 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3869 windowClass.off('noInteractionDetected'); 3870} catch (exception) { 3871 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3872} 3873``` 3874 3875### on('windowStatusChange')<sup>11+</sup> 3876 3877on(type: 'windowStatusChange', callback: Callback<WindowStatusType>): void 3878 3879开启窗口模式变化的监听,当窗口windowStatus发生变化时进行通知(此时窗口属性可能还没有更新)。 3880 3881> **说明:** 3882> 3883> 在2in1设备上调用本接口时,在窗口最大化状态时返回值对应为WindowStatusType::FULL_SCREEN。 3884> 3885> 若想在2in1设备上区分当前窗口状态为最大化还是全屏,可在窗口状态为WindowStatusType::FULL_SCREEN的情况下,再调用[getImmersiveModeEnabledState()](#getimmersivemodeenabledstate12) 接口进行进一步判断,到底是最大化状态还是全屏状态。若接口返回true则表示当前窗口为全屏状态,若接口返回false则表示当前窗口为最大化状态。 3886 3887**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3888 3889**系统能力:** SystemCapability.Window.SessionManager 3890 3891**参数:** 3892 3893| 参数名 | 类型 | 必填 | 说明 | 3894| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 3895| type | string | 是 | 监听事件,固定为'windowStatusChange',即窗口模式变化事件。 | 3896| callback | Callback<[WindowStatusType](#windowstatustype11)> | 是 | 回调函数。返回当前的窗口模式。 | 3897 3898**错误码:** 3899 3900以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3901 3902| 错误码ID | 错误信息 | 3903| ------- | ------------------------------ | 3904| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3905| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3906 3907**示例:** 3908 3909```ts 3910try { 3911 windowClass.on('windowStatusChange', (WindowStatusType) => { 3912 console.info('Succeeded in enabling the listener for window status changes. Data: ' + JSON.stringify(WindowStatusType)); 3913 }); 3914} catch (exception) { 3915 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3916} 3917``` 3918 3919### off('windowStatusChange')<sup>11+</sup> 3920 3921off(type: 'windowStatusChange', callback?: Callback<WindowStatusType>): void 3922 3923关闭窗口模式变化的监听。 3924 3925**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3926 3927**系统能力:** SystemCapability.Window.SessionManager 3928 3929**参数:** 3930 3931| 参数名 | 类型 | 必填 | 说明 | 3932| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 3933| type | string | 是 | 监听事件,固定为'windowStatusChange',即窗口模式变化事件。 | 3934| callback | Callback<[WindowStatusType](#windowstatustype11)> | 否 | 回调函数。返回当前的窗口模式。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有窗口模式变化的监听。 | 3935 3936**错误码:** 3937 3938以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3939 3940| 错误码ID | 错误信息 | 3941| ------- | ------------------------------ | 3942| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3943| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3944 3945**示例:** 3946 3947```ts 3948const callback = (windowStatusType: window.WindowStatusType) => { 3949 // ... 3950} 3951try { 3952 windowClass.on('windowStatusChange', callback); 3953 windowClass.off('windowStatusChange', callback); 3954 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3955 windowClass.off('windowStatusChange'); 3956} catch (exception) { 3957 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 3958} 3959``` 3960 3961### setWindowGrayScale<sup>12+</sup> 3962 3963setWindowGrayScale(grayScale: number): Promise<void> 3964 3965设置窗口灰阶,使用Promise异步回调。该接口需要在调用[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)使窗口加载页面内容后调用。 3966 3967**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3968 3969**系统能力:** SystemCapability.Window.SessionManager 3970 3971**参数:** 3972 3973| 参数名 | 类型 | 必填 | 说明 | 3974| --------- | ------ | -- | ---------------------------------------- | 3975| grayScale | number | 是 | 窗口灰阶。该参数为浮点数,取值范围为[0.0, 1.0]。0.0表示窗口图像无变化,1.0表示窗口图像完全转为灰度图像,0.0至1.0之间时效果呈线性变化。 | 3976 3977**返回值:** 3978 3979| 类型 | 说明 | 3980| ------------------- | ------------------------ | 3981| Promise<void> | 无返回结果的Promise对象。 | 3982 3983**错误码:** 3984 3985以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3986 3987| 错误码ID | 错误信息 | 3988| ------- | --------------------------------------------- | 3989| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3990| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3991| 1300002 | This window state is abnormal. | 3992| 1300003 | This window manager service works abnormally. | 3993 3994**示例:** 3995 3996```ts 3997import { BusinessError } from '@kit.BasicServicesKit'; 3998 3999windowClass?.setUIContent('pages/Index', (error: BusinessError) => { 4000 if (error.code) { 4001 console.error(`Failed to set the content. Cause code: ${error.code}`); 4002 return; 4003 } 4004 console.info('Succeeded in setting the content.'); 4005 let grayScale: number = 0.5; 4006 try { 4007 if (canIUse("SystemCapability.Window.SessionManager")) { 4008 let promise = windowClass?.setWindowGrayScale(grayScale); 4009 promise?.then(() => { 4010 console.info('Succeeded in setting the grayScale.'); 4011 }).catch((err: BusinessError) => { 4012 console.error(`Failed to set the grayScale. Cause code: ${err.code}, message: ${err.message}`); 4013 }); 4014 } 4015 } catch (exception) { 4016 console.error(`Failed to set the grayScale. Cause code: ${exception.code}, message: ${exception.message}`); 4017 } 4018}); 4019``` 4020 4021### on('windowTitleButtonRectChange')<sup>11+</sup> 4022 4023on(type: 'windowTitleButtonRectChange', callback: Callback<TitleButtonRect>): void 4024 4025开启窗口标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 4026 4027**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4028 4029**系统能力:** SystemCapability.Window.SessionManager 4030 4031**参数:** 4032 4033| 参数名 | 类型 | 必填 | 说明 | 4034| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 4035| type | string | 是 | 监听事件,固定为'windowTitleButtonRectChange',即标题栏上的最小化、最大化、关闭按钮矩形区域变化事件。 | 4036| callback | Callback<[TitleButtonRect](#titlebuttonrect11)> | 是 | 回调函数。返回当前标题栏上的最小化、最大化、关闭按钮矩形区域。 | 4037 4038**错误码:** 4039 4040以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4041 4042| 错误码ID | 错误信息 | 4043| -------- | ------------------------------ | 4044| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4045| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4046| 1300002 | This window state is abnormal. | 4047 4048**示例:** 4049 4050```ts 4051windowClass.setUIContent('pages/WindowPage').then(() => { 4052 try { 4053 windowClass?.on('windowTitleButtonRectChange', (titleButtonRect) => { 4054 console.info('Succeeded in enabling the listener for window title buttons area changes. Data: ' + JSON.stringify(titleButtonRect)); 4055 }); 4056 } catch (exception) { 4057 console.error(`Failed to enable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`); 4058 } 4059}) 4060``` 4061 4062### off('windowTitleButtonRectChange')<sup>11+</sup> 4063 4064off(type: 'windowTitleButtonRectChange', callback?: Callback<TitleButtonRect>): void 4065 4066关闭窗口标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 4067 4068**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4069 4070**系统能力:** SystemCapability.Window.SessionManager 4071 4072**参数:** 4073 4074| 参数名 | 类型 | 必填 | 说明 | 4075| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 4076| type | string | 是 | 监听事件,固定为'windowTitleButtonRectChange',即标题栏上的最小化、最大化、关闭按钮矩形区域变化事件。 | 4077| callback | Callback<[TitleButtonRect](#titlebuttonrect11)> | 否 | 回调函数。返回当前标题栏上的最小化、最大化、关闭按钮矩形区域。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听。 | 4078 4079**错误码:** 4080 4081以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4082 4083| 错误码ID | 错误信息 | 4084| -------- | ------------------------------ | 4085| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4086| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4087| 1300002 | This window state is abnormal. | 4088 4089**示例:** 4090 4091```ts 4092windowClass.setUIContent('pages/WindowPage').then(() => { 4093 const callback = (titleButtonRect: window.TitleButtonRect) => { 4094 // ... 4095 } 4096 try { 4097 // 通过on接口开启监听 4098 windowClass?.on('windowTitleButtonRectChange', callback); 4099 // 关闭指定callback的监听 4100 windowClass?.off('windowTitleButtonRectChange', callback); 4101 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4102 windowClass?.off('windowTitleButtonRectChange'); 4103 } catch (exception) { 4104 console.error(`Failed to disable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`); 4105 } 4106}) 4107``` 4108 4109### on('windowRectChange')<sup>12+</sup> 4110 4111on(type: 'windowRectChange', callback: Callback<RectChangeOptions>): void 4112 4113开启窗口矩形(窗口位置及窗口大小)变化的监听。 4114 4115**系统能力:** SystemCapability.Window.SessionManager 4116 4117**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4118 4119**参数:** 4120 4121| 参数名 | 类型 | 必填 | 说明 | 4122| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4123| type | string | 是 | 监听事件,固定为'windowRectChange',即窗口矩形变化事件。 | 4124| callback | Callback<[RectChangeOptions](#rectchangeoptions12)> | 是 | 回调函数。返回当前窗口矩形变化值及变化原因。 | 4125 4126**错误码:** 4127 4128以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4129 4130| 错误码ID | 错误信息 | 4131| ------- | -------------------------------------------- | 4132| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4133| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4134| 1300002 | This window state is abnormal. | 4135| 1300003 | This window manager service works abnormally. | 4136 4137**示例:** 4138 4139```ts 4140windowClass.on('windowRectChange', (data: window.RectChangeOptions) => { 4141 console.info('Succeeded window rect changes. Data: ' + JSON.stringify(data)); 4142}); 4143``` 4144 4145### off('windowRectChange')<sup>12+</sup> 4146 4147off(type: 'windowRectChange', callback?: Callback<RectChangeOptions>): void 4148 4149关闭窗口矩形(窗口位置及窗口大小)变化的监听。 4150 4151**系统能力:** SystemCapability.Window.SessionManager 4152 4153**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4154 4155**参数:** 4156 4157| 参数名 | 类型 | 必填 | 说明 | 4158| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 4159| type | string | 是 | 监听事件,固定为'windowRectChange',即窗口矩形变化事件。 | 4160| callback | Callback<[RectChangeOptions](#rectchangeoptions12)> | 否 | 回调函数。返回当前的窗口矩形及变化原因。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有窗口矩形变化的监听。 | 4161 4162**错误码:** 4163 4164以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4165 4166| 错误码ID | 错误信息 | 4167| ------- | -------------------------------------------- | 4168| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4169| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4170| 1300002 | This window state is abnormal. | 4171| 1300003 | This window manager service works abnormally. | 4172 4173**示例:** 4174 4175```ts 4176const callback = (rectChangeOptions: window.RectChangeOptions) => { 4177 // ... 4178} 4179windowClass.on('windowRectChange', callback); 4180windowClass.off('windowRectChange', callback); 4181// 如果通过on开启多个callback进行监听,同时关闭所有监听: 4182windowClass.off('windowRectChange'); 4183``` 4184 4185### on('subWindowClose')<sup>12+</sup> 4186 4187on(type: 'subWindowClose', callback: Callback<void>): void 4188 4189开启子窗口关闭事件的监听。此监听仅在点击系统提供的右上角关闭按钮关闭子窗时触发,其余关闭方式不触发回调。 4190 4191**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4192 4193**系统能力:** SystemCapability.Window.SessionManager 4194 4195**参数:** 4196 4197| 参数名 | 类型 | 必填 | 说明 | 4198| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4199| type | string | 是 | 监听事件,固定为'subWindowClose',即子窗口关闭事件。 | 4200| callback | Callback<void> | 是 | 回调函数。当点击子窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前子窗是否继续关闭,true表示不关闭子窗,false表示关闭子窗。 | 4201 4202**错误码:** 4203 4204以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4205 4206| 错误码ID | 错误信息 | 4207| ------- | -------------------------------------------- | 4208| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4209| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4210| 1300002 | This window state is abnormal. | 4211| 1300004 | Unauthorized operation. | 4212 4213**示例:** 4214 4215```ts 4216const callback = () => { 4217 // ... 4218 return true; 4219} 4220try { 4221 windowClass.on('subWindowClose', callback); 4222} catch (exception) { 4223 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4224} 4225``` 4226 4227### off('subWindowClose')<sup>12+</sup> 4228 4229off(type: 'subWindowClose', callback?: Callback<void>): void 4230 4231关闭子窗口关闭事件的监听。 4232 4233**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4234 4235**系统能力:** SystemCapability.Window.SessionManager 4236 4237**参数:** 4238 4239| 参数名 | 类型 | 必填 | 说明 | 4240| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 4241| type | string | 是 | 监听事件,固定为'subWindowClose',即子窗口关闭事件。 | 4242| callback | Callback<void> | 否 | 回调函数。当点击子窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前子窗是否继续关闭,true表示不关闭子窗,false表示关闭子窗。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有子窗口关闭的监听。 | 4243 4244**错误码:** 4245 4246以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4247 4248| 错误码ID | 错误信息 | 4249| ------- | -------------------------------------------- | 4250| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4251| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4252| 1300002 | This window state is abnormal. | 4253| 1300004 | Unauthorized operation. | 4254 4255**示例:** 4256 4257```ts 4258const callback = () => { 4259 // ... 4260 return true; 4261} 4262try { 4263 windowClass.on('subWindowClose', callback); 4264 windowClass.off('subWindowClose', callback); 4265 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4266 windowClass.off('subWindowClose'); 4267} catch (exception) { 4268 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4269} 4270``` 4271 4272### isWindowSupportWideGamut<sup>9+</sup> 4273 4274isWindowSupportWideGamut(callback: AsyncCallback<boolean>): void 4275 4276判断当前窗口是否支持广色域模式,使用callback异步回调。 4277 4278**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4279 4280**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4281 4282**参数:** 4283 4284| 参数名 | 类型 | 必填 | 说明 | 4285| -------- | ---------------------------- | -- | -------------------------------------------------------------------------------- | 4286| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 4287 4288**错误码:** 4289 4290以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 4291 4292| 错误码ID | 错误信息 | 4293| ------- | ------------------------------ | 4294| 1300002 | This window state is abnormal. | 4295 4296**示例:** 4297 4298```ts 4299import { BusinessError } from '@kit.BasicServicesKit'; 4300 4301windowClass.isWindowSupportWideGamut((err: BusinessError, data) => { 4302 const errCode: number = err.code; 4303 if (errCode) { 4304 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 4305 return; 4306 } 4307 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 4308}); 4309``` 4310 4311### isWindowSupportWideGamut<sup>9+</sup> 4312 4313isWindowSupportWideGamut(): Promise<boolean> 4314 4315判断当前窗口是否支持广色域模式,使用Promise异步回调。 4316 4317**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4318 4319**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4320 4321**返回值:** 4322 4323| 类型 | 说明 | 4324| ---------------------- | ------------------------------------------------------------------------------------ | 4325| Promise<boolean> | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 4326 4327**错误码:** 4328 4329以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 4330 4331| 错误码ID | 错误信息 | 4332| ------- | ------------------------------ | 4333| 1300002 | This window state is abnormal. | 4334 4335**示例:** 4336 4337```ts 4338import { BusinessError } from '@kit.BasicServicesKit'; 4339 4340let promise = windowClass.isWindowSupportWideGamut(); 4341promise.then((data) => { 4342 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 4343}).catch((err: BusinessError) => { 4344 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 4345}); 4346``` 4347 4348### setWindowColorSpace<sup>9+</sup> 4349 4350setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 4351 4352设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。 4353 4354**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4355 4356**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4357 4358**参数:** 4359 4360| 参数名 | 类型 | 必填 | 说明 | 4361| ---------- | ------------------------- | -- | ----------- | 4362| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 4363| callback | AsyncCallback<void> | 是 | 回调函数。 | 4364 4365**错误码:** 4366 4367以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4368 4369| 错误码ID | 错误信息 | 4370| ------- | ------------------------------ | 4371| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4372| 1300002 | This window state is abnormal. | 4373 4374**示例:** 4375 4376```ts 4377import { BusinessError } from '@kit.BasicServicesKit'; 4378 4379try { 4380 windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 4381 const errCode: number = err.code; 4382 if (errCode) { 4383 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 4384 return; 4385 } 4386 console.info('Succeeded in setting window colorspace.'); 4387 }); 4388} catch (exception) { 4389 console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`); 4390} 4391``` 4392 4393### setWindowColorSpace<sup>9+</sup> 4394 4395setWindowColorSpace(colorSpace:ColorSpace): Promise<void> 4396 4397设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。 4398 4399**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4400 4401**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4402 4403**参数:** 4404 4405| 参数名 | 类型 | 必填 | 说明 | 4406| ---------- | ------------------------- | -- | ------------- | 4407| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 4408 4409**返回值:** 4410 4411| 类型 | 说明 | 4412| ------------------- | ------------------------ | 4413| Promise<void> | 无返回结果的Promise对象。 | 4414 4415**错误码:** 4416 4417以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4418 4419| 错误码ID | 错误信息 | 4420| ------- | ------------------------------ | 4421| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4422| 1300002 | This window state is abnormal. | 4423 4424**示例:** 4425 4426```ts 4427import { BusinessError } from '@kit.BasicServicesKit'; 4428 4429try { 4430 let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT); 4431 promise.then(() => { 4432 console.info('Succeeded in setting window colorspace.'); 4433 }).catch((err: BusinessError) => { 4434 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 4435 }); 4436} catch (exception) { 4437 console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`); 4438} 4439``` 4440 4441### getWindowColorSpace<sup>9+</sup> 4442 4443getWindowColorSpace(): ColorSpace 4444 4445获取当前窗口色域模式。 4446 4447**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4448 4449**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4450 4451**返回值:** 4452 4453| 类型 | 说明 | 4454| ------------------------- | ------------- | 4455| [ColorSpace](#colorspace8) | 当前色域模式。 | 4456 4457**错误码:** 4458 4459以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 4460 4461| 错误码ID | 错误信息 | 4462| ------- | ------------------------------ | 4463| 1300002 | This window state is abnormal. | 4464 4465**示例:** 4466 4467```ts 4468let colorSpace = windowClass.getWindowColorSpace(); 4469``` 4470 4471### setWindowBackgroundColor<sup>9+</sup> 4472 4473setWindowBackgroundColor(color: string): void 4474 4475设置窗口的背景色。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 4476 4477**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4478 4479**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4480 4481**参数:** 4482 4483| 参数名 | 类型 | 必填 | 说明 | 4484| ----- | ------ | -- | ----------------------------------------------------------------------- | 4485| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 | 4486 4487**错误码:** 4488 4489以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4490 4491| 错误码ID | 错误信息 | 4492| ------- | ------------------------------ | 4493| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4494| 1300002 | This window state is abnormal. | 4495 4496**示例:** 4497 4498```ts 4499import { BusinessError } from '@kit.BasicServicesKit'; 4500 4501let storage: LocalStorage = new LocalStorage(); 4502storage.setOrCreate('storageSimpleProp', 121); 4503windowClass.loadContent("pages/page2", storage, (err: BusinessError) => { 4504 let errCode: number = err.code; 4505 if (errCode) { 4506 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 4507 return; 4508 } 4509 console.info('Succeeded in loading the content.'); 4510 let color: string = '#00ff33'; 4511 try { 4512 windowClass?.setWindowBackgroundColor(color); 4513 } catch (exception) { 4514 console.error(`Failed to set the background color. Cause code: ${exception.code}, message: ${exception.message}`); 4515 }; 4516}); 4517``` 4518 4519### setWindowBrightness<sup>9+</sup> 4520 4521setWindowBrightness(brightness: number, callback: AsyncCallback<void>): void 4522 4523允许应用主窗口设置屏幕亮度值,使用callback异步回调。 4524 4525当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 4526 4527**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4528 4529**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4530 4531**参数:** 4532 4533| 参数名 | 类型 | 必填 | 说明 | 4534| ---------- | ------------------------- | -- |-------------------------------------------| 4535| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 4536| callback | AsyncCallback<void> | 是 | 回调函数。 | 4537 4538**错误码:** 4539 4540以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4541 4542| 错误码ID | 错误信息 | 4543| ------- | -------------------------------------------- | 4544| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4545| 1300002 | This window state is abnormal. | 4546| 1300003 | This window manager service works abnormally. | 4547 4548**示例:** 4549 4550```ts 4551// EntryAbility.ets 4552import { UIAbility } from '@kit.AbilityKit'; 4553import { BusinessError } from '@kit.BasicServicesKit'; 4554 4555export default class EntryAbility extends UIAbility { 4556 // ... 4557 onWindowStageCreate(windowStage: window.WindowStage): void { 4558 console.info('onWindowStageCreate'); 4559 let windowClass: window.Window | undefined = undefined; 4560 windowStage.getMainWindow((err: BusinessError, data) => { 4561 const errCode: number = err.code; 4562 if (errCode) { 4563 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 4564 return; 4565 } 4566 windowClass = data; 4567 let brightness: number = 1; 4568 try { 4569 windowClass.setWindowBrightness(brightness, (err: BusinessError) => { 4570 const errCode: number = err.code; 4571 if (errCode) { 4572 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 4573 return; 4574 } 4575 console.info('Succeeded in setting the brightness.'); 4576 }); 4577 } catch (exception) { 4578 console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`); 4579 } 4580 }); 4581 } 4582} 4583``` 4584 4585### setWindowBrightness<sup>9+</sup> 4586 4587setWindowBrightness(brightness: number): Promise<void> 4588 4589允许应用主窗口设置屏幕亮度值,使用Promise异步回调。 4590 4591当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 4592 4593**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4594 4595**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4596 4597**参数:** 4598 4599| 参数名 | 类型 | 必填 | 说明 | 4600| ---------- | ------ | -- |----------------------------------------| 4601| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 4602 4603**返回值:** 4604 4605| 类型 | 说明 | 4606| ------------------- | ------------------------ | 4607| Promise<void> | 无返回结果的Promise对象。 | 4608 4609**错误码:** 4610 4611以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4612 4613| 错误码ID | 错误信息 | 4614| ------- | -------------------------------------------- | 4615| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4616| 1300002 | This window state is abnormal. | 4617| 1300003 | This window manager service works abnormally. | 4618 4619**示例:** 4620 4621```ts 4622// EntryAbility.ets 4623import { UIAbility } from '@kit.AbilityKit'; 4624import { BusinessError } from '@kit.BasicServicesKit'; 4625 4626export default class EntryAbility extends UIAbility { 4627 // ... 4628 onWindowStageCreate(windowStage: window.WindowStage): void { 4629 console.info('onWindowStageCreate'); 4630 let windowClass: window.Window | undefined = undefined; 4631 windowStage.getMainWindow((err: BusinessError, data) => { 4632 const errCode: number = err.code; 4633 if (errCode) { 4634 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 4635 return; 4636 } 4637 windowClass = data; 4638 let brightness: number = 1; 4639 try { 4640 let promise = windowClass.setWindowBrightness(brightness); 4641 promise.then(() => { 4642 console.info('Succeeded in setting the brightness.'); 4643 }).catch((err: BusinessError) => { 4644 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 4645 }); 4646 } catch (exception) { 4647 console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`); 4648 } 4649 }); 4650 } 4651} 4652``` 4653 4654### setWindowFocusable<sup>9+</sup> 4655 4656setWindowFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 4657 4658设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用callback异步回调。 4659 4660**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4661 4662**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4663 4664**参数:** 4665 4666| 参数名 | 类型 | 必填 | 说明 | 4667| ----------- | ------------------------- | -- | ------------------------------------------------------- | 4668| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 4669| callback | AsyncCallback<void> | 是 | 回调函数。 | 4670 4671**错误码:** 4672 4673以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4674 4675| 错误码ID | 错误信息 | 4676| ------- | -------------------------------------------- | 4677| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4678| 1300002 | This window state is abnormal. | 4679| 1300003 | This window manager service works abnormally. | 4680 4681**示例:** 4682 4683```ts 4684import { BusinessError } from '@kit.BasicServicesKit'; 4685 4686let isFocusable: boolean = true; 4687try { 4688 windowClass.setWindowFocusable(isFocusable, (err: BusinessError) => { 4689 const errCode: number = err.code; 4690 if (errCode) { 4691 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 4692 return; 4693 } 4694 console.info('Succeeded in setting the window to be focusable.'); 4695 }); 4696} catch (exception) { 4697 console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`); 4698} 4699``` 4700 4701### setWindowFocusable<sup>9+</sup> 4702 4703setWindowFocusable(isFocusable: boolean): Promise<void> 4704 4705设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用Promise异步回调。 4706 4707**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4708 4709**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4710 4711**参数:** 4712 4713| 参数名 | 类型 | 必填 | 说明 | 4714| ----------- | ------- | -- | -------------------------------------------------------- | 4715| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 4716 4717**返回值:** 4718 4719| 类型 | 说明 | 4720| ------------------- | ------------------------ | 4721| Promise<void> | 无返回结果的Promise对象。 | 4722 4723**错误码:** 4724 4725以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4726 4727| 错误码ID | 错误信息 | 4728| ------- | -------------------------------------------- | 4729| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4730| 1300002 | This window state is abnormal. | 4731| 1300003 | This window manager service works abnormally. | 4732 4733**示例:** 4734 4735```ts 4736import { BusinessError } from '@kit.BasicServicesKit'; 4737 4738let isFocusable: boolean = true; 4739try { 4740 let promise = windowClass.setWindowFocusable(isFocusable); 4741 promise.then(() => { 4742 console.info('Succeeded in setting the window to be focusable.'); 4743 }).catch((err: BusinessError) => { 4744 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 4745 }); 4746} catch (exception) { 4747 console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`); 4748} 4749``` 4750 4751### setWindowKeepScreenOn<sup>9+</sup> 4752 4753setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 4754 4755设置屏幕是否为常亮状态,使用callback异步回调。 4756 4757规范使用该接口:仅在必要场景(导航、视频播放、绘画、游戏等场景)下,设置该属性为true;退出上述场景后,应当重置该属性为false;其他场景(无屏幕互动、音频播放等)下,不使用该接口;系统检测到非规范使用该接口时,可能会恢复自动灭屏功能。 4758 4759**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4760 4761**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4762 4763**参数:** 4764 4765| 参数名 | 类型 | 必填 | 说明 | 4766| -------------- | ------------------------- | -- | ---------------------------------------------------- | 4767| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 4768| callback | AsyncCallback<void> | 是 | 回调函数。 | 4769 4770**错误码:** 4771 4772以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4773 4774| 错误码ID | 错误信息 | 4775| ------- | -------------------------------------------- | 4776| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4777| 1300002 | This window state is abnormal. | 4778| 1300003 | This window manager service works abnormally. | 4779 4780**示例:** 4781 4782```ts 4783import { BusinessError } from '@kit.BasicServicesKit'; 4784 4785let isKeepScreenOn: boolean = true; 4786try { 4787 windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 4788 const errCode: number = err.code; 4789 if (errCode) { 4790 console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 4791 return; 4792 } 4793 console.info('Succeeded in setting the screen to be always on.'); 4794 }); 4795} catch (exception) { 4796 console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`); 4797} 4798``` 4799 4800### setWindowKeepScreenOn<sup>9+</sup> 4801 4802setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 4803 4804设置屏幕是否为常亮状态,使用Promise异步回调。 4805 4806规范使用该接口:仅在必要场景(导航、视频播放、绘画、游戏等场景)下,设置该属性为true;退出上述场景后,应当重置该属性为false;其他场景(无屏幕互动、音频播放等)下,不使用该接口;系统检测到非规范使用该接口时,可能会恢复自动灭屏功能。 4807 4808**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4809 4810**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4811 4812**参数:** 4813 4814| 参数名 | 类型 | 必填 | 说明 | 4815| -------------- | ------- | -- | --------------------------------------------------- | 4816| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 4817 4818**返回值:** 4819 4820| 类型 | 说明 | 4821| ------------------- | ------------------------ | 4822| Promise<void> | 无返回结果的Promise对象。 | 4823 4824**错误码:** 4825 4826以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4827 4828| 错误码ID | 错误信息 | 4829| ------- | -------------------------------------------- | 4830| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4831| 1300002 | This window state is abnormal. | 4832| 1300003 | This window manager service works abnormally. | 4833 4834**示例:** 4835 4836```ts 4837import { BusinessError } from '@kit.BasicServicesKit'; 4838 4839let isKeepScreenOn: boolean = true; 4840try { 4841 let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn); 4842 promise.then(() => { 4843 console.info('Succeeded in setting the screen to be always on.'); 4844 }).catch((err: BusinessError) => { 4845 console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 4846 }); 4847} catch (exception) { 4848 console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`); 4849} 4850``` 4851 4852### setWindowPrivacyMode<sup>9+</sup> 4853 4854setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 4855 4856设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 4857 4858**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4859 4860**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4861 4862**需要权限:** ohos.permission.PRIVACY_WINDOW 4863 4864**参数:** 4865 4866| 参数名 | 类型 | 必填 | 说明 | 4867| ------------- | ------------------------- | -- | ------------------------------------------------------ | 4868| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 4869| callback | AsyncCallback<void> | 是 | 回调函数。 | 4870 4871**错误码:** 4872 4873以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4874 4875| 错误码ID | 错误信息 | 4876| ------- | ------------------------------ | 4877| 201 | Permission verification failed. The application does not have the permission required to call the API. | 4878| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4879| 1300002 | This window state is abnormal. | 4880 4881**示例:** 4882 4883```ts 4884import { BusinessError } from '@kit.BasicServicesKit'; 4885 4886let isPrivacyMode: boolean = true; 4887try { 4888 windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => { 4889 const errCode: number = err.code; 4890 if (errCode) { 4891 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 4892 return; 4893 } 4894 console.info('Succeeded in setting the window to privacy mode.'); 4895 }); 4896} catch (exception) { 4897 console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`); 4898} 4899``` 4900 4901### setWindowPrivacyMode<sup>9+</sup> 4902 4903setWindowPrivacyMode(isPrivacyMode: boolean): Promise<void> 4904 4905设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 4906 4907**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4908 4909**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4910 4911**需要权限:** ohos.permission.PRIVACY_WINDOW 4912 4913**参数:** 4914 4915| 参数名 | 类型 | 必填 | 说明 | 4916| ------------- | ------- | -- | ----------------------------------------------------- | 4917| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 4918 4919**返回值:** 4920 4921| 类型 | 说明 | 4922| ------------------- | ------------------------ | 4923| Promise<void> | 无返回结果的Promise对象。 | 4924 4925**错误码:** 4926 4927以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4928 4929| 错误码ID | 错误信息 | 4930| ------- | ------------------------------ | 4931| 201 | Permission verification failed. The application does not have the permission required to call the API. | 4932| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4933| 1300002 | This window state is abnormal. | 4934 4935**示例:** 4936 4937```ts 4938import { BusinessError } from '@kit.BasicServicesKit'; 4939 4940let isPrivacyMode: boolean = true; 4941try { 4942 let promise = windowClass.setWindowPrivacyMode(isPrivacyMode); 4943 promise.then(() => { 4944 console.info('Succeeded in setting the window to privacy mode.'); 4945 }).catch((err: BusinessError) => { 4946 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 4947 }); 4948} catch (exception) { 4949 console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`); 4950} 4951``` 4952 4953### setWindowTouchable<sup>9+</sup> 4954 4955setWindowTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 4956 4957设置窗口是否为可触状态,使用callback异步回调。 4958 4959**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4960 4961**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4962 4963**参数:** 4964 4965| 参数名 | 类型 | 必填 | 说明 | 4966| ----------- | ------------------------- | -- | ----------------------------------------------- | 4967| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 4968| callback | AsyncCallback<void> | 是 | 回调函数。 | 4969 4970**错误码:** 4971 4972以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4973 4974| 错误码ID | 错误信息 | 4975| ------- | -------------------------------------------- | 4976| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4977| 1300002 | This window state is abnormal. | 4978| 1300003 | This window manager service works abnormally. | 4979 4980**示例:** 4981 4982```ts 4983import { BusinessError } from '@kit.BasicServicesKit'; 4984 4985let isTouchable = true; 4986try { 4987 windowClass.setWindowTouchable(isTouchable, (err: BusinessError) => { 4988 const errCode: number = err.code; 4989 if (errCode) { 4990 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 4991 return; 4992 } 4993 console.info('Succeeded in setting the window to be touchable.'); 4994 }); 4995} catch (exception) { 4996 console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 4997} 4998``` 4999 5000### setWindowTouchable<sup>9+</sup> 5001 5002setWindowTouchable(isTouchable: boolean): Promise<void> 5003 5004设置窗口是否为可触状态,使用Promise异步回调。 5005 5006**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5007 5008**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5009 5010**参数:** 5011 5012| 参数名 | 类型 | 必填 | 说明 | 5013| ----------- | ------- | -- | ----------------------------------------------- | 5014| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 5015 5016**返回值:** 5017 5018| 类型 | 说明 | 5019| ------------------- | ------------------------- | 5020| Promise<void> | 无返回结果的Promise对象。 | 5021 5022**错误码:** 5023 5024以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5025 5026| 错误码ID | 错误信息 | 5027| ------- | -------------------------------------------- | 5028| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5029| 1300002 | This window state is abnormal. | 5030| 1300003 | This window manager service works abnormally. | 5031 5032**示例:** 5033 5034```ts 5035import { BusinessError } from '@kit.BasicServicesKit'; 5036 5037let isTouchable: boolean = true; 5038try { 5039 let promise = windowClass.setWindowTouchable(isTouchable); 5040 promise.then(() => { 5041 console.info('Succeeded in setting the window to be touchable.'); 5042 }).catch((err: BusinessError) => { 5043 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 5044 }); 5045} catch (exception) { 5046 console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 5047} 5048``` 5049 5050### snapshot<sup>9+</sup> 5051 5052snapshot(callback: AsyncCallback<image.PixelMap>): void 5053 5054获取窗口截图,使用callback异步回调。 5055 5056**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5057 5058**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5059 5060**参数:** 5061 5062| 参数名 | 类型 | 必填 | 说明 | 5063| ----------- | ------------------------- | ---- | -------------------- | 5064| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | 是 | 回调函数。 | 5065 5066**错误码:** 5067 5068以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 5069 5070| 错误码ID | 错误信息 | 5071| ------- | ------------------------------ | 5072| 1300002 | This window state is abnormal. | 5073 5074**示例:** 5075 5076```ts 5077import { BusinessError } from '@kit.BasicServicesKit'; 5078import { image } from '@kit.ImageKit'; 5079 5080windowClass.snapshot((err: BusinessError, pixelMap: image.PixelMap) => { 5081 const errCode: number = err.code; 5082 if (errCode) { 5083 console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`); 5084 return; 5085 } 5086 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 5087 pixelMap.release(); // PixelMap使用完后及时释放内存 5088}); 5089``` 5090 5091### snapshot<sup>9+</sup> 5092 5093snapshot(): Promise<image.PixelMap> 5094 5095获取窗口截图,使用Promise异步回调。 5096 5097**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5098 5099**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5100 5101**返回值:** 5102 5103| 类型 | 说明 | 5104| ------------------- | ------------------------- | 5105| Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise对象。返回当前窗口截图。 | 5106 5107**错误码:** 5108 5109以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 5110 5111| 错误码ID | 错误信息 | 5112| ------- | ------------------------------ | 5113| 1300002 | This window state is abnormal. | 5114 5115**示例:** 5116 5117```ts 5118import { BusinessError } from '@kit.BasicServicesKit'; 5119import { image } from '@kit.ImageKit'; 5120 5121let promise = windowClass.snapshot(); 5122promise.then((pixelMap: image.PixelMap) => { 5123 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 5124 pixelMap.release(); // PixelMap使用完后及时释放内存 5125}).catch((err: BusinessError) => { 5126 console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`); 5127}); 5128``` 5129 5130### setAspectRatio<sup>10+</sup> 5131 5132setAspectRatio(ratio: number): Promise<void> 5133 5134设置窗口内容布局的比例,使用Promise异步回调。 5135 5136通过其他接口如[resize](#resize9)、[resizeAsync](#resizeasync12)设置窗口大小时,不受ratio约束。 5137 5138仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。 5139 5140**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5141 5142**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5143 5144**参数:** 5145 5146| 参数名 | 类型 | 必填 | 说明 | 5147| ------------------ | ------- | ---- |-------------------------------------------| 5148| ratio | number | 是 | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,受窗口最大最小尺寸限制,比例值下限为最小宽度/最大高度,上限为最大宽度/最小高度。窗口最大最小尺寸由[WindowLimits](#windowlimits11)和系统限制的交集决定,系统限制优先级高于[WindowLimits](#windowlimits11)。ratio的有效范围会随[WindowLimits](#windowlimits11)变化而变化。如果先设置了[WindowLimits](#windowlimits11),后设置的ratio与其冲突,会返回错误码;如果先设置了ratio,后设置的[WindowLimits](#windowlimits11)与其冲突,窗口的宽高比可能会不跟随设置的宽高比(ratio)。 | 5149 5150**返回值:** 5151 5152| 类型 | 说明 | 5153| ------------------- | ------------------------- | 5154| Promise<void> | 无返回结果的Promise对象。 | 5155 5156**错误码:** 5157 5158以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5159 5160| 错误码ID | 错误信息 | 5161| ------- | -------------------------------------------- | 5162| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5163| 1300002 | This window state is abnormal. | 5164| 1300004 | Unauthorized operation. | 5165 5166**示例:** 5167<!--code_no_check--> 5168```ts 5169// EntryAbility.ets 5170import { UIAbility } from '@kit.AbilityKit'; 5171import { BusinessError } from '@kit.BasicServicesKit'; 5172 5173export default class EntryAbility extends UIAbility { 5174 5175 // ... 5176 onWindowStageCreate(windowStage: window.WindowStage) { 5177 console.info('onWindowStageCreate'); 5178 let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 5179 if (!windowClass) { 5180 console.info('windowClass is null'); 5181 } 5182 try { 5183 let ratio = 1.0; 5184 let promise = windowClass.setAspectRatio(ratio); 5185 promise.then(() => { 5186 console.info('Succeeded in setting aspect ratio of window.'); 5187 }).catch((err: BusinessError) => { 5188 console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 5189 }); 5190 } catch (exception) { 5191 console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 5192 } 5193 } 5194} 5195``` 5196 5197### setAspectRatio<sup>10+</sup> 5198 5199setAspectRatio(ratio: number, callback: AsyncCallback<void>): void 5200 5201设置窗口内容布局的比例,使用callback异步回调。 5202 5203通过其他接口如[resize](#resize9)、[resizeAsync](#resizeasync12)设置窗口大小时,不受ratio约束。 5204 5205仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。 5206 5207**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5208 5209**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5210 5211**参数:** 5212 5213| 参数名 | 类型 | 必填 | 说明 | 5214| ------------------ | ------- | ---- |--------------------------------------------| 5215| ratio | number | 是 | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,受窗口最大最小尺寸限制,比例值下限为最小宽度/最大高度,上限为最大宽度/最小高度。窗口最大最小尺寸由[WindowLimits](#windowlimits11)和系统限制的交集决定,系统限制优先级高于[WindowLimits](#windowlimits11)。ratio的有效范围会随[WindowLimits](#windowlimits11)变化而变化。如果先设置了[WindowLimits](#windowlimits11),后设置的ratio与其冲突,会返回错误码;如果先设置了ratio,后设置的[WindowLimits](#windowlimits11)与其冲突,窗口的宽高比可能会不跟随设置的宽高比(ratio)。 | 5216| callback | AsyncCallback<void> | 是 | 回调函数。 | 5217 5218**错误码:** 5219 5220以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5221 5222| 错误码ID | 错误信息 | 5223| ------- | -------------------------------------------- | 5224| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5225| 1300002 | This window state is abnormal. | 5226| 1300004 | Unauthorized operation. | 5227 5228**示例:** 5229<!--code_no_check--> 5230```ts 5231// EntryAbility.ets 5232import { UIAbility } from '@kit.AbilityKit'; 5233import { BusinessError } from '@kit.BasicServicesKit'; 5234 5235export default class EntryAbility extends UIAbility { 5236 5237 // ... 5238 onWindowStageCreate(windowStage: window.WindowStage) { 5239 console.info('onWindowStageCreate'); 5240 let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 5241 if (!windowClass) { 5242 console.info('Failed to load the content. Cause: windowClass is null'); 5243 } 5244 try { 5245 let ratio = 1.0; 5246 windowClass.setAspectRatio(ratio, (err: BusinessError) => { 5247 const errCode: number = err.code; 5248 if (errCode) { 5249 console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 5250 return; 5251 } 5252 console.info('Succeeded in setting the aspect ratio of window.'); 5253 }); 5254 } catch (exception) { 5255 console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 5256 } 5257 } 5258} 5259 5260``` 5261 5262### resetAspectRatio<sup>10+</sup> 5263 5264resetAspectRatio(): Promise<void> 5265 5266取消设置窗口内容布局的比例,使用Promise异步回调。 5267 5268仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,调用后将清除持久化储存的比例信息。 5269 5270**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5271 5272**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5273 5274**返回值:** 5275 5276| 类型 | 说明 | 5277| ------------------- | ------------------------- | 5278| Promise<void> | 无返回结果的Promise对象。 | 5279 5280**错误码:** 5281 5282以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 5283 5284| 错误码ID | 错误信息 | 5285| ------- | -------------------------------------------- | 5286| 1300002 | This window state is abnormal. | 5287| 1300004 | Unauthorized operation. | 5288 5289**示例:** 5290<!--code_no_check--> 5291```ts 5292// EntryAbility.ets 5293import { UIAbility } from '@kit.AbilityKit'; 5294import { BusinessError } from '@kit.BasicServicesKit'; 5295 5296export default class EntryAbility extends UIAbility { 5297 5298 // ... 5299 onWindowStageCreate(windowStage: window.WindowStage) { 5300 console.info('onWindowStageCreate'); 5301 let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 5302 if (!windowClass) { 5303 console.info('Failed to load the content. Cause: windowClass is null'); 5304 } 5305 try { 5306 let promise = windowClass.resetAspectRatio(); 5307 promise.then(() => { 5308 console.info('Succeeded in resetting aspect ratio of window.'); 5309 }).catch((err: BusinessError) => { 5310 console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 5311 }); 5312 } catch (exception) { 5313 console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 5314 } 5315 } 5316} 5317``` 5318 5319### resetAspectRatio<sup>10+</sup> 5320 5321resetAspectRatio(callback: AsyncCallback<void>): void 5322 5323取消设置窗口内容布局的比例,使用callback异步回调。 5324 5325仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,调用后将清除持久化储存的比例信息。 5326 5327**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5328 5329**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5330 5331**参数:** 5332 5333| 参数名 | 类型 | 必填 | 说明 | 5334| ------------------ | ------- | ---- | ------------------------------------------------------------ | 5335| callback | AsyncCallback<void> | 是 | 回调函数。 | 5336 5337**错误码:** 5338 5339以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 5340 5341| 错误码ID | 错误信息 | 5342| ------- | -------------------------------------------- | 5343| 1300002 | This window state is abnormal. | 5344| 1300004 | Unauthorized operation. | 5345 5346**示例:** 5347<!--code_no_check--> 5348```ts 5349// EntryAbility.ets 5350import { UIAbility } from '@kit.AbilityKit'; 5351import { BusinessError } from '@kit.BasicServicesKit'; 5352 5353export default class EntryAbility extends UIAbility { 5354 5355 // ... 5356 onWindowStageCreate(windowStage: window.WindowStage) { 5357 console.info('onWindowStageCreate'); 5358 let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 5359 if (!windowClass) { 5360 console.info('Failed to load the content. Cause: windowClass is null'); 5361 } 5362 try { 5363 windowClass.resetAspectRatio((err: BusinessError) => { 5364 const errCode: number = err.code; 5365 if (errCode) { 5366 console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 5367 return; 5368 } 5369 console.info('Succeeded in resetting aspect ratio of window.'); 5370 }); 5371 } catch (exception) { 5372 console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 5373 } 5374 } 5375} 5376``` 5377 5378### minimize<sup>11+</sup> 5379 5380minimize(callback: AsyncCallback<void>): void 5381 5382此接口根据调用对象不同,实现不同的两个功能: 5383 5384当调用对象为主窗口时,实现最小化功能,可在Dock栏中还原; 5385 5386当调用对象为子窗口时,实现隐藏功能,不可在Dock栏中还原。 5387 5388使用callback异步回调。 5389 5390**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5391 5392**系统能力:** SystemCapability.Window.SessionManager 5393 5394**参数:** 5395 5396| 参数名 | 类型 | 必填 | 说明 | 5397| -------- | ------------------------- | ---- | ---------- | 5398| callback | AsyncCallback<void> | 是 | 回调函数。 | 5399 5400**错误码:** 5401 5402以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5403 5404| 错误码ID | 错误信息 | 5405| ------- | ------------------------------ | 5406| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5407| 1300002 | This window state is abnormal. | 5408| 1300003 | This window manager service works abnormally. | 5409 5410**示例:** 5411 5412```ts 5413import { BusinessError } from '@kit.BasicServicesKit'; 5414 5415windowClass.minimize((err: BusinessError) => { 5416 const errCode: number = err.code; 5417 if (errCode) { 5418 console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`); 5419 return; 5420 } 5421 console.info('Succeeded in minimizing the window.'); 5422}); 5423``` 5424 5425### minimize<sup>11+</sup> 5426 5427minimize(): Promise<void> 5428 5429此接口根据调用对象不同,实现不同的两个功能: 5430 5431当调用对象为主窗口时,实现最小化功能,可在Dock栏中还原; 5432 5433当调用对象为子窗口时,实现隐藏功能,不可在Dock栏中还原。 5434 5435使用Promise异步回调。 5436 5437**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5438 5439**系统能力:** SystemCapability.Window.SessionManager 5440 5441**返回值:** 5442 5443| 类型 | 说明 | 5444| ------------------- | ------------------------- | 5445| Promise<void> | 无返回结果的Promise对象。 | 5446 5447**错误码:** 5448 5449以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5450 5451| 错误码ID | 错误信息 | 5452| ------- | ------------------------------ | 5453| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5454| 1300002 | This window state is abnormal. | 5455| 1300003 | This window manager service works abnormally. | 5456 5457**示例:** 5458 5459```ts 5460import { BusinessError } from '@kit.BasicServicesKit'; 5461 5462let promise = windowClass.minimize(); 5463promise.then(() => { 5464 console.info('Succeeded in minimizing the window.'); 5465}).catch((err: BusinessError) => { 5466 console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`); 5467}); 5468``` 5469 5470### maximize<sup>12+</sup> 5471maximize(presentation?: MaximizePresentation): Promise<void> 5472 5473主窗口调用,实现最大化功能,使用Promise异步回调。 5474 5475<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 5476 5477**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5478 5479**系统能力:** SystemCapability.Window.SessionManager 5480 5481**参数:** 5482 5483| 参数名 | 类型 | 必填 | 说明 | 5484| ----- | ---------------------------- | -- | --------------------------------- | 5485| presentation | [MaximizePresentation](#maximizepresentation12) | 否 | 主窗口最大化时候的布局枚举。默认值window.MaximizePresentation.ENTER_IMMERSIVE,即默认最大化时进入沉浸式布局。 | 5486 5487**返回值:** 5488 5489| 类型 | 说明 | 5490| ------------------- | ------------------------- | 5491| Promise<void> | 无返回结果的Promise对象。 | 5492 5493**错误码:** 5494 5495以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5496 5497| 错误码ID | 错误信息 | 5498| ------- | ------------------------------ | 5499| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5500| 1300002 | This window state is abnormal. | 5501| 1300003 | This window manager service works abnormally. | 5502| 1300004 | Unauthorized operation. | 5503| 1300005 | This window stage is abnormal. | 5504 5505**示例:** 5506 5507```ts 5508// EntryAbility.ets 5509import { UIAbility } from '@kit.AbilityKit'; 5510import { BusinessError } from '@kit.BasicServicesKit'; 5511export default class EntryAbility extends UIAbility { 5512 // ... 5513 5514 onWindowStageCreate(windowStage: window.WindowStage) { 5515 console.info('onWindowStageCreate'); 5516 let windowClass: window.Window | undefined = undefined; 5517 windowStage.getMainWindow((err: BusinessError, data) => { 5518 const errCode: number = err.code; 5519 if (errCode) { 5520 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 5521 return; 5522 } 5523 windowClass = data; 5524 let promise = windowClass.maximize(); 5525 // let promise = windowClass.maximize(window.MaximizePresentation.ENTER_IMMERSIVE); 5526 promise.then(() => { 5527 console.info('Succeeded in maximizing the window.'); 5528 }).catch((err: BusinessError) => { 5529 console.error(`Failed to maximize the window. Cause code: ${err.code}, message: ${err.message}`); 5530 }); 5531 }); 5532 } 5533}; 5534``` 5535 5536### setResizeByDragEnabled<sup>14+</sup> 5537setResizeByDragEnabled(enable: boolean, callback: AsyncCallback<void>): void 5538 5539禁止/使能通过拖拽方式缩放主窗口或启用装饰的子窗口的功能。使用callback异步回调。 5540 5541**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 5542 5543**系统能力:** SystemCapability.Window.SessionManager 5544 5545**参数:** 5546 5547| 参数名 | 类型 | 必填 | 说明 | 5548| ----- | ---------------------------- | -- | --------------------------------- | 5549| enable | boolean | 是 | 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。 | 5550| callback | AsyncCallback<void> | 是 | 回调函数。 | 5551 5552**错误码:** 5553 5554以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5555 5556| 错误码ID | 错误信息 | 5557| ------- | ------------------------------ | 5558| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5559| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5560| 1300002 | This window state is abnormal. | 5561| 1300003 | This window manager service works abnormally. | 5562 5563**示例:** 5564 5565```ts 5566import { BusinessError } from '@kit.BasicServicesKit'; 5567 5568let enabled = false; 5569windowClass.setResizeByDragEnabled(enabled, (err) => { 5570 if (err.code) { 5571 console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${err.code}, message: ${err.message}`); 5572 return; 5573 } 5574 console.info('Succeeded in setting the function of disabling the resize by drag window.'); 5575}); 5576``` 5577 5578### setResizeByDragEnabled<sup>14+</sup> 5579setResizeByDragEnabled(enable: boolean): Promise<void> 5580 5581禁止/使能通过拖拽方式缩放主窗口或启用装饰的子窗口的功能。使用Promise异步回调。 5582 5583**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 5584 5585**系统能力:** SystemCapability.Window.SessionManager 5586 5587**参数:** 5588 5589| 参数名 | 类型 | 必填 | 说明 | 5590| ----- | ---------------------------- | -- | --------------------------------- | 5591| enable | boolean | 是 | 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。 | 5592 5593**返回值:** 5594 5595| 类型 | 说明 | 5596| ------------------- | ------------------------ | 5597| Promise<void> | 无返回结果的Promise对象。 | 5598 5599**错误码:** 5600 5601以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5602 5603| 错误码ID | 错误信息 | 5604| ------- | ------------------------------ | 5605| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5606| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5607| 1300002 | This window state is abnormal. | 5608| 1300003 | This window manager service works abnormally. | 5609 5610**示例:** 5611 5612```ts 5613import { BusinessError } from '@kit.BasicServicesKit'; 5614 5615let enabled = false; 5616let promise = windowClass.setResizeByDragEnabled(enabled); 5617promise.then(() => { 5618 console.info('Succeeded in setting the function of disabling the resize by drag window.'); 5619}).catch((err: BusinessError) => { 5620 console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${err.code}, message: ${err.message}`); 5621}); 5622``` 5623 5624### recover<sup>11+</sup> 5625 5626recover(): Promise<void> 5627 5628将主窗口从全屏、最大化、分屏模式下还原为浮动窗口,并恢复到进入该模式之前的大小和位置,已经是浮动窗口模式不可再还原。使用Promise异步回调。此接口仅在多窗层叠布局效果下生效,仅2in1设备可用。 5629 5630**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5631 5632**系统能力:** SystemCapability.Window.SessionManager 5633 5634**返回值:** 5635 5636| 类型 | 说明 | 5637| ------------------- | ------------------------- | 5638| Promise<void> | 无返回结果的Promise对象。 | 5639 5640**错误码:** 5641 5642以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5643 5644| 错误码ID | 错误信息 | 5645| ------- | ------------------------------ | 5646| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5647| 1300001 | Repeated operation. | 5648| 1300002 | This window state is abnormal. | 5649 5650**示例:** 5651 5652```ts 5653// EntryAbility.ets 5654import { UIAbility } from '@kit.AbilityKit'; 5655import { BusinessError } from '@kit.BasicServicesKit'; 5656 5657export default class EntryAbility extends UIAbility { 5658 // ... 5659 onWindowStageCreate(windowStage: window.WindowStage): void { 5660 console.info('onWindowStageCreate'); 5661 let windowClass: window.Window | undefined = undefined; 5662 windowStage.getMainWindow((err: BusinessError, data) => { 5663 const errCode: number = err.code; 5664 if (errCode) { 5665 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 5666 return; 5667 } 5668 windowClass = data; 5669 let promise = windowClass.recover(); 5670 promise.then(() => { 5671 console.info('Succeeded in recovering the window.'); 5672 }).catch((err: BusinessError) => { 5673 console.error(`Failed to recover the window. Cause code: ${err.code}, message: ${err.message}`); 5674 }); 5675 }); 5676 } 5677} 5678``` 5679 5680### restore<sup>14+</sup> 5681 5682restore(): Promise<void> 5683 5684将主窗口从最小化状态,恢复到前台显示,并恢复到进入该模式之前的大小和位置。使用Promise异步回调。 5685此接口仅在多窗层叠布局效果下生效,仅在主窗口为最小化状态且UIAbility生命周期为onForeground时生效,仅2in1设备可用。 5686 5687**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 5688 5689**系统能力:** SystemCapability.Window.SessionManager 5690 5691**返回值:** 5692 5693| 类型 | 说明 | 5694| ------------------- | ------------------------- | 5695| Promise<void> | 无返回结果的Promise对象。 | 5696 5697**错误码:** 5698 5699以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5700 5701| **错误码ID** | **错误信息** | 5702| ------------ | ------------------------------------------------------------ | 5703| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5704| 1300002 | This window state is abnormal. | 5705| 1300003 | This window manager service works abnormally. | 5706| 1300004 | Unauthorized operation. | 5707 5708**示例** 5709 5710```ts 5711// EntryAbility.ets 5712import { UIAbility } from '@kit.AbilityKit'; 5713import { BusinessError } from '@kit.BasicServicesKit'; 5714import { window } from '@kit.ArkUI'; 5715import { BusinessError } from '@kit.BasicServicesKit'; 5716 5717export default class EntryAbility extends UIAbility { 5718 onWindowStageCreate(windowStage: window.WindowStage): void { 5719 // 加载主窗口对应的页面 5720 windowStage.loadContent('pages/Index', (err) => { 5721 let mainWindow: window.Window | undefined = undefined; 5722 // 获取应用主窗口。 5723 windowStage.getMainWindow().then( 5724 data => { 5725 mainWindow = data; 5726 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 5727 // 调用minimize, 使主窗缩小。 5728 mainWindow.minimize(); 5729 //设置延时函数延时5秒钟后对主窗进行恢复。 5730 setTimeout(()=>{ 5731 //调用restore()函数对主窗进行恢复。 5732 let promise = mainWindow.restore(); 5733 promise.then(() => { 5734 console.info('Succeeded in restoring the window.'); 5735 }).catch((err: BusinessError) => { 5736 console.error(`Failed to restore the window. Cause code: ${err.code}, 5737 message: ${err.message}`); 5738 }); 5739 },5000); 5740 } 5741 ).catch((err: BusinessError) => { 5742 if(err.code){ 5743 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 5744 } 5745 }); 5746 }); 5747 } 5748} 5749``` 5750 5751### getWindowLimits<sup>11+</sup> 5752 5753getWindowLimits(): WindowLimits 5754 5755获取当前应用窗口的尺寸限制。 5756 5757**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5758 5759**系统能力:** SystemCapability.Window.SessionManager 5760 5761**返回值:** 5762 5763| 类型 | 说明 | 5764| ----------------------------- | ------------------ | 5765| [WindowLimits](#windowlimits11) | 当前窗口尺寸限制。 | 5766 5767**错误码:** 5768 5769以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5770 5771| 错误码ID | 错误信息 | 5772| :------- | :----------------------------- | 5773| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5774| 1300002 | This window state is abnormal. | 5775 5776**示例:** 5777 5778```ts 5779try { 5780 let windowLimits = windowClass.getWindowLimits(); 5781} catch (exception) { 5782 console.error(`Failed to obtain the window limits of window. Cause code: ${exception.code}, message: ${exception.message}`); 5783} 5784``` 5785 5786### setWindowLimits<sup>11+</sup> 5787 5788setWindowLimits(windowLimits: WindowLimits): Promise<WindowLimits> 5789 5790设置当前应用窗口的尺寸限制,使用Promise异步回调。 5791默认存在一个系统尺寸限制,系统尺寸限制由产品配置决定,不可修改。未调用setWindowLimits配置过WindowLimits时,使用[getWindowLimits](#getwindowlimits11)可获取系统限制。 5792 5793**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5794 5795**系统能力:** SystemCapability.Window.SessionManager 5796 5797**参数:** 5798 5799| 参数名 | 类型 | 必填 | 说明 | 5800| :----------- | :---------------------------- | :--- | :----------------------------- | 5801| windowLimits | [WindowLimits](#windowlimits11) | 是 | 目标窗口的尺寸限制,单位为px。 | 5802 5803**返回值:** 5804 5805| 类型 | 说明 | 5806| :------------------------------------------- | :---------------------------------- | 5807| Promise<[WindowLimits](#windowlimits11)> | Promise对象。返回设置后的尺寸限制,为入参与系统尺寸限制的交集。 | 5808 5809**错误码:** 5810 5811以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5812 5813| 错误码ID | 错误信息 | 5814| :------- | :-------------------------------------------- | 5815| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5816| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5817| 1300002 | This window state is abnormal. | 5818| 1300003 | This window manager service works abnormally. | 5819| 1300004 | Unauthorized operation. | 5820 5821**示例:** 5822 5823```ts 5824import { BusinessError } from '@kit.BasicServicesKit'; 5825try { 5826 let windowLimits: window.WindowLimits = { 5827 maxWidth: 1500, 5828 maxHeight: 1000, 5829 minWidth: 500, 5830 minHeight: 400 5831 }; 5832 let promise = windowClass.setWindowLimits(windowLimits); 5833 promise.then((data) => { 5834 console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data)); 5835 }).catch((err: BusinessError) => { 5836 console.error(`Failed to change the window limits. Cause code: ${err.code}, message: ${err.message}`); 5837 }); 5838} catch (exception) { 5839 console.error(`Failed to change the window limits. Cause code: ${exception.code}, message: ${exception.message}`); 5840} 5841``` 5842 5843### setWindowMask<sup>12+</sup> 5844 5845setWindowMask(windowMask: Array<Array<number>>): Promise<void>; 5846 5847设置异形窗口的掩码,使用Promise异步回调。异形窗口为非常规形状的窗口,掩码用于描述异形窗口的形状。此接口仅限子窗和全局悬浮窗可用,仅2in1设备可用。 5848当异形窗口大小发生变化时,实际的显示内容为掩码大小和窗口大小的交集部分。 5849 5850**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5851 5852**系统能力:** SystemCapability.Window.SessionManager 5853 5854**参数:** 5855 5856| 参数名 | 类型 | 必填 | 说明 | 5857| :----------- | :---------------------------- | :--- | :----------------------------- | 5858| windowMask | Array<Array<number>> | 是 | 异形窗口的掩码,该参数仅支持宽高为窗口宽高、取值为整数0和整数1的二维数组输入,整数0代表所在像素透明,整数1代表所在像素不透明,宽高不符合的二维数组或二维数组取值不为整数0和整数1的二维数组为非法参数。 | 5859 5860**返回值:** 5861 5862| 类型 | 说明 | 5863| :------------------------------------------- | :---------------------------------- | 5864| Promise<void> | 无返回结果的Promise对象。 | 5865 5866**错误码:** 5867 5868以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5869 5870| 错误码ID | 错误信息 | 5871| :------- | :-------------------------------------------- | 5872| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5873| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5874| 1300002 | This window state is abnormal. | 5875| 1300003 | This window manager service works abnormally. | 5876| 1300004 | Unauthorized operation. | 5877 5878**示例:** 5879 5880```ts 5881import { BusinessError } from '@kit.BasicServicesKit'; 5882try { 5883 let windowMask: Array<Array<number>> = [ 5884 [0, 0, 0, 1, 0, 0, 0], 5885 [0, 0, 1, 1, 1, 0, 0], 5886 [0, 1, 1, 0, 1, 1, 0], 5887 [1, 1, 0, 0, 0, 1, 1] 5888 ]; 5889 let promise = windowClass.setWindowMask(windowMask); 5890 promise.then(() => { 5891 console.info('Succeeded in setting the window mask.'); 5892 }).catch((err: BusinessError) => { 5893 console.error(`Failed to set the window mask. Cause code: ${err.code}, message: ${err.message}`); 5894 }); 5895} catch (exception) { 5896 console.error(`Failed to set the window mask. Cause code: ${exception.code}, message: ${exception.message}`); 5897} 5898``` 5899 5900### keepKeyboardOnFocus<sup>11+</sup> 5901 5902keepKeyboardOnFocus(keepKeyboardFlag: boolean): void 5903 5904窗口获焦时保留由其他窗口创建的软键盘,仅支持系统窗口与应用子窗口。 5905 5906**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5907 5908**系统能力:** SystemCapability.Window.SessionManager 5909 5910**参数:** 5911 5912| 参数名 | 类型 | 必填 | 说明 | 5913| ---------------- | ------- | ---- | ------------------------------------------------------------ | 5914| keepKeyboardFlag | boolean | 是 | 是否保留其他窗口创建的软键盘。true表示保留;false表示不保留。| 5915 5916**错误码:** 5917 5918以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5919 5920| 错误码ID | 错误信息 | 5921| ------- | ---------------------------------------- | 5922| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5923| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5924| 1300002 | This window state is abnormal. | 5925| 1300004 | Unauthorized operation. | 5926 5927**示例:** 5928 5929```ts 5930try { 5931 windowClass.keepKeyboardOnFocus(true); 5932} catch (exception) { 5933 console.error(`Failed to keep keyboard onFocus. Cause code: ${exception.code}, message: ${exception.message}`); 5934} 5935``` 5936 5937### setWindowDecorVisible<sup>11+</sup> 5938 5939setWindowDecorVisible(isVisible: boolean): void 5940 5941设置窗口标题栏是否可见,对存在标题栏和三键区的窗口形态生效。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 5942 5943设置窗口标题栏不可见后,当主窗口进入全屏沉浸状态时,此时鼠标Hover到上方窗口标题栏热区上会显示悬浮标题栏。若想禁用悬浮标题栏显示,请使用[setTitleAndDockHoverShown()](#settitleanddockhovershown14)接口。 5944 5945**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5946 5947**系统能力:** SystemCapability.Window.SessionManager 5948 5949**参数:** 5950 5951| 参数名 | 类型 | 必填 | 说明 | 5952| --------- | ------- | ---- | --------------------------------------------- | 5953| isVisible | boolean | 是 | 设置标题栏是否可见,true为可见,false为隐藏。 | 5954 5955**错误码:** 5956 5957以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5958 5959| 错误码ID | 错误信息 | 5960| -------- | ------------------------------ | 5961| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5962| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5963| 1300002 | This window state is abnormal. | 5964| 1300004 | Unauthorized operation. | 5965 5966**示例:** 5967 5968```ts 5969import { BusinessError } from '@kit.BasicServicesKit'; 5970let storage: LocalStorage = new LocalStorage(); 5971storage.setOrCreate('storageSimpleProp', 121); 5972windowClass.loadContent("pages/page2", storage, (err: BusinessError) => { 5973 let errCode: number = err.code; 5974 if (errCode) { 5975 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 5976 return; 5977 } 5978 console.info('Succeeded in loading the content.'); 5979 let isVisible = false; 5980 // 调用setWindowDecorVisible接口 5981 try { 5982 windowClass?.setWindowDecorVisible(isVisible); 5983 } catch (exception) { 5984 console.error(`Failed to set the visibility of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 5985 } 5986}); 5987``` 5988 5989### setWindowTitleMoveEnabled<sup>14+</sup> 5990 5991setWindowTitleMoveEnabled(enabled: boolean): void 5992 5993禁止/使能主窗或子窗标题栏默认移动窗口和双击最大化的功能,仅对2in1设备生效,当禁用标题栏默认移动窗口和双击最大化的功能时,可使用[startMoving()](#startmoving14)在应用热区中发起拖拽移动,使用[maximize()](#maximize12)实现最大化功能。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 5994 5995**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 5996 5997**系统能力:** SystemCapability.Window.SessionManager 5998 5999**参数:** 6000 6001| 参数名 | 类型 | 必填 | 说明 | 6002| --------- | ------- | ---- | --------------------------------------------- | 6003| enabled | boolean | 是 | 是否使能标题栏默认移动窗口和双击最大化功能,true表示使能,false表示不使能。| 6004 6005**错误码:** 6006 6007以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6008 6009| 错误码ID | 错误信息 | 6010| -------- | ------------------------------ | 6011| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6012| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6013| 1300002 | This window state is abnormal. | 6014| 1300004 | Unauthorized operation. | 6015 6016**示例:** 6017 6018```ts 6019windowClass.setUIContent('pages/WindowPage').then(() => { 6020 try { 6021 let enabled = false; 6022 windowClass.setWindowTitleMoveEnabled(enabled); 6023 } catch (exception) { 6024 console.error(`Failed to set the window title move enabled. Cause code: ${exception.code}, message: ${exception.message}`); 6025 } 6026}) 6027``` 6028 6029### setSubWindowModal<sup>12+</sup> 6030 6031setSubWindowModal(isModal: boolean): Promise<void> 6032 6033设置子窗的模态属性是否启用,使用Promise异步回调。 6034 6035子窗口调用该接口时,设置子窗口模态属性是否启用。启用子窗口模态属性后,其父级窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态属性被禁用。 6036 6037子窗口之外的窗口调用该接口时,会报错。 6038 6039**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6040 6041**系统能力:** SystemCapability.Window.SessionManager 6042 6043**参数:** 6044 6045| 参数名 | 类型 | 必填 | 说明 | 6046| --------- | ------- | ---- | --------------------------------------------- | 6047| isModal | boolean | 是 | 设置子窗口模态属性是否启用,true为启用,false为不启用。 | 6048 6049 6050**返回值:** 6051 6052| 类型 | 说明 | 6053| ------------------- | ------------------------ | 6054| Promise<void> | 无返回结果的Promise对象。 | 6055 6056**错误码:** 6057 6058以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6059 6060| 错误码ID | 错误信息 | 6061| -------- | ------------------------------ | 6062| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6063| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6064| 1300002 | This window state is abnormal. | 6065| 1300004 | Unauthorized operation. | 6066 6067**示例:** 6068 6069```ts 6070// EntryAbility.ets 6071import { UIAbility } from '@kit.AbilityKit'; 6072import { BusinessError } from '@kit.BasicServicesKit'; 6073 6074export default class EntryAbility extends UIAbility { 6075 // ... 6076 onWindowStageCreate(windowStage: window.WindowStage): void { 6077 console.info('onWindowStageCreate'); 6078 let windowClass: window.Window | undefined = undefined; 6079 // 创建子窗 6080 try { 6081 let subWindow = windowStage.createSubWindow("testSubWindow"); 6082 subWindow.then((data) => { 6083 if (data == null) { 6084 console.error("Failed to create the subWindow. Cause: The data is empty"); 6085 return; 6086 } 6087 windowClass = data; 6088 let promise = windowClass.setSubWindowModal(true); 6089 promise.then(() => { 6090 console.info('Succeeded in setting subwindow modal'); 6091 }).catch((err: BusinessError) => { 6092 console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`); 6093 }); 6094 }); 6095 } catch (exception) { 6096 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 6097 } 6098 } 6099} 6100``` 6101 6102### setSubWindowModal<sup>14+</sup> 6103 6104setSubWindowModal(isModal: boolean, modalityType: ModalityType): Promise<void> 6105 6106设置子窗的模态类型,使用Promise异步回调。 6107 6108当子窗口模态类型为模窗口子窗时,其父级窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态类型被禁用。 6109 6110当子窗口模态类型为模应用子窗时,其父级窗口与该应用其他实例的窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态类型被禁用。 6111 6112此接口仅支持设置子窗口模态类型,当需要禁用子窗口模态属性时,建议使用[setSubWindowModal<sup>12+</sup>](#setsubwindowmodal12)。 6113 6114子窗口之外的窗口调用该接口时,会报错。 6115 6116**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 6117 6118**系统能力:** SystemCapability.Window.SessionManager 6119 6120**参数:** 6121 6122| 参数名 | 类型 | 必填 | 说明 | 6123| --------- | ------- | ---- | --------------------------------------------- | 6124| isModal | boolean | 是 | 设置子窗口模态属性是否启用,true为启用,false为不启用。当前仅支持设置为true。 | 6125| modalityType | [ModalityType](#modalitytype14) | 是 | 子窗口模态类型。 | 6126 6127**返回值:** 6128 6129| 类型 | 说明 | 6130| ------------------- | ------------------------ | 6131| Promise<void> | 无返回结果的Promise对象。 | 6132 6133**错误码:** 6134 6135以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6136 6137| 错误码ID | 错误信息 | 6138| -------- | ------------------------------ | 6139| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6140| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6141| 1300002 | This window state is abnormal. | 6142| 1300004 | Unauthorized operation. | 6143 6144**示例:** 6145 6146```ts 6147// EntryAbility.ets 6148import { UIAbility } from '@kit.AbilityKit'; 6149import { BusinessError } from '@kit.BasicServicesKit'; 6150import { window } from '@kit.ArkUI'; 6151 6152export default class EntryAbility extends UIAbility { 6153 // ... 6154 onWindowStageCreate(windowStage: window.WindowStage): void { 6155 console.info('onWindowStageCreate'); 6156 let windowClass: window.Window | undefined = undefined; 6157 // 创建子窗 6158 try { 6159 let subWindow = windowStage.createSubWindow("testSubWindow"); 6160 subWindow.then((data) => { 6161 if (data == null) { 6162 console.error("Failed to create the subWindow. Cause: The data is empty"); 6163 return; 6164 } 6165 windowClass = data; 6166 let promise = windowClass.setSubWindowModal(true, window.ModalityType.WINDOW_MODALITY); 6167 promise.then(() => { 6168 console.info('Succeeded in setting subwindow modal'); 6169 }).catch((err: BusinessError) => { 6170 console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`); 6171 }); 6172 }); 6173 } catch (exception) { 6174 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 6175 } 6176 } 6177} 6178``` 6179 6180### setWindowDecorHeight<sup>11+</sup> 6181 6182setWindowDecorHeight(height: number): void 6183 6184<!--RP1--> 6185设置窗口的标题栏高度,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 6186<!--RP1End--> 6187 6188当主窗口进入全屏沉浸状态时,此时鼠标Hover到窗口标题栏热区时,会显示悬浮标题栏,悬浮标题栏高度固定为37vp。 6189 6190**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6191 6192**系统能力:** SystemCapability.Window.SessionManager 6193 6194**参数:** 6195 6196| 参数名 | 类型 | 必填 | 说明 | 6197| ------ | ------ | ---- | ------------------------------------------------------------ | 6198| height | number | 是 |设置的窗口标题栏高度,仅支持具有窗口标题栏的窗口。该参数为整数,浮点数输入将向下取整,取值范围为[37,112],范围外为非法参数,单位为vp。 | 6199 6200**错误码:** 6201 6202以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6203 6204| 错误码ID | 错误信息 | 6205| -------- | ------------------------------ | 6206| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6207| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6208| 1300002 | This window state is abnormal. | 6209 6210**示例:** 6211 6212```ts 6213windowClass.setUIContent('pages/WindowPage').then(() => { 6214 let height: number = 50; 6215 try { 6216 windowClass?.setWindowDecorHeight(height); 6217 console.info(`Succeeded in setting the height of window decor: ${height}`); 6218 } catch (exception) { 6219 console.error(`Failed to set the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 6220 } 6221}) 6222``` 6223 6224### setDecorButtonStyle<sup>14+</sup> 6225 6226setDecorButtonStyle(dectorStyle: DecorButtonStyle): void 6227 6228设置装饰栏按钮样式,仅对2in1设备的主窗和使能窗口标题的子窗生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 6229 6230**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 6231 6232**系统能力:** SystemCapability.Window.SessionManager 6233 6234**参数:** 6235 6236| 参数名 | 类型 | 必填 | 说明 | 6237| --------- | ------- | ---- | --------------------------------------------- | 6238| dectorStyle | [DecorButtonStyle](#decorbuttonstyle14) | 是 | 要设置的装饰栏按钮样式。 | 6239 6240**错误码:** 6241 6242以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6243 6244| 错误码ID | 错误信息 | 6245| -------- | ------------------------------ | 6246| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6247| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6248| 1300002 | This window state is abnormal. | 6249| 1300004 | Unauthorized operation. | 6250 6251**示例:** 6252 6253```ts 6254import { ConfigurationConstant } from '@kit.AbilityKit'; 6255 6256windowClass.setUIContent('pages/WindowPage').then(() => { 6257 try { 6258 let colorMode : ConfigurationConstant.ColorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT; 6259 let style: window.DecorButtonStyle = { 6260 colorMode: colorMode, 6261 buttonBackgroundSize: 24, 6262 spacingBetweenButtons: 12, 6263 closeButtonRightMargin: 20 6264 }; 6265 windowClass.setDecorButtonStyle(style); 6266 console.info('Succeeded in setting the style of button. Data: ' + JSON.stringify(style)); 6267 } catch (exception) { 6268 console.error(`Failed to set the style of button. Cause code: ${exception.code}, message: ${exception.message}`); 6269 } 6270}) 6271``` 6272 6273### getDecorButtonStyle<sup>14+</sup> 6274 6275getDecorButtonStyle(): DecorButtonStyle 6276 6277获取装饰栏按钮样式,仅对2in1设备的主窗和使能窗口标题的子窗生效。 6278 6279**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 6280 6281**系统能力:** SystemCapability.Window.SessionManager 6282 6283**返回值:** 6284 6285| 类型 | 说明 | 6286| ------------------------------------- | ------------------------------------------------------------ | 6287| [DecorButtonStyle](#decorbuttonstyle14) | 返回当前窗口装饰栏上的按钮样式,窗口装饰按钮区域位于窗口的右上角。 | 6288 6289**错误码:** 6290 6291以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6292 6293| 错误码ID | 错误信息 | 6294| -------- | ------------------------------ | 6295| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6296| 1300002 | This window state is abnormal. | 6297| 1300003 | This window manager service works abnormally. | 6298| 1300004 | Unauthorized operation. | 6299 6300**示例:** 6301 6302```ts 6303try { 6304 let decorButtonStyle = windowClass.getDecorButtonStyle(); 6305 console.info('Succeeded in getting the style of button. Data: ' + JSON.stringify(decorButtonStyle)); 6306} catch (exception) { 6307 console.error(`Failed to get the style of button. Cause code: ${exception.code}, message: ${exception.message}`); 6308} 6309``` 6310 6311### getWindowDecorHeight<sup>11+</sup> 6312 6313getWindowDecorHeight(): number 6314 6315<!--RP2--> 6316获取窗口的标题栏高度,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 6317<!--RP2End--> 6318 6319**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6320 6321**系统能力:** SystemCapability.Window.SessionManager 6322 6323**返回值:** 6324 6325| 类型 | 说明 | 6326| ------ | ------------------------------------------------------------ | 6327| number | 返回的窗口标题栏高度。该参数为整数,取值范围为[37,112],单位为vp。 | 6328 6329**错误码:** 6330 6331以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6332 6333| 错误码ID | 错误信息 | 6334| -------- | ------------------------------ | 6335| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6336| 1300002 | This window state is abnormal. | 6337 6338**示例:** 6339 6340```ts 6341windowClass.setUIContent('pages/WindowPage').then(() => { 6342 try { 6343 let height = windowClass?.getWindowDecorHeight(); 6344 console.info(`Succeeded in getting the height of window decor: ${height}`); 6345 } catch (exception) { 6346 console.error(`Failed to get the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 6347 } 6348}) 6349``` 6350 6351### getTitleButtonRect<sup>11+</sup> 6352 6353getTitleButtonRect(): TitleButtonRect 6354 6355获取主窗口或启用装饰的子窗口的标题栏上的最小化、最大化、关闭按钮矩形区域。 6356 6357**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6358 6359**系统能力:** SystemCapability.Window.SessionManager 6360 6361**返回值:** 6362 6363| 类型 | 说明 | 6364| ------------------------------------- | ------------------------------------------------------------ | 6365| [TitleButtonRect](#titlebuttonrect11) | 标题栏上的最小化、最大化、关闭按钮矩形区域,该区域位置坐标相对窗口右上角。 | 6366 6367**错误码:** 6368 6369以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6370 6371| 错误码ID | 错误信息 | 6372| -------- | ------------------------------ | 6373| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6374| 1300002 | This window state is abnormal. | 6375 6376**示例:** 6377 6378```ts 6379// EntryAbility.ets 6380import { UIAbility } from '@kit.AbilityKit'; 6381import { BusinessError } from '@kit.BasicServicesKit'; 6382 6383export default class EntryAbility extends UIAbility { 6384 // ... 6385 onWindowStageCreate(windowStage: window.WindowStage): void { 6386 console.info('onWindowStageCreate'); 6387 let windowClass: window.Window | undefined = undefined; 6388 windowStage.getMainWindow((err: BusinessError, data) => { 6389 const errCode: number = err.code; 6390 if (errCode) { 6391 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 6392 return; 6393 } 6394 windowClass = data; 6395 try { 6396 let titleButtonArea = windowClass.getTitleButtonRect(); 6397 console.info('Succeeded in obtaining the area of title buttons. Data: ' + JSON.stringify(titleButtonArea)); 6398 } catch (exception) { 6399 console.error(`Failed to get the area of title buttons. Cause code: ${exception.code}, message: ${exception.message}`); 6400 } 6401 }); 6402 } 6403} 6404``` 6405 6406### getWindowStatus<sup>12+</sup> 6407 6408getWindowStatus(): WindowStatusType 6409 6410获取当前应用窗口的模式。 6411 6412> **说明:** 6413> 6414> 在2in1设备上调用本接口时,在窗口最大化状态时返回值对应为WindowStatusType::FULL_SCREEN。 6415> 6416> 若想在2in1设备上区分当前窗口状态为最大化还是全屏,可在窗口状态为WindowStatusType::FULL_SCREEN的情况下,再调用[getImmersiveModeEnabledState()](#getimmersivemodeenabledstate12) 接口进行进一步判断,到底是最大化状态还是全屏状态。若接口返回true则表示当前窗口为全屏状态,若接口返回false则表示当前窗口为最大化状态。 6417 6418**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6419 6420**系统能力:** SystemCapability.Window.SessionManager 6421 6422**返回值:** 6423 6424| 类型 | 说明 | 6425| ------------------------------ | ----------------------------------------| 6426| [WindowStatusType](#windowstatustype11) | 当前窗口模式。 | 6427 6428**错误码:** 6429 6430以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6431 6432| 错误码ID | 错误信息 | 6433| ------- | ------------------------------ | 6434| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6435| 1300002 | This window state is abnormal. | 6436 6437**示例:** 6438 6439```ts 6440try { 6441 let windowStatusType = windowClass.getWindowStatus(); 6442} catch (exception) { 6443 console.error(`Failed to obtain the window status of window. Cause code: ${exception.code}, message: ${exception.message}`); 6444} 6445``` 6446 6447### isFocused<sup>12+</sup> 6448 6449isFocused(): boolean 6450 6451判断当前窗口是否已获焦。 6452 6453**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6454 6455**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6456 6457**返回值:** 6458 6459| 类型 | 说明 | 6460| ------- | ------------------------------------------------------------------ | 6461| boolean | 当前窗口是否已获焦。true表示当前窗口已获焦,false则表示当前窗口未获焦。 | 6462 6463**错误码:** 6464 6465以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 6466 6467| 错误码ID | 错误信息 | 6468| ------- | ------------------------------ | 6469| 1300002 | This window state is abnormal. | 6470 6471**示例:** 6472 6473```ts 6474try { 6475 let focus = windowClass.isFocused(); 6476 console.info('Succeeded in checking whether the window is focused. Data: ' + JSON.stringify(focus)); 6477} catch (exception) { 6478 console.error(`Failed to check whether the window is focused. Cause code: ${exception.code}, message: ${exception.message}`); 6479} 6480``` 6481 6482### createSubWindowWithOptions<sup>12+</sup> 6483 6484createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise<Window> 6485 6486创建主窗口或子窗口下的子窗口,使用Promise异步回调,该接口仅在2in1设备上调用生效。 6487 6488**模型约束:** 此接口仅可在Stage模型下使用。 6489 6490**系统能力:** SystemCapability.Window.SessionManager 6491 6492**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6493 6494**参数:** 6495 6496| 参数名 | 类型 | 必填 | 说明 | 6497| ------ | ------ | ---- | -------------- | 6498| name | string | 是 | 子窗口的名字。 | 6499| options | [SubWindowOptions](#subwindowoptions11) | 是 | 子窗口参数。 | 6500 6501**返回值:** 6502 6503| 类型 | 说明 | 6504| -------------------------------- | ------------------------------------------------ | 6505| Promise<[Window](#window)> | Promise对象。返回当前Window下创建的子窗口对象。 | 6506 6507**错误码:** 6508 6509以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6510 6511| 错误码ID | 错误信息 | 6512| ------- | ------------------------------ | 6513| 401 | Parameter error. Possible cause: Incorrect parameter types. | 6514| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6515| 1300002 | This window state is abnormal. | 6516| 1300003 | This window manager service works abnormally. | 6517| 1300004 | Unauthorized operation. | 6518 6519**示例:** 6520 6521```ts 6522import { BusinessError } from '@kit.BasicServicesKit'; 6523 6524try { 6525 let options : window.SubWindowOptions = { 6526 title: 'title', 6527 decorEnabled: true, 6528 isModal: true 6529 }; 6530 let promise = windowClass.createSubWindowWithOptions('mySubWindow', options); 6531 promise.then((data) => { 6532 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 6533 }).catch((err: BusinessError) => { 6534 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 6535 }); 6536} catch (exception) { 6537 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 6538} 6539``` 6540 6541### setWindowTitleButtonVisible<sup>14+</sup> 6542 6543setWindowTitleButtonVisible(isMaximizeButtonVisible: boolean, isMinimizeButtonVisible: boolean, isCloseButtonVisible?: boolean): void 6544 6545设置主窗标题栏上的最大化、最小化、关闭按钮是否可见。 6546 6547此接口仅支持2in1设备。 6548 6549**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 6550 6551**系统能力:** SystemCapability.Window.SessionManager 6552 6553**参数:** 6554 6555| 参数名 | 类型 | 必填 | 说明 | 6556| --------- | ------- | ---- | --------------------------------------------- | 6557| isMaximizeButtonVisible | boolean | 是 | 设置最大化按钮是否可见,true为可见,false为隐藏。如果最大化按钮隐藏,那么在最大化场景下,也隐藏对应的还原按钮。 | 6558| isMinimizeButtonVisible | boolean | 是 | 设置最小化按钮是否可见,true为可见,false为隐藏。 | 6559| isCloseButtonVisible | boolean | 否 | 设置关闭按钮是否可见,true为可见,false为隐藏,默认值true。 | 6560 6561**错误码:** 6562 6563以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6564 6565| 错误码ID | 错误信息 | 6566| -------- | ------------------------------ | 6567| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6568| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6569| 1300002 | This window state is abnormal. | 6570| 1300004 | Unauthorized operation. | 6571 6572**示例:** 6573 6574```ts 6575// EntryAbility.ets 6576import { UIAbility } from '@kit.AbilityKit'; 6577import { BusinessError } from '@kit.BasicServicesKit'; 6578import { window } from '@kit.ArkUI'; 6579 6580export default class EntryAbility extends UIAbility { 6581 onWindowStageCreate(windowStage: window.WindowStage): void { 6582 // 加载主窗口对应的页面 6583 windowStage.loadContent('pages/Index', (err) => { 6584 let mainWindow: window.Window | undefined = undefined; 6585 // 获取应用主窗口。 6586 windowStage.getMainWindow().then( 6587 data => { 6588 mainWindow = data; 6589 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 6590 // 调用setWindowTitleButtonVisible接口,隐藏主窗标题栏最大化、最小化、关闭按钮。 6591 mainWindow.setWindowTitleButtonVisible(false, false, false); 6592 } 6593 ).catch((err: BusinessError) => { 6594 if(err.code){ 6595 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 6596 } 6597 }); 6598 }); 6599 } 6600} 6601``` 6602 6603### setWindowTopmost<sup>14+</sup> 6604 6605setWindowTopmost(isWindowTopmost: boolean): Promise<void> 6606 6607应用主窗口调用,实现将窗口置于其他应用窗口之上不被遮挡,使用Promise异步回调。 6608 6609应用可通过自定义快捷键实现主窗口的置顶和取消置顶。 6610 6611<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 6612 6613**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 6614 6615**系统能力:** SystemCapability.Window.SessionManager 6616 6617**需要权限:** ohos.permission.WINDOW_TOPMOST 6618 6619**参数:** 6620 6621| 参数名 | 类型 | 必填 | 说明 | 6622| --------- | ------- | ---- | --------------------------------------------- | 6623| isWindowTopmost | boolean | 是 | 设置主窗口置顶,true为置顶,false为取消置顶。 | 6624 6625 6626**错误码:** 6627 6628以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6629 6630| 错误码ID | 错误信息 | 6631| -------- | ------------------------------ | 6632| 201 | Permission verification failed. The application does not have the permission required to call the API. | 6633| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6634| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6635| 1300002 | This window state is abnormal. | 6636| 1300004 | Unauthorized operation. | 6637 6638**示例:** 6639 6640```ts 6641// ets/pages/Index.ets 6642import { window } from '@kit.ArkUI'; 6643import { common } from '@kit.AbilityKit'; 6644import { BusinessError } from '@kit.BasicServicesKit'; 6645 6646const context = (getContext(this) as common.UIAbilityContext); 6647let windowClass: window.Window | undefined; 6648let keyUpEventAry: string[] = []; 6649 6650@Entry 6651@Component 6652struct Index { 6653 build() { 6654 RelativeContainer() { 6655 Button("窗口置顶") 6656 .onClick(() => { 6657 try { 6658 let promiseCtx = window.getLastWindow(context); 6659 promiseCtx.then((data) => { 6660 windowClass = data; 6661 // true:窗口置顶,false:取消窗口置顶 6662 let isWindowTopmost: boolean = true; 6663 let promiseTopmost = windowClass.setWindowTopmost(isWindowTopmost); 6664 promiseTopmost.then(() => { 6665 console.info('Succeeded in setting the main window to be topmost.'); 6666 }).catch((err: BusinessError) => { 6667 console.error(`Failed to set the main window to be topmost. Cause code: ${err.code}, message: ${err.message}`); 6668 }); 6669 }) 6670 } catch (exception) { 6671 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`) 6672 } 6673 }) 6674 } 6675 .height('100%') 6676 .width('100%') 6677 .onKeyEvent((event) => { 6678 if(event) { 6679 if(event.type === KeyType.Down) { 6680 keyUpEventAry = []; 6681 } 6682 if(event.type === KeyType.Up) { 6683 keyUpEventAry.push(event.keyText); 6684 // 自定义快捷键 ctrl+T 执行主窗口置顶、取消置顶的操作 6685 if(windowClass && keyUpEventAry.includes('KEYCODE_CTRL_LEFT') && keyUpEventAry.includes('KEYCODE_T')) { 6686 let isWindowTopmost: boolean = false; 6687 windowClass.setWindowTopmost(isWindowTopmost); 6688 } 6689 } 6690 } 6691 }) 6692 } 6693} 6694``` 6695 6696### raiseToAppTop<sup>14+</sup> 6697 6698raiseToAppTop(): Promise<void> 6699 6700应用子窗口调用,提升应用子窗口到顶层,只在当前应用同一个父窗口下的相同类型子窗范围内生效。使用Promise异步回调。 6701 6702**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6703 6704**返回值:** 6705 6706| 类型 | 说明 | 6707| ------------------- | ------------------------- | 6708| Promise<void> | 无返回结果的Promise对象。 | 6709 6710**错误码:** 6711 6712以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6713 6714| 错误码ID | 错误信息 | 6715| ------- | ------------------------------ | 6716| 1300002 | This window state is abnormal. | 6717| 1300003 | This window manager service works abnormally. | 6718| 1300004 | Unauthorized operation. | 6719| 1300009 | The parent window is invalid. | 6720 6721**示例:** 6722 6723```ts 6724import { BusinessError } from '@kit.BasicServicesKit'; 6725 6726let promise = windowClass.raiseToAppTop(); 6727promise.then(() => { 6728 console.info('Succeeded in raising the window to app top.'); 6729}).catch((err: BusinessError) => { 6730 console.error(`Failed to raise the window to app top. Cause code: ${err.code}, message: ${err.message}`); 6731}); 6732``` 6733 6734### setRaiseByClickEnabled<sup>14+</sup> 6735 6736setRaiseByClickEnabled(enable: boolean): Promise<void> 6737 6738禁止/使能子窗点击抬升功能。使用Promise异步回调。 6739 6740通常来说,点击一个子窗口,会将该子窗口显示抬升到应用内同一个父窗口下同类型子窗口的最上方,如果设置为false,那么点击子窗口的时候,不会将该子窗口进行抬升,而是保持不变。 6741 6742**系统能力:** SystemCapability.Window.SessionManager 6743 6744**参数:** 6745 6746| 参数名 | 类型 | 必填 | 说明 | 6747| -------- | ------------------------- | ---- | ---------- | 6748| enable | boolean | 是 | 设置子窗口点击抬升功能是否使能,true表示使能,false表示禁止。 | 6749 6750**返回值:** 6751 6752| 类型 | 说明 | 6753| ------------------- | ------------------------- | 6754| Promise<void> | 无返回结果的Promise对象。 | 6755 6756**错误码:** 6757 6758以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6759 6760| 错误码ID | 错误信息 | 6761| ------- | ------------------------------ | 6762| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6763| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6764| 1300002 | This window state is abnormal. | 6765| 1300003 | This window manager service works abnormally. | 6766| 1300004 | Unauthorized operation. | 6767| 1300009 | The parent window is invalid. | 6768 6769**示例:** 6770 6771```ts 6772// EntryAbility.ets 6773import { UIAbility } from '@kit.AbilityKit'; 6774import { BusinessError } from '@kit.BasicServicesKit'; 6775 6776export default class EntryAbility extends UIAbility { 6777 // ... 6778 onWindowStageCreate(windowStage: window.WindowStage): void { 6779 console.info('onWindowStageCreate'); 6780 let windowClass: window.Window | undefined = undefined; 6781 // 创建子窗 6782 try { 6783 let subWindow = windowStage.createSubWindow("testSubWindow"); 6784 subWindow.then((data) => { 6785 if (data == null) { 6786 console.error("Failed to create the subWindow. Cause: The data is empty"); 6787 return; 6788 } 6789 windowClass = data; 6790 let enabled = false; 6791 let promise = windowClass.setRaiseByClickEnabled(enabled); 6792 promise.then(()=> { 6793 console.info('Succeeded in disabling the raise-by-click function.'); 6794 }).catch((err: BusinessError)=>{ 6795 console.error(`Failed to disable the raise-by-click function. Cause code: ${err.code}, message: ${err.message}`); 6796 }); 6797 }); 6798 } catch (exception) { 6799 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 6800 } 6801 } 6802} 6803``` 6804 6805### enableLandscapeMultiWindow<sup>12+</sup> 6806 6807enableLandscapeMultiWindow(): Promise<void> 6808 6809应用部分界面支持横向布局时,在进入该界面时使能,使能后可支持进入横向多窗。不建议竖向布局界面使用。 6810 6811此接口只对应用主窗口生效,且需要在module.json5配置文件中[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中配置preferMultiWindowOrientation属性为"landscape_auto"。 6812 6813**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6814 6815**系统能力:** SystemCapability.Window.SessionManager 6816 6817**返回值:** 6818 6819| 类型 | 说明 | 6820| ------------------- | ------------------------- | 6821| Promise<void> | 无返回结果的Promise对象。 | 6822 6823**错误码:** 6824 6825以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 6826 6827| 错误码ID | 错误信息 | 6828| ------- | -------------------------------------------- | 6829| 1300002 | This window state is abnormal. | 6830| 1300003 | This window manager service works abnormally. | 6831 6832**示例:** 6833 6834```ts 6835// EntryAbility.ets 6836import { UIAbility } from '@kit.AbilityKit'; 6837import { BusinessError } from '@kit.BasicServicesKit'; 6838import { window } from '@kit.ArkUI'; 6839 6840export default class EntryAbility extends UIAbility { 6841 // ... 6842 onWindowStageCreate(windowStage: window.WindowStage): void { 6843 console.info('onWindowStageCreate'); 6844 let windowClass: window.Window | undefined = undefined; 6845 windowStage.getMainWindow((err: BusinessError, data) => { 6846 const errCode: number = err.code; 6847 if (errCode) { 6848 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 6849 return; 6850 } 6851 windowClass = data; 6852 let promise = windowClass.enableLandscapeMultiWindow(); 6853 promise.then(() => { 6854 console.info('Succeeded in making multi-window become landscape.'); 6855 }).catch((err: BusinessError) => { 6856 console.error(`Failed to make multi-window become landscape. Cause code: ${err.code}, message: ${err.message}`); 6857 }); 6858 }); 6859 } 6860} 6861``` 6862 6863### disableLandscapeMultiWindow<sup>12+</sup> 6864 6865disableLandscapeMultiWindow(): Promise<void> 6866 6867应用部分界面支持横向布局时,在退出该界面时去使能,去使能后不支持进入横向多窗。 6868 6869此接口只对应用主窗口生效,且需要在module.json5配置文件中[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中配置preferMultiWindowOrientation属性为"landscape_auto"。 6870 6871**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6872 6873**系统能力:** SystemCapability.Window.SessionManager 6874 6875**返回值:** 6876 6877| 类型 | 说明 | 6878| ------------------- | ------------------------- | 6879| Promise<void> | 无返回结果的Promise对象。 | 6880 6881**错误码:** 6882 6883以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 6884 6885| 错误码ID | 错误信息 | 6886| ------- | -------------------------------------------- | 6887| 1300002 | This window state is abnormal. | 6888| 1300003 | This window manager service works abnormally. | 6889 6890**示例:** 6891 6892```ts 6893// EntryAbility.ets 6894import { UIAbility } from '@kit.AbilityKit'; 6895import { BusinessError } from '@kit.BasicServicesKit'; 6896import { window } from '@kit.ArkUI'; 6897 6898export default class EntryAbility extends UIAbility { 6899 // ... 6900 onWindowStageCreate(windowStage: window.WindowStage): void { 6901 console.info('onWindowStageCreate'); 6902 let windowClass: window.Window | undefined = undefined; 6903 windowStage.getMainWindow((err: BusinessError, data) => { 6904 const errCode: number = err.code; 6905 if (errCode) { 6906 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 6907 return; 6908 } 6909 windowClass = data; 6910 let promise = windowClass.disableLandscapeMultiWindow(); 6911 promise.then(() => { 6912 console.info('Succeeded in making multi-window become not landscape.'); 6913 }).catch((err: BusinessError) => { 6914 console.error(`Failed to make multi-window become not landscape. Cause code: ${err.code}, message: ${err.message}`); 6915 }); 6916 }); 6917 } 6918} 6919``` 6920 6921### setDialogBackGestureEnabled<sup>12+</sup> 6922 6923setDialogBackGestureEnabled(enabled: boolean): Promise<void> 6924 6925设置模态窗口是否响应手势返回事件,非模态窗口调用返回错误码。 6926 6927**系统能力**:SystemCapability.Window.SessionManager 6928 6929**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6930 6931**参数:** 6932 6933| 参数名 | 类型 | 必填 | 说明 | 6934| ---------- | ------- | ---- | ------------------------------------------------------------ | 6935| enabled | boolean | 是 | 是否响应手势返回事件。<br>true表示响应手势返回事件,触发onBackPress回调;false表示不响应手势返回事件,不触发onBackPress回调。</br> | 6936 6937**返回值:** 6938 6939| 类型 | 说明 | 6940| ------------------- | ------------------------- | 6941| Promise<void> | 无返回结果的Promise对象。 | 6942 6943**错误码:** 6944 6945以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6946 6947| 错误码ID | 错误信息 | 6948| ------- | -------------------------------------------- | 6949| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6950| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6951| 1300002 | This window state is abnormal. | 6952| 1300003 | This window manager service works abnormally. | 6953| 1300004 | Unauthorized operation. | 6954 6955**示例:** 6956 6957```ts 6958// EntryAbility.ets 6959import { UIAbility } from '@kit.AbilityKit'; 6960import { BusinessError } from '@kit.BasicServicesKit'; 6961 6962export default class EntryAbility extends UIAbility { 6963 onWindowStageCreate(windowStage: window.WindowStage): void { 6964 console.info('onWindowStageCreate'); 6965 let windowClass: window.Window | undefined = undefined; 6966 let config: window.Configuration = { 6967 name: "test", 6968 windowType: window.WindowType.TYPE_DIALOG, 6969 ctx: this.context 6970 }; 6971 try { 6972 window.createWindow(config, (err: BusinessError, data) => { 6973 const errCode: number = err.code; 6974 if (errCode) { 6975 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 6976 return; 6977 } 6978 windowClass = data; 6979 windowClass.setUIContent("pages/Index"); 6980 let enabled = true; 6981 let promise = windowClass.setDialogBackGestureEnabled(enabled); 6982 promise.then(() => { 6983 console.info('Succeeded in setting dialog window to respond back gesture.'); 6984 }).catch((err: BusinessError) => { 6985 console.error(`Failed to set dialog window to respond back gesture. Cause code: ${err.code}, message: ${err.message}`); 6986 }); 6987 }); 6988 } catch (exception) { 6989 console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`); 6990 } 6991 } 6992} 6993``` 6994 6995```ts 6996// ets/pages/Index.ets 6997@Entry 6998@Component 6999struct Index { 7000 @State message: string = 'Hello World' 7001 build() { 7002 RelativeContainer() { 7003 Text(this.message) 7004 .id('HelloWorld') 7005 .fontSize(50) 7006 .fontWeight(FontWeight.Bold) 7007 } 7008 .height('100%') 7009 .width('100%') 7010 } 7011 7012 onBackPress(): boolean | void { 7013 console.info('Succeeded in setting dialog window to respond back gesture.'); 7014 return true; 7015 } 7016} 7017``` 7018 7019### startMoving<sup>14+</sup> 7020 7021startMoving(): Promise<void> 7022 7023开始移动窗口,使用Promise异步回调。 7024 7025仅在[onTouch](./arkui-ts/ts-universal-events-touch.md#touchevent)事件(其中,事件类型必须为TouchType.Down)的回调方法中调用此接口才会有移动效果,成功调用此接口后,窗口将跟随鼠标移动。 7026 7027仅对2in1设备的主窗、子窗、系统窗口生效,其它设备类型和窗口类型调用此接口会报错。 7028 7029**系统能力:** SystemCapability.Window.SessionManager 7030 7031**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 7032 7033**返回值:** 7034 7035| 类型 | 说明 | 7036| ------------------- | ------------------------- | 7037| Promise<void> | 无返回结果的Promise对象。 | 7038 7039**错误码:** 7040 7041以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7042 7043| 错误码ID | 错误信息 | 7044| -------- | -------------------------------------------- | 7045| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7046| 1300001 | Repeated operation. | 7047| 1300002 | This window state is abnormal. | 7048| 1300003 | This window manager service works abnormally. | 7049| 1300004 | Unauthorized operation. | 7050 7051**示例:** 7052 7053```ts 7054// ets/pages/Index.ets 7055import { BusinessError } from '@kit.BasicServicesKit'; 7056 7057@Entry 7058@Component 7059struct Index { 7060 build() { 7061 Row() { 7062 Column() { 7063 Blank('160') 7064 .color(Color.Blue) 7065 .onTouch((event: TouchEvent) => { 7066 if (event.type === TouchType.Down) { 7067 try { 7068 windowClass.startMoving().then(() => { 7069 console.info('Succeeded in starting moving window.') 7070 }).catch((err: BusinessError) => { 7071 console.error(`Failed to start moving. Cause code: ${err.code}, message: ${err.message}`); 7072 }); 7073 } catch (exception) { 7074 console.error(`Failed to start moving window. Cause code: ${exception.code}, message: ${exception.message}`); 7075 } 7076 } 7077 }) 7078 }.width('100%') 7079 }.height('100%').width('100%') 7080 } 7081} 7082``` 7083 7084### setGestureBackEnabled<sup>13+<sup> 7085 7086setGestureBackEnabled(enabled: boolean): Promise<void> 7087 7088设置当前窗口是否禁用返回手势功能,仅主窗全屏模式下生效,2in1设备下不生效。 7089禁用返回手势功能后,当前应用会禁用手势热区,侧滑返回功能失效;切换到其他应用或者回到桌面后,手势热区恢复,侧滑返回功能正常。 7090开启返回手势功能后,当前应用会恢复手势热区,侧滑返回功能正常。 7091 7092**系统能力:** SystemCapability.Window.SessionManager 7093 7094**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 7095 7096**参数:** 7097 7098| 参数名 | 类型 | 必填 | 说明 | 7099| ---------- | --------- | -------- | --------------------------------------------- | 7100| enabled | boolean | 是 | true时开启返回手势功能,false时禁用返回手势功能。 | 7101 7102**返回值:** 7103 7104| 类型 | 说明 | 7105| ------------------- | ------------------------- | 7106| Promise<void> | 无返回结果的Promise对象。 | 7107 7108**错误码:** 7109 7110以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7111 7112| 错误码ID | 错误信息 | 7113| -------- | ------------------------------------------------------------------------------------------------------------ | 7114| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7115| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7116| 1300002 | This window state is abnormal. | 7117| 1300003 | This window manager service works abnormally. | 7118| 1300004 | Unauthorized operation. | 7119 7120**示例:** 7121 7122```ts 7123// EntryAbility.ets 7124import { UIAbility } from '@kit.AbilityKit'; 7125import { BusinessError } from '@kit.BasicServicesKit'; 7126import { window } from '@kit.ArkUI'; 7127 7128export default class EntryAbility extends UIAbility { 7129 // ... 7130 onWindowStageCreate(windowStage: window.WindowStage): void { 7131 console.info('onWindowStageCreate'); 7132 let windowClass: window.Window | undefined = undefined; 7133 windowStage.getMainWindow((err: BusinessError, data) => { 7134 const errCode: number = err.code; 7135 if (errCode) { 7136 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7137 return; 7138 } 7139 windowClass = data; 7140 7141 // 设置当前窗口禁用返回手势功能 7142 try { 7143 let gestureBackEnabled: boolean = false; 7144 let promise = windowClass.setGestureBackEnabled(gestureBackEnabled); 7145 promise.then(() => { 7146 console.info(`Succeeded in setting gesture back disabled`); 7147 }).catch((err: BusinessError) => { 7148 console.error(`Failed to set gesture back disabled, Cause code: ${err.code}, message: ${err.message}`); 7149 }); 7150 } catch(exception) { 7151 console.error(`Failed to set gesture back disabled, Cause code: ${exception.code}, message: ${exception.message}`); 7152 } 7153 }); 7154 } 7155} 7156``` 7157 7158### isGestureBackEnabled<sup>13+<sup> 7159 7160isGestureBackEnabled(): boolean 7161 7162获取当前窗口是否禁用返回手势功能,仅主窗全屏模式下生效,2in1设备不生效。 7163 7164**系统能力:** SystemCapability.Window.SessionManager 7165 7166**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 7167 7168**返回值:** 7169 7170| 类型 | 说明 | 7171| ------------------- | --------------------------------------------- | 7172| boolean | 是否已经禁用返回手势。true表示未禁用返回手势功能,false表示已禁用返回手势功能。 | 7173 7174**错误码:** 7175 7176以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7177 7178| 错误码ID | 错误信息 | 7179| -------- | ------------------------------------------------------------------------------------------------------------ | 7180| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7181| 1300002 | This window state is abnormal. | 7182| 1300003 | This window manager service works abnormally. | 7183| 1300004 | Unauthorized operation. | 7184 7185**示例:** 7186 7187```ts 7188// EntryAbility.ets 7189import { UIAbility } from '@kit.AbilityKit'; 7190import { BusinessError } from '@kit.BasicServicesKit'; 7191import { window } from '@kit.ArkUI'; 7192 7193export default class EntryAbility extends UIAbility { 7194 // ... 7195 onWindowStageCreate(windowStage: window.WindowStage): void { 7196 console.info('onWindowStageCreate'); 7197 let windowClass: window.Window | undefined = undefined; 7198 windowStage.getMainWindow((err: BusinessError, data) => { 7199 const errCode: number = err.code; 7200 if (errCode) { 7201 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7202 return; 7203 } 7204 windowClass = data; 7205 7206 // 获取当前窗口是否禁用返回手势功能 7207 try { 7208 let gestureBackEnabled: boolean = windowClass.isGestureBackEnabled(); 7209 console.info(`Succeeded in obtaining gesture back enabled status: ${gestureBackEnabled}`); 7210 } catch (exception) { 7211 console.error(`Failed to get gesture back enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 7212 } 7213 }); 7214 } 7215} 7216``` 7217 7218### setWindowSystemBarProperties<sup>(deprecated)</sup> 7219 7220setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 7221 7222设置主窗口三键导航栏、状态栏的属性,使用callback异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 7223 7224子窗口调用后不生效。 7225 7226> **说明:** 7227> 7228> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowSystemBarProperties](#setwindowsystembarproperties9)。 7229 7230**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7231 7232**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7233 7234**参数:** 7235 7236| 参数名 | 类型 | 必填 | 说明 | 7237| ------------------- | ------------------------------------------- | ---- | ---------------------- | 7238| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 三键导航栏、状态栏的属性。 | 7239| callback | AsyncCallback<void> | 是 | 回调函数。 | 7240 7241**错误码:** 7242 7243以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7244 7245| 错误码ID | 错误信息 | 7246| -------- | ------------------------------------------------------------------------------------------------------------ | 7247| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7248| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7249| 1300002 | This window state is abnormal. | 7250| 1300003 | This window manager service works abnormally. | 7251 7252**示例:** 7253 7254```ts 7255// EntryAbility.ets 7256import { UIAbility } from '@kit.AbilityKit'; 7257import { BusinessError } from '@kit.BasicServicesKit'; 7258 7259export default class EntryAbility extends UIAbility { 7260 // ... 7261 onWindowStageCreate(windowStage: window.WindowStage): void { 7262 console.info('onWindowStageCreate'); 7263 let windowClass: window.Window | undefined = undefined; 7264 windowStage.getMainWindow((err: BusinessError, data) => { 7265 const errCode: number = err.code; 7266 if (errCode) { 7267 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7268 return; 7269 } 7270 windowClass = data; 7271 let SystemBarProperties: window.SystemBarProperties = { 7272 statusBarColor: '#ff00ff', 7273 navigationBarColor: '#00ff00', 7274 //以下两个属性从API Version8开始支持 7275 statusBarContentColor: '#ffffff', 7276 navigationBarContentColor: '#00ffff' 7277 }; 7278 try { 7279 windowClass.setWindowSystemBarProperties(SystemBarProperties, (err: BusinessError) => { 7280 const errCode: number = err.code; 7281 if (errCode) { 7282 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 7283 return; 7284 } 7285 console.info('Succeeded in setting the system bar properties.'); 7286 }); 7287 } catch (exception) { 7288 console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); 7289 } 7290 }); 7291 } 7292} 7293``` 7294 7295### setWindowSystemBarEnable<sup>(deprecated)</sup> 7296 7297setWindowSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 7298 7299设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用callback异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 7300 7301调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。 7302 7303> **说明:** 7304> 7305> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowSystemBarEnable](#setwindowsystembarenable9)。 7306 7307**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7308 7309**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7310 7311**参数:** 7312 7313| 参数名 | 类型 | 必填 | 说明 | 7314| -------- | ----------------------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------- | 7315| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 7316| callback | AsyncCallback<void> | 是 | 回调函数。 | 7317 7318**错误码:** 7319 7320以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7321 7322| 错误码ID | 错误信息 | 7323| -------- | ------------------------------------------------------------------------------------------------------------ | 7324| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7325| 1300002 | This window state is abnormal. | 7326| 1300003 | This window manager service works abnormally. | 7327 7328**示例:** 7329 7330```ts 7331// 此处以不显示三键导航栏、状态栏、底部导航条为例 7332// EntryAbility.ets 7333import { UIAbility } from '@kit.AbilityKit'; 7334import { BusinessError } from '@kit.BasicServicesKit'; 7335 7336export default class EntryAbility extends UIAbility { 7337 // ... 7338 onWindowStageCreate(windowStage: window.WindowStage): void { 7339 console.info('onWindowStageCreate'); 7340 let windowClass: window.Window | undefined = undefined; 7341 windowStage.getMainWindow((err: BusinessError, data) => { 7342 const errCode: number = err.code; 7343 if (errCode) { 7344 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7345 return; 7346 } 7347 windowClass = data; 7348 let names: Array<'status' | 'navigation'> = []; 7349 try { 7350 windowClass.setWindowSystemBarEnable(names, (err: BusinessError) => { 7351 const errCode: number = err.code; 7352 if (errCode) { 7353 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 7354 return; 7355 } 7356 console.info('Succeeded in setting the system bar to be invisible.'); 7357 }); 7358 } catch (exception) { 7359 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 7360 } 7361 }); 7362 } 7363} 7364``` 7365 7366### setWindowLayoutFullScreen<sup>(deprecated)</sup> 7367 7368setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 7369 7370设置主窗口或子窗口的布局是否为沉浸式布局,使用callback异步回调。 7371沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 7372非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 7373 7374> **说明:** 7375> 7376> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowLayoutFullScreen](#setwindowlayoutfullscreen9)。 7377 7378**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7379 7380**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7381 7382**参数:** 7383 7384| 参数名 | 类型 | 必填 | 说明 | 7385| ------------------ | ------------------------- | ---- | ------------------------------------------------------------------------------------------------------------- | 7386| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 7387| callback | AsyncCallback<void> | 是 | 回调函数。 | 7388 7389**错误码:** 7390 7391以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7392 7393| 错误码ID | 错误信息 | 7394| -------- | ------------------------------------------------------------------------------------------------------------ | 7395| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7396| 1300002 | This window state is abnormal. | 7397| 1300003 | This window manager service works abnormally. | 7398 7399**示例:** 7400 7401```ts 7402// EntryAbility.ets 7403import { UIAbility } from '@kit.AbilityKit'; 7404import { BusinessError } from '@kit.BasicServicesKit'; 7405 7406export default class EntryAbility extends UIAbility { 7407 // ... 7408 onWindowStageCreate(windowStage: window.WindowStage): void { 7409 console.info('onWindowStageCreate'); 7410 let windowClass: window.Window | undefined = undefined; 7411 windowStage.getMainWindow((err: BusinessError, data) => { 7412 const errCode: number = err.code; 7413 if (errCode) { 7414 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7415 return; 7416 } 7417 windowClass = data; 7418 let isLayoutFullScreen = true; 7419 try { 7420 windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 7421 const errCode: number = err.code; 7422 if (errCode) { 7423 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 7424 return; 7425 } 7426 console.info('Succeeded in setting the window layout to full-screen mode.'); 7427 }); 7428 } catch (exception) { 7429 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`); 7430 } 7431 }); 7432 } 7433} 7434``` 7435 7436### show<sup>(deprecated)</sup> 7437 7438show(callback: AsyncCallback<void>): void 7439 7440显示当前窗口,使用callback异步回调。 7441 7442> **说明:** 7443> 7444> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9)。 7445 7446**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7447 7448**参数:** 7449 7450| 参数名 | 类型 | 必填 | 说明 | 7451| -------- | ------------------------- | ---- | ---------- | 7452| callback | AsyncCallback<void> | 是 | 回调函数。 | 7453 7454**示例:** 7455 7456```ts 7457import { BusinessError } from '@kit.BasicServicesKit'; 7458 7459windowClass.show((err: BusinessError) => { 7460 const errCode: number = err.code; 7461 if (errCode) { 7462 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 7463 return; 7464 } 7465 console.info('Succeeded in showing the window.'); 7466}); 7467``` 7468 7469### show<sup>(deprecated)</sup> 7470 7471show(): Promise<void> 7472 7473显示当前窗口,使用Promise异步回调。 7474 7475> **说明:** 7476> 7477> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9-1)。 7478 7479**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7480 7481**返回值:** 7482 7483| 类型 | 说明 | 7484| ------------------- | ------------------------- | 7485| Promise<void> | 无返回结果的Promise对象。 | 7486 7487**示例:** 7488 7489```ts 7490import { BusinessError } from '@kit.BasicServicesKit'; 7491 7492let promise = windowClass.show(); 7493promise.then(() => { 7494 console.info('Succeeded in showing the window.'); 7495}).catch((err: BusinessError) => { 7496 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 7497}); 7498``` 7499 7500### destroy<sup>(deprecated)</sup> 7501 7502destroy(callback: AsyncCallback<void>): void 7503 7504销毁当前窗口,使用callback异步回调。 7505 7506> **说明:** 7507> 7508> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9)。 7509 7510**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7511 7512**参数:** 7513 7514| 参数名 | 类型 | 必填 | 说明 | 7515| -------- | ------------------------- | ---- | ---------- | 7516| callback | AsyncCallback<void> | 是 | 回调函数。 | 7517 7518**示例:** 7519 7520```ts 7521import { BusinessError } from '@kit.BasicServicesKit'; 7522 7523windowClass.destroy((err: BusinessError) => { 7524 const errCode: number = err.code; 7525 if (err.code) { 7526 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 7527 return; 7528 } 7529 console.info('Succeeded in destroying the window.'); 7530}); 7531``` 7532 7533### destroy<sup>(deprecated)</sup> 7534 7535destroy(): Promise<void> 7536 7537销毁当前窗口,使用Promise异步回调。 7538 7539> **说明:** 7540> 7541> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9-1)。 7542 7543**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7544 7545**返回值:** 7546 7547| 类型 | 说明 | 7548| ------------------- | ------------------------- | 7549| Promise<void> | 无返回结果的Promise对象。 | 7550 7551**示例:** 7552 7553```ts 7554import { BusinessError } from '@kit.BasicServicesKit'; 7555 7556let promise = windowClass.destroy(); 7557promise.then(() => { 7558 console.info('Succeeded in destroying the window.'); 7559}).catch((err: BusinessError) => { 7560 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 7561}); 7562``` 7563 7564### moveTo<sup>(deprecated)</sup> 7565 7566moveTo(x: number, y: number, callback: AsyncCallback<void>): void 7567 7568移动窗口位置,使用callback异步回调。 7569 7570全屏模式窗口不支持该操作。 7571 7572> **说明:** 7573> 7574> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9)。 7575 7576**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7577 7578**参数:** 7579 7580| 参数名 | 类型 | 必填 | 说明 | 7581| -------- | ------------------------- | ---- | ------------------------------------------------- | 7582| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 | 7583| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 | 7584| callback | AsyncCallback<void> | 是 | 回调函数。 | 7585 7586**示例:** 7587 7588```ts 7589import { BusinessError } from '@kit.BasicServicesKit'; 7590 7591windowClass.moveTo(300, 300, (err: BusinessError) => { 7592 const errCode: number = err.code; 7593 if (errCode) { 7594 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 7595 return; 7596 } 7597 console.info('Succeeded in moving the window.'); 7598}); 7599``` 7600 7601### moveTo<sup>(deprecated)</sup> 7602 7603moveTo(x: number, y: number): Promise<void> 7604 7605移动窗口位置,使用Promise异步回调。 7606 7607全屏模式窗口不支持该操作。 7608 7609> **说明:** 7610> 7611> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9-1)。 7612 7613**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7614 7615**参数:** 7616 7617| 参数名 | 类型 | 必填 | 说明 | 7618| ------ | ------ | ---- | ------------------------------------------------- | 7619| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 | 7620| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入,浮点数输入将向下取整。 | 7621 7622**返回值:** 7623 7624| 类型 | 说明 | 7625| ------------------- | ------------------------- | 7626| Promise<void> | 无返回结果的Promise对象。 | 7627 7628**示例:** 7629 7630```ts 7631import { BusinessError } from '@kit.BasicServicesKit'; 7632 7633let promise = windowClass.moveTo(300, 300); 7634promise.then(() => { 7635 console.info('Succeeded in moving the window.'); 7636}).catch((err: BusinessError) => { 7637 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 7638}); 7639``` 7640 7641### resetSize<sup>(deprecated)</sup> 7642 7643resetSize(width: number, height: number, callback: AsyncCallback<void>): void 7644 7645改变当前窗口大小,使用callback异步回调。 7646 7647应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 7648应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 7649 7650系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 7651 7652设置的宽度与高度受到此约束限制,规则: 7653若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 7654若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 7655 7656全屏模式窗口不支持该操作。 7657 7658> **说明:** 7659> 7660> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9)。 7661 7662**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7663 7664**参数:** 7665 7666| 参数名 | 类型 | 必填 | 说明 | 7667| -------- | ------------------------- | ---- | -------------------------- | 7668| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 7669| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 7670| callback | AsyncCallback<void> | 是 | 回调函数。 | 7671 7672**示例:** 7673 7674```ts 7675import { BusinessError } from '@kit.BasicServicesKit'; 7676 7677windowClass.resetSize(500, 1000, (err: BusinessError) => { 7678 const errCode: number = err.code; 7679 if (errCode) { 7680 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 7681 return; 7682 } 7683 console.info('Succeeded in changing the window size.'); 7684}); 7685``` 7686 7687### resetSize<sup>(deprecated)</sup> 7688 7689resetSize(width: number, height: number): Promise<void> 7690 7691改变当前窗口大小,使用Promise异步回调。 7692 7693应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 7694应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 7695 7696系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 7697 7698设置的宽度与高度受到此约束限制,规则: 7699若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 7700若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 7701 7702全屏模式窗口不支持该操作。 7703 7704> **说明:** 7705> 7706> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9-1)。 7707 7708**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7709 7710**参数:** 7711 7712| 参数名 | 类型 | 必填 | 说明 | 7713| ------ | ------ | ---- | -------------------------- | 7714| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 7715| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 7716 7717**返回值:** 7718 7719| 类型 | 说明 | 7720| ------------------- | ------------------------- | 7721| Promise<void> | 无返回结果的Promise对象。 | 7722 7723**示例:** 7724 7725```ts 7726import { BusinessError } from '@kit.BasicServicesKit'; 7727 7728let promise = windowClass.resetSize(500, 1000); 7729promise.then(() => { 7730 console.info('Succeeded in changing the window size.'); 7731}).catch((err: BusinessError) => { 7732 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 7733}); 7734``` 7735 7736### getProperties<sup>(deprecated)</sup> 7737 7738getProperties(callback: AsyncCallback<WindowProperties>): void 7739 7740获取当前窗口的属性,使用callback异步回调,返回WindowProperties。 7741 7742> **说明:** 7743> 7744> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。 7745 7746**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7747 7748**参数:** 7749 7750| 参数名 | 类型 | 必填 | 说明 | 7751| -------- | ---------------------------------------------------------- | ---- | ---------------------------- | 7752| callback | AsyncCallback<[WindowProperties](#windowproperties)> | 是 | 回调函数。返回当前窗口属性。 | 7753 7754**示例:** 7755 7756```ts 7757import { BusinessError } from '@kit.BasicServicesKit'; 7758 7759windowClass.getProperties((err: BusinessError, data) => { 7760 const errCode: number = err.code; 7761 if (errCode) { 7762 console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`); 7763 return; 7764 } 7765 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 7766}); 7767``` 7768 7769### getProperties<sup>(deprecated)</sup> 7770 7771getProperties(): Promise<WindowProperties> 7772 7773获取当前窗口的属性,使用Promise异步回调,返回WindowProperties。 7774 7775> **说明:** 7776> 7777> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。 7778 7779**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7780 7781**返回值:** 7782 7783| 类型 | 说明 | 7784| ---------------------------------------------------- | ------------------------------- | 7785| Promise<[WindowProperties](#windowproperties)> | Promise对象。返回当前窗口属性。 | 7786 7787**示例:** 7788 7789```ts 7790import { BusinessError } from '@kit.BasicServicesKit'; 7791 7792let promise = windowClass.getProperties(); 7793promise.then((data) => { 7794 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 7795}).catch((err: BusinessError) => { 7796 console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`); 7797}); 7798``` 7799 7800### getAvoidArea<sup>(deprecated)</sup> 7801 7802getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback<[AvoidArea](#avoidarea7)>): void 7803 7804获取当前窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 7805 7806> **说明:** 7807> 7808> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。 7809 7810**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7811 7812**参数:** 7813 7814| 参数名 | 类型 | 必填 | 说明 | 7815| -------- |-----------------------------------------------| ---- | ------------------------------------------------------------ | 7816| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。| 7817| callback | AsyncCallback<[AvoidArea](#avoidarea7)> | 是 | 回调函数。返回窗口内容规避区域。 | 7818 7819**示例:** 7820 7821```ts 7822import { BusinessError } from '@kit.BasicServicesKit'; 7823 7824let type = window.AvoidAreaType.TYPE_SYSTEM; 7825windowClass.getAvoidArea(type, (err: BusinessError, data) => { 7826 const errCode: number = err.code; 7827 if (errCode) { 7828 console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`); 7829 return; 7830 } 7831 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 7832}); 7833``` 7834 7835### getAvoidArea<sup>(deprecated)</sup> 7836 7837getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise<[AvoidArea](#avoidarea7)> 7838 7839获取当前窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 7840 7841> **说明:** 7842> 7843> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。 7844 7845**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7846 7847**参数:** 7848 7849| 参数名 | 类型 | 必填 | 说明 | 7850| ------ |----------------------------------| ---- | ------------------------------------------------------------ | 7851| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。 | 7852 7853**返回值:** 7854 7855| 类型 | 说明 | 7856|-----------------------------------------| ----------------------------------- | 7857| Promise<[AvoidArea](#avoidarea7)> | Promise对象。返回窗口内容规避区域。 | 7858 7859**示例:** 7860 7861```ts 7862import { BusinessError } from '@kit.BasicServicesKit'; 7863 7864let type = window.AvoidAreaType.TYPE_SYSTEM; 7865let promise = windowClass.getAvoidArea(type); 7866promise.then((data) => { 7867 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 7868}).catch((err: BusinessError) => { 7869 console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`); 7870}); 7871``` 7872 7873### setFullScreen<sup>(deprecated)</sup> 7874 7875setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void 7876 7877设置主窗口或子窗口的布局是否为全屏布局,使用callback异步回调。 7878全屏布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 7879非全屏布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 7880 7881> **说明:** 7882> 7883> 从 API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)实现全屏。 7884 7885**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7886 7887**参数:** 7888 7889| 参数名 | 类型 | 必填 | 说明 | 7890| ------------ | ------------------------- | ---- | ---------------------------------------------- | 7891| isFullScreen | boolean | 是 | 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。 | 7892| callback | AsyncCallback<void> | 是 | 回调函数。 | 7893 7894**示例:** 7895 7896```ts 7897// EntryAbility.ets 7898import { UIAbility } from '@kit.AbilityKit'; 7899import { BusinessError } from '@kit.BasicServicesKit'; 7900 7901export default class EntryAbility extends UIAbility { 7902 // ... 7903 onWindowStageCreate(windowStage: window.WindowStage): void { 7904 console.info('onWindowStageCreate'); 7905 let windowClass: window.Window | undefined = undefined; 7906 windowStage.getMainWindow((err: BusinessError, data) => { 7907 const errCode: number = err.code; 7908 if (errCode) { 7909 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7910 return; 7911 } 7912 windowClass = data; 7913 let isFullScreen: boolean = true; 7914 windowClass.setFullScreen(isFullScreen, (err: BusinessError) => { 7915 const errCode: number = err.code; 7916 if (errCode) { 7917 console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 7918 return; 7919 } 7920 console.info('Succeeded in enabling the full-screen mode.'); 7921 }); 7922 }); 7923 } 7924} 7925``` 7926 7927### setFullScreen<sup>(deprecated)</sup> 7928 7929setFullScreen(isFullScreen: boolean): Promise<void> 7930 7931设置主窗口或子窗口的布局是否为全屏布局,使用Promise异步回调。 7932全屏布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 7933非全屏布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 7934 7935> **说明:** 7936> 7937> 从 API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)实现全屏。 7938 7939**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7940 7941**参数:** 7942 7943| 参数名 | 类型 | 必填 | 说明 | 7944| ------------ | ------- | ---- | ---------------------------------------------- | 7945| isFullScreen | boolean | 是 | 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。 | 7946 7947**返回值:** 7948 7949| 类型 | 说明 | 7950| ------------------- | ------------------------- | 7951| Promise<void> | 无返回结果的Promise对象。 | 7952 7953**示例:** 7954 7955```ts 7956// EntryAbility.ets 7957import { UIAbility } from '@kit.AbilityKit'; 7958import { BusinessError } from '@kit.BasicServicesKit'; 7959 7960export default class EntryAbility extends UIAbility { 7961 // ... 7962 onWindowStageCreate(windowStage: window.WindowStage): void { 7963 console.info('onWindowStageCreate'); 7964 let windowClass: window.Window | undefined = undefined; 7965 windowStage.getMainWindow((err: BusinessError, data) => { 7966 const errCode: number = err.code; 7967 if (errCode) { 7968 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7969 return; 7970 } 7971 windowClass = data; 7972 let isFullScreen: boolean = true; 7973 let promise = windowClass.setFullScreen(isFullScreen); 7974 promise.then(() => { 7975 console.info('Succeeded in enabling the full-screen mode.'); 7976 }).catch((err: BusinessError) => { 7977 console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 7978 }); 7979 }); 7980 } 7981} 7982``` 7983 7984### setLayoutFullScreen<sup>(deprecated)</sup> 7985 7986setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 7987 7988设置主窗口或子窗口的布局是否为沉浸式布局,使用callback异步回调。 7989沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 7990非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 7991 7992> **说明:** 7993> 7994> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)。 7995 7996**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7997 7998**参数:** 7999 8000| 参数名 | 类型 | 必填 | 说明 | 8001| ------------------ | ------------------------- | ---- | ------------------------------------------------------------ | 8002| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 8003| callback | AsyncCallback<void> | 是 | 回调函数。 | 8004 8005**示例:** 8006 8007```ts 8008// EntryAbility.ets 8009import { UIAbility } from '@kit.AbilityKit'; 8010import { BusinessError } from '@kit.BasicServicesKit'; 8011 8012export default class EntryAbility extends UIAbility { 8013 // ... 8014 onWindowStageCreate(windowStage: window.WindowStage): void { 8015 console.info('onWindowStageCreate'); 8016 let windowClass: window.Window | undefined = undefined; 8017 windowStage.getMainWindow((err: BusinessError, data) => { 8018 const errCode: number = err.code; 8019 if (errCode) { 8020 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8021 return; 8022 } 8023 windowClass = data; 8024 let isLayoutFullScreen: boolean = true; 8025 windowClass.setLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 8026 const errCode: number = err.code; 8027 if (errCode) { 8028 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 8029 return; 8030 } 8031 console.info('Succeeded in setting the window layout to full-screen mode.'); 8032 }); 8033 }); 8034 } 8035} 8036``` 8037 8038### setLayoutFullScreen<sup>(deprecated)</sup> 8039 8040setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 8041 8042设置主窗口或子窗口的布局是否为沉浸式布局,使用Promise异步回调。 8043沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 8044非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 8045 8046> **说明:** 8047> 8048> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)。 8049 8050**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8051 8052**参数:** 8053 8054| 参数名 | 类型 | 必填 | 说明 | 8055| ------------------ | ------- | ---- | ------------------------------------------------------------ | 8056| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 8057 8058**返回值:** 8059 8060| 类型 | 说明 | 8061| ------------------- | ------------------------- | 8062| Promise<void> | 无返回结果的Promise对象。 | 8063 8064**示例:** 8065 8066```ts 8067// EntryAbility.ets 8068import { UIAbility } from '@kit.AbilityKit'; 8069import { BusinessError } from '@kit.BasicServicesKit'; 8070 8071export default class EntryAbility extends UIAbility { 8072 // ... 8073 onWindowStageCreate(windowStage: window.WindowStage): void { 8074 console.info('onWindowStageCreate'); 8075 let windowClass: window.Window | undefined = undefined; 8076 windowStage.getMainWindow((err: BusinessError, data) => { 8077 const errCode: number = err.code; 8078 if (errCode) { 8079 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8080 return; 8081 } 8082 windowClass = data; 8083 let isLayoutFullScreen: boolean = true; 8084 let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen); 8085 promise.then(() => { 8086 console.info('Succeeded in setting the window layout to full-screen mode.'); 8087 }).catch((err: BusinessError) => { 8088 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 8089 }); 8090 }); 8091 } 8092} 8093``` 8094 8095### setSystemBarEnable<sup>(deprecated)</sup> 8096 8097setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 8098 8099设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用callback异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 8100 8101调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。 8102 8103> **说明:** 8104> 8105> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)。 8106 8107**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8108 8109**参数:** 8110 8111| 参数名 | 类型 | 必填 | 说明 | 8112| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 8113| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 8114| callback | AsyncCallback<void> | 是 | 回调函数。 | 8115 8116 8117**示例:** 8118 8119```ts 8120// 此处以不显示三键导航栏、状态栏、底部导航条为例 8121// EntryAbility.ets 8122import { UIAbility } from '@kit.AbilityKit'; 8123import { BusinessError } from '@kit.BasicServicesKit'; 8124 8125export default class EntryAbility extends UIAbility { 8126 // ... 8127 onWindowStageCreate(windowStage: window.WindowStage): void { 8128 console.info('onWindowStageCreate'); 8129 let windowClass: window.Window | undefined = undefined; 8130 windowStage.getMainWindow((err: BusinessError, data) => { 8131 const errCode: number = err.code; 8132 if (errCode) { 8133 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8134 return; 8135 } 8136 windowClass = data; 8137 let names: Array<'status' | 'navigation'> = []; 8138 windowClass.setSystemBarEnable(names, (err: BusinessError) => { 8139 const errCode: number = err.code; 8140 if (errCode) { 8141 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 8142 return; 8143 } 8144 console.info('Succeeded in setting the system bar to be invisible.'); 8145 }); 8146 }); 8147 } 8148} 8149``` 8150 8151### setSystemBarEnable<sup>(deprecated)</sup> 8152 8153setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 8154 8155设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 8156 8157调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。 8158 8159> **说明:** 8160> 8161> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)。 8162 8163**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8164 8165**参数:** 8166 8167| 参数名 | 类型 | 必填 | 说明 | 8168| ------ | ---------------------------- | ---- | ------------------------ | 8169| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏、底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 8170 8171**返回值:** 8172 8173| 类型 | 说明 | 8174| ------------------- | ------------------------- | 8175| Promise<void> | 无返回结果的Promise对象。 | 8176 8177 8178**示例:** 8179 8180```ts 8181// 此处以不显示三键导航栏、状态栏、底部导航条为例 8182// EntryAbility.ets 8183import { UIAbility } from '@kit.AbilityKit'; 8184import { BusinessError } from '@kit.BasicServicesKit'; 8185 8186export default class EntryAbility extends UIAbility { 8187 // ... 8188 onWindowStageCreate(windowStage: window.WindowStage): void { 8189 console.info('onWindowStageCreate'); 8190 let windowClass: window.Window | undefined = undefined; 8191 windowStage.getMainWindow((err: BusinessError, data) => { 8192 const errCode: number = err.code; 8193 if (errCode) { 8194 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8195 return; 8196 } 8197 windowClass = data; 8198 let names: Array<'status' | 'navigation'> = []; 8199 let promise = windowClass.setSystemBarEnable(names); 8200 promise.then(() => { 8201 console.info('Succeeded in setting the system bar to be invisible.'); 8202 }).catch((err: BusinessError) => { 8203 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 8204 }); 8205 }); 8206 } 8207} 8208``` 8209 8210### setSystemBarProperties<sup>(deprecated)</sup> 8211 8212setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 8213 8214设置主窗口三键导航栏、状态栏的属性,使用callback异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 8215 8216子窗口调用后不生效。 8217 8218> **说明:** 8219> 8220> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9)。 8221 8222**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8223 8224**参数:** 8225 8226| 参数名 | 类型 | 必填 | 说明 | 8227| ------------------- | ------------------------------------------- | ---- | ---------------------- | 8228| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 三键导航栏、状态栏的属性。 | 8229| callback | AsyncCallback<void> | 是 | 回调函数。 | 8230 8231**示例:** 8232 8233```ts 8234// EntryAbility.ets 8235import { UIAbility } from '@kit.AbilityKit'; 8236import { BusinessError } from '@kit.BasicServicesKit'; 8237 8238export default class EntryAbility extends UIAbility { 8239 // ... 8240 onWindowStageCreate(windowStage: window.WindowStage): void { 8241 console.info('onWindowStageCreate'); 8242 let windowClass: window.Window | undefined = undefined; 8243 windowStage.getMainWindow((err: BusinessError, data) => { 8244 const errCode: number = err.code; 8245 if (errCode) { 8246 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8247 return; 8248 } 8249 windowClass = data; 8250 let SystemBarProperties: window.SystemBarProperties = { 8251 statusBarColor: '#ff00ff', 8252 navigationBarColor: '#00ff00', 8253 //以下两个属性从API Version8开始支持 8254 statusBarContentColor: '#ffffff', 8255 navigationBarContentColor: '#00ffff' 8256 }; 8257 windowClass.setSystemBarProperties(SystemBarProperties, (err) => { 8258 const errCode: number = err.code; 8259 if (errCode) { 8260 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 8261 return; 8262 } 8263 console.info('Succeeded in setting the system bar properties.'); 8264 }); 8265 }); 8266 } 8267} 8268``` 8269 8270### setSystemBarProperties<sup>(deprecated)</sup> 8271 8272setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 8273 8274设置主窗口三键导航栏、状态栏的属性,使用Promise异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 8275 8276子窗口调用后不生效。 8277 8278> **说明:** 8279> 8280> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9-1)。 8281 8282**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8283 8284**参数:** 8285 8286| 参数名 | 类型 | 必填 | 说明 | 8287| ------------------- | ------------------------------------------- | ---- | ---------------------- | 8288| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 三键导航栏、状态栏的属性。 | 8289 8290**返回值:** 8291 8292| 类型 | 说明 | 8293| ------------------- | ------------------------- | 8294| Promise<void> | 无返回结果的Promise对象。 | 8295 8296**示例:** 8297 8298```ts 8299// EntryAbility.ets 8300import { UIAbility } from '@kit.AbilityKit'; 8301import { BusinessError } from '@kit.BasicServicesKit'; 8302 8303export default class EntryAbility extends UIAbility { 8304 // ... 8305 onWindowStageCreate(windowStage: window.WindowStage): void { 8306 console.info('onWindowStageCreate'); 8307 let windowClass: window.Window | undefined = undefined; 8308 windowStage.getMainWindow((err: BusinessError, data) => { 8309 const errCode: number = err.code; 8310 if (errCode) { 8311 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8312 return; 8313 } 8314 windowClass = data; 8315 let SystemBarProperties: window.SystemBarProperties = { 8316 statusBarColor: '#ff00ff', 8317 navigationBarColor: '#00ff00', 8318 //以下两个属性从API Version8开始支持 8319 statusBarContentColor: '#ffffff', 8320 navigationBarContentColor: '#00ffff' 8321 }; 8322 let promise = windowClass.setSystemBarProperties(SystemBarProperties); 8323 promise.then(() => { 8324 console.info('Succeeded in setting the system bar properties.'); 8325 }).catch((err: BusinessError) => { 8326 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 8327 }); 8328 }); 8329 } 8330} 8331``` 8332 8333### loadContent<sup>(deprecated)</sup> 8334 8335loadContent(path: string, callback: AsyncCallback<void>): void 8336 8337为当前窗口加载具体页面内容,使用callback异步回调。 8338 8339> **说明:** 8340> 8341> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9)。 8342 8343**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8344 8345**参数:** 8346 8347| 参数名 | 类型 | 必填 | 说明 | 8348| -------- | ------------------------- | ---- | -------------------- | 8349| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 8350| callback | AsyncCallback<void> | 是 | 回调函数。 | 8351 8352**示例:** 8353 8354```ts 8355import { BusinessError } from '@kit.BasicServicesKit'; 8356 8357windowClass.loadContent('pages/page2/page3', (err: BusinessError) => { 8358 const errCode: number = err.code; 8359 if (errCode) { 8360 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 8361 return; 8362 } 8363 console.info('Succeeded in loading the content.'); 8364}); 8365``` 8366 8367### loadContent<sup>(deprecated)</sup> 8368 8369loadContent(path: string): Promise<void> 8370 8371为当前窗口加载具体页面内容,使用Promise异步回调。 8372 8373> **说明:** 8374> 8375> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9-1)。 8376 8377**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8378 8379**参数:** 8380 8381| 参数名 | 类型 | 必填 | 说明 | 8382| ------ | ------ | ---- | -------------------- | 8383| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 8384 8385**返回值:** 8386 8387| 类型 | 说明 | 8388| ------------------- | ------------------------- | 8389| Promise<void> | 无返回结果的Promise对象。 | 8390 8391**示例:** 8392 8393```ts 8394import { BusinessError } from '@kit.BasicServicesKit'; 8395 8396let promise = windowClass.loadContent('pages/page2/page3'); 8397promise.then(() => { 8398 console.info('Succeeded in loading the content.'); 8399}).catch((err: BusinessError) => { 8400 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 8401}); 8402``` 8403 8404### isShowing<sup>(deprecated)</sup> 8405 8406isShowing(callback: AsyncCallback<boolean>): void 8407 8408判断当前窗口是否已显示,使用callback异步回调。 8409 8410> **说明:** 8411> 8412> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。 8413 8414**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8415 8416**参数:** 8417 8418| 参数名 | 类型 | 必填 | 说明 | 8419| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 8420| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 | 8421 8422**示例:** 8423 8424```ts 8425import { BusinessError } from '@kit.BasicServicesKit'; 8426 8427windowClass.isShowing((err: BusinessError, data) => { 8428 const errCode: number = err.code; 8429 if (errCode) { 8430 console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`); 8431 return; 8432 } 8433 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 8434}); 8435``` 8436 8437### isShowing<sup>(deprecated)</sup> 8438 8439isShowing(): Promise<boolean> 8440 8441判断当前窗口是否已显示,使用Promise异步回调。 8442 8443> **说明:** 8444> 8445> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。 8446 8447**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8448 8449**返回值:** 8450 8451| 类型 | 说明 | 8452| ---------------------- | ------------------------------------------------------------ | 8453| Promise<boolean> | Promise对象。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 | 8454 8455**示例:** 8456 8457```ts 8458import { BusinessError } from '@kit.BasicServicesKit'; 8459 8460let promise = windowClass.isShowing(); 8461promise.then((data) => { 8462 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 8463}).catch((err: BusinessError) => { 8464 console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`); 8465}); 8466``` 8467 8468### on('systemAvoidAreaChange')<sup>(deprecated)</sup> 8469 8470on(type: 'systemAvoidAreaChange', callback: Callback<AvoidArea>): void 8471 8472开启当前窗口系统规避区变化的监听。 8473 8474> **说明:** 8475> 8476> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[on('avoidAreaChange')](#onavoidareachange9)。 8477 8478**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8479 8480**参数:** 8481 8482| 参数名 | 类型 | 必填 | 说明 | 8483| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 8484| type | string | 是 | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 | 8485| callback | Callback<[AvoidArea](#avoidarea7)> | 是 | 回调函数。返回当前规避区。 | 8486 8487 8488**示例:** 8489 8490```ts 8491windowClass.on('systemAvoidAreaChange', (data) => { 8492 console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data)); 8493}); 8494``` 8495 8496### off('systemAvoidAreaChange')<sup>(deprecated)</sup> 8497 8498off(type: 'systemAvoidAreaChange', callback?: Callback<AvoidArea>): void 8499 8500关闭当前窗口系统规避区变化的监听。 8501 8502> **说明:** 8503> 8504> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[off('avoidAreaChange')](#offavoidareachange9)。 8505 8506**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8507 8508**参数:** 8509 8510| 参数名 | 类型 | 必填 | 说明 | 8511| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 8512| type | string | 是 | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 | 8513| callback | Callback<[AvoidArea](#avoidarea7)> | 否 | 回调函数。返回当前规避区。若传入参数,则关闭该监听。若未传入参数,则关闭所有系统规避区变化的监听。 | 8514 8515**示例:** 8516 8517```ts 8518const callback = (avoidArea: window.AvoidArea) => { 8519 // ... 8520} 8521windowClass.on('systemAvoidAreaChange', callback); 8522windowClass.off('systemAvoidAreaChange', callback); 8523// 如果通过on开启多个callback进行监听,同时关闭所有监听: 8524windowClass.off('systemAvoidAreaChange'); 8525``` 8526 8527### isSupportWideGamut<sup>(deprecated)</sup> 8528 8529isSupportWideGamut(callback: AsyncCallback<boolean>): void 8530 8531判断当前窗口是否支持广色域模式,使用callback异步回调。 8532 8533> **说明:** 8534> 8535> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9)。 8536 8537**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8538 8539**参数:** 8540 8541| 参数名 | 类型 | 必填 | 说明 | 8542| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 8543| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 8544 8545**示例:** 8546 8547```ts 8548import { BusinessError } from '@kit.BasicServicesKit'; 8549 8550windowClass.isSupportWideGamut((err: BusinessError, data) => { 8551 const errCode: number = err.code; 8552 if (errCode) { 8553 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 8554 return; 8555 } 8556 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 8557}); 8558``` 8559 8560### isSupportWideGamut<sup>(deprecated)</sup> 8561 8562isSupportWideGamut(): Promise<boolean> 8563 8564判断当前窗口是否支持广色域模式,使用Promise异步回调。 8565 8566> **说明:** 8567> 8568> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9-1)。 8569 8570**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8571 8572**返回值:** 8573 8574| 类型 | 说明 | 8575| ---------------------- | ------------------------------------------------------------ | 8576| Promise<boolean> | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 8577 8578**示例:** 8579 8580```ts 8581import { BusinessError } from '@kit.BasicServicesKit'; 8582 8583let promise = windowClass.isSupportWideGamut(); 8584promise.then((data) => { 8585 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 8586}).catch((err: BusinessError) => { 8587 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 8588}); 8589``` 8590 8591### setColorSpace<sup>(deprecated)</sup> 8592 8593setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 8594 8595设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。 8596 8597> **说明:** 8598> 8599> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9)。 8600 8601**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8602 8603**参数:** 8604 8605| 参数名 | 类型 | 必填 | 说明 | 8606| ---------- | ------------------------- | ---- | ------------ | 8607| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 8608| callback | AsyncCallback<void> | 是 | 回调函数。 | 8609 8610 8611**示例:** 8612 8613```ts 8614import { BusinessError } from '@kit.BasicServicesKit'; 8615 8616windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 8617 const errCode: number = err.code; 8618 if (errCode) { 8619 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 8620 return; 8621 } 8622 console.info('Succeeded in setting window colorspace.'); 8623}); 8624``` 8625 8626### setColorSpace<sup>(deprecated)</sup> 8627 8628setColorSpace(colorSpace:ColorSpace): Promise<void> 8629 8630设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。 8631 8632> **说明:** 8633> 8634> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9-1)。 8635 8636**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8637 8638**参数:** 8639 8640| 参数名 | 类型 | 必填 | 说明 | 8641| ---------- | ------------------------- | ---- | -------------- | 8642| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 8643 8644**返回值:** 8645 8646| 类型 | 说明 | 8647| ------------------- | ------------------------- | 8648| Promise<void> | 无返回结果的Promise对象。 | 8649 8650 8651**示例:** 8652 8653```ts 8654import { BusinessError } from '@kit.BasicServicesKit'; 8655 8656let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT); 8657promise.then(() => { 8658 console.info('Succeeded in setting window colorspace.'); 8659}).catch((err: BusinessError) => { 8660 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 8661}); 8662``` 8663 8664### getColorSpace<sup>(deprecated)</sup> 8665 8666getColorSpace(callback: AsyncCallback<ColorSpace>): void 8667 8668获取当前窗口色域模式,使用callback异步回调。 8669 8670> **说明:** 8671> 8672> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。 8673 8674**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8675 8676**参数:** 8677 8678| 参数名 | 类型 | 必填 | 说明 | 8679| -------- | ---------------------------------------------- | ---- | ---------------------------------------------------------- | 8680| callback | AsyncCallback<[ColorSpace](#colorspace8)> | 是 | 回调函数。当获取成功,err为undefined,data为当前色域模式。 | 8681 8682**示例:** 8683 8684```ts 8685import { BusinessError } from '@kit.BasicServicesKit'; 8686 8687windowClass.getColorSpace((err: BusinessError, data) => { 8688 const errCode: number = err.code; 8689 if (errCode) { 8690 console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`); 8691 return; 8692 } 8693 console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data)); 8694}); 8695``` 8696 8697### getColorSpace<sup>(deprecated)</sup> 8698 8699getColorSpace(): Promise<ColorSpace> 8700 8701获取当前窗口色域模式,使用Promise异步回调。 8702 8703> **说明:** 8704> 8705> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。 8706 8707**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8708 8709**返回值:** 8710 8711| 类型 | 说明 | 8712| ---------------------------------------- | ------------------------------- | 8713| Promise<[ColorSpace](#colorspace8)> | Promise对象。返回当前色域模式。 | 8714 8715**示例:** 8716 8717```ts 8718import { BusinessError } from '@kit.BasicServicesKit'; 8719 8720let promise = windowClass.getColorSpace(); 8721promise.then((data) => { 8722 console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data)); 8723}).catch((err: BusinessError) => { 8724 console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`); 8725}); 8726``` 8727 8728### setBackgroundColor<sup>(deprecated)</sup> 8729 8730setBackgroundColor(color: string, callback: AsyncCallback<void>): void 8731 8732设置窗口的背景色,使用callback异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 8733 8734> **说明:** 8735> 8736> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。 8737 8738**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8739 8740**参数:** 8741 8742| 参数名 | 类型 | 必填 | 说明 | 8743| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 8744| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 | 8745| callback | AsyncCallback<void> | 是 | 回调函数。 | 8746 8747 8748**示例:** 8749 8750```ts 8751import { BusinessError } from '@kit.BasicServicesKit'; 8752 8753let color: string = '#00ff33'; 8754windowClass.setBackgroundColor(color, (err: BusinessError) => { 8755 const errCode: number = err.code; 8756 if (errCode) { 8757 console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`); 8758 return; 8759 } 8760 console.info('Succeeded in setting the background color.'); 8761}); 8762``` 8763 8764### setBackgroundColor<sup>(deprecated)</sup> 8765 8766setBackgroundColor(color: string): Promise<void> 8767 8768设置窗口的背景色,使用Promise异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 8769 8770> **说明:** 8771> 8772> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。 8773 8774**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8775 8776**参数:** 8777 8778| 参数名 | 类型 | 必填 | 说明 | 8779| ------ | ------ | ---- | ------------------------------------------------------------ | 8780| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 | 8781 8782**返回值:** 8783 8784| 类型 | 说明 | 8785| ------------------- | ------------------------- | 8786| Promise<void> | 无返回结果的Promise对象。 | 8787 8788 8789**示例:** 8790 8791```ts 8792import { BusinessError } from '@kit.BasicServicesKit'; 8793 8794let color: string = '#00ff33'; 8795let promise = windowClass.setBackgroundColor(color); 8796promise.then(() => { 8797 console.info('Succeeded in setting the background color.'); 8798}).catch((err: BusinessError) => { 8799 console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`); 8800}); 8801``` 8802 8803### setBrightness<sup>(deprecated)</sup> 8804 8805setBrightness(brightness: number, callback: AsyncCallback<void>): void 8806 8807允许应用窗口设置屏幕亮度值,使用callback异步回调。 8808 8809当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 8810 8811> **说明:** 8812> 8813> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9)。 8814 8815**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8816 8817**参数:** 8818 8819| 参数名 | 类型 | 必填 | 说明 | 8820| ---------- | ------------------------- | ---- |---------------------------------------| 8821| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 8822| callback | AsyncCallback<void> | 是 | 回调函数。 | 8823 8824 8825**示例:** 8826 8827```ts 8828import { BusinessError } from '@kit.BasicServicesKit'; 8829 8830let brightness: number = 1; 8831windowClass.setBrightness(brightness, (err: BusinessError) => { 8832 const errCode: number = err.code; 8833 if (errCode) { 8834 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 8835 return; 8836 } 8837 console.info('Succeeded in setting the brightness.'); 8838}); 8839``` 8840 8841### setBrightness<sup>(deprecated)</sup> 8842 8843setBrightness(brightness: number): Promise<void> 8844 8845允许应用窗口设置屏幕亮度值,使用Promise异步回调。 8846 8847当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 8848 8849> **说明:** 8850> 8851> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9-1)。 8852 8853**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8854 8855**参数:** 8856 8857| 参数名 | 类型 | 必填 | 说明 | 8858| ---------- | ------ | ---- |------------------------------------------| 8859| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 8860 8861**返回值:** 8862 8863| 类型 | 说明 | 8864| ------------------- | ------------------------- | 8865| Promise<void> | 无返回结果的Promise对象。 | 8866 8867 8868**示例:** 8869 8870```ts 8871import { BusinessError } from '@kit.BasicServicesKit'; 8872 8873let brightness: number = 1; 8874let promise = windowClass.setBrightness(brightness); 8875promise.then(() => { 8876 console.info('Succeeded in setting the brightness.'); 8877}).catch((err: BusinessError) => { 8878 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 8879}); 8880``` 8881 8882### setDimBehind<sup>(deprecated)</sup> 8883 8884setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void 8885 8886窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用callback异步回调。 8887 8888> **说明:** 8889> 8890> 该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。 8891 8892**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8893 8894**参数:** 8895 8896| 参数名 | 类型 | 必填 | 说明 | 8897| -------------- | ------------------------- | ---- |----------------------------------------| 8898| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为[0.0, 1.0],取1.0时表示最暗。 | 8899| callback | AsyncCallback<void> | 是 | 回调函数。 | 8900 8901**示例:** 8902 8903```ts 8904import { BusinessError } from '@kit.BasicServicesKit'; 8905 8906windowClass.setDimBehind(0.5, (err: BusinessError) => { 8907 const errCode: number = err.code; 8908 if (errCode) { 8909 console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`); 8910 return; 8911 } 8912 console.info('Succeeded in setting the dimness.'); 8913}); 8914``` 8915 8916### setDimBehind<sup>(deprecated)</sup> 8917 8918setDimBehind(dimBehindValue: number): Promise<void> 8919 8920窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用Promise异步回调。 8921 8922> **说明:** 8923> 8924> 该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。 8925 8926**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8927 8928**参数:** 8929 8930| 参数名 | 类型 | 必填 | 说明 | 8931| -------------- | ------ | ---- | -------------------------------------------------- | 8932| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 | 8933 8934**返回值:** 8935 8936| 类型 | 说明 | 8937| ------------------- | ------------------------- | 8938| Promise<void> | 无返回结果的Promise对象。 | 8939 8940**示例:** 8941 8942```ts 8943import { BusinessError } from '@kit.BasicServicesKit'; 8944 8945let promise = windowClass.setDimBehind(0.5); 8946promise.then(() => { 8947 console.info('Succeeded in setting the dimness.'); 8948}).catch((err: BusinessError) => { 8949 console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`); 8950}); 8951``` 8952 8953### setFocusable<sup>(deprecated)</sup> 8954 8955setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 8956 8957设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从操作前的获焦窗口切换到该窗口,使用callback异步回调。 8958 8959> **说明:** 8960> 8961> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9)。 8962 8963**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8964 8965**参数:** 8966 8967| 参数名 | 类型 | 必填 | 说明 | 8968| ----------- | ------------------------- | ---- | ---------------------------- | 8969| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 8970| callback | AsyncCallback<void> | 是 | 回调函数。 | 8971 8972 8973**示例:** 8974 8975```ts 8976import { BusinessError } from '@kit.BasicServicesKit'; 8977 8978let isFocusable: boolean = true; 8979windowClass.setFocusable(isFocusable, (err: BusinessError) => { 8980 const errCode: number = err.code; 8981 if (errCode) { 8982 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 8983 return; 8984 } 8985 console.info('Succeeded in setting the window to be focusable.'); 8986}); 8987``` 8988 8989### setFocusable<sup>(deprecated)</sup> 8990 8991setFocusable(isFocusable: boolean): Promise<void> 8992 8993设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用Promise异步回调。 8994 8995> **说明:** 8996> 8997> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9-1)。 8998 8999**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9000 9001**参数:** 9002 9003| 参数名 | 类型 | 必填 | 说明 | 9004| ----------- | ------- | ---- | ---------------------------- | 9005| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 9006 9007**返回值:** 9008 9009| 类型 | 说明 | 9010| ------------------- | ------------------------- | 9011| Promise<void> | 无返回结果的Promise对象。 | 9012 9013 9014**示例:** 9015 9016```ts 9017import { BusinessError } from '@kit.BasicServicesKit'; 9018 9019let isFocusable: boolean = true; 9020let promise = windowClass.setFocusable(isFocusable); 9021promise.then(() => { 9022 console.info('Succeeded in setting the window to be focusable.'); 9023}).catch((err: BusinessError) => { 9024 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 9025}); 9026``` 9027 9028### setKeepScreenOn<sup>(deprecated)</sup> 9029 9030setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 9031 9032设置屏幕是否为常亮状态,使用callback异步回调。 9033 9034> **说明:** 9035> 9036> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9)。 9037 9038**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9039 9040**参数:** 9041 9042| 参数名 | 类型 | 必填 | 说明 | 9043| -------------- | ------------------------- | ---- | ------------------------ | 9044| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 9045| callback | AsyncCallback<void> | 是 | 回调函数。 | 9046 9047 9048**示例:** 9049 9050```ts 9051import { BusinessError } from '@kit.BasicServicesKit'; 9052 9053let isKeepScreenOn: boolean = true; 9054windowClass.setKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 9055 const errCode: number = err.code; 9056 if (errCode) { 9057 console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 9058 return; 9059 } 9060 console.info('Succeeded in setting the screen to be always on.'); 9061}); 9062``` 9063 9064### setKeepScreenOn<sup>(deprecated)</sup> 9065 9066setKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 9067 9068设置屏幕是否为常亮状态,使用Promise异步回调。 9069 9070> **说明:** 9071> 9072> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9-1)。 9073 9074**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9075 9076**参数:** 9077 9078| 参数名 | 类型 | 必填 | 说明 | 9079| -------------- | ------- | ---- | ------------------------ | 9080| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 9081 9082**返回值:** 9083 9084| 类型 | 说明 | 9085| ------------------- | ------------------------- | 9086| Promise<void> | 无返回结果的Promise对象。 | 9087 9088**示例:** 9089 9090```ts 9091import { BusinessError } from '@kit.BasicServicesKit'; 9092 9093let isKeepScreenOn: boolean = true; 9094let promise = windowClass.setKeepScreenOn(isKeepScreenOn); 9095promise.then(() => { 9096 console.info('Succeeded in setting the screen to be always on.'); 9097}).catch((err: BusinessError) => { 9098 console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 9099}); 9100``` 9101 9102### setOutsideTouchable<sup>(deprecated)</sup> 9103 9104setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void 9105 9106设置是否允许可点击子窗口之外的区域,使用callback异步回调。 9107 9108> **说明:** 9109> 9110> 从 API version 7开始支持,从API version 9开始废弃。 9111> 9112> 从 API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。 9113 9114**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9115 9116**参数:** 9117 9118| 参数名 | 类型 | 必填 | 说明 | 9119| --------- | ------------------------- | ---- | ---------------- | 9120| touchable | boolean | 是 | 设置是否可点击。true表示可点击;false表示不可点击。 | 9121| callback | AsyncCallback<void> | 是 | 回调函数。 | 9122 9123**示例:** 9124 9125```ts 9126import { BusinessError } from '@kit.BasicServicesKit'; 9127 9128windowClass.setOutsideTouchable(true, (err: BusinessError) => { 9129 const errCode: number = err.code; 9130 if (errCode) { 9131 console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`); 9132 return; 9133 } 9134 console.info('Succeeded in setting the area to be touchable.'); 9135}); 9136``` 9137 9138### setOutsideTouchable<sup>(deprecated)</sup> 9139 9140setOutsideTouchable(touchable: boolean): Promise<void> 9141 9142设置是否允许可点击子窗口之外的区域,使用Promise异步回调。 9143 9144> **说明:** 9145> 9146> 从 API version 7开始支持,从API version 9开始废弃。 9147> 9148> 从 API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。 9149 9150**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9151 9152**参数:** 9153 9154| 参数名 | 类型 | 必填 | 说明 | 9155| --------- | ------- | ---- | ---------------- | 9156| touchable | boolean | 是 | 设置是否可点击。true表示可点击;false表示不可点击。 | 9157 9158**返回值:** 9159 9160| 类型 | 说明 | 9161| ------------------- | ------------------------- | 9162| Promise<void> | 无返回结果的Promise对象。 | 9163 9164**示例:** 9165 9166```ts 9167import { BusinessError } from '@kit.BasicServicesKit'; 9168 9169let promise = windowClass.setOutsideTouchable(true); 9170promise.then(() => { 9171 console.info('Succeeded in setting the area to be touchable.'); 9172}).catch((err: BusinessError) => { 9173 console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`); 9174}); 9175``` 9176 9177### setPrivacyMode<sup>(deprecated)</sup> 9178 9179setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 9180 9181设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 9182 9183> **说明:** 9184> 9185> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9)。 9186 9187**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9188 9189**参数:** 9190 9191| 参数名 | 类型 | 必填 | 说明 | 9192| ------------- | ------------------------- | ---- | -------------------- | 9193| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 9194| callback | AsyncCallback<void> | 是 | 回调函数。 | 9195 9196**示例:** 9197 9198```ts 9199import { BusinessError } from '@kit.BasicServicesKit'; 9200 9201let isPrivacyMode: boolean = true; 9202windowClass.setPrivacyMode(isPrivacyMode, (err: BusinessError) => { 9203 const errCode: number = err.code; 9204 if (errCode) { 9205 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 9206 return; 9207 } 9208 console.info('Succeeded in setting the window to privacy mode.'); 9209}); 9210``` 9211 9212### setPrivacyMode<sup>(deprecated)</sup> 9213 9214setPrivacyMode(isPrivacyMode: boolean): Promise<void> 9215 9216设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 9217 9218> **说明:** 9219> 9220> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9-1)。 9221 9222**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9223 9224**参数:** 9225 9226| 参数名 | 类型 | 必填 | 说明 | 9227| ------------- | ------- | ---- | -------------------- | 9228| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 9229 9230**返回值:** 9231 9232| 类型 | 说明 | 9233| ------------------- | ------------------------- | 9234| Promise<void> | 无返回结果的Promise对象。 | 9235 9236**示例:** 9237 9238```ts 9239import { BusinessError } from '@kit.BasicServicesKit'; 9240 9241let isPrivacyMode: boolean = true; 9242let promise = windowClass.setPrivacyMode(isPrivacyMode); 9243promise.then(() => { 9244 console.info('Succeeded in setting the window to privacy mode.'); 9245}).catch((err: BusinessError) => { 9246 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 9247}); 9248``` 9249 9250### setTouchable<sup>(deprecated)</sup> 9251 9252setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 9253 9254设置窗口是否为可触状态,使用callback异步回调。 9255 9256> **说明:** 9257> 9258> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9)。 9259 9260**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9261 9262**参数:** 9263 9264| 参数名 | 类型 | 必填 | 说明 | 9265| ----------- | ------------------------- | ---- | -------------------- | 9266| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 9267| callback | AsyncCallback<void> | 是 | 回调函数。 | 9268 9269 9270**示例:** 9271 9272```ts 9273import { BusinessError } from '@kit.BasicServicesKit'; 9274 9275let isTouchable = true; 9276windowClass.setTouchable(isTouchable, (err: BusinessError) => { 9277 const errCode: number = err.code; 9278 if (errCode) { 9279 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 9280 return; 9281 } 9282 console.info('Succeeded in setting the window to be touchable.'); 9283}); 9284``` 9285 9286### setTouchable<sup>(deprecated)</sup> 9287 9288setTouchable(isTouchable: boolean): Promise<void> 9289 9290设置窗口是否为可触状态,使用Promise异步回调。 9291 9292> **说明:** 9293> 9294> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9-1)。 9295 9296**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9297 9298**参数:** 9299 9300| 参数名 | 类型 | 必填 | 说明 | 9301| ----------- | ------- | ---- | -------------------- | 9302| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 9303 9304**返回值:** 9305 9306| 类型 | 说明 | 9307| ------------------- | ------------------------- | 9308| Promise<void> | 无返回结果的Promise对象。 | 9309 9310 9311**示例:** 9312 9313```ts 9314import { BusinessError } from '@kit.BasicServicesKit'; 9315 9316let isTouchable = true; 9317let promise = windowClass.setTouchable(isTouchable); 9318promise.then(() => { 9319 console.info('Succeeded in setting the window to be touchable.'); 9320}).catch((err: BusinessError) => { 9321 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 9322}); 9323``` 9324 9325## WindowStageEventType<sup>9+</sup> 9326 9327WindowStage生命周期。 9328 9329**模型约束:** 此接口仅可在Stage模型下使用。 9330 9331**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9332 9333**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 9334 9335| 名称 | 值 | 说明 | 9336| ---------- | ------ | ---------- | 9337| SHOWN | 1 | 切到前台,例如点击应用图标启动,无论是首次启动还是从后台启动均会触发。 | 9338| ACTIVE | 2 | 获焦状态,例如应用窗口处理点击事件后的状态、应用启动后的状态。 | 9339| INACTIVE | 3 | 失焦状态,例如打开新应用或点击其他窗口后,原获焦窗口的状态。 | 9340| HIDDEN | 4 | 切到后台,例如应用上滑退出、应用窗口关闭。 | 9341| RESUMED<sup>11+</sup> | 5 | 前台可交互状态,例如应用打开后,可以与用户交互的状态。 | 9342| PAUSED<sup>11+</sup> | 6 | 前台不可交互状态,例如从屏幕底部上划,应用进入到多任务界面后的状态。 | 9343 9344## ModalityType<sup>14+</sup> 9345 9346子窗口模态类型枚举。 9347 9348**系统能力:** SystemCapability.Window.SessionManager 9349 9350**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 9351 9352| 名称 | 值 | 说明 | 9353| -------------------- | ------ | ---------- | 9354| WINDOW_MODALITY | 0 | 模态子窗类型为模窗口子窗,当仅需要其父级窗口不响应用户操作时,可选此参数。 | 9355| APPLICATION_MODALITY | 1 | 模态子窗类型为模应用子窗,除其父级窗口外还需要该应用其他实例的窗口不响应用户操作时,可选此参数。<br> 此接口仅支持在2in1设备下使用。 | 9356 9357## SubWindowOptions<sup>11+</sup> 9358 9359子窗口创建参数。 9360 9361**系统能力:** SystemCapability.Window.SessionManager 9362 9363| 名称 | 类型 | 只读 | 可选 | 说明 | 9364| ---------- | ---- | ---- | ---- | ----------- | 9365| title<sup>11+</sup> | string | 否 | 否 | 子窗口标题。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 9366| decorEnabled<sup>11+</sup> | boolean | 否 | 否 | 子窗口是否显示装饰。true表示子窗口显示装饰,false表示子窗口不显示装饰。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 9367| isModal<sup>12+</sup> | boolean | 否 | 是 | 子窗口是否启用模态属性。true表示子窗口启用模态属性,false表示子窗口禁用模态属性。不设置,则默认为false。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 9368| modalityType<sup>14+</sup> | [ModalityType](#modalitytype14) | 否 | 是 | 子窗口模态类型,仅当子窗口启用模态属性时生效。WINDOW_MODALITY表示子窗口模态类型为模窗口子窗,APPLICATION_MODALITY表示子窗口模态类型为模应用子窗。不设置,则默认为WINDOW_MODALITY。<br>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 | 9369 9370## WindowStage<sup>9+</sup> 9371 9372窗口管理器。管理各个基本窗口单元,即[Window](#window)实例。 9373 9374下列API示例中都需在[onWindowStageCreate()](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate)函数中使用WindowStage的实例调用对应方法。 9375 9376### getMainWindow<sup>9+</sup> 9377 9378getMainWindow(callback: AsyncCallback<Window>): void 9379 9380获取该WindowStage实例下的主窗口,使用callback异步回调。 9381 9382**模型约束:** 此接口仅可在Stage模型下使用。 9383 9384**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9385 9386**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 9387 9388**参数:** 9389 9390| 参数名 | 类型 | 必填 | 说明 | 9391| -------- | -------------------------------------- | ---- | --------------------------------------------- | 9392| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前WindowStage下的主窗口对象。 | 9393 9394**错误码:** 9395 9396以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 9397 9398| 错误码ID | 错误信息 | 9399| ------- | ------------------------------ | 9400| 1300002 | This window state is abnormal. | 9401| 1300005 | This window stage is abnormal. | 9402 9403**示例:** 9404 9405```ts 9406// EntryAbility.ets 9407import { UIAbility } from '@kit.AbilityKit'; 9408import { BusinessError } from '@kit.BasicServicesKit'; 9409 9410export default class EntryAbility extends UIAbility { 9411 // ... 9412 9413 onWindowStageCreate(windowStage: window.WindowStage) { 9414 console.log('onWindowStageCreate'); 9415 let windowClass: window.Window | undefined = undefined; 9416 windowStage.getMainWindow((err: BusinessError, data) => { 9417 const errCode: number = err.code; 9418 if (errCode) { 9419 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9420 return; 9421 } 9422 windowClass = data; 9423 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 9424 }); 9425 } 9426}; 9427``` 9428 9429### getMainWindow<sup>9+</sup> 9430 9431getMainWindow(): Promise<Window> 9432 9433获取该WindowStage实例下的主窗口,使用Promise异步回调。 9434 9435**模型约束:** 此接口仅可在Stage模型下使用。 9436 9437**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9438 9439**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 9440 9441**返回值:** 9442 9443| 类型 | 说明 | 9444| -------------------------------- | ------------------------------------------------ | 9445| Promise<[Window](#window)> | Promise对象。返回当前WindowStage下的主窗口对象。 | 9446 9447**错误码:** 9448 9449以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 9450 9451| 错误码ID | 错误信息 | 9452| ------- | ------------------------------ | 9453| 1300002 | This window state is abnormal. | 9454| 1300005 | This window stage is abnormal. | 9455 9456**示例:** 9457 9458```ts 9459// EntryAbility.ets 9460import { UIAbility } from '@kit.AbilityKit'; 9461import { BusinessError } from '@kit.BasicServicesKit'; 9462 9463export default class EntryAbility extends UIAbility { 9464 // ... 9465 9466 onWindowStageCreate(windowStage: window.WindowStage) { 9467 console.log('onWindowStageCreate'); 9468 let windowClass: window.Window | undefined = undefined; 9469 let promise = windowStage.getMainWindow(); 9470 promise.then((data) => { 9471 windowClass = data; 9472 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 9473 }).catch((err: BusinessError) => { 9474 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9475 }); 9476 } 9477}; 9478``` 9479 9480### getMainWindowSync<sup>9+</sup> 9481 9482getMainWindowSync(): Window 9483 9484获取该WindowStage实例下的主窗口。 9485 9486**模型约束:** 此接口仅可在Stage模型下使用。 9487 9488**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9489 9490**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 9491 9492**返回值:** 9493 9494| 类型 | 说明 | 9495| ----------------- | --------------------------------- | 9496| [Window](#window) | 返回当前WindowStage下的主窗口对象。 | 9497 9498**错误码:** 9499 9500以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 9501 9502| 错误码ID | 错误信息 | 9503| ------- | ------------------------------ | 9504| 1300002 | This window state is abnormal. | 9505| 1300005 | This window stage is abnormal. | 9506 9507**示例:** 9508<!--code_no_check--> 9509```ts 9510// EntryAbility.ets 9511import { UIAbility } from '@kit.AbilityKit'; 9512 9513export default class EntryAbility extends UIAbility { 9514 // ... 9515 9516 onWindowStageCreate(windowStage: window.WindowStage) { 9517 console.log('onWindowStageCreate'); 9518 try { 9519 let windowClass = windowStage.getMainWindowSync(); 9520 } catch (exception) { 9521 console.error(`Failed to obtain the main window. Cause code: ${exception.code}, message: ${exception.message}`); 9522 } 9523 } 9524}; 9525``` 9526 9527### createSubWindow<sup>9+</sup> 9528 9529createSubWindow(name: string, callback: AsyncCallback<Window>): void 9530 9531创建该WindowStage实例下的子窗口,使用callback异步回调。 9532 9533**模型约束:** 此接口仅可在Stage模型下使用。 9534 9535**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9536 9537**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 9538 9539**参数:** 9540 9541| 参数名 | 类型 | 必填 | 说明 | 9542| -------- | -------------------------------------- | ---- | --------------------------------------------- | 9543| name | string | 是 | 子窗口的名字。 | 9544| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前WindowStage下的子窗口对象。 | 9545 9546**错误码:** 9547 9548以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 9549 9550| 错误码ID | 错误信息 | 9551| ------- | ------------------------------ | 9552| 401 | Parameter error. Possible cause: Incorrect parameter types. | 9553| 1300002 | This window state is abnormal. | 9554| 1300005 | This window stage is abnormal. | 9555 9556**示例:** 9557 9558```ts 9559// EntryAbility.ets 9560import { UIAbility } from '@kit.AbilityKit'; 9561import { BusinessError } from '@kit.BasicServicesKit'; 9562 9563export default class EntryAbility extends UIAbility { 9564 // ... 9565 9566 onWindowStageCreate(windowStage: window.WindowStage) { 9567 console.log('onWindowStageCreate'); 9568 let windowClass: window.Window | undefined = undefined; 9569 try { 9570 windowStage.createSubWindow('mySubWindow', (err: BusinessError, data) => { 9571 const errCode: number = err.code; 9572 if (errCode) { 9573 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 9574 return; 9575 } 9576 windowClass = data; 9577 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 9578 if (!windowClass) { 9579 console.info('Failed to load the content. Cause: windowClass is null'); 9580 } 9581 else { 9582 (windowClass as window.Window).resize(500, 1000); 9583 } 9584 }); 9585 } catch (exception) { 9586 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 9587 } 9588 } 9589}; 9590``` 9591 9592### createSubWindow<sup>9+</sup> 9593 9594createSubWindow(name: string): Promise<Window> 9595 9596创建该WindowStage实例下的子窗口,使用Promise异步回调。 9597 9598**模型约束:** 此接口仅可在Stage模型下使用。 9599 9600**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9601 9602**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 9603 9604**参数:** 9605 9606| 参数名 | 类型 | 必填 | 说明 | 9607| ------ | ------ | ---- | -------------- | 9608| name | string | 是 | 子窗口的名字。 | 9609 9610**返回值:** 9611 9612| 类型 | 说明 | 9613| -------------------------------- | ------------------------------------------------ | 9614| Promise<[Window](#window)> | Promise对象。返回当前WindowStage下的子窗口对象。 | 9615 9616**错误码:** 9617 9618以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 9619 9620| 错误码ID | 错误信息 | 9621| ------- | ------------------------------ | 9622| 401 | Parameter error. Possible cause: Incorrect parameter types. | 9623| 1300002 | This window state is abnormal. | 9624| 1300005 | This window stage is abnormal. | 9625 9626**示例:** 9627 9628```ts 9629// EntryAbility.ets 9630import { UIAbility } from '@kit.AbilityKit'; 9631import { BusinessError } from '@kit.BasicServicesKit'; 9632 9633export default class EntryAbility extends UIAbility { 9634 // ... 9635 9636 onWindowStageCreate(windowStage: window.WindowStage) { 9637 console.log('onWindowStageCreate'); 9638 let windowClass: window.Window | undefined = undefined; 9639 try { 9640 let promise = windowStage.createSubWindow('mySubWindow'); 9641 promise.then((data) => { 9642 windowClass = data; 9643 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 9644 }).catch((err: BusinessError) => { 9645 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 9646 }); 9647 } catch (exception) { 9648 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 9649 } 9650 } 9651}; 9652``` 9653 9654### createSubWindowWithOptions<sup>11+</sup> 9655 9656createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise<Window> 9657 9658创建该WindowStage实例下的子窗口,使用Promise异步回调。 9659 9660**模型约束:** 此接口仅可在Stage模型下使用。 9661 9662**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 9663 9664**系统能力:** SystemCapability.Window.SessionManager 9665 9666**参数:** 9667 9668| 参数名 | 类型 | 必填 | 说明 | 9669| ------ | ------ | ---- | -------------- | 9670| name | string | 是 | 子窗口的名字。 | 9671| options | [SubWindowOptions](#subwindowoptions11) | 是 | 子窗口参数。 | 9672 9673**返回值:** 9674 9675| 类型 | 说明 | 9676| -------------------------------- | ------------------------------------------------ | 9677| Promise<[Window](#window)> | Promise对象。返回当前WindowStage下创建的子窗口对象。 | 9678 9679**错误码:** 9680 9681以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 9682 9683| 错误码ID | 错误信息 | 9684| ------- | ------------------------------ | 9685| 401 | Parameter error. Possible cause: Incorrect parameter types. | 9686| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 9687| 1300002 | This window state is abnormal. | 9688| 1300005 | This window stage is abnormal. | 9689 9690**示例:** 9691 9692```ts 9693// EntryAbility.ets 9694import { UIAbility } from '@kit.AbilityKit'; 9695import { BusinessError } from '@kit.BasicServicesKit'; 9696 9697export default class EntryAbility extends UIAbility { 9698 // ... 9699 9700 onWindowStageCreate(windowStage: window.WindowStage) { 9701 console.info('onWindowStageCreate'); 9702 let windowClass: window.Window | undefined = undefined; 9703 try { 9704 let options : window.SubWindowOptions = { 9705 title: 'title', 9706 decorEnabled: true 9707 }; 9708 let promise = windowStage.createSubWindowWithOptions('mySubWindow', options); 9709 promise.then((data) => { 9710 windowClass = data; 9711 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 9712 }).catch((err: BusinessError) => { 9713 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 9714 }); 9715 } catch (exception) { 9716 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 9717 } 9718 } 9719}; 9720``` 9721 9722### getSubWindow<sup>9+</sup> 9723 9724getSubWindow(callback: AsyncCallback<Array<Window>>): void 9725 9726获取该WindowStage实例下的所有子窗口,使用callback异步回调。 9727 9728**模型约束:** 此接口仅可在Stage模型下使用。 9729 9730**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9731 9732**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 9733 9734**参数:** 9735 9736| 参数名 | 类型 | 必填 | 说明 | 9737| -------- | --------------------------------------------------- | ---- | ------------------------------------------------- | 9738| callback | AsyncCallback<Array<[Window](#window)>> | 是 | 回调函数。返回当前WindowStage下的所有子窗口对象。 | 9739 9740**错误码:** 9741 9742以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 9743 9744| 错误码ID | 错误信息 | 9745| ------- | ------------------------------ | 9746| 1300005 | This window stage is abnormal. | 9747 9748**示例:** 9749<!--code_no_check--> 9750```ts 9751// EntryAbility.ets 9752import { UIAbility } from '@kit.AbilityKit'; 9753import { BusinessError } from '@kit.BasicServicesKit'; 9754 9755export default class EntryAbility extends UIAbility { 9756 // ... 9757 9758 onWindowStageCreate(windowStage: window.WindowStage) { 9759 console.log('onWindowStageCreate'); 9760 let windowClass: window.Window[] = []; 9761 windowStage.getSubWindow((err: BusinessError, data) => { 9762 const errCode: number = err.code; 9763 if (errCode) { 9764 console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`); 9765 return; 9766 } 9767 windowClass = data; 9768 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 9769 }); 9770 } 9771}; 9772``` 9773 9774### getSubWindow<sup>9+</sup> 9775 9776getSubWindow(): Promise<Array<Window>> 9777 9778获取该WindowStage实例下的所有子窗口,使用Promise异步回调。 9779 9780**模型约束:** 此接口仅可在Stage模型下使用。 9781 9782**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9783 9784**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 9785 9786**返回值:** 9787 9788| 类型 | 说明 | 9789| --------------------------------------------- | ---------------------------------------------------- | 9790| Promise<Array<[Window](#window)>> | Promise对象。返回当前WindowStage下的所有子窗口对象。 | 9791 9792**错误码:** 9793 9794以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 9795 9796| 错误码ID | 错误信息 | 9797| ------- | ------------------------------ | 9798| 1300005 | This window stage is abnormal. | 9799 9800**示例:** 9801<!--code_no_check--> 9802```ts 9803// EntryAbility.ets 9804import { UIAbility } from '@kit.AbilityKit'; 9805import { BusinessError } from '@kit.BasicServicesKit'; 9806 9807export default class EntryAbility extends UIAbility { 9808 // ... 9809 9810 onWindowStageCreate(windowStage: window.WindowStage) { 9811 console.log('onWindowStageCreate'); 9812 let windowClass: window.Window[] = []; 9813 let promise = windowStage.getSubWindow(); 9814 promise.then((data) => { 9815 windowClass = data; 9816 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 9817 }).catch((err: BusinessError) => { 9818 console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`); 9819 }); 9820 } 9821}; 9822``` 9823 9824### loadContent<sup>9+</sup> 9825 9826loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 9827 9828为当前WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。 9829 9830**模型约束:** 此接口仅可在Stage模型下使用。 9831 9832**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9833 9834**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 9835 9836**参数:** 9837 9838| 参数名 | 类型 | 必填 | 说明 | 9839| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 9840| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 9841| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 9842| callback | AsyncCallback<void> | 是 | 回调函数。 | 9843 9844**错误码:** 9845 9846以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 9847 9848| 错误码ID | 错误信息 | 9849| ------- | ------------------------------ | 9850| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9851| 1300002 | This window state is abnormal. | 9852| 1300005 | This window stage is abnormal. | 9853 9854**示例:** 9855 9856```ts 9857// EntryAbility.ets 9858import { UIAbility } from '@kit.AbilityKit'; 9859import { BusinessError } from '@kit.BasicServicesKit'; 9860 9861export default class EntryAbility extends UIAbility { 9862 // ... 9863 9864 storage: LocalStorage = new LocalStorage(); 9865 9866 onWindowStageCreate(windowStage: window.WindowStage) { 9867 this.storage.setOrCreate('storageSimpleProp', 121); 9868 console.log('onWindowStageCreate'); 9869 try { 9870 windowStage.loadContent('pages/page2', this.storage, (err: BusinessError) => { 9871 const errCode: number = err.code; 9872 if (errCode) { 9873 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 9874 return; 9875 } 9876 console.info('Succeeded in loading the content.'); 9877 }); 9878 } catch (exception) { 9879 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 9880 } 9881 } 9882}; 9883``` 9884 9885### loadContent<sup>9+</sup> 9886 9887loadContent(path: string, storage?: LocalStorage): Promise<void> 9888 9889为当前WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。 9890 9891**模型约束:** 此接口仅可在Stage模型下使用。 9892 9893**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9894 9895**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 9896 9897**参数:** 9898 9899| 参数名 | 类型 | 必填 | 说明 | 9900| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 9901| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 9902| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 否 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 9903 9904**返回值:** 9905 9906| 类型 | 说明 | 9907| ------------------- | ------------------------- | 9908| Promise<void> | 无返回结果的Promise对象。 | 9909 9910**错误码:** 9911 9912以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 9913 9914| 错误码ID | 错误信息 | 9915| ------- | ------------------------------ | 9916| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9917| 1300002 | This window state is abnormal. | 9918| 1300005 | This window stage is abnormal. | 9919 9920**示例:** 9921 9922```ts 9923// EntryAbility.ets 9924import { UIAbility } from '@kit.AbilityKit'; 9925import { BusinessError } from '@kit.BasicServicesKit'; 9926 9927export default class EntryAbility extends UIAbility { 9928 // ... 9929 9930 storage: LocalStorage = new LocalStorage(); 9931 9932 onWindowStageCreate(windowStage: window.WindowStage) { 9933 this.storage.setOrCreate('storageSimpleProp', 121); 9934 console.log('onWindowStageCreate'); 9935 try { 9936 let promise = windowStage.loadContent('pages/page2', this.storage); 9937 promise.then(() => { 9938 console.info('Succeeded in loading the content.'); 9939 }).catch((err: BusinessError) => { 9940 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 9941 }); 9942 } catch (exception) { 9943 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 9944 } 9945 ; 9946 } 9947}; 9948``` 9949 9950### loadContent<sup>9+</sup> 9951 9952loadContent(path: string, callback: AsyncCallback<void>): void 9953 9954为当前WindowStage的主窗口加载具体页面内容,使用callback异步回调。 9955 9956**模型约束:** 此接口仅可在Stage模型下使用。 9957 9958**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9959 9960**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 9961 9962**参数:** 9963 9964| 参数名 | 类型 | 必填 | 说明 | 9965| -------- | ------------------------- | ---- | -------------------- | 9966| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 9967| callback | AsyncCallback<void> | 是 | 回调函数。 | 9968 9969**错误码:** 9970 9971以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 9972 9973| 错误码ID | 错误信息 | 9974| ------- | ------------------------------ | 9975| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9976| 1300002 | This window state is abnormal. | 9977| 1300005 | This window stage is abnormal. | 9978 9979**示例:** 9980 9981```ts 9982// EntryAbility.ets 9983import { UIAbility } from '@kit.AbilityKit'; 9984import { BusinessError } from '@kit.BasicServicesKit'; 9985 9986export default class EntryAbility extends UIAbility { 9987 // ... 9988 9989 onWindowStageCreate(windowStage: window.WindowStage) { 9990 console.log('onWindowStageCreate'); 9991 try { 9992 windowStage.loadContent('pages/page2', (err: BusinessError) => { 9993 const errCode: number = err.code; 9994 if (errCode) { 9995 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 9996 return; 9997 } 9998 console.info('Succeeded in loading the content.'); 9999 }); 10000 } catch (exception) { 10001 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 10002 } 10003 } 10004}; 10005``` 10006 10007### loadContentByName<sup>11+</sup> 10008 10009loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback<void>): void 10010 10011为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。 10012 10013**模型约束:** 此接口仅可在Stage模型下使用。 10014 10015**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10016 10017**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10018 10019**参数:** 10020 10021| 参数名 | 类型 | 必填 | 说明 | 10022| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 10023| name | string | 是 | 命名路由页面的名称。 | 10024| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 10025| callback | AsyncCallback<void> | 是 | 回调函数。 | 10026 10027**错误码:** 10028 10029以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10030 10031| 错误码ID | 错误信息 | 10032| -------- | --------------------------------------------- | 10033| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10034| 1300002 | This window state is abnormal. | 10035| 1300003 | This window manager service works abnormally. | 10036 10037**示例:** 10038 10039<!--code_no_check--> 10040```ts 10041// EntryAbility.ets 10042import { UIAbility } from '@kit.AbilityKit'; 10043import { BusinessError } from '@kit.BasicServicesKit'; 10044import * as Index from '../pages/Index'; // 导入命名路由页面 10045 10046export default class EntryAbility extends UIAbility { 10047 // ... 10048 10049 storage: LocalStorage = new LocalStorage(); 10050 10051 onWindowStageCreate(windowStage: window.WindowStage) { 10052 console.log('onWindowStageCreate'); 10053 this.storage.setOrCreate('storageSimpleProp', 121); 10054 try { 10055 windowStage.loadContentByName(Index.entryName, this.storage, (err: BusinessError) => { 10056 const errCode: number = err.code; 10057 if (errCode) { 10058 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 10059 return; 10060 } 10061 console.info('Succeeded in loading the content.'); 10062 }); 10063 } catch (exception) { 10064 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 10065 } 10066 } 10067}; 10068``` 10069<!--code_no_check--> 10070```ts 10071// ets/pages/Index.ets 10072export const entryName : string = 'Index'; 10073@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 10074@Component 10075export struct Index { 10076 @State message: string = 'Hello World' 10077 build() { 10078 Row() { 10079 Column() { 10080 Text(this.message) 10081 .fontSize(50) 10082 .fontWeight(FontWeight.Bold) 10083 } 10084 .width('100%') 10085 } 10086 .height('100%') 10087 } 10088} 10089``` 10090 10091### loadContentByName<sup>11+</sup> 10092 10093loadContentByName(name: string, callback: AsyncCallback<void>): void 10094 10095为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,使用callback异步回调。 10096 10097**模型约束:** 此接口仅可在Stage模型下使用。 10098 10099**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10100 10101**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10102 10103**参数:** 10104 10105| 参数名 | 类型 | 必填 | 说明 | 10106| -------- | ------------------------- | ---- | ---------------- | 10107| name | string | 是 | 命名路由页面的名称。 | 10108| callback | AsyncCallback<void> | 是 | 回调函数。 | 10109 10110**错误码:** 10111 10112以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10113 10114| 错误码ID | 错误信息 | 10115| -------- | --------------------------------------------- | 10116| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10117| 1300002 | This window state is abnormal. | 10118| 1300003 | This window manager service works abnormally. | 10119 10120**示例:** 10121 10122<!--code_no_check--> 10123```ts 10124// EntryAbility.ets 10125import { UIAbility } from '@kit.AbilityKit'; 10126import { BusinessError } from '@kit.BasicServicesKit'; 10127import * as Index from '../pages/Index'; // 导入命名路由页面 10128 10129export default class EntryAbility extends UIAbility { 10130 // ... 10131 10132 onWindowStageCreate(windowStage: window.WindowStage) { 10133 console.log('onWindowStageCreate'); 10134 try { 10135 windowStage.loadContentByName(Index.entryName, (err: BusinessError) => { 10136 const errCode: number = err.code; 10137 if (errCode) { 10138 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 10139 return; 10140 } 10141 console.info('Succeeded in loading the content.'); 10142 }); 10143 } catch (exception) { 10144 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 10145 } 10146 } 10147}; 10148``` 10149<!--code_no_check--> 10150```ts 10151// ets/pages/Index.ets 10152export const entryName : string = 'Index'; 10153@Entry({routeName: entryName}) 10154@Component 10155export struct Index { 10156 @State message: string = 'Hello World' 10157 build() { 10158 Row() { 10159 Column() { 10160 Text(this.message) 10161 .fontSize(50) 10162 .fontWeight(FontWeight.Bold) 10163 } 10164 .width('100%') 10165 } 10166 .height('100%') 10167 } 10168} 10169``` 10170 10171### loadContentByName<sup>11+</sup> 10172 10173loadContentByName(name: string, storage?: LocalStorage): Promise<void>; 10174 10175为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用promise异步回调。 10176 10177**模型约束:** 此接口仅可在Stage模型下使用。 10178 10179**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10180 10181**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10182 10183**参数:** 10184 10185| 参数名 | 类型 | 必填 | 说明 | 10186| ------- | ------------ | ---- | ------------------------------------------------------------ | 10187| name | string | 是 | 命名路由页面的名称。 | 10188| storage | LocalStorage | 否 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 10189 10190**错误码:** 10191 10192以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10193 10194| 错误码ID | 错误信息 | 10195| -------- | --------------------------------------------- | 10196| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10197| 1300002 | This window state is abnormal. | 10198| 1300003 | This window manager service works abnormally. | 10199 10200**示例:** 10201 10202<!--code_no_check--> 10203```ts 10204// EntryAbility.ets 10205import { UIAbility } from '@kit.AbilityKit'; 10206import { BusinessError } from '@kit.BasicServicesKit'; 10207import * as Index from '../pages/Index'; // 导入命名路由页面 10208 10209export default class EntryAbility extends UIAbility { 10210 // ... 10211 10212 storage: LocalStorage = new LocalStorage(); 10213 10214 onWindowStageCreate(windowStage: window.WindowStage) { 10215 console.log('onWindowStageCreate'); 10216 this.storage.setOrCreate('storageSimpleProp', 121); 10217 try { 10218 let promise = windowStage.loadContentByName(Index.entryName, this.storage); 10219 promise.then(() => { 10220 console.info('Succeeded in loading the content.'); 10221 }).catch((err: BusinessError) => { 10222 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 10223 }); 10224 } catch (exception) { 10225 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 10226 } 10227 } 10228}; 10229``` 10230<!--code_no_check--> 10231```ts 10232// ets/pages/Index.ets 10233export const entryName : string = 'Index'; 10234@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 10235@Component 10236export struct Index { 10237 @State message: string = 'Hello World' 10238 build() { 10239 Row() { 10240 Column() { 10241 Text(this.message) 10242 .fontSize(50) 10243 .fontWeight(FontWeight.Bold) 10244 } 10245 .width('100%') 10246 } 10247 .height('100%') 10248 } 10249} 10250``` 10251 10252### on('windowStageEvent')<sup>9+</sup> 10253 10254on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void 10255 10256开启WindowStage生命周期变化的监听。 10257 10258**模型约束:** 此接口仅可在Stage模型下使用。 10259 10260**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10261 10262**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10263 10264**参数:** 10265 10266| 参数名 | 类型 | 必填 | 说明 | 10267| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 10268| eventType | string | 是 | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 | 10269| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | 是 | 回调函数。返回当前的WindowStage生命周期状态。 | 10270 10271**错误码:** 10272 10273以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10274 10275| 错误码ID | 错误信息 | 10276| ------- | ------------------------------ | 10277| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 10278| 1300002 | This window state is abnormal. | 10279| 1300005 | This window stage is abnormal. | 10280 10281**示例:** 10282 10283```ts 10284// EntryAbility.ets 10285import { UIAbility } from '@kit.AbilityKit'; 10286 10287export default class EntryAbility extends UIAbility { 10288 // ... 10289 10290 onWindowStageCreate(windowStage: window.WindowStage) { 10291 console.log('onWindowStageCreate'); 10292 try { 10293 windowStage.on('windowStageEvent', (data) => { 10294 console.info('Succeeded in enabling the listener for window stage event changes. Data: ' + 10295 JSON.stringify(data)); 10296 }); 10297 } catch (exception) { 10298 console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`); 10299 } 10300 } 10301}; 10302``` 10303 10304### off('windowStageEvent')<sup>9+</sup> 10305 10306off(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType>): void 10307 10308关闭WindowStage生命周期变化的监听。 10309 10310**模型约束:** 此接口仅可在Stage模型下使用。 10311 10312**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10313 10314**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 10315 10316**参数:** 10317 10318| 参数名 | 类型 | 必填 | 说明 | 10319| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 10320| eventType | string | 是 | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 | 10321| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | 否 | 回调函数。返回当前的WindowStage生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有WindowStage生命周期变化的监听。 | 10322 10323**错误码:** 10324 10325以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10326 10327| 错误码ID | 错误信息 | 10328| ------- | ------------------------------ | 10329| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 10330| 1300002 | This window state is abnormal. | 10331| 1300005 | This window stage is abnormal. | 10332 10333**示例:** 10334 10335```ts 10336// EntryAbility.ets 10337import { UIAbility } from '@kit.AbilityKit'; 10338 10339export default class EntryAbility extends UIAbility { 10340 // ... 10341 10342 onWindowStageCreate(windowStage: window.WindowStage) { 10343 console.log('onWindowStageCreate'); 10344 const callback = (windowStageEventType: window.WindowStageEventType) => { 10345 // ... 10346 } 10347 try { 10348 windowStage.on('windowStageEvent', callback); 10349 } catch (exception) { 10350 console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`); 10351 } 10352 try { 10353 windowStage.off('windowStageEvent', callback); 10354 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 10355 windowStage.off('windowStageEvent'); 10356 } catch (exception) { 10357 console.error(`Failed to disable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`); 10358 } 10359 } 10360}; 10361``` 10362 10363### on('windowStageClose')<sup>14+</sup> 10364 10365on(eventType: 'windowStageClose', callback: Callback<void>): void 10366 10367开启点击主窗三键区的关闭按钮监听事件,仅在2in1设备中生效。点击主窗口的三键区域的关闭键时触发该回调函数,将不执行注册的[UIAbility.onPrepareToTerminate](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonpreparetoterminate10)生命周期回调函数。 10368 10369**模型约束:** 此接口仅可在Stage模型下使用。 10370 10371**系统能力:** SystemCapability.Window.SessionManager 10372 10373**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 10374 10375**参数:** 10376 10377| 参数名 | 类型 | 必填 | 说明 | 10378| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 10379| eventType | string | 是 | 监听事件,固定为'windowStageClose',即开启主窗三键区的关闭按钮监听。| 10380| callback | Callback<void> | 是 | 回调函数。当点击主窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前主窗是否继续关闭,true表示不关闭,false表示关闭。| 10381 10382**错误码:** 10383 10384以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10385 10386| 错误码ID | 错误信息 | 10387| ------- | ------------------------------ | 10388| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 10389| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 10390| 1300002 | This window state is abnormal. | 10391 10392**示例:** 10393 10394```ts 10395// EntryAbility.ets 10396import { UIAbility } from '@kit.AbilityKit'; 10397import { window } from '@kit.ArkUI'; 10398 10399export default class EntryAbility extends UIAbility { 10400 // ... 10401 10402 onWindowStageCreate(windowStage: window.WindowStage) { 10403 console.info('onWindowStageCreate'); 10404 try { 10405 windowStage.on('windowStageClose', () => { 10406 console.info('Succeeded in enabling the listener for window stage close event.'); 10407 return false; 10408 }); 10409 } catch (exception) { 10410 console.error(`Failed to enable the listener for window stage close event. Cause code: ${exception.code}, message: ${exception.message}`); 10411 } 10412 } 10413}; 10414``` 10415 10416### off('windowStageClose')<sup>14+</sup> 10417 10418off(eventType: 'windowStageClose', callback?: Callback<void>): void 10419 10420关闭主窗口关闭事件的监听,仅在2in1设备中生效。 10421 10422**模型约束:** 此接口仅可在Stage模型下使用。 10423 10424**系统能力:** SystemCapability.Window.SessionManager 10425 10426**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 10427 10428**参数:** 10429 10430| 参数名 | 类型 | 必填 | 说明 | 10431| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 10432| eventType | string | 是 | 监听事件,固定为'windowStageClose',即关闭主窗口关闭事件的监听。 | 10433| callback | Callback<void> | 否 | 回调函数。当点击主窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前主窗是否继续关闭,true表示不关闭,false表示关闭。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有主窗口关闭的监听。 | 10434 10435**错误码:** 10436 10437以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10438 10439| 错误码ID | 错误信息 | 10440| ------- | ------------------------------ | 10441| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 10442| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 10443| 1300002 | This window state is abnormal. | 10444 10445**示例:** 10446 10447```ts 10448// EntryAbility.ets 10449import { UIAbility } from '@kit.AbilityKit'; 10450import { window } from '@kit.ArkUI'; 10451 10452export default class EntryAbility extends UIAbility { 10453 // ... 10454 10455 onWindowStageCreate(windowStage: window.WindowStage) { 10456 console.info('onWindowStageCreate'); 10457 const callback = () => { 10458 // ... 10459 return false; 10460 } 10461 try { 10462 windowStage.on('windowStageClose', callback); 10463 windowStage.off('windowStageClose', callback); 10464 windowStage.off('windowStageClose'); 10465 } catch (exception) { 10466 console.error(`Failed to disable the listener for window stage close changes. Cause code: ${exception.code}, message: ${exception.message}`); 10467 } 10468 } 10469}; 10470``` 10471 10472### setDefaultDensityEnabled<sup>12+</sup> 10473 10474setDefaultDensityEnabled(enabled: boolean): void 10475 10476设置应用是否使用系统默认Density。 10477 10478不调用此接口进行设置,则表示不使用系统默认Density,即窗口会跟随系统显示大小变化重新布局。 10479 10480**模型约束:** 此接口仅可在Stage模型下使用。 10481 10482**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 10483 10484**系统能力:** SystemCapability.Window.SessionManager 10485 10486**参数:** 10487 10488| 参数名 | 类型 | 必填 | 说明 | 10489| ---------------- | ------- | ---- | ---------------------------- | 10490| enabled | boolean | 是 | 是否设置应用使用系统默认Density。true表示使用系统默认Density,窗口不跟随系统显示大小变化重新布局;false表示不使用系统默认Density,窗口跟随系统显示大小变化重新布局。 | 10491 10492**错误码:** 10493 10494以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10495 10496| 错误码ID | 错误信息 | 10497| ------- | ------------------------------ | 10498| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10499| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 10500| 1300002 | This window state is abnormal. | 10501| 1300005 | This window stage is abnormal. | 10502 10503**示例:** 10504 10505```ts 10506// EntryAbility.ets 10507import { UIAbility } from '@kit.AbilityKit'; 10508 10509export default class EntryAbility extends UIAbility { 10510 // ... 10511 10512 onWindowStageCreate(windowStage: window.WindowStage) { 10513 console.log('onWindowStageCreate'); 10514 try { 10515 windowStage.setDefaultDensityEnabled(true); 10516 } catch (exception) { 10517 console.error(`Failed to set default density enabled. Cause code: ${exception.code}, message: ${exception.message}`); 10518 } 10519 } 10520}; 10521``` 10522 10523### setWindowModal<sup>14+</sup> 10524 10525setWindowModal(isModal: boolean): Promise<void> 10526 10527设置主窗的模态属性是否启用,使用Promise异步回调。 10528 10529主窗口调用该接口时,设置主窗口模态属性是否启用。启用主窗口模态属性后,其相同应用进程下的其他主窗口以及其他主窗口的子窗口不能响应用户操作,直到该主窗口关闭或者主窗口的模态属性被禁用。 10530 10531此接口仅支持2in1设备。 10532 10533**模型约束:** 此接口仅可在Stage模型下使用。 10534 10535**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 10536 10537**系统能力:** SystemCapability.Window.SessionManager 10538 10539**参数:** 10540 10541| 参数名 | 类型 | 必填 | 说明 | 10542| --------- | ------- | ---- | --------------------------------------------- | 10543| isModal | boolean | 是 | 设置主窗口模态属性是否启用,true为启用,false为不启用。 | 10544 10545 10546**返回值:** 10547 10548| 类型 | 说明 | 10549| ------------------- | ------------------------ | 10550| Promise<void> | 无返回结果的Promise对象。 | 10551 10552**错误码:** 10553 10554以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10555 10556| 错误码ID | 错误信息 | 10557| -------- | ------------------------------ | 10558| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10559| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 10560| 1300002 | This window state is abnormal. | 10561| 1300003 | This window manager service works abnormally. | 10562 10563**示例:** 10564 10565```ts 10566// EntryAbility.ets 10567import { UIAbility } from '@kit.AbilityKit'; 10568import { BusinessError } from '@kit.BasicServicesKit'; 10569 10570export default class EntryAbility extends UIAbility { 10571 // ... 10572 onWindowStageCreate(windowStage: window.WindowStage): void { 10573 console.info('onWindowStageCreate'); 10574 try { 10575 let promise = windowStage.setWindowModal(true); 10576 promise.then(() => { 10577 console.info('Succeeded in setting window modal'); 10578 }).catch((err: BusinessError) => { 10579 console.error(`Failed to set window modal. Cause code: ${err.code}, message: ${err.message}`); 10580 }); 10581 } catch (exception) { 10582 console.error(`Failed to set window modal. Cause code: ${exception.code}, message: ${exception.message}`); 10583 } 10584 } 10585} 10586``` 10587 10588### removeStartingWindow<sup>14+</sup> 10589 10590removeStartingWindow(): Promise<void> 10591 10592支持应用控制启动页消失时机。 10593 10594此接口只对应用主窗口生效,且需要在module.json5配置文件[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中的metadata标签下配置"enable.remove.starting.window"为"true"才会生效。 10595 10596在标签配置为"true"的情况下,系统提供了启动页超时保护机制,若5s内未调用此接口,系统将自动移除启动页。 10597 10598若标签配置为"false"或未配置标签,则此接口不生效,启动页将会在应用首帧渲染完成后自动移除。 10599 10600**模型约束:** 此接口仅可在Stage模型下使用。 10601 10602**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 10603 10604**系统能力:** SystemCapability.Window.SessionManager 10605 10606**返回值:** 10607 10608| 类型 | 说明 | 10609| ------------------- | ------------------------- | 10610| Promise<void> | 无返回结果的Promise对象。 | 10611 10612**错误码:** 10613 10614以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10615 10616| 错误码ID | 错误信息 | 10617| ------- | ------------------------------ | 10618| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 10619| 1300002 | This window state is abnormal. | 10620| 1300003 | This window manager service works abnormally. | 10621 10622**示例:** 10623 10624```ts 10625// EntryAbility.ets 10626import { UIAbility } from '@kit.AbilityKit'; 10627import { BusinessError } from '@kit.BasicServicesKit'; 10628 10629export default class EntryAbility extends UIAbility { 10630 // ... 10631 10632 onWindowStageCreate(windowStage: window.WindowStage) { 10633 console.info('onWindowStageCreate'); 10634 windowStage.removeStartingWindow().then(() => { 10635 console.info('Succeeded in removing starting window.'); 10636 }).catch((err: BusinessError) => { 10637 console.error(`Failed to remove starting window. Cause code: ${err.code}, message: ${err.message}`); 10638 }); 10639 } 10640}; 10641``` 10642 10643### setWindowRectAutoSave<sup>14+</sup> 10644 10645setWindowRectAutoSave(enabled: boolean): Promise<void> 10646 10647设置主窗的尺寸记忆是否启用,使用Promise异步回调,仅对2in1设备生效。 10648 10649主窗口调用该接口时,设置主窗口的尺寸记忆是否启用。启用主窗口尺寸记忆功能后,在同一个UIAbility下,记忆最后关闭的窗口的尺寸和模式。 10650 10651窗口再次启动时,以记忆的尺寸和模式按照规则进行打开。 10652 10653层叠规则: 106541、当前实例是自由窗口时,打开下一实例窗口层叠时,大小要跟随。 106552、当前实例是最大化或全屏窗口时,打开下一个实例窗口层叠时,保持最大化。 10656 10657记忆规则: 10658|上一次窗口状态|记忆规则| 10659|-------------|-------| 10660|自由窗口|保留自由窗口的大小/位置,超出工作区回弹| 10661|二分屏窗口|保留二分屏之前自由窗口的大小/位置| 10662|最大化窗口|保留最大化| 10663|沉浸式窗口|保留沉浸式之前自由窗口的大小/位置| 10664|最小化窗口|保留最小化之前自由窗口的大小/位置| 10665 10666**模型约束:** 此接口仅可在Stage模型下使用。 10667 10668**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 10669 10670**系统能力:** SystemCapability.Window.SessionManager 10671 10672**参数:** 10673 10674| 参数名 | 类型 | 必填 | 说明 | 10675| --------- | ------- | ---- | --------------------------------------------- | 10676| enabled | boolean | 是 | 设置主窗口的尺寸记忆是否启用,true为启用,false为不启用。 | 10677 10678 10679**返回值:** 10680 10681| 类型 | 说明 | 10682| ------------------- | ------------------------ | 10683| Promise<void> | 无返回结果的Promise对象。 | 10684 10685**错误码:** 10686 10687以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 10688 10689| 错误码ID | 错误信息 | 10690| -------- | ------------------------------ | 10691| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10692| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 10693| 1300002 | This window state is abnormal. | 10694| 1300003 | This window manager service works abnormally. | 10695 10696**示例:** 10697 10698```ts 10699// EntryAbility.ets 10700import { UIAbility } from '@kit.AbilityKit'; 10701import { BusinessError } from '@kit.BasicServicesKit'; 10702 10703export default class EntryAbility extends UIAbility { 10704 // ... 10705 onWindowStageCreate(windowStage: window.WindowStage): void { 10706 console.info('onWindowStageCreate'); 10707 try { 10708 let promise = windowStage.setWindowRectAutoSave(true); 10709 promise.then(() => { 10710 console.info('Succeeded in setting window rect auto-save'); 10711 }).catch((err: BusinessError) => { 10712 console.error(`Failed to set window rect auto-save. Cause code: ${err.code}, message: ${err.message}`); 10713 }); 10714 } catch (exception) { 10715 console.error(`Failed to set window rect auto-save. Cause code: ${exception.code}, message: ${exception.message}`); 10716 } 10717 } 10718} 10719``` 10720 10721### isWindowRectAutoSave<sup>14+</sup> 10722 10723isWindowRectAutoSave(): Promise<boolean> 10724 10725判断当前主窗口是否已经启用尺寸记忆,使用Promise异步回调,仅对2in1设备生效。 10726 10727**模型约束:** 此接口仅可在Stage模型下使用。 10728 10729**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 10730 10731**系统能力:** SystemCapability.Window.SessionManager 10732 10733**返回值:** 10734 10735| 类型 | 说明 | 10736| ---------------------- | ------------------------------------------------------------------------------------ | 10737| Promise<boolean> | Promise对象。返回true表示当前窗口启用尺寸记忆,返回false表示当前窗口禁用尺寸记忆。 | 10738 10739**错误码:** 10740 10741以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 10742 10743| 错误码ID | 错误信息 | 10744| ------- | ------------------------------ | 10745| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 10746| 1300002 | This window state is abnormal. | 10747 10748**示例:** 10749 10750```ts 10751// EntryAbility.ets 10752import { UIAbility } from '@kit.AbilityKit'; 10753import { BusinessError } from '@kit.BasicServicesKit'; 10754 10755export default class EntryAbility extends UIAbility { 10756 // ... 10757 onWindowStageCreate(windowStage: window.WindowStage): void { 10758 console.info('onWindowStageCreate'); 10759 try { 10760 let promise = windowStage.isWindowRectAutoSave(); 10761 promise.then((data) => { 10762 console.info('Succeeded in checking whether the window support the rect auto-save. Data: ' + JSON.stringify(data)); 10763 }).catch((err: BusinessError) => { 10764 console.error(`Failed to check whether the window support the rect auto-save. Cause code: ${err.code}, message: ${err.message}`); 10765 }); 10766 } catch (exception) { 10767 console.error(`Failed to check whether the window support the rect auto-save. Cause code: ${exception.code}, message: ${exception.message}`); 10768 } 10769 } 10770} 10771```