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| TYPE_MAIN<sup>18+</sup> | 32 | 表示应用主窗口。<br>此窗口类型不支持在创建窗口时使用,仅可在getWindowProperties接口的返回值中用于读取。 | 33 34## Configuration<sup>9+</sup> 35 36创建子窗口或系统窗口时的参数。 37 38**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 39 40**系统能力:** SystemCapability.WindowManager.WindowManager.Core 41 42| 名称 | 类型 | 必填 | 说明 | 43| ---------- | -------------------------- | -- |-----------------------------------------------------------------------------| 44| name | string | 是 | 窗口名字。 | 45| windowType | [WindowType](#windowtype7) | 是 | 窗口类型。 | 46| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 否 | 当前应用上下文信息。不设置,则默认为空。<br>FA模型下不需要使用该参数,即可创建子窗口,使用该参数时会报错。<br>Stage模型必须使用该参数,用于创建悬浮窗、模态窗或系统窗口。 | 47| displayId | number | 否 | 当前物理屏幕id。不设置,则默认为-1,该参数应为整数。 | 48| parentId | number | 否 | 父窗口id。不设置,则默认为-1,该参数应为整数。 | 49| decorEnabled<sup>12+</sup> | boolean | 否 | 是否显示窗口装饰,仅在windowType为TYPE_DIALOG时生效。true表示显示,false表示不显示。此参数默认值为false。<br>**系统能力:** SystemCapability.Window.SessionManager | 50| title<sup>12+</sup> | string| 否 | `decorEnabled`属性设置为true时,窗口的标题内容。标题显示区域最右端不超过系统三键区域最左端,超过部分以省略号表示。不设置,则默认为空字符串。 <br>**系统能力:** SystemCapability.Window.SessionManager | 51 52## AvoidAreaType<sup>7+</sup> 53 54窗口内容需要规避区域的类型枚举。 55 56**系统能力:** SystemCapability.WindowManager.WindowManager.Core 57 58**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 59 60| 名称 | 值 | 说明 | 61| -------------------------------- | ---- | ------------------------------------------------------------ | 62| TYPE_SYSTEM | 0 | 表示系统默认区域。<!--RP11-->包含状态栏和三键导航栏区域。<!--RP11End--> | 63| TYPE_CUTOUT | 1 | 表示刘海屏区域。 | 64| TYPE_SYSTEM_GESTURE<sup>9+</sup> | 2 | 表示手势区域。当前,各设备均无此类型避让区域。 | 65| TYPE_KEYBOARD<sup>9+</sup> | 3 | 表示软键盘区域。 | 66| TYPE_NAVIGATION_INDICATOR<sup>11+</sup> | 4 | 表示底部导航条区域。 | 67 68 69## SystemBarProperties 70 71状态栏、三键导航栏的属性。在设置窗口级状态栏、三键导航栏属性时使用。 72 73**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 74 75| 名称 | 类型 | 必填 | 说明 | 76| -------------------------------------- | -------- | ---- | ------------------------------------------------------------ | 77| statusBarColor | string | 否 | 状态栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。默认值:`'#66000000'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 78| isStatusBarLightIcon<sup>7+</sup> | boolean | 否 | 状态栏图标是否为高亮状态。true表示高亮;false表示不高亮。默认值:false。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 79| statusBarContentColor<sup>8+</sup> | string | 否 | 状态栏文字颜色。当设置此属性后, `isStatusBarLightIcon`属性设置无效。默认值:`'#E5FFFFFF'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 80| navigationBarColor | string | 否 | 三键导航栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。默认值:`'#66000000'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 81| isNavigationBarLightIcon<sup>7+</sup> | boolean | 否 | 三键导航栏图标是否为高亮状态。true表示高亮;false表示不高亮。默认值:false。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 82| navigationBarContentColor<sup>8+</sup> | string | 否 | 三键导航栏文字颜色。当设置此属性后, `isNavigationBarLightIcon`属性设置无效。默认值:`'#E5FFFFFF'`。 <br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 83| enableStatusBarAnimation<sup>12+</sup> | boolean | 否 | 是否使能状态栏属性变化时动画效果。true表示变化时使能动画效果;false表示没有使能动画效果。默认值:false。 <br> **系统能力:** SystemCapability.Window.SessionManager| 84| enableNavigationBarAnimation<sup>12+</sup> | boolean | 否 | 是否使能三键导航栏属性变化时动画效果。true表示变化时使能动画效果;false表示没有使能动画效果。默认值:false。 <br> **系统能力:** SystemCapability.Window.SessionManager| 85 86## StatusBarProperty<sup>18+</sup> 87 88状态栏的属性。在获取状态栏属性信息时返回。 89 90**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 91 92| 名称 | 类型 | 必填 | 说明 | 93| ------------------------------------- | -------- | ---- |------- | 94| contentColor | string | 是 | 状态栏文字颜色,固定为ARGB格式, 如:`#E5FFFFFF`。 <br> **系统能力:** SystemCapability.Window.SessionManager| 95 96## SystemBarStyle<sup>12+</sup> 97 98状态栏的属性。在设置页面级状态栏属性时使用。 99 100**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 101 102**系统能力:** SystemCapability.WindowManager.WindowManager.Core 103 104| 名称 | 类型 | 只读 | 可选 | 说明 | 105| ------ | -------- | ---- | ---- | ------------------ | 106| statusBarContentColor | string | 是 | 是 | 状态栏文字颜色。默认值:`'#E5FFFFFF'`。| 107 108## Orientation<sup>9+</sup> 109 110窗口显示方向类型枚举。 111 112| 名称 | 值 | 说明 | 113| ------------------------------------- | ---- | ----------------------------- | 114| UNSPECIFIED | 0 | 表示未定义方向模式,由系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 115| PORTRAIT | 1 | 表示竖屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。| 116| LANDSCAPE | 2 | 表示横屏显示模式。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 117| PORTRAIT_INVERTED | 3 | 表示反向竖屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 118| LANDSCAPE_INVERTED | 4 | 表示反向横屏显示模式。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 119| AUTO_ROTATION | 5 | 跟随传感器自动旋转,可以旋转到竖屏、横屏、反向竖屏、反向横屏四个方向。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。| 120| AUTO_ROTATION_PORTRAIT | 6 | 跟随传感器自动竖向旋转,可以旋转到竖屏、反向竖屏,无法旋转到横屏、反向横屏。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 121| AUTO_ROTATION_LANDSCAPE | 7 | 跟随传感器自动横向旋转,可以旋转到横屏、反向横屏,无法旋转到竖屏、反向竖屏。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 122| AUTO_ROTATION_RESTRICTED | 8 | 跟随传感器自动旋转,可以旋转到竖屏、横屏、反向竖屏、反向横屏四个方向,且受控制中心的旋转开关控制。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 123| AUTO_ROTATION_PORTRAIT_RESTRICTED | 9 | 跟随传感器自动竖向旋转,可以旋转到竖屏、反向竖屏,无法旋转到横屏、反向横屏,且受控制中心的旋转开关控制。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 124| AUTO_ROTATION_LANDSCAPE_RESTRICTED | 10 | 跟随传感器自动横向旋转,可以旋转到横屏、反向横屏,无法旋转到竖屏、反向竖屏,且受控制中心的旋转开关控制。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 125| LOCKED | 11 | 表示锁定模式。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 126| AUTO_ROTATION_UNSPECIFIED<sup>12+</sup> | 12 | 跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定(如在某种设备,可以旋转到竖屏、横屏、反向横屏三个方向,无法旋转到反向竖屏)。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager| 127| USER_ROTATION_PORTRAIT<sup>12+</sup> | 13 | 调用时临时旋转到竖屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager| 128| USER_ROTATION_LANDSCAPE<sup>12+</sup> | 14 | 调用时临时旋转到横屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager| 129| USER_ROTATION_PORTRAIT_INVERTED<sup>12+</sup> | 15 | 调用时临时旋转到反向竖屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager| 130| USER_ROTATION_LANDSCAPE_INVERTED<sup>12+</sup> | 16 | 调用时临时旋转到反向横屏,之后跟随传感器自动旋转,受控制中心的旋转开关控制,且可旋转方向受系统判定。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager| 131| FOLLOW_DESKTOP<sup>12+</sup> | 17 | 表示跟随桌面的旋转模式。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br> **系统能力:** SystemCapability.Window.SessionManager| 132 133## Rect<sup>7+</sup> 134 135窗口矩形区域。 136 137**系统能力:** SystemCapability.WindowManager.WindowManager.Core 138 139**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 140 141| 名称 | 类型 | 可读 | 可写 | 说明 | 142| ------ | -------- | ---- | ---- | ------------------ | 143| left | number | 是 | 是 | 矩形区域的左边界,单位为px,该参数为整数。 | 144| top | number | 是 | 是 | 矩形区域的上边界,单位为px,该参数应为整数。 | 145| width | number | 是 | 是 | 矩形区域的宽度,单位为px,该参数应为整数。 | 146| height | number | 是 | 是 | 矩形区域的高度,单位为px,该参数应为整数。 | 147 148## AvoidArea<sup>7+</sup> 149 150窗口内容规避区域。如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。在规避区无法响应用户点击事件。 151 152除此之外还需注意规避区域的如下约束,具体为: 153 154- 底部手势区域中非底部导航条区域支持点击、长按事件透传,不支持拖入。 155 156- 左右侧边手势区域支持点击、长按以及上下滑动事件透传,不支持拖入。 157 158- 底部导航条区域支持长按、点击、拖入事件响应,不支持事件向下透传。 159 160**系统能力:** SystemCapability.WindowManager.WindowManager.Core 161 162**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 163 164| 名称 | 类型 | 可读 | 可写 | 说明 | 165| ---------- | ------------- | ---- | ---- | ------------------ | 166| visible<sup>9+</sup> | boolean | 是 | 是 | 规避区域是否可见。true表示可见;false表示不可见。 | 167| leftRect | [Rect](#rect7) | 是 | 是 | 屏幕左侧的矩形区。 | 168| topRect | [Rect](#rect7) | 是 | 是 | 屏幕顶部的矩形区。 | 169| rightRect | [Rect](#rect7) | 是 | 是 | 屏幕右侧的矩形区。 | 170| bottomRect | [Rect](#rect7) | 是 | 是 | 屏幕底部的矩形区。 | 171 172## Size<sup>7+</sup> 173 174窗口大小。 175 176**系统能力:** SystemCapability.WindowManager.WindowManager.Core 177 178**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 179 180| 名称 | 类型 | 可读 | 可写 | 说明 | 181| ------ | -------- | ---- | ---- | ---------- | 182| width | number | 是 | 是 | 窗口宽度,单位为px,该参数应为整数。 | 183| height | number | 是 | 是 | 窗口高度,单位为px,该参数应为整数。 | 184 185## RectChangeReason<sup>12+</sup> 186 187窗口矩形(窗口位置及窗口大小)变化的原因。 188 189**系统能力:** SystemCapability.Window.SessionManager 190 191**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 192 193| 名称 | 值 | 说明 | 194| --------------------- | ---- | ------------------------------------------------------------ | 195| UNDEFINED | 0 | 默认值。 | 196| MAXIMIZE | 1 | 窗口最大化。 | 197| RECOVER | 2 | 窗口恢复到上一次的状态。 | 198| MOVE | 3 | 窗口拖拽移动。 | 199| DRAG | 4 | 窗口拖拽缩放。 | 200| DRAG_START | 5 | 窗口开始拖拽缩放。 | 201| DRAG_END | 6 | 窗口结束拖拽缩放。 | 202 203## RectChangeOptions<sup>12+</sup> 204 205窗口矩形(窗口位置及窗口大小)变化返回的值及变化原因。 206 207**系统能力:** SystemCapability.Window.SessionManager 208 209**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 210 211| 名称 | 类型 | 可读 | 可写 | 说明 | 212| ---------- | ------------- | ---- | ---- | ------------------ | 213| rect | [Rect](#rect7) | 是 | 是 | 窗口矩形变化后的值。 | 214| reason | [RectChangeReason](#rectchangereason12) | 是 | 是 | 窗口矩形变化的原因。 | 215 216## AvoidAreaOptions<sup>12+</sup> 217 218系统规避区变化后返回当前规避区域以及规避区域类型。 219 220**系统能力:** SystemCapability.WindowManager.WindowManager.Core 221 222**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 223 224| 名称 | 类型 | 可读 | 可写 | 说明 | 225| ---------- | ------------- | ---- | ---- | ------------------ | 226| type | [AvoidAreaType](#avoidareatype7) | 是 | 是 | 系统规避区变化后返回的规避区域类型。 | 227| area | [AvoidArea](#avoidarea7) | 是 | 是 | 系统规避区变化后返回的规避区域。 | 228 229## WindowProperties 230 231窗口属性。 232 233**系统能力:** SystemCapability.WindowManager.WindowManager.Core 234 235| 名称 | 类型 | 只读 | 可选 | 说明 | 236| ------------------------------------- | ------------------------- | ---- | ---- |--------------------------------------------------------------------------------------------------------| 237| 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开始,该接口支持在原子化服务中使用。 | 238| drawableRect<sup>11+</sup> | [Rect](#rect7) | 否 | 否 | 窗口内的可绘制区域尺寸,其中左边界上边界是相对于窗口计算。在Stage模型下,需要在调用[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)加载页面内容后使用该接口。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 239| type<sup>7+</sup> | [WindowType](#windowtype7) | 否 | 否 | 窗口类型。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 240| isFullScreen | boolean | 否 | 否 | 是否全屏,默认为false。true表示全屏;false表示非全屏。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 241| isLayoutFullScreen<sup>7+</sup> | boolean | 否 | 否 | 窗口是否为沉浸式且处于全屏模式(不在悬浮窗、分屏等场景下),默认为false。true表示沉浸式且处于全屏模式;false表示非沉浸式或非全屏模式。<br> **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 242| focusable<sup>7+</sup> | boolean | 是 | 否 | 窗口是否可聚焦,默认为true。true表示可聚焦;false表示不可聚焦。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 243| touchable<sup>7+</sup> | boolean | 是 | 否 | 窗口是否可触摸,默认为true。true表示可触摸;false表示不可触摸。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 244| brightness | number | 否 | 否 | 屏幕亮度。该参数为浮点数,可设置的亮度范围为[0.0, 1.0],其取1.0时表示最大亮度值。如果窗口没有设置亮度值,表示亮度跟随系统,此时获取到的亮度值为-1。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 245| dimBehindValue<sup>(deprecated)</sup> | number | 否 | 否 | 靠后窗口的暗度值。该参数为浮点数,取值范围为[0.0, 1.0],其取1.0表示最暗。<br>- **说明:** 从API version 9开始废弃。<br>- 从API version 7开始支持。 | 246| isKeepScreenOn | boolean | 否 | 否 | 屏幕是否常亮,默认为false。true表示常亮;false表示不常亮。<br> **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 247| isPrivacyMode<sup>7+</sup> | boolean | 否 | 否 | 隐私模式,默认为false。true表示模式开启;false表示模式关闭。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 248| isRoundCorner<sup>(deprecated)</sup> | boolean | 否 | 否 | 窗口是否为圆角。默认为false。true表示圆角;false表示非圆角。<br>- **说明:** 从API version 9开始废弃。<br/>- 从API version 7开始支持。 | 249| isTransparent<sup>7+</sup> | boolean | 否 | 否 | 窗口是否透明。默认为false。true表示透明;false表示不透明。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 250| id<sup>9+</sup> | number | 是 | 否 | 窗口ID,默认值为0,该参数应为整数。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 251| displayId<sup>12+</sup> | number | 是 | 是 | 窗口所在屏幕ID,默认返回主屏幕ID,该参数应为整数。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 252| name<sup>18+</sup> | string | 是 | 是 | 窗口名字,默认为空字符串。<br/>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 | 253 254## DecorButtonStyle<sup>14+</sup> 255 256系统装饰栏按钮样式。 257 258**系统能力:** SystemCapability.Window.SessionManager 259 260**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 261 262| 名称 | 类型 | 可读 | 可写 | 说明 | 263| ---------- | ------------- | ---- | ---- | ------------------ | 264| colorMode | [ConfigurationConstant.ColorMode](../apis-ability-kit/js-apis-app-ability-configurationConstant.md#colormode) | 是 | 是 | 颜色模式。深色模式下按钮颜色适配为浅色,浅色模式下按钮颜色适配为深色。未设置则默认跟随系统颜色模式。 | 265| buttonBackgroundSize | number | 是 | 是 | 按钮高亮显示时的大小,取值范围20vp-40vp,默认值28vp。 | 266| spacingBetweenButtons | number | 是 | 是 | 按钮间距,取值范围12vp-24vp,默认值12vp。 | 267| closeButtonRightMargin | number | 是 | 是 | 关闭按钮右侧距窗口边距,取值范围8vp-22vp,默认值20vp。 | 268 269## ColorSpace<sup>8+</sup> 270 271色域模式。 272 273**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 274 275**系统能力:** SystemCapability.WindowManager.WindowManager.Core 276 277| 名称 | 值 | 说明 | 278| ---------- | ------ | -------------- | 279| DEFAULT | 0 | 默认SRGB色域模式。 | 280| WIDE_GAMUT | 1 | 广色域模式。 | 281 282## WindowEventType<sup>10+</sup> 283 284窗口生命周期。 285 286**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 287 288| 名称 | 值 | 说明 | 289| ---------- | ------ | ---------- | 290| WINDOW_SHOWN | 1 | 切到前台。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 291| WINDOW_ACTIVE | 2 | 获焦状态。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 292| WINDOW_INACTIVE | 3 | 失焦状态。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 293| WINDOW_HIDDEN | 4 | 切到后台。<br> **系统能力:** SystemCapability.WindowManager.WindowManager.Core| 294| WINDOW_DESTROYED<sup>11+</sup> | 7 | 窗口销毁。<br> **系统能力:** SystemCapability.Window.SessionManager| 295 296## WindowLimits<sup>11+</sup> 297 298窗口尺寸限制参数。可以通过[setWindowLimits](#setwindowlimits11)设置窗口尺寸限制,并且可以通过[getWindowLimits](#getwindowlimits11)获得当前的窗口尺寸限制。 299 300**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 301 302**系统能力:** SystemCapability.Window.SessionManager 303 304| 名称 | 类型 | 可读 | 可写 | 说明 | 305| :-------- | :----- | :--- | :--- | :----------------------------------------------------------- | 306| maxWidth | number | 是 | 是 | 窗口的最大宽度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最大宽度。 | 307| maxHeight | number | 是 | 是 | 窗口的最大高度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最大高度。 | 308| minWidth | number | 是 | 是 | 窗口的最小宽度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最小宽度。 | 309| minHeight | number | 是 | 是 | 窗口的最小高度。单位为px,该参数为整数。值默认为0,表示该属性不发生变化。下限值为0,上限值为系统限定的最小高度。 | 310 311## WindowStatusType<sup>11+</sup> 312 313窗口模式枚举。 314 315**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 316 317**系统能力:** SystemCapability.Window.SessionManager 318 319| 名称 | 值 | 说明 | 320| ---------- | ---- | ----------------------------- | 321| UNDEFINED | 0 | 表示APP未定义窗口模式。 | 322| FULL_SCREEN | 1 | 表示APP全屏模式。 | 323| MAXIMIZE | 2 | 表示APP窗口最大化模式。 | 324| MINIMIZE | 3 | 表示APP窗口最小化模式。 | 325| FLOATING | 4 | 表示APP自由悬浮形式窗口模式。 | 326| SPLIT_SCREEN | 5 | 表示APP分屏模式。 | 327 328## TitleButtonRect<sup>11+</sup> 329 330标题栏上的最小化、最大化、关闭按钮矩形区域,该区域位置坐标相对窗口右上角。 331 332**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 333 334**系统能力:** SystemCapability.Window.SessionManager 335 336| 名称 | 类型 | 可读 | 可写 | 说明 | 337| ------ | ------ | ---- | ---- | ------------------------------------------ | 338| right | number | 是 | 是 | 矩形区域的右边界,单位为vp,该参数为整数。 | 339| top | number | 是 | 是 | 矩形区域的上边界,单位为vp,该参数为整数。 | 340| width | number | 是 | 是 | 矩形区域的宽度,单位为vp,该参数为整数。 | 341| height | number | 是 | 是 | 矩形区域的高度,单位为vp,该参数为整数。 | 342 343## MaximizePresentation<sup>12+</sup> 344 345窗口最大化时的布局枚举。 346 347**系统能力:** SystemCapability.Window.SessionManager 348 349| 名称 | 值 | 说明 | 350| ---------- | ---- | ----------------------------- | 351| FOLLOW_APP_IMMERSIVE_SETTING | 0 | 最大化时,跟随应用app当前设置的沉浸式布局。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 352| EXIT_IMMERSIVE | 1 | 最大化时,如果当前窗口设置了沉浸式布局会退出沉浸式布局。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 353| ENTER_IMMERSIVE | 2 | 最大化时,进入沉浸式布局,鼠标Hover在热区上显示窗口标题栏和dock栏。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 354| ENTER_IMMERSIVE_DISABLE_TITLE_AND_DOCK_HOVER<sup>14+</sup> | 3 | 最大化时,进入沉浸式布局,鼠标Hover在热区上不显示窗口标题栏和dock栏。<br/>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 | 355 356## MoveConfiguration<sup>15+</sup> 357 358窗口移动选项。 359 360**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 361 362**系统能力:** SystemCapability.Window.SessionManager 363 364| 名称 | 类型 | 必填 | 说明 | 365| ------ | ------ | ---- | ------------------------------------------ | 366| displayId | number | 否 | 目标屏幕ID,该参数应为整数,输入非整数时将向下取整。填入该参数时,将移动到相对于目标屏幕左上角的指定位置。此参数不填或传入目标屏幕ID不存在时,将移动到相对于当前屏幕左上角的指定位置。 | 367 368## WindowDensityInfo<sup>15+</sup> 369 370窗口所在显示设备和窗口自定义的显示密度信息,是与像素单位无关的缩放系数,即显示大小缩放系数。 371 372**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 373 374**系统能力:** SystemCapability.Window.SessionManager 375 376| 名称 | 类型 | 可读 | 可写 | 说明 | 377| ------ | -------- | ---- | ---- | ---------- | 378| systemDensity | number | 是 | 否 | 窗口所在屏幕的系统显示大小缩放系数,跟随用户设置变化,该参数变化范围为0.5-4.0。 | 379| defaultDensity | number | 是 | 否 | 窗口所在屏幕的系统默认显示大小缩放系数,跟随窗口所在屏幕变化,该参数变化范围为0.5-4.0。 | 380| customDensity | number | 是 | 否 | 窗口自定义设置的显示大小缩放系数,该参数取值范围为0.5-4.0。未设置该参数时,将跟随系统显示大小缩放系数变化。 | 381 382## WindowLayoutInfo<sup>15+</sup> 383 384窗口布局信息。 385 386**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 387 388**系统能力:** SystemCapability.Window.SessionManager 389 390| 名称 | 类型 | 必填 | 说明 | 391| ------ | ------ | ---- | ------------------------------------------ | 392| windowRect<sup>15+</sup> | [Rect](#rect7) | 是 | 窗口尺寸,窗口在屏幕上的实际位置和大小。 | 393 394## KeyboardInfo<sup>18+</sup> 395 396软键盘窗口信息。 397 398**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 399 400**系统能力:** SystemCapability.Window.SessionManager 401 402| 名称 | 类型 | 必填 | 说明 | 403| ------ | ------ | ---- | ------------------------------------------ | 404| beginRect | [Rect](#rect7) | 是 | 动画开始前软键盘的位置和大小。 | 405| endRect | [Rect](#rect7) | 是 | 动画结束后软键盘的位置和大小。 | 406 407## WindowInfo<sup>18+</sup> 408 409当前窗口的详细信息。 410 411**系统能力:** SystemCapability.Window.SessionManager 412 413| 名称 | 类型 | 只读 | 可选 | 说明 | 414| ------ | ------ | ---- | ---- | ------------------------------------------ | 415| rect | [Rect](js-apis-window.md#rect7) | 是 | 否 | 窗口尺寸。 | 416| bundleName | string | 是 | 否 | 应用Bundle的名称。 | 417| abilityName | string | 是 | 否 | Ability的名称。 | 418| windowId | number | 是 | 否 | 窗口ID。 | 419| windowStatusType | [WindowStatusType](js-apis-window.md#windowstatustype11) | 是 | 否 | 窗口模式枚举。 | 420| isFocused | boolean | 是 | 是 | 窗口是否获焦。true表示窗口获焦;false表示窗口未获焦。 | 421 422## Callback<sup>15+</sup> 423 424### (data: T)<sup>15+</sup> 425 426(data: T): V; 427 428通用回调函数。 429 430开发者在使用时,可自定义data的参数类型,回调函数返回对应类型的信息。 431 432**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 433 434**系统能力:** SystemCapability.Window.SessionManager 435 436**参数:** 437 438| 参数名 | 类型 | 必填 | 说明 | 439| ---- | ---- | ---- | -------------------------- | 440| data | T | 是 | 回调函数调用时需要传入T类型的参数。 | 441 442**返回值:** 443 444| 类型 | 说明 | 445| -------------------------------- | ------------------------------------ | 446| V | 回调函数需要返回V类型的返回值。 | 447 448## window.createWindow<sup>9+</sup> 449 450createWindow(config: Configuration, callback: AsyncCallback<Window>): void 451 452创建子窗口或者系统窗口,使用callback异步回调。 453 454**需要权限:** ohos.permission.SYSTEM_FLOAT_WINDOW(仅当创建窗口类型为window.WindowType.TYPE_FLOAT时需要申请) 455 456**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 457 458**系统能力:** SystemCapability.WindowManager.WindowManager.Core 459 460**参数:** 461 462| 参数名 | 类型 | 必填 | 说明 | 463| -------- | -------------------------------------- | -- | --------------------------------- | 464| config | [Configuration](#configuration9) | 是 | 创建窗口时的参数。 | 465| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的窗口对象。 | 466 467**错误码:** 468 469以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 470 471| 错误码ID | 错误信息 | 472| ------- | -------------------------------- | 473| 201 | Permission verification failed. The application does not have the permission required to call the API. | 474| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 475| 801 | Capability not supported. createWindow can not work correctly due to limited device capabilities. | 476| 1300001 | Repeated operation. | 477| 1300002 | This window state is abnormal. | 478| 1300004 | Unauthorized operation. | 479| 1300006 | This window context is abnormal. | 480| 1300009 | The parent window is invalid. | 481 482**示例:** 483 484```ts 485import { UIAbility } from '@kit.AbilityKit'; 486import { window } from '@kit.ArkUI'; 487import { BusinessError } from '@kit.BasicServicesKit'; 488 489export default class EntryAbility extends UIAbility { 490 onWindowStageCreate(windowStage: window.WindowStage): void { 491 let windowClass: window.Window | undefined = undefined; 492 let config: window.Configuration = { 493 name: "test", 494 windowType: window.WindowType.TYPE_DIALOG, 495 ctx: this.context // context对象也可在组件中通过getContext()方法获取 496 }; 497 try { 498 window.createWindow(config, (err: BusinessError, data) => { 499 const errCode: number = err.code; 500 if (errCode) { 501 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 502 return; 503 } 504 windowClass = data; 505 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 506 windowClass.resize(500, 1000); 507 }); 508 } catch (exception) { 509 console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`); 510 } 511 } 512} 513``` 514 515## window.createWindow<sup>9+</sup> 516 517createWindow(config: Configuration): Promise<Window> 518 519创建子窗口或者系统窗口,使用Promise异步回调。 520 521**需要权限:** ohos.permission.SYSTEM_FLOAT_WINDOW(仅当创建窗口类型为window.WindowType.TYPE_FLOAT时需要申请) 522 523**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 524 525**系统能力:** SystemCapability.WindowManager.WindowManager.Core 526 527**参数:** 528 529| 参数名 | 类型 | 必填 | 说明 | 530| ------ | -------------------------------- | -- | ------------------ | 531| config | [Configuration](#configuration9) | 是 | 创建窗口时的参数。 | 532 533**返回值:** 534 535| 类型 | 说明 | 536| -------------------------------- | ------------------------------------ | 537| Promise<[Window](#window)> | Promise对象。返回当前创建的窗口对象。 | 538 539**错误码:** 540 541以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 542 543| 错误码ID | 错误信息 | 544| ------- | -------------------------------- | 545| 201 | Permission verification failed. The application does not have the permission required to call the API. | 546| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 547| 801 | Capability not supported. createWindow can not work correctly due to limited device capabilities. | 548| 1300001 | Repeated operation. | 549| 1300002 | This window state is abnormal. | 550| 1300004 | Unauthorized operation. | 551| 1300006 | This window context is abnormal. | 552| 1300009 | The parent window is invalid. | 553 554**示例:** 555 556```ts 557import { UIAbility } from '@kit.AbilityKit'; 558import { window } from '@kit.ArkUI'; 559import { BusinessError } from '@kit.BasicServicesKit'; 560 561export default class EntryAbility extends UIAbility { 562 onWindowStageCreate(windowStage: window.WindowStage): void { 563 let config: window.Configuration = { 564 name: "test", 565 windowType: window.WindowType.TYPE_DIALOG, 566 ctx: this.context // context对象也可以在组件中通过getContext()方法获取 567 }; 568 try { 569 window.createWindow(config).then((value:window.Window) => { 570 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(value)); 571 value.resize(500, 1000); 572 }).catch((err:BusinessError)=> { 573 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 574 }); 575 } catch (exception) { 576 console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`); 577 } 578 } 579} 580``` 581 582## window.findWindow<sup>9+</sup> 583 584findWindow(name: string): Window 585 586查找name所对应的窗口。 587 588**系统能力:** SystemCapability.WindowManager.WindowManager.Core 589 590**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 591 592**参数:** 593 594| 参数名 | 类型 | 必填 | 说明 | 595| ------ | ------ | ---- | -------- | 596| name | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 597 598**返回值:** 599 600| 类型 | 说明 | 601| ----------------- | ------------------- | 602| [Window](#window) | 当前查找的窗口对象。 | 603 604**错误码:** 605 606以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 607 608| 错误码ID | 错误信息 | 609| ------- | -------------------------------- | 610| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 611| 1300002 | This window state is abnormal. | 612 613**示例:** 614 615```ts 616let windowClass: window.Window | undefined = undefined; 617try { 618 windowClass = window.findWindow('test'); 619} catch (exception) { 620 console.error(`Failed to find the Window. Cause code: ${exception.code}, message: ${exception.message}`); 621} 622``` 623 624## window.getLastWindow<sup>9+</sup> 625 626getLastWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 627 628获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口,使用callback异步回调。 629 630**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 631 632**系统能力:** SystemCapability.WindowManager.WindowManager.Core 633 634**参数:** 635 636| 参数名 | 类型 | 必填 | 说明 | 637| -------- | -------------------------------------- | -- | ---------------------------------------- | 638| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 639| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 640 641**错误码:** 642 643以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 644 645| 错误码ID | 错误信息 | 646| ------- | -------------------------------- | 647| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 648| 1300002 | This window state is abnormal. | 649| 1300006 | This window context is abnormal. | 650 651**示例:** 652 653```ts 654// EntryAbility.ets 655import { UIAbility } from '@kit.AbilityKit'; 656import { BusinessError } from '@kit.BasicServicesKit'; 657 658export default class EntryAbility extends UIAbility { 659 // ... 660 onWindowStageCreate(windowStage: window.WindowStage) { 661 console.info('onWindowStageCreate'); 662 let windowClass: window.Window | undefined = undefined; 663 try { 664 window.getLastWindow(this.context, (err: BusinessError, data) => { 665 const errCode: number = err.code; 666 if (errCode) { 667 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 668 return; 669 } 670 windowClass = data; 671 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 672 }); 673 } catch (exception) { 674 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`); 675 } 676 } 677} 678``` 679 680## window.getLastWindow<sup>9+</sup> 681 682getLastWindow(ctx: BaseContext): Promise<Window> 683 684获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口,使用Promise异步回调。 685 686**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 687 688**系统能力:** SystemCapability.WindowManager.WindowManager.Core 689 690**参数:** 691 692| 参数名 | 类型 | 必填 | 说明 | 693| ------ | ----------- | ---- | ------------------------------------------------------------ | 694| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 695 696**返回值:** 697 698| 类型 | 说明 | 699| -------------------------------- | ------------------------------------------- | 700| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 701 702**错误码:** 703 704以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 705 706| 错误码ID | 错误信息 | 707| ------- | -------------------------------- | 708| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 709| 1300002 | This window state is abnormal. | 710| 1300006 | This window context is abnormal. | 711 712**示例:** 713 714```ts 715// EntryAbility.ets 716import { UIAbility } from '@kit.AbilityKit'; 717import { BusinessError } from '@kit.BasicServicesKit'; 718 719export default class EntryAbility extends UIAbility { 720 // ... 721 onWindowStageCreate(windowStage: window.WindowStage) { 722 console.info('onWindowStageCreate'); 723 let windowClass: window.Window | undefined = undefined; 724 try { 725 let promise = window.getLastWindow(this.context); 726 promise.then((data) => { 727 windowClass = data; 728 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 729 }).catch((err: BusinessError) => { 730 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 731 }); 732 } catch (exception) { 733 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`); 734 } 735 } 736} 737``` 738 739## window.shiftAppWindowFocus<sup>11+</sup> 740shiftAppWindowFocus(sourceWindowId: number, targetWindowId: number): Promise<void> 741 742在同应用内将窗口焦点从源窗口转移到目标窗口,仅支持应用主窗和子窗的焦点转移。 743 744**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 745 746**系统能力:** SystemCapability.Window.SessionManager 747 748**参数:** 749 750| 参数名 | 类型 | 必填 | 说明 | 751| -------------- | ------ | ----- | ----------------------- | 752| sourceWindowId | number | 是 | 源窗口id,必须是获焦状态。| 753| targetWindowId | number | 是 | 目标窗口id。 | 754 755**返回值:** 756 757| 类型 | 说明 | 758| ------------------- | ------------------------- | 759| Promise<void> | 无返回结果的Promise对象。 | 760 761**错误码:** 762 763以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 764 765| 错误码ID | 错误信息 | 766| ------- | --------------------------------------------- | 767| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 768| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 769| 1300002 | This window state is abnormal. | 770| 1300003 | This window manager service works abnormally. | 771| 1300004 | Unauthorized operation. | 772 773**示例:** 774 775```ts 776// EntryAbility.ets 777import { UIAbility } from '@kit.AbilityKit'; 778import { BusinessError } from '@kit.BasicServicesKit'; 779 780export default class EntryAbility extends UIAbility { 781 onWindowStageCreate(windowStage: window.WindowStage) { 782 // ... 783 console.info('onWindowStageCreate'); 784 let windowClass: window.Window | undefined = undefined; 785 let subWindowClass: window.Window | undefined = undefined; 786 let windowClassId: number = -1; 787 let subWindowClassId: number = -1; 788 789 try { 790 // 获取应用主窗及ID 791 let promise = windowStage.getMainWindow(); 792 promise.then((data) => { 793 if (data == null) { 794 console.error("Failed to obtaining the window. Cause: The data is empty"); 795 return; 796 } 797 windowClass = data; 798 windowClass.setUIContent("pages/Index"); 799 windowClassId = windowClass.getWindowProperties().id; 800 console.info('Succeeded in obtaining the window') 801 }).catch((err: BusinessError) => { 802 console.error(`Failed to obtaining the window. Cause code: ${err.code}, message: ${err.message}`); 803 }); 804 805 // 创建或获取子窗及ID,此时子窗口获焦 806 let promiseSub = windowStage.createSubWindow("testSubWindow"); 807 promiseSub.then((data) => { 808 if (data == null) { 809 console.error("Failed to obtaining the window. Cause: The data is empty"); 810 return; 811 } 812 subWindowClass = data; 813 subWindowClassId = subWindowClass.getWindowProperties().id; 814 subWindowClass.resize(500, 500); 815 subWindowClass.setUIContent("pages/Index2"); 816 subWindowClass.showWindow(); 817 818 // 监听Window状态,确保已经就绪 819 subWindowClass.on("windowEvent", (windowEvent) => { 820 if (windowEvent == window.WindowEventType.WINDOW_ACTIVE) { 821 // 切换焦点 822 let promise = window.shiftAppWindowFocus(subWindowClassId, windowClassId); 823 promise.then(() => { 824 console.info('Succeeded in shifting app window focus'); 825 }).catch((err: BusinessError) => { 826 console.error(`Failed to shift app window focus. Cause code: ${err.code}, message: ${err.message}`); 827 }); 828 } 829 }); 830 }); 831 } catch (exception) { 832 console.error(`Failed to shift app focus. Cause code: ${exception.code}, message: ${exception.message}`); 833 } 834 } 835} 836``` 837 838## window.shiftAppWindowPointerEvent<sup>15+</sup> 839shiftAppWindowPointerEvent(sourceWindowId: number, targetWindowId: number): Promise<void> 840 841在同应用内窗口分合场景下,需要将输入事件从源窗口转移到目标窗口,使用Promise异步回调,仅在2in1设备上,针对主窗和子窗生效。 842 843在2in1设备上,源窗口需要处于鼠标按下状态,否则调用此接口将不生效。输入事件转移后,会向源窗口补发鼠标抬起事件,并且向目标窗口补发鼠标按下事件。 844 845**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 846 847**系统能力:** SystemCapability.Window.SessionManager 848 849**参数:** 850 851| 参数名 | 类型 | 必填 | 说明 | 852| -------------- | ------ | ----- | ----------------------- | 853| sourceWindowId | number | 是 | 源窗口id。推荐使用[getWindowProperties()](#getwindowproperties9)方法获取窗口id属性。 | 854| targetWindowId | number | 是 | 目标窗口id。推荐使用[getWindowProperties()](#getwindowproperties9)方法获取窗口id属性。 | 855 856**返回值:** 857 858| 类型 | 说明 | 859| ------------------- | ------------------------- | 860| Promise<void> | 无返回结果的Promise对象。 | 861 862**错误码:** 863 864以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 865 866| 错误码ID | 错误信息 | 867| ------- | --------------------------------------------- | 868| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 869| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 870| 1300002 | This window state is abnormal. | 871| 1300003 | This window manager service works abnormally. | 872| 1300004 | Unauthorized operation. | 873 874**示例:** 875 876```ts 877// ets/pages/Index.ets 878import { window } from '@kit.ArkUI'; 879import { BusinessError } from '@kit.BasicServicesKit'; 880 881@Entry 882struct Index { 883 build() { 884 Row() { 885 Column() { 886 Blank('160') 887 .color(Color.Blue) 888 .onTouch((event: TouchEvent) => { 889 if (event.type === TouchType.Down) { 890 try { 891 let sourceWindowId = 1; 892 let targetWindowId = 2; 893 let promise = window.shiftAppWindowPointerEvent(sourceWindowId, targetWindowId); 894 promise.then(() => { 895 console.info('Succeeded in shifting app window pointer event'); 896 }).catch((err: BusinessError) => { 897 console.error(`Failed to shift app window pointer event. Cause code: ${err.code}, message: ${err.message}`); 898 }); 899 } catch (exception) { 900 console.error(`Failed to shift app pointer event. Cause code: ${exception.code}, message: ${exception.message}`); 901 } 902 } 903 }) 904 }.width('100%') 905 }.height('100%').width('100%') 906 } 907} 908``` 909 910## window.getWindowsByCoordinate<sup>14+</sup> 911 912getWindowsByCoordinate(displayId: number, windowNumber?: number, x?: number, y?: number): Promise<Array<Window>> 913 914查询本应用指定坐标下的可见窗口,使用Promise异步回调。 915 916**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 917 918**系统能力:** SystemCapability.Window.SessionManager 919 920**参数:** 921 922| 参数名 | 类型 | 必填 | 说明 | 923| ------ | ---------- |----|---------------------------------------------------------------------------| 924| displayId | number| 是 | 查询窗口所在的displayId,该参数应为整数,可以在窗口属性[WindowProperties](#windowproperties)中获取。 | 925| windowNumber | number| 否 | 查询的窗口数量,该参数应为大于0整数,未设置或小于等于0返回所有满足条件的窗口。 | 926| x | number | 否 | 查询的x坐标,该参数应为非负整数,未设置或小于0返回所有可见窗口。 | 927| y | number| 否 | 查询的y坐标,该参数应为非负整数,未设置或小于0返回所有可见窗口。 | 928 929**返回值:** 930 931| 类型 | 说明 | 932| -------------------------------- |-------------------------| 933| Promise<Array<[Window](#window)>> | Promise对象。返回获取到的窗口对象数组。 | 934 935**错误码:** 936 937以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 938 939| 错误码ID | 错误信息 | 940|----------| ------------------------------ | 941| 401 | Parameter error. Possible cause: Incorrect parameter types. | 942| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 943| 1300003 | This window manager service works abnormally. | 944 945```ts 946import { UIAbility } from '@kit.AbilityKit'; 947import { window } from '@kit.ArkUI'; 948import { BusinessError } from '@kit.BasicServicesKit'; 949 950export default class EntryAbility extends UIAbility { 951 952 onWindowStageCreate(windowStage: window.WindowStage): void { 953 let windowClass = windowStage.getMainWindowSync(); 954 try { 955 let properties = windowClass.getWindowProperties(); 956 window.getWindowsByCoordinate(properties.displayId).then((data) => { 957 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 958 for (let window of data) { 959 // do something with window 960 } 961 }).catch((err: BusinessError) => { 962 console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`); 963 }); 964 window.getWindowsByCoordinate(properties.displayId, 2, 500, 500).then((data) => { 965 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 966 for (let window of data) { 967 // do something with window 968 } 969 }).catch((err: BusinessError) => { 970 console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`); 971 }); 972 } catch (exception) { 973 console.error(`Failed to get window from point. Cause code: ${exception.code}, message: ${exception.message}`); 974 } 975 } 976} 977``` 978 979## window.getAllWindowLayoutInfo<sup>15+</sup> 980 981getAllWindowLayoutInfo(displayId: number): Promise<Array<WindowLayoutInfo>> 982 983获取指定屏幕上可见的窗口布局信息数组,按当前窗口层级排列,层级最高的对应数组index为0,使用Promise异步回调。 984 985**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 986 987**系统能力:** SystemCapability.Window.SessionManager 988 989**参数:** 990 991| 参数名 | 类型 | 必填 | 说明 | 992| ------ | ---------- |----|---------------------------------------------------------------------------| 993| displayId | number| 是 | 需要获取窗口布局信息的displayId,该参数应为整数,且为当前实际存在屏幕的displayId,可以通过窗口属性[WindowProperties](#windowproperties)获取。 | 994 995**返回值:** 996 997| 类型 | 说明 | 998| -------------------------------- |-------------------------| 999| Promise<Array<[WindowLayoutInfo](#windowlayoutinfo15)>> | Promise对象。返回获取到的窗口布局信息对象数组。 | 1000 1001**错误码:** 1002 1003以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1004 1005| 错误码ID | 错误信息 | 1006|----------| ------------------------------ | 1007| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1008| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1009| 1300002 | This window state is abnormal. | 1010| 1300003 | This window manager service works abnormally. | 1011 1012```ts 1013import { window } from '@kit.ArkUI'; 1014import { BusinessError } from '@kit.BasicServicesKit'; 1015 1016try { 1017 let displayId = 0; 1018 let promise = window.getAllWindowLayoutInfo(displayId); 1019 promise.then((data) => { 1020 console.info('Succeeded in obtaining all window layout info. Data: ' + JSON.stringify(data)); 1021 }).catch((err: BusinessError) => { 1022 console.error(`Failed to obtain all window layout info. Cause code: ${err.code}, message: ${err.message}`); 1023 }); 1024} catch (exception) { 1025 console.error(`Failed to obtain all window layout info. Cause code: ${exception.code}, message: ${exception.message}`); 1026} 1027``` 1028 1029## window.create<sup>(deprecated)</sup> 1030 1031create(id: string, type: WindowType, callback: AsyncCallback<Window>): void 1032 1033创建子窗口,使用callback异步回调。 1034 1035> **说明:** 1036> 1037> 从API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。 1038 1039**模型约束:** 此接口仅可在FA模型下使用。 1040 1041**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1042 1043**参数:** 1044 1045| 参数名 | 类型 | 必填 | 说明 | 1046| -------- | -------------------------------------- | ---- | ------------------------------------ | 1047| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。| 1048| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 1049| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的子窗口对象。 | 1050 1051 1052**示例:** 1053 1054```ts 1055import { BusinessError } from '@kit.BasicServicesKit'; 1056 1057let windowClass: window.Window | undefined = undefined; 1058window.create('test', window.WindowType.TYPE_APP, (err: BusinessError, data) => { 1059 const errCode: number = err.code; 1060 if (errCode) { 1061 console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`); 1062 return; 1063 } 1064 windowClass = data; 1065 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 1066}); 1067``` 1068 1069## window.create<sup>(deprecated)</sup> 1070 1071create(id: string, type: WindowType): Promise<Window> 1072 1073创建子窗口,使用Promise异步回调。 1074 1075> **说明:** 1076> 1077> 从API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。 1078 1079**模型约束:** 此接口仅可在FA模型下使用。 1080 1081**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1082 1083**参数:** 1084 1085| 参数名 | 类型 | 必填 | 说明 | 1086| ------ | ------------------------- | ---- | ---------- | 1087| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 1088| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 1089 1090**返回值:** 1091 1092| 类型 | 说明 | 1093| -------------------------------- | --------------------------------------- | 1094| Promise<[Window](#window)> | Promise对象。返回当前创建的子窗口对象。 | 1095 1096 1097**示例:** 1098 1099```ts 1100import { BusinessError } from '@kit.BasicServicesKit'; 1101 1102let windowClass: window.Window | undefined = undefined; 1103let promise = window.create('test', window.WindowType.TYPE_APP); 1104promise.then((data) => { 1105 windowClass = data; 1106 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 1107}).catch((err: BusinessError) => { 1108 console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`); 1109}); 1110``` 1111 1112## window.create<sup>(deprecated)</sup> 1113 1114create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback<Window>): void 1115 1116创建系统窗口,使用callback异步回调。 1117 1118> **说明:** 1119> 1120> 从API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。 1121 1122**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1123 1124**参数:** 1125 1126| 参数名 | 类型 | 必填 | 说明 | 1127| -------- | ------------------------------------------------------- | ---- | ------------------------------------ | 1128| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1129| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 1130| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 1131| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的子窗口对象。 | 1132 1133 1134**示例:** 1135 1136```ts 1137import { BusinessError } from '@kit.BasicServicesKit'; 1138 1139let windowClass: window.Window | undefined = undefined; 1140window.create('test', window.WindowType.TYPE_SYSTEM_ALERT, (err: BusinessError, data) => { 1141 const errCode: number = err.code; 1142 if (errCode) { 1143 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 1144 return; 1145 } 1146 windowClass = data; 1147 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 1148 windowClass.resetSize(500, 1000); 1149}); 1150``` 1151 1152## window.create<sup>(deprecated)</sup> 1153 1154create(ctx: BaseContext, id: string, type: WindowType): Promise<Window> 1155 1156创建系统窗口,使用Promise异步回调。 1157 1158> **说明:** 1159> 1160> 从API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。 1161 1162**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1163 1164**参数:** 1165 1166| 参数名 | 类型 | 必填 | 说明 | 1167| ------ | ------------------------- | ---- | ------------------------------------------------------------ | 1168| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1169| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 1170| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 1171 1172**返回值:** 1173 1174| 类型 | 说明 | 1175| -------------------------------- | --------------------------------------- | 1176| Promise<[Window](#window)> | Promise对象。返回当前创建的子窗口对象。 | 1177 1178 1179**示例:** 1180 1181```ts 1182import { BusinessError } from '@kit.BasicServicesKit'; 1183 1184let windowClass: window.Window | undefined = undefined; 1185let promise = window.create('test', window.WindowType.TYPE_SYSTEM_ALERT); 1186promise.then((data) => { 1187 windowClass = data; 1188 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 1189}).catch((err: BusinessError) => { 1190 console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`); 1191}); 1192``` 1193 1194## window.find<sup>(deprecated)</sup> 1195 1196find(id: string, callback: AsyncCallback<Window>): void 1197 1198查找id所对应的窗口,使用callback异步回调。 1199 1200> **说明:** 1201> 1202> 从API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。 1203 1204**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1205 1206**参数:** 1207 1208| 参数名 | 类型 | 必填 | 说明 | 1209| -------- | -------------------------------------- | ---- | ------------------------------------ | 1210| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 1211| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前查找到的窗口对象。 | 1212 1213**示例:** 1214 1215```ts 1216import { BusinessError } from '@kit.BasicServicesKit'; 1217 1218let windowClass: window.Window | undefined = undefined; 1219window.find('test', (err: BusinessError, data) => { 1220 const errCode: number = err.code; 1221 if (errCode) { 1222 console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`); 1223 return; 1224 } 1225 windowClass = data; 1226 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 1227}); 1228``` 1229 1230## window.find<sup>(deprecated)</sup> 1231 1232find(id: string): Promise<Window> 1233 1234查找id所对应的窗口,使用Promise异步回调。 1235 1236> **说明:** 1237> 1238> 从API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。 1239 1240**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1241 1242**参数:** 1243 1244| 参数名 | 类型 | 必填 | 说明 | 1245| ------ | ------ | ---- | -------- | 1246| id | string | 是 | 窗口名字,即[Configuration](#configuration9)中的name。 | 1247 1248**返回值:** 1249 1250| 类型 | 说明 | 1251| -------------------------------- | ------------------------------------- | 1252| Promise<[Window](#window)> | Promise对象。返回当前查找的窗口对象。 | 1253 1254**示例:** 1255 1256```ts 1257import { BusinessError } from '@kit.BasicServicesKit'; 1258 1259let windowClass: window.Window | undefined = undefined; 1260let promise = window.find('test'); 1261promise.then((data) => { 1262 windowClass = data; 1263 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 1264}).catch((err: BusinessError) => { 1265 console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`); 1266}); 1267``` 1268 1269## window.getTopWindow<sup>(deprecated)</sup> 1270 1271getTopWindow(callback: AsyncCallback<Window>): void 1272 1273获取当前应用内最后显示的窗口,使用callback异步回调。 1274 1275> **说明:** 1276> 1277> 从API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。 1278 1279**模型约束:** 此接口仅可在FA模型下使用。 1280 1281**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1282 1283**参数:** 1284 1285| 参数名 | 类型 | 必填 | 说明 | 1286| -------- | -------------------------------------- | ---- | -------------------------------------------- | 1287| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 1288 1289**示例:** 1290 1291```ts 1292import { BusinessError } from '@kit.BasicServicesKit'; 1293 1294let windowClass: window.Window | undefined = undefined; 1295window.getTopWindow((err: BusinessError, data) => { 1296 const errCode: number = err.code; 1297 if (errCode) { 1298 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 1299 return; 1300 } 1301 windowClass = data; 1302 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1303}); 1304``` 1305 1306## window.getTopWindow<sup>(deprecated)</sup> 1307 1308getTopWindow(): Promise<Window> 1309 1310获取当前应用内最后显示的窗口,使用Promise异步回调。 1311 1312> **说明:** 1313> 1314> 从API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。 1315 1316**模型约束:** 此接口仅可在FA模型下使用。 1317 1318**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1319 1320**返回值:** 1321 1322| 类型 | 说明 | 1323| -------------------------------- | ----------------------------------------------- | 1324| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 1325 1326**示例:** 1327 1328```ts 1329import { BusinessError } from '@kit.BasicServicesKit'; 1330 1331let windowClass: window.Window | undefined = undefined; 1332let promise = window.getTopWindow(); 1333promise.then((data)=> { 1334 windowClass = data; 1335 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1336}).catch((err: BusinessError)=>{ 1337 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 1338}); 1339``` 1340 1341## window.getTopWindow<sup>(deprecated)</sup> 1342 1343getTopWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 1344 1345获取当前应用内最后显示的窗口,使用callback异步回调。 1346 1347> **说明:** 1348> 1349> 从API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。 1350 1351**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1352 1353**参数:** 1354 1355| 参数名 | 类型 | 必填 | 说明 | 1356| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 1357| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1358| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 1359 1360**示例:** 1361 1362```ts 1363// EntryAbility.ets 1364import { UIAbility } from '@kit.AbilityKit'; 1365import { BusinessError } from '@kit.BasicServicesKit'; 1366 1367export default class EntryAbility extends UIAbility { 1368 onWindowStageCreate(windowStage:window.WindowStage){ 1369 console.info('onWindowStageCreate'); 1370 let windowClass: window.Window | undefined = undefined; 1371 try { 1372 window.getTopWindow(this.context, (err: BusinessError, data) => { 1373 const errCode: number = err.code; 1374 if(errCode){ 1375 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 1376 return ; 1377 } 1378 windowClass = data; 1379 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1380 }); 1381 } catch(error){ 1382 console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`); 1383 } 1384 } 1385} 1386``` 1387 1388## window.getTopWindow<sup>(deprecated)</sup> 1389 1390getTopWindow(ctx: BaseContext): Promise<Window> 1391 1392获取当前应用内最后显示的窗口,使用Promise异步回调。 1393 1394> **说明:** 1395> 1396> 从API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。 1397 1398**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1399 1400**参数:** 1401 1402| 参数名 | 类型 | 必填 | 说明 | 1403| ------ | ----------- | ---- | ------------------------------------------------------------ | 1404| ctx | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1405 1406**返回值:** 1407 1408| 类型 | 说明 | 1409| -------------------------------- | ----------------------------------------------- | 1410| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 1411 1412**示例:** 1413 1414```ts 1415// EntryAbility.ets 1416import { UIAbility } from '@kit.AbilityKit'; 1417import { BusinessError } from '@kit.BasicServicesKit'; 1418 1419export default class EntryAbility extends UIAbility { 1420 onWindowStageCreate(windowStage:window.WindowStage) { 1421 console.info('onWindowStageCreate'); 1422 let windowClass: window.Window | undefined = undefined; 1423 let promise = window.getTopWindow(this.context); 1424 promise.then((data) => { 1425 windowClass = data; 1426 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1427 }).catch((error: BusinessError) => { 1428 console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`); 1429 }); 1430 } 1431} 1432``` 1433 1434## window.getVisibleWindowInfo<sup>18+</sup> 1435 1436getVisibleWindowInfo(): Promise<Array<WindowInfo>> 1437 1438获取当前屏幕的可见主窗口(未退至后台的主窗口)信息。使用Promise异步回调。 1439 1440**系统能力:** SystemCapability.Window.SessionManager 1441 1442**需要权限:** ohos.permission.VISIBLE_WINDOW_INFO 1443 1444**返回值:** 1445 1446| 类型 | 说明 | 1447| ------------------- | ----------------------- | 1448| Promise<Array<[WindowInfo](#windowinfo18)>> | Promise对象,返回当前可见窗口的相关信息。 | 1449 1450**错误码:** 1451 1452以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1453 1454| 错误码ID | 错误信息 | 1455| ------- | ------------------------------ | 1456| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1457| 801 | Capability not supported. Function getVisibleWindowInfo can not work correctly due to limited device capabilities. | 1458| 1300003 | This window manager service works abnormally. | 1459 1460**示例:** 1461 1462```ts 1463import { window } from '@kit.ArkUI'; 1464import { BusinessError } from '@kit.BasicServicesKit'; 1465 1466let promise = window.getVisibleWindowInfo(); 1467promise.then((data) => { 1468 data.forEach(windowInfo=>{ 1469 console.info(`left:${windowInfo.rect.left}`); 1470 console.info(`top:${windowInfo.rect.top}`); 1471 console.info(`width:${windowInfo.rect.width}`); 1472 console.info(`height:${windowInfo.rect.height}`); 1473 console.info(`windowId:${windowInfo.windowId}`); 1474 console.info(`windowStatusType:${windowInfo.windowStatusType}`); 1475 console.info(`abilityName:${windowInfo.abilityName}`); 1476 console.info(`bundleName:${windowInfo.bundleName}`); 1477 console.info(`isFocused:${windowInfo.isFocused}`); 1478 }) 1479}).catch((err: BusinessError) => { 1480 console.error('Failed to getWindowInfo. Cause: ' + JSON.stringify(err)); 1481}); 1482``` 1483 1484## SpecificSystemBar<sup>11+</sup> 1485 1486type SpecificSystemBar = 'status' \| 'navigation' \| 'navigationIndicator' 1487 1488当前支持显示或隐藏的系统栏类型。 1489 1490**系统能力:** SystemCapability.Window.SessionManager 1491 1492**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1493 1494| 类型 | 说明 | 1495|------------|--------| 1496| 'status' | 状态栏。 | 1497| 'navigation' | 三键导航栏。 | 1498| 'navigationIndicator' | 底部导航条。 | 1499 1500## Window 1501 1502当前窗口实例,窗口管理器管理的基本单元。 1503 1504下列API示例中都需先使用[getLastWindow()](#windowgetlastwindow9)、[createWindow()](#windowcreatewindow9)、[findWindow()](#windowfindwindow9)中的任一方法获取到Window实例(windowClass),再通过此实例调用对应方法。 1505 1506### showWindow<sup>9+</sup> 1507 1508showWindow(callback: AsyncCallback<void>): void 1509 1510显示当前窗口,使用callback异步回调,仅支持系统窗口及应用子窗口,或将已显示的应用主窗口的层级提升至顶部。 1511 1512**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1513 1514**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1515 1516**参数:** 1517 1518| 参数名 | 类型 | 必填 | 说明 | 1519| -------- | ------------------------- | -- | --------- | 1520| callback | AsyncCallback<void> | 是 | 回调函数。 | 1521 1522**错误码:** 1523 1524以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1525 1526| 错误码ID | 错误信息 | 1527| ------- | ------------------------------ | 1528| 1300002 | This window state is abnormal. | 1529 1530**示例:** 1531 1532```ts 1533import { BusinessError } from '@kit.BasicServicesKit'; 1534 1535windowClass.showWindow((err: BusinessError) => { 1536 const errCode: number = err.code; 1537 if (errCode) { 1538 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 1539 return; 1540 } 1541 console.info('Succeeded in showing the window.'); 1542}); 1543``` 1544 1545### showWindow<sup>9+</sup> 1546 1547showWindow(): Promise<void> 1548 1549显示当前窗口,使用Promise异步回调,仅支持系统窗口及应用子窗口,或将已显示的应用主窗口的层级提升至顶部。 1550 1551**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1552 1553**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1554 1555**返回值:** 1556 1557| 类型 | 说明 | 1558| ------------------- | ----------------------- | 1559| Promise<void> | 无返回结果的Promise对象。 | 1560 1561**错误码:** 1562 1563以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1564 1565| 错误码ID | 错误信息 | 1566| ------- | ------------------------------ | 1567| 1300002 | This window state is abnormal. | 1568 1569**示例:** 1570 1571```ts 1572import { BusinessError } from '@kit.BasicServicesKit'; 1573 1574let promise = windowClass.showWindow(); 1575promise.then(() => { 1576 console.info('Succeeded in showing the window.'); 1577}).catch((err: BusinessError) => { 1578 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 1579}); 1580``` 1581 1582### destroyWindow<sup>9+</sup> 1583 1584destroyWindow(callback: AsyncCallback<void>): void 1585 1586销毁当前窗口,使用callback异步回调,仅支持系统窗口及应用子窗口。 1587 1588**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1589 1590**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1591 1592**参数:** 1593 1594| 参数名 | 类型 | 必填 | 说明 | 1595| -------- | ------------------------- | -- | --------- | 1596| callback | AsyncCallback<void> | 是 | 回调函数。 | 1597 1598**错误码:** 1599 1600以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1601 1602| 错误码ID | 错误信息 | 1603| ------- | -------------------------------------------- | 1604| 1300002 | This window state is abnormal. | 1605| 1300003 | This window manager service works abnormally. | 1606 1607**示例:** 1608 1609```ts 1610import { BusinessError } from '@kit.BasicServicesKit'; 1611 1612windowClass.destroyWindow((err) => { 1613 const errCode: number = err.code; 1614 if (errCode) { 1615 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 1616 return; 1617 } 1618 console.info('Succeeded in destroying the window.'); 1619}); 1620``` 1621 1622### destroyWindow<sup>9+</sup> 1623 1624destroyWindow(): Promise<void> 1625 1626销毁当前窗口,使用Promise异步回调,仅支持系统窗口及应用子窗口。 1627 1628**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1629 1630**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1631 1632**返回值:** 1633 1634| 类型 | 说明 | 1635| ------------------- | ------------------------ | 1636| Promise<void> | 无返回结果的Promise对象。 | 1637 1638**错误码:** 1639 1640以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1641 1642| 错误码ID | 错误信息 | 1643| ------- | -------------------------------------------- | 1644| 1300002 | This window state is abnormal. | 1645| 1300003 | This window manager service works abnormally. | 1646 1647**示例:** 1648 1649```ts 1650import { BusinessError } from '@kit.BasicServicesKit'; 1651 1652let promise = windowClass.destroyWindow(); 1653promise.then(() => { 1654 console.info('Succeeded in destroying the window.'); 1655}).catch((err: BusinessError) => { 1656 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 1657}); 1658``` 1659 1660### moveWindowTo<sup>9+</sup> 1661 1662moveWindowTo(x: number, y: number, callback: AsyncCallback<void>): void 1663 1664移动窗口位置,使用callback异步回调。 1665 1666<!--RP4--> 1667全屏模式下,本接口仅在2in1设备上生效。<!--RP4End--> 1668在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。 1669 1670**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1671 1672**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1673 1674**参数:** 1675 1676| 参数名 | 类型 | 必填 | 说明 | 1677| -------- | ------------------------- | -- | --------------------------------------------- | 1678| x | number | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1679| y | number | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在y轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1680| callback | AsyncCallback<void> | 是 | 回调函数。 | 1681 1682**错误码:** 1683 1684以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1685 1686| 错误码ID | 错误信息 | 1687| ------- | -------------------------------------------- | 1688| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1689| 1300002 | This window state is abnormal. | 1690| 1300003 | This window manager service works abnormally. | 1691 1692**示例:** 1693 1694```ts 1695import { BusinessError } from '@kit.BasicServicesKit'; 1696 1697try { 1698 windowClass.moveWindowTo(300, 300, (err: BusinessError) => { 1699 const errCode: number = err.code; 1700 if (errCode) { 1701 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1702 return; 1703 } 1704 console.info('Succeeded in moving the window.'); 1705 }); 1706} catch (exception) { 1707 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1708} 1709``` 1710 1711### moveWindowTo<sup>9+</sup> 1712 1713moveWindowTo(x: number, y: number): Promise<void> 1714 1715移动窗口位置,使用Promise异步回调。调用成功即返回,该接口返回后无法立即获取最终生效结果,如需立即获取,建议使用接口[moveWindowToAsync()](#movewindowtoasync12)。 1716 1717<!--RP4--> 1718全屏模式下,本接口仅在2in1设备上生效。<!--RP4End--> 1719在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。 1720 1721**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1722 1723**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1724 1725**参数:** 1726 1727| 参数名 | 类型 | 必填 | 说明 | 1728| -- | ----- | -- | --------------------------------------------- | 1729| x | number | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1730| y | number | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在y轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1731 1732**返回值:** 1733 1734| 类型 | 说明 | 1735| ------------------- | ------------------------ | 1736| Promise<void> | 无返回结果的Promise对象。 | 1737 1738**错误码:** 1739 1740以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1741 1742| 错误码ID | 错误信息 | 1743| ------- | -------------------------------------------- | 1744| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1745| 1300002 | This window state is abnormal. | 1746| 1300003 | This window manager service works abnormally. | 1747 1748**示例:** 1749 1750```ts 1751import { BusinessError } from '@kit.BasicServicesKit'; 1752 1753try { 1754 let promise = windowClass.moveWindowTo(300, 300); 1755 promise.then(() => { 1756 console.info('Succeeded in moving the window.'); 1757 }).catch((err: BusinessError) => { 1758 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1759 }); 1760} catch (exception) { 1761 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1762} 1763``` 1764 1765### moveWindowToAsync<sup>12+</sup> 1766 1767moveWindowToAsync(x: number, y: number): Promise<void> 1768 1769移动窗口位置,使用Promise异步回调。调用生效后返回,回调中可使用getWindowProperties(见示例)立即获取最终生效结果。 1770 1771仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效。 1772在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。 1773 1774**系统能力:** SystemCapability.Window.SessionManager 1775 1776**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1777 1778**参数:** 1779 1780| 参数名 | 类型 | 必填 | 说明 | 1781| -- | ----- | -- | --------------------------------------------- | 1782| x | number | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1783| y | number | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在y轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 1784 1785**返回值:** 1786 1787| 类型 | 说明 | 1788| ------------------- | ------------------------ | 1789| Promise<void> | 无返回结果的Promise对象。 | 1790 1791**错误码:** 1792 1793以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1794 1795| 错误码ID | 错误信息 | 1796| ------- | -------------------------------------------- | 1797| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1798| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1799| 1300002 | This window state is abnormal. | 1800| 1300003 | This window manager service works abnormally. | 1801| 1300010 | The operation in the current window status is invalid. | 1802 1803**示例:** 1804 1805```ts 1806import { BusinessError } from '@kit.BasicServicesKit'; 1807 1808try { 1809 let promise = windowClass.moveWindowToAsync(300, 300); 1810 promise.then(() => { 1811 console.info('Succeeded in moving the window.'); 1812 let rect = windowClass?.getWindowProperties().windowRect; 1813 console.info(`Get window rect: ` + JSON.stringify(rect)); 1814 }).catch((err: BusinessError) => { 1815 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1816 }); 1817} catch (exception) { 1818 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1819} 1820``` 1821 1822### moveWindowToAsync<sup>15+</sup> 1823 1824moveWindowToAsync(x: number, y: number, moveConfiguration?: MoveConfiguration): Promise<void> 1825 1826移动窗口位置,使用Promise异步回调。调用生效后返回,回调中可使用getWindowProperties(见示例)立即获取最终生效结果。 1827 1828仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效。 1829在2in1设备上窗口相对于屏幕移动,其他设备上窗口相对于父窗口移动。 1830 1831**系统能力:** SystemCapability.Window.SessionManager 1832 1833**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 1834 1835**参数:** 1836 1837| 参数名 | 类型 | 必填 | 说明 | 1838| -- | ----- | -- | --------------------------------------------- | 1839| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数应该为整数,非整数输入将向下取整。 | 1840| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数应该为整数,非整数输入将向下取整。 | 1841| moveConfiguration | [MoveConfiguration](#moveconfiguration15) | 否 | 窗口移动选项,未设置将默认保持为当前屏幕。 | 1842 1843**返回值:** 1844 1845| 类型 | 说明 | 1846| ------------------- | ------------------------ | 1847| Promise<void> | 无返回结果的Promise对象。 | 1848 1849**错误码:** 1850 1851以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1852 1853| 错误码ID | 错误信息 | 1854| ------- | -------------------------------------------- | 1855| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1856| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1857| 1300002 | This window state is abnormal. | 1858| 1300003 | This window manager service works abnormally. | 1859| 1300010 | The operation in the current window status is invalid. | 1860 1861**示例:** 1862 1863```ts 1864import { window } from '@kit.ArkUI'; 1865import { BusinessError } from '@kit.BasicServicesKit'; 1866 1867try { 1868 let moveConfiguration: window.MoveConfiguration = { 1869 displayId: 0 1870 }; 1871 let promise = windowClass.moveWindowToAsync(300, 300, moveConfiguration); 1872 promise.then(() => { 1873 console.info('Succeeded in moving the window.'); 1874 let rect = windowClass?.getWindowProperties().windowRect; 1875 console.info(`Get window rect: ` + JSON.stringify(rect)); 1876 }).catch((err: BusinessError) => { 1877 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1878 }); 1879} catch (exception) { 1880 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1881} 1882``` 1883 1884### moveWindowToGlobal<sup>13+</sup> 1885 1886moveWindowToGlobal(x: number, y: number): Promise<void> 1887 1888基于屏幕坐标移动窗口位置,使用Promise异步回调。调用生效后返回。 1889 1890全屏模式窗口不支持该操作。 1891 1892在非2in1设备下,子窗会跟随主窗移动。 1893 1894**系统能力:** SystemCapability.Window.SessionManager 1895 1896**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 1897 1898**参数:** 1899 1900| 参数名 | 类型 | 必填 | 说明 | 1901| -- | ----- | -- | --------------------------------------------- | 1902| x | number | 是 | 表示以屏幕左上角为起点,窗口在x轴方向移动的值,单位为px。值为正表示右移,值为负表示左移。该参数仅支持整数输入,浮点数输入将向下取整。 | 1903| y | number | 是 | 表示以屏幕左上角为起点,窗口在y轴方向移动的值,单位为px。值为正表示下移,值为负表示上移。该参数仅支持整数输入,浮点数输入将向下取整。 | 1904 1905**返回值:** 1906 1907| 类型 | 说明 | 1908| ------------------- | ------------------------ | 1909| Promise<void> | 无返回结果的Promise对象。 | 1910 1911**错误码:** 1912 1913以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1914 1915| 错误码ID | 错误信息 | 1916| ------- | -------------------------------------------- | 1917| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1918| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1919| 1300002 | This window state is abnormal. | 1920| 1300003 | This window manager service works abnormally. | 1921| 1300010 | The operation in the current window status is invalid. | 1922 1923**示例:** 1924 1925```ts 1926import { BusinessError } from '@kit.BasicServicesKit'; 1927 1928try { 1929 let promise = windowClass.moveWindowToGlobal(300, 300); 1930 promise.then(() => { 1931 console.info('Succeeded in moving the window.'); 1932 }).catch((err: BusinessError) => { 1933 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1934 }); 1935} catch (exception) { 1936 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1937} 1938``` 1939 1940### moveWindowToGlobal<sup>15+</sup> 1941 1942moveWindowToGlobal(x: number, y: number, moveConfiguration?: MoveConfiguration): Promise<void> 1943 1944基于屏幕坐标移动窗口位置,使用Promise异步回调。调用生效后返回。 1945 1946全屏模式窗口不支持该操作。 1947 1948在非2in1设备下,子窗会跟随主窗移动。 1949 1950**系统能力:** SystemCapability.Window.SessionManager 1951 1952**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 1953 1954**参数:** 1955 1956| 参数名 | 类型 | 必填 | 说明 | 1957| -- | ----- | -- | --------------------------------------------- | 1958| x | number | 是 | 表示以目标屏幕左上角为起点,窗口在x轴方向移动的值,单位为px。值为正表示右移,值为负表示左移。该参数应该为整数,非整数输入将向下取整。 | 1959| y | number | 是 | 表示以目标屏幕左上角为起点,窗口在y轴方向移动的值,单位为px。值为正表示下移,值为负表示上移。该参数应该为整数,非整数输入将向下取整。 | 1960| moveConfiguration | [MoveConfiguration](#moveconfiguration15) | 否 | 窗口移动选项,未设置将默认保持为当前屏幕。 | 1961 1962**返回值:** 1963 1964| 类型 | 说明 | 1965| ------------------- | ------------------------ | 1966| Promise<void> | 无返回结果的Promise对象。 | 1967 1968**错误码:** 1969 1970以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1971 1972| 错误码ID | 错误信息 | 1973| ------- | -------------------------------------------- | 1974| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1975| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1976| 1300002 | This window state is abnormal. | 1977| 1300003 | This window manager service works abnormally. | 1978| 1300010 | The operation in the current window status is invalid. | 1979 1980**示例:** 1981 1982```ts 1983import { window } from '@kit.ArkUI'; 1984import { BusinessError } from '@kit.BasicServicesKit'; 1985 1986try { 1987 let moveConfiguration: window.MoveConfiguration = { 1988 displayId: 0 1989 }; 1990 let promise = windowClass.moveWindowToGlobal(300, 300, moveConfiguration); 1991 promise.then(() => { 1992 console.info('Succeeded in moving the window.'); 1993 }).catch((err: BusinessError) => { 1994 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 1995 }); 1996} catch (exception) { 1997 console.error(`Failed to move the window. Cause code: ${exception.code}, message: ${exception.message}`); 1998} 1999``` 2000 2001### resize<sup>9+</sup> 2002 2003resize(width: number, height: number, callback: AsyncCallback<void>): void 2004 2005改变当前窗口大小,使用callback异步回调。 2006 2007应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 2008应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 2009 2010系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 2011 2012设置的宽度与高度受到此约束限制,规则: 2013若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 2014若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 2015 2016全屏模式窗口不支持该操作。 2017 2018**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2019 2020**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2021 2022**参数:** 2023 2024| 参数名 | 类型 | 必填 | 说明 | 2025| -------- | ------------------------- | -- | ------------------------ | 2026| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 2027| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 2028| callback | AsyncCallback<void> | 是 | 回调函数。 | 2029 2030**错误码:** 2031 2032以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2033 2034| 错误码ID | 错误信息 | 2035| ------- | -------------------------------------------- | 2036| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2037| 1300002 | This window state is abnormal. | 2038| 1300003 | This window manager service works abnormally. | 2039 2040**示例:** 2041 2042```ts 2043import { BusinessError } from '@kit.BasicServicesKit'; 2044 2045try { 2046 windowClass.resize(500, 1000, (err: BusinessError) => { 2047 const errCode: number = err.code; 2048 if (errCode) { 2049 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 2050 return; 2051 } 2052 console.info('Succeeded in changing the window size.'); 2053 }); 2054} catch (exception) { 2055 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 2056} 2057``` 2058 2059### resize<sup>9+</sup> 2060 2061resize(width: number, height: number): Promise<void> 2062 2063改变当前窗口大小,使用Promise异步回调。调用成功即返回,该接口返回后无法立即获取最终生效结果,如需立即获取,建议使用接口[resizeAsync()](#resizeasync12)。 2064 2065应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 2066应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 2067 2068系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 2069 2070设置的宽度与高度受到此约束限制,规则: 2071若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 2072若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 2073 2074全屏模式窗口不支持该操作。 2075 2076**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2077 2078**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2079 2080**参数:** 2081 2082| 参数名 | 类型 | 必填 | 说明 | 2083| ------ | ------ | -- | ------------------------ | 2084| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 2085| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 2086 2087**返回值:** 2088 2089| 类型 | 说明 | 2090| ------------------- | ------------------------ | 2091| Promise<void> | 无返回结果的Promise对象。 | 2092 2093**错误码:** 2094 2095以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2096 2097| 错误码ID | 错误信息 | 2098| ------- | -------------------------------------------- | 2099| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2100| 1300002 | This window state is abnormal. | 2101| 1300003 | This window manager service works abnormally. | 2102 2103**示例:** 2104 2105```ts 2106import { BusinessError } from '@kit.BasicServicesKit'; 2107 2108try { 2109 let promise = windowClass.resize(500, 1000); 2110 promise.then(() => { 2111 console.info('Succeeded in changing the window size.'); 2112 }).catch((err: BusinessError) => { 2113 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 2114 }); 2115} catch (exception) { 2116 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 2117} 2118``` 2119 2120### resizeAsync<sup>12+</sup> 2121 2122resizeAsync(width: number, height: number): Promise<void> 2123 2124改变当前窗口大小,使用Promise异步回调。调用生效后返回,回调中可使用getWindowProperties(见示例)立即获取最终生效结果。 2125 2126应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 2127应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 2128 2129系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 2130 2131设置的宽度与高度受到此约束限制,规则: 2132若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 2133若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 2134 2135全屏模式窗口不支持该操作。 2136 2137**系统能力:** SystemCapability.Window.SessionManager 2138 2139**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2140 2141**参数:** 2142 2143| 参数名 | 类型 | 必填 | 说明 | 2144| ------ | ------ | -- | ------------------------ | 2145| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 2146| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 2147 2148**返回值:** 2149 2150| 类型 | 说明 | 2151| ------------------- | ------------------------ | 2152| Promise<void> | 无返回结果的Promise对象。 | 2153 2154**错误码:** 2155 2156以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2157 2158| 错误码ID | 错误信息 | 2159| ------- | -------------------------------------------- | 2160| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2161| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2162| 1300002 | This window state is abnormal. | 2163| 1300003 | This window manager service works abnormally. | 2164| 1300010 | The operation in the current window status is invalid. | 2165 2166**示例:** 2167 2168```ts 2169import { BusinessError } from '@kit.BasicServicesKit'; 2170 2171try { 2172 let promise = windowClass.resizeAsync(500, 1000); 2173 promise.then(() => { 2174 console.info('Succeeded in changing the window size.'); 2175 let rect = windowClass?.getWindowProperties().windowRect; 2176 console.info(`Get window rect: ` + JSON.stringify(rect)); 2177 }).catch((err: BusinessError) => { 2178 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 2179 }); 2180} catch (exception) { 2181 console.error(`Failed to change the window size. Cause code: ${exception.code}, message: ${exception.message}`); 2182} 2183``` 2184 2185### getWindowProperties<sup>9+</sup> 2186 2187getWindowProperties(): WindowProperties 2188 2189获取当前窗口的属性,返回WindowProperties。 2190 2191**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2192 2193**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2194 2195**返回值:** 2196 2197| 类型 | 说明 | 2198| ------------------------------------- | ------------- | 2199| [WindowProperties](#windowproperties) | 当前窗口属性。 | 2200 2201**错误码:** 2202 2203以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 2204 2205| 错误码ID | 错误信息 | 2206| ------- | ------------------------------ | 2207| 1300002 | This window state is abnormal. | 2208 2209**示例:** 2210 2211```ts 2212try { 2213 let properties = windowClass.getWindowProperties(); 2214} catch (exception) { 2215 console.error(`Failed to obtain the window properties. Cause code: ${exception.code}, message: ${exception.message}`); 2216} 2217``` 2218 2219### getWindowDensityInfo<sup>15+</sup> 2220 2221getWindowDensityInfo(): WindowDensityInfo 2222 2223获取当前窗口所在屏幕的系统显示大小缩放系数、系统默认显示大小缩放系数和自定义显示大小缩放系数信息。 2224 2225**系统能力:** SystemCapability.Window.SessionManager 2226 2227**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 2228 2229**返回值:** 2230 2231| 类型 | 说明 | 2232| ------------------------------------- | ------------- | 2233| [WindowDensityInfo](#windowdensityinfo15) | 当前窗口的显示大小缩放系数信息。当返回值为[-1, -1, -1]时,表示当前设备不支持使用该接口。 | 2234 2235**错误码:** 2236 2237以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2238 2239| 错误码ID | 错误信息 | 2240| ------- | ------------------------------ | 2241| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2242| 1300002 | This window state is abnormal. | 2243 2244**示例:** 2245 2246```ts 2247try { 2248 let densityInfo = windowClass.getWindowDensityInfo(); 2249} catch (exception) { 2250 console.error(`Failed to obtain the window densityInfo. Cause code: ${exception.code}, message: ${exception.message}`); 2251} 2252``` 2253 2254### getGlobalRect<sup>13+</sup> 2255 2256getGlobalRect(): Rect 2257 2258获取窗口在屏幕上的真实显示区域,同步接口。 2259 2260在某些设备上,窗口显示时可能经过了缩放,此接口可以获取缩放后窗口在屏幕上的真实位置和大小。 2261 2262**系统能力:** SystemCapability.Window.SessionManager 2263 2264**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 2265 2266**返回值:** 2267 2268| 类型 | 说明 | 2269| ------------------- | ------------------------ | 2270| [Rect](#rect7) | 四元组分别表示距离屏幕左上角的x坐标、距离屏幕左上角的y坐标、缩放后的窗口宽度和缩放后的窗口高度。 | 2271 2272**错误码:** 2273 2274以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2275 2276| 错误码ID | 错误信息 | 2277| ------- | -------------------------------------------- | 2278| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2279| 1300002 | This window state is abnormal. | 2280| 1300003 | This window manager service works abnormally. | 2281 2282**示例:** 2283 2284```ts 2285try { 2286 let rect = windowClass.getGlobalRect(); 2287 console.info(`Succeeded in getting window rect: ` + JSON.stringify(rect)); 2288} catch (exception) { 2289 console.error(`Failed to get window rect. Cause code: ${exception.code}, message: ${exception.message}`); 2290} 2291``` 2292 2293### getWindowAvoidArea<sup>9+</sup> 2294 2295getWindowAvoidArea(type: AvoidAreaType): AvoidArea 2296 2297获取当前应用窗口避让区。避让区指系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 2298 2299该接口一般适用于三种场景:1、在onWindowStageCreate方法中,获取应用启动时的初始布局避让区域时可调用该接口;2、当应用内子窗需要临时显示,对显示内容做布局避让时可调用该接口;3、创建悬浮窗、模态窗或WindowType窗口类型为系统窗口时,调用[setSystemAvoidAreaEnabled](#setsystemavoidareaenabled18)方法使能后,该接口对此类窗口亦生效。 2300 2301**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2302 2303**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2304 2305**参数:** 2306 2307| 参数名 | 类型 | 必填 | 说明 | 2308| ---- |----------------------------------| -- | ------------------------------------------------------------ | 2309| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。 | 2310 2311**返回值:** 2312 2313| 类型 | 说明 | 2314|--------------------------| ----------------- | 2315| [AvoidArea](#avoidarea7) | 窗口内容规避区域。 | 2316 2317**错误码:** 2318 2319以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2320 2321| 错误码ID | 错误信息 | 2322| ------- | ------------------------------ | 2323| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2324| 1300002 | This window state is abnormal. | 2325 2326**示例:** 2327 2328```ts 2329let type = window.AvoidAreaType.TYPE_SYSTEM; 2330try { 2331 let avoidArea = windowClass.getWindowAvoidArea(type); 2332} catch (exception) { 2333 console.error(`Failed to obtain the area. Cause code: ${exception.code}, message: ${exception.message}`); 2334} 2335``` 2336 2337### setSystemAvoidAreaEnabled<sup>18+</sup> 2338 2339setSystemAvoidAreaEnabled(enabled: boolean): Promise<void> 2340 2341创建悬浮窗、模态窗或WindowType窗口类型为系统窗口时,可以调用该接口使能窗口获取[避让区](#avoidarea7)。 2342 2343该接口一般适用于此场景:应用于创建上述类型窗口并希望获取避让区信息时,需要在创建窗口后调用该接口设置使能该窗口,再调用[getWindowAvoidArea()](#getwindowavoidarea9)或[on('avoidAreaChange')](#onavoidareachange9)获取或监听避让区。 2344 2345**系统能力:** SystemCapability.Window.SessionManager 2346 2347**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 2348 2349**参数:** 2350 2351| 参数名 | 类型 | 必填 | 说明 | 2352| ---- |----------------------------------| -- | ------------------------------------------------------------ | 2353| enabled | boolean | 是 | 是否可以获取到避让区。<br> true表示可以获取避让区;false表示不可以获取避让区。默认值是false。 | 2354 2355**错误码:** 2356 2357以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2358 2359| 错误码ID | 错误信息 | 2360| ------- | ------------------------------ | 2361| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2362| 1300002 | This window state is abnormal. | 2363| 1300003 | This window manager service works abnormally. | 2364| 1300004 | Unauthorized operation. | 2365 2366**示例:** 2367 2368```ts 2369import { BusinessError } from '@kit.BasicServicesKit'; 2370 2371let windowClass: window.Window | undefined = undefined; 2372let config: window.Configuration = { 2373 name: "test", 2374 windowType: window.WindowType.TYPE_DIALOG, 2375 decorEnabled: true, 2376 ctx: this.context 2377}; 2378try { 2379 window.createWindow(config, (err: BusinessError, data) => { 2380 const errCode: number = err.code; 2381 if (errCode) { 2382 console.error(`Failed to create the system window. Cause code: ${err.code}, message: ${err.message}`); 2383 return; 2384 } 2385 windowClass = data; 2386 windowClass.setUIContent("pages/Test"); 2387 let enabled = true; 2388 let promise = windowClass.setSystemAvoidAreaEnabled(enabled); 2389 promise.then(() => { 2390 let type = window.AvoidAreaType.TYPE_SYSTEM; 2391 let avoidArea = windowClass?.getWindowAvoidArea(type); 2392 }).catch((err: BusinessError) => { 2393 console.error(`Failed to obtain the system window avoid area. Cause code: ${err.code}, message: ${err.message}`); 2394 }); 2395 }); 2396} catch (exception) { 2397 console.error(`Failed to create the system window. Cause code: ${exception.code}, message: ${exception.message}`); 2398} 2399``` 2400 2401### isSystemAvoidAreaEnabled<sup>18+</sup> 2402 2403isSystemAvoidAreaEnabled(): boolean 2404 2405获取悬浮窗、模态窗或WindowType为系统类型的窗口是否可以获取窗口内容的[避让区](#avoidarea7)。 2406 2407**系统能力:** SystemCapability.Window.SessionManager 2408 2409**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 2410 2411**返回值:** 2412 2413| 类型 | 说明 | 2414| ------------------------------------- | ------------- | 2415| boolean | 是否可以获取窗口内容的避让区。<br> true表示可以获取避让区;false表示不可以获取避让区。 | 2416 2417**错误码:** 2418 2419以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2420 2421| 错误码ID | 错误信息 | 2422| ------- | ------------------------------ | 2423| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2424| 1300002 | This window state is abnormal. | 2425| 1300003 | This window manager service works abnormally. | 2426| 1300004 | Unauthorized operation. | 2427 2428**示例:** 2429 2430```ts 2431import { BusinessError } from '@kit.BasicServicesKit'; 2432 2433let windowClass: window.Window | undefined = undefined; 2434let config: window.Configuration = { 2435 name: "test", 2436 windowType: window.WindowType.TYPE_DIALOG, 2437 decorEnabled: true, 2438 ctx: this.context 2439}; 2440try { 2441 window.createWindow(config, (err: BusinessError, data) => { 2442 const errCode: number = err.code; 2443 if (errCode) { 2444 console.error(`Failed to create the system window. Cause code: ${err.code}, message: ${err.message}`); 2445 return; 2446 } 2447 windowClass = data; 2448 windowClass.setUIContent("pages/Test"); 2449 let enabled = true; 2450 let promise = windowClass.setSystemAvoidAreaEnabled(enabled); 2451 promise.then(() => { 2452 let enable = windowClass?.isSystemAvoidAreaEnabled(); 2453 }).catch((err: BusinessError) => { 2454 console.error(`Failed to obtain whether the system window can get avoid area. Cause code: ${err.code}, message: ${err.message}`); 2455 }); 2456 }); 2457} catch (exception) { 2458 console.error(`Failed to create the system window. Cause code: ${exception.code}, message: ${exception.message}`); 2459} 2460``` 2461 2462### setTitleAndDockHoverShown<sup>14+</sup> 2463 2464setTitleAndDockHoverShown(isTitleHoverShown?: boolean, isDockHoverShown?: boolean): Promise<void> 2465 2466设置主窗口进入全屏沉浸式时鼠标Hover到热区上是否显示窗口标题栏和dock栏,使用Promise异步回调,仅2in1设备可用。 2467 2468**系统能力**:SystemCapability.Window.SessionManager 2469 2470**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 2471 2472**参数:** 2473 2474| 参数名 | 类型 | 必填 | 说明 | 2475| ---------- | ------- | ---- | ------------------------------------------------------------ | 2476| isTitleHoverShown | boolean | 否 | 是否显示窗口标题栏。<br>true表示显示窗口标题栏;false表示不显示窗口标题栏。默认值是true。</br> | 2477| isDockHoverShown | boolean | 否 | 是否显示dock栏。<br>true表示显示dock栏;false表示不显示dock栏。默认值是true。</br> | 2478 2479**错误码:** 2480 2481以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2482 2483| 错误码ID | 错误信息 | 2484| ------- | -------------------------------------------- | 2485| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2486| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2487| 1300002 | This window state is abnormal. | 2488| 1300004 | Unauthorized operation. | 2489 2490**示例:** 2491 2492```ts 2493// EntryAbility.ets 2494import { UIAbility } from '@kit.AbilityKit'; 2495import { BusinessError } from '@kit.BasicServicesKit'; 2496import { window } from '@kit.ArkUI'; 2497 2498export default class EntryAbility extends UIAbility { 2499 // ... 2500 onWindowStageCreate(windowStage: window.WindowStage): void { 2501 // 加载主窗口对应的页面。 2502 windowStage.loadContent('pages/Index', (err) => { 2503 let mainWindow: window.Window | undefined = undefined; 2504 // 获取应用主窗口。 2505 windowStage.getMainWindow().then( 2506 data => { 2507 mainWindow = data; 2508 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 2509 // 调用maximize接口,设置窗口进入全屏沉浸式。 2510 mainWindow.maximize(window.MaximizePresentation.ENTER_IMMERSIVE); 2511 // 调用setTitleAndDockHoverShown接口,隐藏标题栏和dock栏。 2512 mainWindow.setTitleAndDockHoverShown(false, false); 2513 } 2514 ).catch((err: BusinessError) => { 2515 if(err.code){ 2516 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2517 } 2518 }); 2519 }); 2520 } 2521} 2522``` 2523 2524### setWindowLayoutFullScreen<sup>9+</sup> 2525 2526setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 2527 2528设置主窗口或子窗口的布局是否为沉浸式布局,使用Promise异步回调。<!--RP8-->从API version 14开始,该接口在2in1设备上调用不生效。<!--RP8End--> 2529沉浸式布局生效时,布局不避让状态栏与三键导航栏,组件可能产生与其重叠的情况。 2530非沉浸式布局生效时,布局避让状态栏与三键导航栏,组件不会与其重叠。 2531 2532**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2533 2534**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2535 2536**参数:** 2537 2538| 参数名 | 类型 | 必填 | 说明 | 2539| ------------------ | ------- | -- | ------------------------------------------------------------------------------------------------ | 2540| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、三键导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 2541 2542**返回值:** 2543 2544| 类型 | 说明 | 2545| ------------------- | ------------------------ | 2546| Promise<void> | 无返回结果的Promise对象。 | 2547 2548**错误码:** 2549 2550以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2551 2552| 错误码ID | 错误信息 | 2553| ------- | -------------------------------------------- | 2554| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2555| 1300002 | This window state is abnormal. | 2556| 1300003 | This window manager service works abnormally. | 2557 2558**示例:** 2559 2560```ts 2561// EntryAbility.ets 2562import { UIAbility } from '@kit.AbilityKit'; 2563import { BusinessError } from '@kit.BasicServicesKit'; 2564 2565export default class EntryAbility extends UIAbility { 2566 // ... 2567 onWindowStageCreate(windowStage: window.WindowStage): void { 2568 console.info('onWindowStageCreate'); 2569 let windowClass: window.Window | undefined = undefined; 2570 windowStage.getMainWindow((err: BusinessError, data) => { 2571 const errCode: number = err.code; 2572 if (errCode) { 2573 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2574 return; 2575 } 2576 windowClass = data; 2577 let isLayoutFullScreen = true; 2578 try { 2579 let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); 2580 promise.then(() => { 2581 console.info('Succeeded in setting the window layout to full-screen mode.'); 2582 }).catch((err: BusinessError) => { 2583 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 2584 }); 2585 } catch (exception) { 2586 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`); 2587 } 2588 }); 2589 } 2590} 2591``` 2592 2593### setImmersiveModeEnabledState<sup>12+</sup> 2594 2595setImmersiveModeEnabledState(enabled: boolean): void 2596 2597设置当前窗口是否开启沉浸式布局,该调用不会改变窗口模式和窗口大小。<!--RP8-->从API version 14开始,该接口在2in1设备上调用不生效。<!--RP8End--> 2598 2599**系统能力**:SystemCapability.WindowManager.WindowManager.Core 2600 2601**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2602 2603**参数:** 2604 2605| 参数名 | 类型 | 必填 | 说明 | 2606| ---------- | ------- | ---- | ------------------------------------------------------------ | 2607| enabled | boolean | 是 | 是否开启沉浸式布局。<br>true表示开启,false表示关闭。</br> | 2608 2609**错误码:** 2610 2611以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2612 2613| 错误码ID | 错误信息 | 2614| ------- | -------------------------------------------- | 2615| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2616| 1300002 | This window state is abnormal. | 2617| 1300003 | This window manager service works abnormally. | 2618| 1300004 | Unauthorized operation. | 2619 2620**示例:** 2621 2622```ts 2623try { 2624 let enabled = false; 2625 windowClass.setImmersiveModeEnabledState(enabled); 2626} catch (exception) { 2627 console.error(`Failed to set the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 2628} 2629``` 2630 2631### getImmersiveModeEnabledState<sup>12+</sup> 2632 2633getImmersiveModeEnabledState(): boolean 2634 2635查询当前窗口是否已经开启沉浸式布局。 2636 2637**系统能力**:SystemCapability.WindowManager.WindowManager.Core 2638 2639**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2640 2641**返回值:** 2642| 类型 | 说明 | 2643| ------- | ------------------------------------------------------------------------------------ | 2644| boolean | 是否已经开启沉浸式布局。<br>true表示开启,false表示关闭。</br> | 2645 2646**错误码:** 2647 2648以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2649 2650| 错误码ID | 错误信息 | 2651| -------- | -------------------------------------------- | 2652| 1300002 | This window state is abnormal. | 2653| 1300003 | This window manager service works abnormally. | 2654| 1300004 | Unauthorized operation. | 2655 2656**示例:** 2657 2658```ts 2659try { 2660 let isEnabled = windowClass.getImmersiveModeEnabledState(); 2661} catch (exception) { 2662 console.error(`Failed to get the window immersive mode enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 2663} 2664``` 2665 2666### setWindowSystemBarEnable<sup>9+</sup> 2667 2668setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 2669 2670设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 2671 2672调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。非全屏模式(悬浮窗、分屏等场景)下配置不生效。 2673 2674**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2675 2676**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2677 2678**参数:** 2679 2680| 参数名 | 类型 | 必填 | 说明 | 2681| ----- | ---------------------------- | -- | --------------------------------- | 2682| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 2683 2684**返回值:** 2685 2686| 类型 | 说明 | 2687| ------------------- | ------------------------ | 2688| Promise<void> | 无返回结果的Promise对象。 | 2689 2690**错误码:** 2691 2692以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2693 2694| 错误码ID | 错误信息 | 2695| ------- | -------------------------------------------- | 2696| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2697| 1300002 | This window state is abnormal. | 2698| 1300003 | This window manager service works abnormally. | 2699 2700**示例:** 2701 2702```ts 2703// 此处以不显示三键导航栏、状态栏、底部导航条为例 2704// EntryAbility.ets 2705import { UIAbility } from '@kit.AbilityKit'; 2706import { BusinessError } from '@kit.BasicServicesKit'; 2707 2708export default class EntryAbility extends UIAbility { 2709 // ... 2710 onWindowStageCreate(windowStage: window.WindowStage): void { 2711 console.info('onWindowStageCreate'); 2712 let windowClass: window.Window | undefined = undefined; 2713 windowStage.getMainWindow((err: BusinessError, data) => { 2714 const errCode: number = err.code; 2715 if (errCode) { 2716 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2717 return; 2718 } 2719 windowClass = data; 2720 let names: Array<'status' | 'navigation'> = []; 2721 try { 2722 let promise = windowClass.setWindowSystemBarEnable(names); 2723 promise.then(() => { 2724 console.info('Succeeded in setting the system bar to be invisible.'); 2725 }).catch((err: BusinessError) => { 2726 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 2727 }); 2728 } catch (exception) { 2729 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 2730 } 2731 }); 2732 } 2733} 2734``` 2735 2736### setSpecificSystemBarEnabled<sup>11+</sup> 2737 2738setSpecificSystemBarEnabled(name: SpecificSystemBar, enable: boolean, enableAnimation?: boolean): Promise<void> 2739 2740设置主窗口三键导航栏、状态栏、底部导航条的显示和隐藏,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 2741 2742调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。非全屏模式(悬浮窗、分屏等场景)下配置不生效。 2743 2744**系统能力:** SystemCapability.Window.SessionManager 2745 2746**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 2747 2748**参数:** 2749 2750| 参数名 | 类型 | 必填 | 说明 | 2751| ----- | ---------------------------- | -- | --------------------------------- | 2752| name | [SpecificSystemBar](#specificsystembar11) | 是 | 设置窗口全屏模式时,显示或隐藏的系统栏类型。 | 2753| enable | boolean | 是 | 设置窗口全屏模式时状态栏、三键导航栏或底部导航条是否显示,true表示显示, false表示隐藏。| 2754| enableAnimation<sup>12+</sup> | boolean | 否 | 设置状态栏、三键导航栏或底部导航条显示状态变化时是否使用动画,true表示使用, false表示不使用,默认值为false。| 2755 2756**返回值:** 2757 2758| 类型 | 说明 | 2759| ------------------- | ------------------------ | 2760| Promise<void> | 无返回结果的Promise对象。 | 2761 2762**错误码:** 2763 2764以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2765 2766| 错误码ID | 错误信息 | 2767| ------- | -------------------------------------------- | 2768| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2769| 1300002 | This window state is abnormal. | 2770| 1300003 | This window manager service works abnormally. | 2771 2772**示例:** 2773 2774```ts 2775// 此处以隐藏底部导航条为例 2776// EntryAbility.ets 2777import { UIAbility } from '@kit.AbilityKit'; 2778import { BusinessError } from '@kit.BasicServicesKit'; 2779 2780export default class EntryAbility extends UIAbility { 2781 // ... 2782 onWindowStageCreate(windowStage: window.WindowStage): void { 2783 console.info('onWindowStageCreate'); 2784 let windowClass: window.Window | undefined = undefined; 2785 windowStage.getMainWindow((err: BusinessError, data) => { 2786 const errCode: number = err.code; 2787 if (errCode) { 2788 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2789 return; 2790 } 2791 windowClass = data; 2792 try { 2793 let promise = windowClass.setSpecificSystemBarEnabled('navigationIndicator', false); 2794 promise.then(() => { 2795 console.info('Succeeded in setting the system bar to be invisible.'); 2796 }).catch((err: BusinessError) => { 2797 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 2798 }); 2799 } catch (exception) { 2800 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 2801 } 2802 }); 2803 } 2804} 2805``` 2806 2807### setWindowSystemBarProperties<sup>9+</sup> 2808 2809setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 2810 2811设置主窗口三键导航栏、状态栏的属性,使用Promise异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 2812 2813子窗口调用后不生效。 2814 2815**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2816 2817**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2818 2819**参数:** 2820 2821| 参数名 | 类型 | 必填 | 说明 | 2822| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2823| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 三键导航栏、状态栏的属性。 | 2824 2825**返回值:** 2826 2827| 类型 | 说明 | 2828| ------------------- | ------------------------- | 2829| Promise<void> | 无返回结果的Promise对象。 | 2830 2831**错误码:** 2832 2833以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2834 2835| 错误码ID | 错误信息 | 2836| ------- | -------------------------------------------- | 2837| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2838| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2839| 1300002 | This window state is abnormal. | 2840| 1300003 | This window manager service works abnormally. | 2841 2842**示例:** 2843 2844```ts 2845// EntryAbility.ets 2846import { UIAbility } from '@kit.AbilityKit'; 2847import { BusinessError } from '@kit.BasicServicesKit'; 2848 2849export default class EntryAbility extends UIAbility { 2850 // ... 2851 onWindowStageCreate(windowStage: window.WindowStage): void { 2852 console.info('onWindowStageCreate'); 2853 let windowClass: window.Window | undefined = undefined; 2854 windowStage.getMainWindow((err: BusinessError, data) => { 2855 const errCode: number = err.code; 2856 if (errCode) { 2857 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2858 return; 2859 } 2860 windowClass = data; 2861 let SystemBarProperties: window.SystemBarProperties = { 2862 statusBarColor: '#ff00ff', 2863 navigationBarColor: '#00ff00', 2864 //以下两个属性从API Version8开始支持 2865 statusBarContentColor: '#ffffff', 2866 navigationBarContentColor: '#00ffff' 2867 }; 2868 try { 2869 let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties); 2870 promise.then(() => { 2871 console.info('Succeeded in setting the system bar properties.'); 2872 }).catch((err: BusinessError) => { 2873 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 2874 }); 2875 } catch (exception) { 2876 console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); 2877 } 2878 }); 2879 } 2880} 2881``` 2882 2883### getWindowSystemBarProperties<sup>12+</sup> 2884 2885getWindowSystemBarProperties(): SystemBarProperties 2886 2887主窗口获取三键导航栏、状态栏的属性。 2888 2889**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2890 2891**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2892 2893**返回值:** 2894 2895| 类型 | 说明 | 2896| ------------------------------------- | ------------- | 2897| [SystemBarProperties](#systembarproperties) | 当前三键导航栏、状态栏属性。 | 2898 2899**错误码:** 2900 2901以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 2902 2903| 错误码ID | 错误信息 | 2904| ------- | ------------------------------ | 2905| 1300002 | This window state is abnormal. | 2906| 1300003 | This window manager service works abnormally. | 2907| 1300004 | Unauthorized operation. | 2908 2909 2910**示例:** 2911 2912```ts 2913// EntryAbility.ets 2914import { UIAbility } from '@kit.AbilityKit'; 2915import { BusinessError } from '@kit.BasicServicesKit'; 2916 2917export default class EntryAbility extends UIAbility { 2918 // ... 2919 2920 onWindowStageCreate(windowStage: window.WindowStage) { 2921 let windowClass: window.Window | undefined = undefined; 2922 windowStage.getMainWindow((err: BusinessError, data) => { 2923 const errCode: number = err.code; 2924 if (errCode) { 2925 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2926 return; 2927 } 2928 windowClass = data; 2929 try { 2930 let systemBarProperty = windowClass.getWindowSystemBarProperties(); 2931 console.info('Success in obtaining system bar properties. Property: ' + JSON.stringify(systemBarProperty)); 2932 } catch (err) { 2933 console.error(`Failed to get system bar properties. Code: ${err.code}, message: ${err.message}`); 2934 } 2935 }); 2936 } 2937}; 2938``` 2939 2940### setStatusBarColor<sup>18+</sup> 2941 2942setStatusBarColor(color: ColorMetrics): Promise<void> 2943 2944设置主窗口状态栏的文字颜色,使用Promise异步回调。该接口在2in1设备上调用不生效。 2945 2946子窗口不支持设置状态栏文字颜色,调用无效果。 2947 2948**系统能力:** SystemCapability.Window.SessionManager 2949 2950**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 2951 2952**参数:** 2953 2954| 参数名 | 类型 | 必填 | 说明 | 2955| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2956| color | [ColorMetrics](js-apis-arkui-graphics.md#colormetrics12) | 是 | 要设置的状态栏颜色值。 | 2957 2958**返回值:** 2959 2960| 类型 | 说明 | 2961| ------------------- | ------------------------- | 2962| Promise<void> | 无返回结果的Promise对象。 | 2963 2964**错误码:** 2965 2966以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2967 2968| 错误码ID | 错误信息 | 2969| ------- | -------------------------------------------- | 2970| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2971| 801 | Capability not supported on this device. | 2972| 1300002 | This window state is abnormal. | 2973| 1300003 | This window manager service works abnormally. | 2974 2975**示例:** 2976 2977```ts 2978// EntryAbility.ets 2979import { UIAbility } from '@kit.AbilityKit'; 2980import { BusinessError } from '@kit.BasicServicesKit'; 2981import { ColorMetrics, window } from '@kit.ArkUI'; 2982 2983export default class EntryAbility extends UIAbility { 2984 // ... 2985 onWindowStageCreate(windowStage: window.WindowStage): void { 2986 console.info('onWindowStageCreate'); 2987 let windowClass: window.Window | undefined = undefined; 2988 windowStage.getMainWindow((err: BusinessError, data) => { 2989 const errCode: number = err.code; 2990 if (errCode) { 2991 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2992 return; 2993 } 2994 windowClass = data; 2995 try { 2996 let promise = windowClass.setStatusBarColor(ColorMetrics.numeric(0x112233)); 2997 promise.then(() => { 2998 console.info('Succeeded in setting the status bar color.'); 2999 }).catch((err: BusinessError) => { 3000 console.error(`Set the status bar color failed. Cause code: ${err.code}, message: ${err.message}`); 3001 }); 3002 } catch (exception) { 3003 console.error(`Failed to set the status bar color. Cause code: ${exception.code}, message: ${exception.message}`); 3004 } 3005 }); 3006 } 3007} 3008``` 3009 3010### getStatusBarProperty<sup>18+</sup> 3011 3012getStatusBarProperty(): StatusBarProperty 3013 3014获取主窗口状态栏的属性,如状态栏文字颜色。 3015 3016子窗口不支持查询,调用会返回错误码1300002。 3017 3018**系统能力:** SystemCapability.Window.SessionManager 3019 3020**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 3021 3022**返回值:** 3023 3024| 类型 | 说明 | 3025| ------------------------------------- | ------------- | 3026| [StatusBarProperty](#statusbarproperty18) | 当前状态栏属性,如状态栏颜色。 | 3027 3028**错误码:** 3029 3030以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3031 3032| 错误码ID | 错误信息 | 3033| ------- | ------------------------------ | 3034| 801 | Capability not supported on this device. | 3035| 1300002 | This window state is abnormal. | 3036 3037**示例:** 3038 3039```ts 3040// EntryAbility.ets 3041import { UIAbility } from '@kit.AbilityKit'; 3042import { BusinessError } from '@kit.BasicServicesKit'; 3043import { window } from '@kit.ArkUI'; 3044 3045export default class EntryAbility extends UIAbility { 3046 // ... 3047 onWindowStageCreate(windowStage: window.WindowStage) { 3048 let windowClass: window.Window | undefined = undefined; 3049 windowStage.getMainWindow((err: BusinessError, data) => { 3050 const errCode: number = err.code; 3051 if (errCode) { 3052 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 3053 return; 3054 } 3055 windowClass = data; 3056 try { 3057 let statusBarProperty = windowClass.getStatusBarProperty(); 3058 console.info('Succeeded in obtaining system bar properties. Property: ' + JSON.stringify(statusBarProperty)); 3059 } catch (err) { 3060 console.error(`Failed to get system bar properties. Code: ${err.code}, message: ${err.message}`); 3061 } 3062 }); 3063 } 3064}; 3065``` 3066 3067### setPreferredOrientation<sup>9+</sup> 3068 3069setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void 3070 3071设置主窗口的显示方向属性,使用callback异步回调。<!--RP9-->仅在支持跟随sensor旋转的设备上生效,2in1设备上调用不生效,子窗口调用后不生效。<!--RP9End--> 3072 3073**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3074 3075**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3076 3077**参数:** 3078 3079| 参数名 | 类型 | 必填 | 说明 | 3080| ------------------- | ------------------------------------------- | ---- | ---------------------- | 3081| orientation | [Orientation](#orientation9) | 是 | 窗口显示方向的属性。 | 3082| callback | AsyncCallback<void> | 是 | 回调函数。该回调函数返回调用结果是否成功,非应用旋转动效结束。 | 3083 3084**错误码:** 3085 3086以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3087 3088| 错误码ID | 错误信息 | 3089| ------- | ------------------------------ | 3090| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3091| 1300002 | This window state is abnormal. | 3092 3093**示例:** 3094 3095```ts 3096// EntryAbility.ets 3097import { UIAbility } from '@kit.AbilityKit'; 3098import { BusinessError } from '@kit.BasicServicesKit'; 3099 3100export default class EntryAbility extends UIAbility { 3101 // ... 3102 onWindowStageCreate(windowStage: window.WindowStage): void { 3103 console.info('onWindowStageCreate'); 3104 let windowClass: window.Window | undefined = undefined; 3105 windowStage.getMainWindow((err: BusinessError, data) => { 3106 const errCode: number = err.code; 3107 if (errCode) { 3108 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 3109 return; 3110 } 3111 windowClass = data; 3112 let orientation = window.Orientation.AUTO_ROTATION; 3113 try { 3114 windowClass.setPreferredOrientation(orientation, (err: BusinessError) => { 3115 const errCode: number = err.code; 3116 if (errCode) { 3117 console.error(`Failed to set window orientation. Cause code: ${err.code}, message: ${err.message}`); 3118 return; 3119 } 3120 console.info('Succeeded in setting window orientation.'); 3121 }); 3122 } catch (exception) { 3123 console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 3124 } 3125 }); 3126 } 3127} 3128``` 3129 3130### setPreferredOrientation<sup>9+</sup> 3131 3132setPreferredOrientation(orientation: Orientation): Promise<void> 3133 3134设置主窗口的显示方向属性,使用Promise异步回调。<!--RP9-->仅在支持跟随sensor旋转的设备上生效,2in1设备上调用不生效,子窗口调用后不生效。<!--RP9End--> 3135 3136**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3137 3138**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3139 3140**参数:** 3141 3142| 参数名 | 类型 | 必填 | 说明 | 3143| ------------------- | ------------------------------------------- | ---- | ---------------------- | 3144| orientation | [Orientation](#orientation9) | 是 | 窗口显示方向的属性。 | 3145 3146**返回值:** 3147 3148| 类型 | 说明 | 3149| ------------------- | ------------------------- | 3150| Promise<void> | 无返回结果的Promise对象。 | 3151 3152**错误码:** 3153 3154以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3155 3156| 错误码ID | 错误信息 | 3157| ------- | ------------------------------ | 3158| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3159| 1300002 | This window state is abnormal. | 3160 3161**示例:** 3162 3163```ts 3164// EntryAbility.ets 3165import { UIAbility } from '@kit.AbilityKit'; 3166import { BusinessError } from '@kit.BasicServicesKit'; 3167 3168export default class EntryAbility extends UIAbility { 3169 // ... 3170 onWindowStageCreate(windowStage: window.WindowStage): void { 3171 console.info('onWindowStageCreate'); 3172 let windowClass: window.Window | undefined = undefined; 3173 windowStage.getMainWindow((err: BusinessError, data) => { 3174 const errCode: number = err.code; 3175 if (errCode) { 3176 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 3177 return; 3178 } 3179 windowClass = data; 3180 let orientation = window.Orientation.AUTO_ROTATION; 3181 try { 3182 let promise = windowClass.setPreferredOrientation(orientation); 3183 promise.then(() => { 3184 console.info('Succeeded in setting the window orientation.'); 3185 }).catch((err: BusinessError) => { 3186 console.error(`Failed to set the window orientation. Cause code: ${err.code}, message: ${err.message}`); 3187 }); 3188 } catch (exception) { 3189 console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 3190 } 3191 }); 3192 } 3193} 3194``` 3195 3196### getPreferredOrientation<sup>12+</sup> 3197 3198getPreferredOrientation(): Orientation 3199 3200主窗口调用,获取窗口的显示方向属性。 3201 3202**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3203 3204**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3205 3206**返回值:** 3207 3208| 类型 | 说明 | 3209|------------------------------| ------------------ | 3210| [Orientation](#orientation9) | 窗口显示方向的属性。 | 3211 3212**错误码:** 3213 3214以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 3215 3216| 错误码ID | 错误信息 | 3217| ------- | ------------------------------ | 3218| 1300002 | This window state is abnormal. | 3219 3220**示例:** 3221 3222```ts 3223// EntryAbility.ets 3224import { UIAbility } from '@kit.AbilityKit'; 3225import { BusinessError } from '@kit.BasicServicesKit'; 3226export default class EntryAbility extends UIAbility { 3227 // ... 3228 3229 onWindowStageCreate(windowStage: window.WindowStage) { 3230 console.info('onWindowStageCreate'); 3231 let windowClass: window.Window | undefined = undefined; 3232 windowStage.getMainWindow((err: BusinessError, data) => { 3233 const errCode: number = err.code; 3234 if (errCode) { 3235 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 3236 return; 3237 } 3238 windowClass = data; 3239 try { 3240 let orientation = windowClass.getPreferredOrientation(); 3241 } catch (exception) { 3242 console.error(`Failed to get window orientation. Cause code: ${exception.code}, message: ${exception.message}`); 3243 } 3244 }); 3245 } 3246}; 3247``` 3248 3249### getUIContext<sup>10+</sup> 3250 3251getUIContext(): UIContext 3252 3253获取UIContext实例。 3254 3255**模型约束:** 此接口仅可在Stage模型下使用。 3256 3257**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3258 3259**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3260 3261**返回值:** 3262 3263| 类型 | 说明 | 3264| ---------- | ---------------------- | 3265| [UIContext](js-apis-arkui-UIContext.md#uicontext) | 返回UIContext实例对象。 | 3266 3267**错误码:** 3268 3269以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 3270 3271| 错误码ID | 错误信息 | 3272| ------- | ------------------------------ | 3273| 1300002 | This window state is abnormal. | 3274 3275**示例:** 3276 3277```ts 3278// EntryAbility.ets 3279import { UIAbility } from '@kit.AbilityKit'; 3280import { window, UIContext } from '@kit.ArkUI'; 3281import { BusinessError } from '@kit.BasicServicesKit'; 3282 3283export default class EntryAbility extends UIAbility { 3284 onWindowStageCreate(windowStage: window.WindowStage) { 3285 // 为主窗口加载对应的目标页面。 3286 windowStage.loadContent("pages/page2", (err: BusinessError) => { 3287 let errCode: number = err.code; 3288 if (errCode) { 3289 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3290 return; 3291 } 3292 console.info('Succeeded in loading the content.'); 3293 // 获取应用主窗口。 3294 let windowClass: window.Window | undefined = undefined; 3295 windowStage.getMainWindow((err: BusinessError, data) => { 3296 let errCode: number = err.code; 3297 if (errCode) { 3298 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 3299 return; 3300 } 3301 windowClass = data; 3302 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 3303 // 获取UIContext实例。 3304 let uiContext: UIContext | null = null; 3305 uiContext = windowClass.getUIContext(); 3306 }); 3307 }); 3308 } 3309}; 3310``` 3311 3312### setUIContent<sup>9+</sup> 3313 3314setUIContent(path: string, callback: AsyncCallback<void>): void 3315 3316根据当前工程中某个页面的路径为窗口加载具体页面内容,使用callback异步回调。 3317 3318**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3319 3320**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3321 3322**参数:** 3323 3324| 参数名 | 类型 | 必填 | 说明 | 3325| -------- | ------------------------- | -- | -------------------- | 3326| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 3327| callback | AsyncCallback<void> | 是 | 回调函数。 | 3328 3329**错误码:** 3330 3331以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3332 3333| 错误码ID | 错误信息 | 3334| ------- | -------------------------------------------- | 3335| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3336| 1300002 | This window state is abnormal. | 3337| 1300003 | This window manager service works abnormally. | 3338 3339**示例:** 3340 3341```ts 3342import { BusinessError } from '@kit.BasicServicesKit'; 3343 3344try { 3345 windowClass.setUIContent('pages/page2/page3', (err: BusinessError) => { 3346 const errCode: number = err.code; 3347 if (errCode) { 3348 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3349 return; 3350 } 3351 console.info('Succeeded in loading the content.'); 3352 }); 3353} catch (exception) { 3354 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3355} 3356``` 3357 3358### setUIContent<sup>9+</sup> 3359 3360setUIContent(path: string): Promise<void> 3361 3362根据当前工程中某个页面的路径为窗口加载具体页面内容,使用Promise异步回调。 3363 3364**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3365 3366**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3367 3368**参数:** 3369 3370| 参数名 | 类型 | 必填 | 说明 | 3371| ---- | ------ | -- | ------------------ | 3372| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 3373 3374**返回值:** 3375 3376| 类型 | 说明 | 3377| ------------------- | ------------------------ | 3378| Promise<void> | 无返回结果的Promise对象。 | 3379 3380**错误码:** 3381 3382以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3383 3384| 错误码ID | 错误信息 | 3385| ------- | -------------------------------------------- | 3386| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3387| 1300002 | This window state is abnormal. | 3388| 1300003 | This window manager service works abnormally. | 3389 3390**示例:** 3391 3392```ts 3393import { BusinessError } from '@kit.BasicServicesKit'; 3394 3395try { 3396 let promise = windowClass.setUIContent('pages/page2/page3'); 3397 promise.then(() => { 3398 console.info('Succeeded in loading the content.'); 3399 }).catch((err: BusinessError) => { 3400 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3401 }); 3402} catch (exception) { 3403 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3404} 3405``` 3406 3407### loadContent<sup>9+</sup> 3408 3409loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 3410 3411根据当前工程中某个页面的路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 3412 3413**模型约束:** 此接口仅可在Stage模型下使用。 3414 3415**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3416 3417**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3418 3419**参数:** 3420 3421| 参数名 | 类型 | 必填 | 说明 | 3422| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 3423| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 3424| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 3425| callback | AsyncCallback<void> | 是 | 回调函数。 | 3426 3427**错误码:** 3428 3429以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3430 3431| 错误码ID | 错误信息 | 3432| ------- | -------------------------------------------- | 3433| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3434| 1300002 | This window state is abnormal. | 3435| 1300003 | This window manager service works abnormally. | 3436 3437**示例:** 3438 3439```ts 3440import { BusinessError } from '@kit.BasicServicesKit'; 3441 3442let storage: LocalStorage = new LocalStorage(); 3443storage.setOrCreate('storageSimpleProp', 121); 3444windowClass.loadContent('pages/page2', storage, (err: BusinessError) => { 3445 const errCode: number = err.code; 3446 if (errCode) { 3447 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3448 return; 3449 } 3450 console.info('Succeeded in loading the content.'); 3451}); 3452``` 3453 3454### loadContent<sup>9+</sup> 3455 3456loadContent(path: string, storage: LocalStorage): Promise<void> 3457 3458根据当前工程中某个页面的路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 3459 3460**模型约束:** 此接口仅可在Stage模型下使用。 3461 3462**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3463 3464**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3465 3466**参数:** 3467 3468| 参数名 | 类型 | 必填 | 说明 | 3469| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 3470| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 3471| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 3472 3473**返回值:** 3474 3475| 类型 | 说明 | 3476| ------------------- | ------------------------- | 3477| Promise<void> | 无返回结果的Promise对象。 | 3478 3479**错误码:** 3480 3481以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3482 3483| 错误码ID | 错误信息 | 3484| ------- | -------------------------------------------- | 3485| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3486| 1300002 | This window state is abnormal. | 3487| 1300003 | This window manager service works abnormally. | 3488 3489**示例:** 3490 3491```ts 3492import { BusinessError } from '@kit.BasicServicesKit'; 3493 3494let storage: LocalStorage = new LocalStorage(); 3495storage.setOrCreate('storageSimpleProp', 121); 3496let promise = windowClass.loadContent('pages/page2', storage); 3497promise.then(() => { 3498 console.info('Succeeded in loading the content.'); 3499}).catch((err: BusinessError) => { 3500 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3501}); 3502``` 3503 3504### loadContentByName<sup>11+</sup> 3505 3506loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback<void>): void 3507 3508为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 3509 3510**模型约束:** 此接口仅可在Stage模型下使用。 3511 3512**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3513 3514**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3515 3516**参数:** 3517 3518| 参数名 | 类型 | 必填 | 说明 | 3519| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3520| name | string | 是 | 命名路由页面的名称。 | 3521| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 3522| callback | AsyncCallback<void> | 是 | 回调函数。 | 3523 3524**错误码:** 3525 3526以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3527 3528| 错误码ID | 错误信息 | 3529| -------- | --------------------------------------------- | 3530| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3531| 1300002 | This window state is abnormal. | 3532| 1300003 | This window manager service works abnormally. | 3533 3534**示例:** 3535<!--code_no_check--> 3536```ts 3537import { BusinessError } from '@kit.BasicServicesKit'; 3538import * as Index from '../pages/Index'; // 导入命名路由页面 3539 3540console.info('onWindowStageCreate'); 3541let storage: LocalStorage = new LocalStorage(); 3542storage.setOrCreate('storageSimpleProp', 121); 3543try { 3544 (windowClass as window.Window).loadContentByName(Index.entryName, storage, (err: BusinessError) => { 3545 const errCode: number = err.code; 3546 if (errCode) { 3547 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3548 return; 3549 } 3550 console.info('Succeeded in loading the content.'); 3551 }); 3552} catch (exception) { 3553 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3554} 3555``` 3556<!--code_no_check--> 3557```ts 3558// ets/pages/Index.ets 3559export const entryName : string = 'Index'; 3560@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 3561@Component 3562export struct Index { 3563 @State message: string = 'Hello World' 3564 build() { 3565 Row() { 3566 Column() { 3567 Text(this.message) 3568 .fontSize(50) 3569 .fontWeight(FontWeight.Bold) 3570 } 3571 .width('100%') 3572 } 3573 .height('100%') 3574 } 3575} 3576``` 3577 3578### loadContentByName<sup>11+</sup> 3579 3580loadContentByName(name: string, callback: AsyncCallback<void>): void 3581 3582为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面内容,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 3583 3584**模型约束:** 此接口仅可在Stage模型下使用。 3585 3586**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3587 3588**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3589 3590**参数:** 3591 3592| 参数名 | 类型 | 必填 | 说明 | 3593| -------- | ------------------------- | ---- | ---------------- | 3594| name | string | 是 | 命名路由页面的名称。 | 3595| callback | AsyncCallback<void> | 是 | 回调函数。 | 3596 3597**错误码:** 3598 3599以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3600 3601| 错误码ID | 错误信息 | 3602| -------- | --------------------------------------------- | 3603| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3604| 1300002 | This window state is abnormal. | 3605| 1300003 | This window manager service works abnormally. | 3606 3607**示例:** 3608<!--code_no_check--> 3609```ts 3610import { BusinessError } from '@kit.BasicServicesKit'; 3611import * as Index from '../pages/Index'; // 导入命名路由页面 3612 3613try { 3614 (windowClass as window.Window).loadContentByName(Index.entryName, (err: BusinessError) => { 3615 const errCode: number = err.code; 3616 if (errCode) { 3617 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3618 return; 3619 } 3620 console.info('Succeeded in loading the content.'); 3621 }); 3622} catch (exception) { 3623 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3624} 3625``` 3626<!--code_no_check--> 3627```ts 3628// ets/pages/Index.ets 3629export const entryName : string = 'Index'; 3630@Entry({routeName: entryName}) 3631@Component 3632export struct Index { 3633 @State message: string = 'Hello World' 3634 build() { 3635 Row() { 3636 Column() { 3637 Text(this.message) 3638 .fontSize(50) 3639 .fontWeight(FontWeight.Bold) 3640 } 3641 .width('100%') 3642 } 3643 .height('100%') 3644 } 3645} 3646``` 3647 3648### loadContentByName<sup>11+</sup> 3649 3650loadContentByName(name: string, storage?: LocalStorage): Promise<void> 3651 3652为当前窗口加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 3653 3654**模型约束:** 此接口仅可在Stage模型下使用。 3655 3656**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3657 3658**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3659 3660**参数:** 3661 3662| 参数名 | 类型 | 必填 | 说明 | 3663| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3664| name | string | 是 | 命名路由页面的名称。 | 3665| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 否 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 3666 3667**返回值:** 3668 3669| 类型 | 说明 | 3670| ------------------- | ------------------------- | 3671| Promise<void> | 无返回结果的Promise对象。 | 3672 3673**错误码:** 3674 3675以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3676 3677| 错误码ID | 错误信息 | 3678| -------- | --------------------------------------------- | 3679| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3680| 1300002 | This window state is abnormal. | 3681| 1300003 | This window manager service works abnormally. | 3682 3683**示例:** 3684<!--code_no_check--> 3685```ts 3686import { BusinessError } from '@kit.BasicServicesKit'; 3687import * as Index from '../pages/Index'; // 导入命名路由页面 3688 3689let storage: LocalStorage = new LocalStorage(); 3690storage.setOrCreate('storageSimpleProp', 121); 3691try { 3692 let promise = (windowClass as window.Window).loadContentByName(Index.entryName, storage); 3693 promise.then(() => { 3694 console.info('Succeeded in loading the content.'); 3695 }).catch((err: BusinessError) => { 3696 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 3697 }); 3698} catch (exception) { 3699 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 3700} 3701``` 3702<!--code_no_check--> 3703```ts 3704// ets/pages/Index.ets 3705export const entryName : string = 'Index'; 3706@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 3707@Component 3708export struct Index { 3709 @State message: string = 'Hello World' 3710 build() { 3711 Row() { 3712 Column() { 3713 Text(this.message) 3714 .fontSize(50) 3715 .fontWeight(FontWeight.Bold) 3716 } 3717 .width('100%') 3718 } 3719 .height('100%') 3720 } 3721} 3722``` 3723 3724### isWindowShowing<sup>9+</sup> 3725 3726isWindowShowing(): boolean 3727 3728判断当前窗口是否已显示。 3729 3730**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3731 3732**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3733 3734**返回值:** 3735 3736| 类型 | 说明 | 3737| ------- | ------------------------------------------------------------------ | 3738| boolean | 当前窗口是否已显示。true表示当前窗口已显示,false则表示当前窗口未显示。 | 3739 3740**错误码:** 3741 3742以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 3743 3744| 错误码ID | 错误信息 | 3745| ------- | ------------------------------ | 3746| 1300002 | This window state is abnormal. | 3747 3748**示例:** 3749 3750```ts 3751try { 3752 let data = windowClass.isWindowShowing(); 3753 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 3754} catch (exception) { 3755 console.error(`Failed to check whether the window is showing. Cause code: ${exception.code}, message: ${exception.message}`); 3756} 3757``` 3758 3759### on('windowSizeChange')<sup>7+</sup> 3760 3761on(type: 'windowSizeChange', callback: Callback<Size>): void 3762 3763开启窗口尺寸变化的监听。 3764 3765**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3766 3767**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3768 3769**参数:** 3770 3771| 参数名 | 类型 | 必填 | 说明 | 3772| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 3773| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 | 3774| callback | Callback<[Size](#size7)> | 是 | 回调函数。返回当前的窗口尺寸。 | 3775 3776**错误码:** 3777 3778以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3779 3780| 错误码ID | 错误信息 | 3781| ------- | -------------------------------------------- | 3782| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3783 3784**示例:** 3785 3786```ts 3787try { 3788 windowClass.on('windowSizeChange', (data) => { 3789 console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data)); 3790 }); 3791} catch (exception) { 3792 console.error(`Failed to enable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`); 3793} 3794``` 3795 3796### off('windowSizeChange')<sup>7+</sup> 3797 3798off(type: 'windowSizeChange', callback?: Callback<Size>): void 3799 3800关闭窗口尺寸变化的监听。 3801 3802**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3803 3804**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3805 3806**参数:** 3807 3808| 参数名 | 类型 | 必填 | 说明 | 3809| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 3810| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 | 3811| callback | Callback<[Size](#size7)> | 否 | 回调函数。返回当前的窗口尺寸。如果传入参数,则关闭该监听。如果未传入参数,则关闭窗口尺寸变化的监听。 | 3812 3813**错误码:** 3814 3815以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3816 3817| 错误码ID | 错误信息 | 3818| ------- | -------------------------------------------- | 3819| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3820 3821**示例:** 3822 3823```ts 3824const callback = (size: window.Size) => { 3825 // ... 3826} 3827try { 3828 // 通过on接口开启监听 3829 windowClass.on('windowSizeChange', callback); 3830 // 关闭指定callback的监听 3831 windowClass.off('windowSizeChange', callback); 3832 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3833 windowClass.off('windowSizeChange'); 3834} catch (exception) { 3835 console.error(`Failed to disable the listener for window size changes. Cause code: ${exception.code}, message: ${exception.message}`); 3836} 3837``` 3838 3839### on('avoidAreaChange')<sup>9+</sup> 3840 3841on(type: 'avoidAreaChange', callback: Callback<AvoidAreaOptions>): void 3842 3843开启当前应用窗口系统规避区变化的监听。 3844<!--RP7-->常见的触发避让区回调的场景如下:应用窗口在全屏模式、悬浮模式、分屏模式之间的切换;应用窗口旋转;多折叠设备在屏幕折叠态和展开态之间的切换;应用窗口在多设备之间的流转。<!--RP7End--> 3845 3846**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3847 3848**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3849 3850**参数:** 3851 3852| 参数名 | 类型 | 必填 | 说明 | 3853| -------- |----------------------------------| ---- |--------------------------------------| 3854| type | string | 是 | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 | 3855| callback | Callback<[AvoidAreaOptions](#avoidareaoptions12)> | 是 | 回调函数。返回当前规避区以及规避区类型。| 3856 3857**错误码:** 3858 3859以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3860 3861| 错误码ID | 错误信息 | 3862| ------- | -------------------------------------------- | 3863| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3864 3865**示例:** 3866 3867```ts 3868try { 3869 windowClass.on('avoidAreaChange', (data) => { 3870 console.info('Succeeded in enabling the listener for system avoid area changes. type:' + 3871 JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area)); 3872 }); 3873} catch (exception) { 3874 console.error(`Failed to enable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`); 3875} 3876``` 3877 3878### off('avoidAreaChange')<sup>9+</sup> 3879 3880off(type: 'avoidAreaChange', callback?: Callback<AvoidAreaOptions>): void 3881 3882关闭当前窗口系统规避区变化的监听。 3883 3884**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3885 3886**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 3887 3888**参数:** 3889 3890| 参数名 | 类型 | 必填 | 说明 | 3891| -------- |----------------------------------|------|------------------------------------| 3892| type | string | 是 | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 | 3893| callback | Callback<[AvoidAreaOptions](#avoidareaoptions12)> | 否 | 回调函数。返回当前规避区以及规避区类型。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有系统规避区变化的监听。| 3894 3895**错误码:** 3896 3897以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3898 3899| 错误码ID | 错误信息 | 3900| ------- | -------------------------------------------- | 3901| 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed. | 3902 3903**示例:** 3904 3905```ts 3906interface Param { 3907 type: window.AvoidAreaType, 3908 area: window.AvoidArea 3909} 3910const callback = (data: Param) => { 3911 // ... 3912} 3913try { 3914 windowClass.on('avoidAreaChange', callback); 3915 3916 windowClass.off('avoidAreaChange', callback); 3917 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3918 windowClass.off('avoidAreaChange'); 3919} catch (exception) { 3920 console.error(`Failed to enable or disable the listener for system avoid area changes. Cause code: ${exception.code}, message: ${exception.message}`); 3921} 3922``` 3923 3924### on('keyboardHeightChange')<sup>7+</sup> 3925 3926on(type: 'keyboardHeightChange', callback: Callback<number>): void 3927 3928开启固定态软键盘高度变化的监听,当软键盘由本窗口唤出并存在重叠区域时通知键盘高度变化。从API version 10开始,改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。 3929 3930**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3931 3932**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3933 3934**参数:** 3935 3936| 参数名 | 类型 | 必填 | 说明 | 3937| -------- | ------------------- | ---- |-------------------------------------------| 3938| type | string | 是 | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 | 3939| callback | Callback<number> | 是 | 回调函数。返回当前的键盘高度,返回值为整数,单位为px。 | 3940 3941**错误码:** 3942 3943以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3944 3945| 错误码ID | 错误信息 | 3946| ------- | -------------------------------------------- | 3947| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3948 3949**示例:** 3950 3951```ts 3952import { BusinessError } from '@kit.BasicServicesKit'; 3953 3954try { 3955 windowClass.on('keyboardHeightChange', (data) => { 3956 console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); 3957 }); 3958} catch (exception) { 3959 console.error(`Failed to enable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`); 3960} 3961``` 3962 3963### off('keyboardHeightChange')<sup>7+</sup> 3964 3965off(type: 'keyboardHeightChange', callback?: Callback<number>): void 3966 3967关闭固定态软键盘高度变化的监听。从API version 10开始,改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。 3968 3969**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3970 3971**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3972 3973**参数:** 3974 3975| 参数名 | 类型 | 必填 | 说明 | 3976| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3977| type | string | 是 | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 | 3978| callback | Callback<number> | 否 | 回调函数。返回当前的键盘高度,返回值为整数,单位为px。若传入参数,则关闭该监听。如果未传入参数,则关闭所有固定态软键盘高度变化的监听。 | 3979 3980**错误码:** 3981 3982以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3983 3984| 错误码ID | 错误信息 | 3985| ------- | -------------------------------------------- | 3986| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 3987 3988**示例:** 3989 3990```ts 3991import { BusinessError } from '@kit.BasicServicesKit'; 3992 3993const callback = (height: number) => { 3994 // ... 3995} 3996try { 3997 windowClass.on('keyboardHeightChange', callback); 3998 3999 windowClass.off('keyboardHeightChange', callback); 4000 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4001 windowClass.off('keyboardHeightChange'); 4002} catch (exception) { 4003 console.error(`Failed to disable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`); 4004} 4005``` 4006 4007### on('keyboardDidShow')<sup>18+</sup> 4008 4009on(type: 'keyboardDidShow', callback: Callback<KeyboardInfo>): void 4010 4011开启固定态软键盘显示动画完成的监听。此监听在固定态软键盘显示动画完成或软键盘由悬浮态切换至固定态时触发。 4012 4013改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。 4014 4015**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 4016 4017**系统能力:** SystemCapability.Window.SessionManager 4018 4019**参数:** 4020 4021| 参数名 | 类型 | 必填 | 说明 | 4022| -------- | ------------------- | ---- |-------------------------------------------| 4023| type | string | 是 | 监听事件,固定为'keyboardDidShow',即固定态软键盘显示动画完成事件。 | 4024| callback | Callback<[KeyboardInfo](#keyboardinfo18)> | 是 | 回调函数。返回软键盘窗口信息。 | 4025 4026**错误码:** 4027 4028以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4029 4030| 错误码ID | 错误信息 | 4031| ------- | -------------------------------------------- | 4032| 801 | Capability not supported. Function keyboardDidShow can not work correctly due to limited device capabilities. | 4033| 1300002 | This window state is abnormal. | 4034 4035**示例:** 4036 4037```ts 4038import { BusinessError } from '@kit.BasicServicesKit'; 4039 4040try { 4041 windowClass.on('keyboardDidShow', (keyboardInfo) => { 4042 console.info('keyboard show animation completion. keyboardInfo: ' + JSON.stringify(keyboardInfo)); 4043 }); 4044} catch (exception) { 4045 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4046} 4047``` 4048 4049### off('keyboardDidShow')<sup>18+</sup> 4050 4051off(type: 'keyboardDidShow', callback?: Callback<KeyboardInfo>): void 4052 4053关闭固定态软键盘显示动画完成的监听。改变输入法窗口为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。 4054 4055**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 4056 4057**系统能力:** SystemCapability.Window.SessionManager 4058 4059**参数:** 4060 4061| 参数名 | 类型 | 必填 | 说明 | 4062| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 4063| type | string | 是 | 监听事件,固定为'keyboardDidShow',即固定态软键盘显示动画完成事件。 | 4064| callback | Callback<[KeyboardInfo](#keyboardinfo18)> | 否 | 回调函数。返回软键盘窗口信息。若传入参数,则关闭该监听。如果未传入参数,则关闭所有固定态软键盘显示动画完成的监听。 | 4065 4066**错误码:** 4067 4068以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4069 4070| 错误码ID | 错误信息 | 4071| ------- | -------------------------------------------- | 4072| 801 | Capability not supported. Function keyboardDidShow can not work correctly due to limited device capabilities. | 4073| 1300002 | This window state is abnormal. | 4074 4075**示例:** 4076 4077```ts 4078import { BusinessError } from '@kit.BasicServicesKit'; 4079 4080const callback = (keyboardInfo: window.KeyboardInfo) => { 4081 // ... 4082} 4083try { 4084 windowClass.on('keyboardDidShow', callback); 4085 windowClass.off('keyboardDidShow', callback); 4086 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4087 windowClass.off('keyboardDidShow'); 4088} catch (exception) { 4089 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4090} 4091``` 4092 4093### on('keyboardDidHide')<sup>18+</sup> 4094 4095on(type: 'keyboardDidHide', callback: Callback<KeyboardInfo>): void 4096 4097开启固定态软键盘隐藏动画完成的监听。此监听在固定态软键盘隐藏动画完成或软键盘由固定态切换至悬浮态时触发。 4098 4099改变软键盘为固定态或者悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。 4100 4101**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 4102 4103**系统能力:** SystemCapability.Window.SessionManager 4104 4105**参数:** 4106 4107| 参数名 | 类型 | 必填 | 说明 | 4108| -------- | ------------------- | ---- |-------------------------------------------| 4109| type | string | 是 | 监听事件,固定为'keyboardDidHide',即固定态软键盘隐藏动画完成事件。 | 4110| callback | Callback<[KeyboardInfo](#keyboardinfo18)> | 是 | 回调函数。返回软键盘窗口信息。 | 4111 4112**错误码:** 4113 4114以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4115 4116| 错误码ID | 错误信息 | 4117| ------- | -------------------------------------------- | 4118| 801 | Capability not supported. Function keyboardDidHide can not work correctly due to limited device capabilities. | 4119| 1300002 | This window state is abnormal. | 4120 4121**示例:** 4122 4123```ts 4124import { BusinessError } from '@kit.BasicServicesKit'; 4125 4126try { 4127 windowClass.on('keyboardDidHide', (keyboardInfo) => { 4128 console.info('keyboard hide animation completion. keyboardInfo: ' + JSON.stringify(keyboardInfo)); 4129 }); 4130} catch (exception) { 4131 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4132} 4133``` 4134 4135### off('keyboardDidHide')<sup>18+</sup> 4136 4137off(type: 'keyboardDidHide', callback?: Callback<KeyboardInfo>): void 4138 4139关闭固定态软键盘隐藏动画完成的监听。改变输入法窗口为固定态切换至悬浮态方法详细介绍请参见[输入法服务](../apis-ime-kit/js-apis-inputmethodengine.md#changeflag10)。 4140 4141**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 4142 4143**系统能力:** SystemCapability.Window.SessionManager 4144 4145**参数:** 4146 4147| 参数名 | 类型 | 必填 | 说明 | 4148| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 4149| type | string | 是 | 监听事件,固定为'keyboardDidHide',即固定态软键盘隐藏动画完成事件。 | 4150| callback | Callback<[KeyboardInfo](#keyboardinfo18)> | 否 | 回调函数。返回软键盘窗口信息。若传入参数,则关闭该监听。如果未传入参数,则关闭所有固定态软键盘隐藏动画完成的监听。 | 4151 4152**错误码:** 4153 4154以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4155 4156| 错误码ID | 错误信息 | 4157| ------- | -------------------------------------------- | 4158| 801 | Capability not supported. Function keyboardDidHide can not work correctly due to limited device capabilities. | 4159| 1300002 | This window state is abnormal. | 4160 4161**示例:** 4162 4163```ts 4164import { BusinessError } from '@kit.BasicServicesKit'; 4165 4166const callback = (keyboardInfo: window.KeyboardInfo) => { 4167 // ... 4168} 4169try { 4170 windowClass.on('keyboardDidHide', callback); 4171 windowClass.off('keyboardDidHide', callback); 4172 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4173 windowClass.off('keyboardDidHide'); 4174} catch (exception) { 4175 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4176} 4177``` 4178 4179### on('touchOutside')<sup>11+</sup> 4180 4181on(type: 'touchOutside', callback: Callback<void>): void 4182 4183开启本窗口区域范围外的点击事件的监听。 4184 4185**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4186 4187**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4188 4189**参数:** 4190 4191| 参数名 | 类型 | 必填 | 说明 | 4192| -------- | ------------------- | ---- | ------------------------------------------------------------ | 4193| type | string | 是 | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 | 4194| callback | Callback<void> | 是 | 回调函数。当点击事件发生在本窗口范围之外的回调。 | 4195 4196**错误码:** 4197 4198以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4199 4200| 错误码ID | 错误信息 | 4201| ------- | -------------------------------------------- | 4202| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4203 4204**示例:** 4205 4206```ts 4207try { 4208 windowClass.on('touchOutside', () => { 4209 console.info('touch outside'); 4210 }); 4211} catch (exception) { 4212 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4213} 4214``` 4215 4216### off('touchOutside')<sup>11+</sup> 4217 4218off(type: 'touchOutside', callback?: Callback<void>): void 4219 4220关闭本窗口区域范围外的点击事件的监听。 4221 4222**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4223 4224**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4225 4226**参数:** 4227 4228| 参数名 | 类型 | 必填 | 说明 | 4229| -------- |----------------------| ---- |--------------------------------------| 4230| type | string | 是 | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 | 4231| callback | Callback<void> | 否 | 回调函数。当点击事件发生在本窗口范围之外的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口区域范围外的点击事件的监听。 | 4232 4233**错误码:** 4234 4235以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4236 4237| 错误码ID | 错误信息 | 4238| ------- | -------------------------------------------- | 4239| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4240 4241**示例:** 4242 4243```ts 4244const callback = () => { 4245 // ... 4246} 4247try { 4248 windowClass.on('touchOutside', callback); 4249 windowClass.off('touchOutside', callback); 4250 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4251 windowClass.off('touchOutside'); 4252} catch (exception) { 4253 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4254} 4255``` 4256 4257### on('screenshot')<sup>9+</sup> 4258 4259on(type: 'screenshot', callback: Callback<void>): void 4260 4261开启截屏事件的监听。 4262 4263**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4264 4265**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4266 4267**参数:** 4268 4269| 参数名 | 类型 | 必填 | 说明 | 4270| -------- | ------------------- | ---- | ------------------------------------------------------------ | 4271| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件,对控制中心截屏、hdc命令截屏、整屏截屏接口生效。 | 4272| callback | Callback<void> | 是 | 回调函数。发生截屏事件时的回调。 | 4273 4274**错误码:** 4275 4276以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4277 4278| 错误码ID | 错误信息 | 4279| ------- | -------------------------------------------- | 4280| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4281 4282**示例:** 4283 4284```ts 4285try { 4286 windowClass.on('screenshot', () => { 4287 console.info('screenshot happened'); 4288 }); 4289} catch (exception) { 4290 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4291} 4292``` 4293 4294### off('screenshot')<sup>9+</sup> 4295 4296off(type: 'screenshot', callback?: Callback<void>): void 4297 4298关闭截屏事件的监听。 4299 4300**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4301 4302**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4303 4304**参数:** 4305 4306| 参数名 | 类型 | 必填 | 说明 | 4307| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 4308| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件。 | 4309| callback | Callback<void> | 否 | 回调函数。发生截屏事件时的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有截屏事件的监听。 | 4310 4311**错误码:** 4312 4313以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4314 4315| 错误码ID | 错误信息 | 4316| ------- | -------------------------------------------- | 4317| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4318 4319**示例:** 4320 4321```ts 4322let callback = () => { 4323 console.info('screenshot happened'); 4324}; 4325try { 4326 windowClass.on('screenshot', callback); 4327 windowClass.off('screenshot', callback); 4328 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4329 windowClass.off('screenshot'); 4330} catch (exception) { 4331 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4332} 4333``` 4334 4335### on('dialogTargetTouch')<sup>10+</sup> 4336 4337on(type: 'dialogTargetTouch', callback: Callback<void>): void 4338 4339开启模态窗口所遮盖窗口的点击或触摸事件的监听,除模态窗口以外其他窗口调用此接口不生效。 4340 4341**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4342 4343**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4344 4345**参数:** 4346 4347| 参数名 | 类型 | 必填 | 说明 | 4348| -------- | ------------------- | ---- | ------------------------------------------------------------ | 4349| type | string | 是 | 监听事件,固定为'dialogTargetTouch',即模态窗口所遮盖窗口的点击或触摸事件。 | 4350| callback | Callback<void>| 是 | 回调函数。当点击或触摸事件发生在模态窗口所遮盖窗口的回调。 | 4351 4352**错误码:** 4353 4354以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4355 4356| 错误码ID | 错误信息 | 4357| ------- | -------------------------------------------- | 4358| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4359 4360**示例:** 4361 4362```ts 4363try { 4364 windowClass.on('dialogTargetTouch', () => { 4365 console.info('touch dialog target'); 4366 }); 4367} catch (exception) { 4368 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4369} 4370``` 4371 4372### off('dialogTargetTouch')<sup>10+</sup> 4373 4374off(type: 'dialogTargetTouch', callback?: Callback<void>): void 4375 4376关闭模态窗口目标窗口的点击事件的监听。 4377 4378**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4379 4380**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4381 4382**参数:** 4383 4384| 参数名 | 类型 | 必填 | 说明 | 4385| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 4386| type | string | 是 | 监听事件,固定为'dialogTargetTouch',即模态窗口目标窗口的点击事件。 | 4387| callback | Callback<void> | 否 | 回调函数。当点击事件发生在模态窗口目标窗口的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有模态窗口目标窗口的点击事件的监听。 | 4388 4389**错误码:** 4390 4391以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4392 4393| 错误码ID | 错误信息 | 4394| ------- | -------------------------------------------- | 4395| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4396 4397**示例:** 4398 4399```ts 4400const callback = () => { 4401 // ... 4402} 4403try { 4404 windowClass.on('dialogTargetTouch', callback); 4405 windowClass.off('dialogTargetTouch', callback); 4406 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4407 windowClass.off('dialogTargetTouch'); 4408} catch (exception) { 4409 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4410} 4411``` 4412 4413### on('windowEvent')<sup>10+</sup> 4414 4415on(type: 'windowEvent', callback: Callback<WindowEventType>): void 4416 4417开启窗口生命周期变化的监听。 4418 4419**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4420 4421**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4422 4423**参数:** 4424 4425| 参数名 | 类型 | 必填 | 说明 | 4426| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 4427| type | string | 是 | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 | 4428| callback | Callback<[WindowEventType](#windoweventtype10)> | 是 | 回调函数。返回当前的窗口生命周期状态。 | 4429 4430**错误码:** 4431 4432以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4433 4434| 错误码ID | 错误信息 | 4435| ------- | -------------------------------------------- | 4436| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4437 4438**示例:** 4439 4440```ts 4441try { 4442 windowClass.on('windowEvent', (data) => { 4443 console.info('Window event happened. Event:' + JSON.stringify(data)); 4444 }); 4445} catch (exception) { 4446 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4447} 4448``` 4449 4450### off('windowEvent')<sup>10+</sup> 4451 4452off(type: 'windowEvent', callback?: Callback<WindowEventType>): void 4453 4454关闭窗口生命周期变化的监听。 4455 4456**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4457 4458**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 4459 4460**参数:** 4461 4462| 参数名 | 类型 | 必填 | 说明 | 4463| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 4464| type | string | 是 | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 | 4465| callback | Callback<[WindowEventType](#windoweventtype10)> | 否 | 回调函数。返回当前的窗口生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有窗口生命周期变化的监听。 | 4466 4467**错误码:** 4468 4469以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4470 4471| 错误码ID | 错误信息 | 4472| ------- | -------------------------------------------- | 4473| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4474 4475**示例:** 4476 4477```ts 4478const callback = (windowEventType: window.WindowEventType) => { 4479 // ... 4480} 4481try { 4482 // 通过on接口开启监听 4483 windowClass.on('windowEvent', callback); 4484 // 关闭指定callback的监听 4485 windowClass.off('windowEvent', callback); 4486 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4487 windowClass.off('windowEvent'); 4488} catch (exception) { 4489 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4490} 4491``` 4492 4493### on('displayIdChange')<sup>14+</sup> 4494 4495on(type: 'displayIdChange', callback: Callback<number>): void 4496 4497开启本窗口所处屏幕变化事件的监听。比如,当前窗口移动到其他屏幕时,可以从此接口监听到这个行为。 4498 4499**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 4500 4501**系统能力:** SystemCapability.Window.SessionManager 4502 4503**参数:** 4504 4505| 参数名 | 类型 | 必填 | 说明 | 4506| -------- | --------------------------| ---- | ------------------------------------------------------------ | 4507| type | string | 是 | 监听事件,固定为'displayIdChange',即本窗口所处屏幕变化的事件。 | 4508| callback | Callback<number> | 是 | 回调函数。当本窗口所处屏幕发生变化后的回调。回调函数返回number类型参数,表示窗口所处屏幕的displayId。 | 4509 4510**错误码:** 4511 4512以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4513 4514| 错误码ID | 错误信息 | 4515| ------- | ------------------------------ | 4516| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4517| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4518| 1300002 | This window state is abnormal. | 4519 4520**示例:** 4521 4522```ts 4523try { 4524 windowClass.on('displayIdChange', (data) => { 4525 console.info('Window displayId changed, displayId=' + JSON.stringify(data)); 4526 }); 4527} catch (exception) { 4528 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4529} 4530``` 4531### off('displayIdChange')<sup>14+</sup> 4532 4533off(type: 'displayIdChange', callback?: Callback<number>): void 4534 4535关闭本窗口所处屏幕变化事件的监听。 4536 4537**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 4538 4539**系统能力:** SystemCapability.Window.SessionManager 4540 4541**参数:** 4542 4543| 参数名 | 类型 | 必填 | 说明 | 4544| -------- |----------------------------| ---- |--------------------------------------| 4545| type | string | 是 | 监听事件,固定为'displayIdChange',即本窗口所处屏幕变化的事件。 | 4546| callback | Callback<number> | 否 | 回调函数。当本窗口所处屏幕发生变化时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口所处屏幕变化事件的回调。 | 4547 4548**错误码:** 4549 4550以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4551 4552| 错误码ID | 错误信息 | 4553| ------- | ------------------------------ | 4554| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4555| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4556| 1300002 | This window state is abnormal. | 4557 4558**示例:** 4559 4560```ts 4561const callback = (displayId: number) => { 4562 // ... 4563} 4564try { 4565 // 通过on接口开启监听 4566 windowClass.on('displayIdChange', callback); 4567 // 关闭指定callback的监听 4568 windowClass.off('displayIdChange', callback); 4569 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4570 windowClass.off('displayIdChange'); 4571} catch (exception) { 4572 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4573} 4574``` 4575 4576### on('windowVisibilityChange')<sup>11+</sup> 4577 4578on(type: 'windowVisibilityChange', callback: Callback<boolean>): void 4579 4580开启本窗口可见状态变化事件的监听。 4581 4582**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4583 4584**系统能力:** SystemCapability.Window.SessionManager 4585 4586**参数:** 4587 4588| 参数名 | 类型 | 必填 | 说明 | 4589| -------- | --------------------------| ---- | ------------------------------------------------------------ | 4590| type | string | 是 | 监听事件,固定为'windowVisibilityChange',即本窗口可见状态变化的事件。 | 4591| callback | Callback<boolean> | 是 | 回调函数。当本窗口可见状态发生变化后的回调。回调函数返回boolean类型参数,当返回参数为true时表示窗口可见,否则表示窗口不可见。 | 4592 4593**错误码:** 4594 4595以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4596 4597| 错误码ID | 错误信息 | 4598| ------- | ------------------------------ | 4599| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4600| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4601| 1300002 | This window state is abnormal. | 4602| 1300003 | This window manager service works abnormally. | 4603 4604**示例:** 4605 4606```ts 4607try { 4608 windowClass.on('windowVisibilityChange', (boolean) => { 4609 console.info('Window visibility changed, isVisible=' + boolean); 4610 }); 4611} catch (exception) { 4612 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4613} 4614``` 4615 4616### off('windowVisibilityChange')<sup>11+</sup> 4617 4618off(type: 'windowVisibilityChange', callback?: Callback<boolean>): void 4619 4620关闭本窗口可见状态变化事件的监听。 4621 4622**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4623 4624**系统能力:** SystemCapability.Window.SessionManager 4625 4626**参数:** 4627 4628| 参数名 | 类型 | 必填 | 说明 | 4629| -------- |----------------------------| ---- |--------------------------------------| 4630| type | string | 是 | 监听事件,固定为'windowVisibilityChange',即本窗口可见状态变化的事件。 | 4631| callback | Callback<boolean> | 否 | 回调函数。当本窗口可见状态发生变化时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口可见状态变化事件的回调。 | 4632 4633**错误码:** 4634 4635以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4636 4637| 错误码ID | 错误信息 | 4638| ------- | ------------------------------ | 4639| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4640| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4641| 1300002 | This window state is abnormal. | 4642| 1300003 | This window manager service works abnormally. | 4643 4644**示例:** 4645 4646```ts 4647const callback = (bool: boolean) => { 4648 // ... 4649} 4650try { 4651 // 通过on接口开启监听 4652 windowClass.on('windowVisibilityChange', callback); 4653 // 关闭指定callback的监听 4654 windowClass.off('windowVisibilityChange', callback); 4655 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4656 windowClass.off('windowVisibilityChange'); 4657} catch (exception) { 4658 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4659} 4660``` 4661 4662### on('systemDensityChange')<sup>15+</sup> 4663 4664on(type: 'systemDensityChange', callback: Callback<number>): void 4665 4666开启本窗口所处屏幕的系统显示大小缩放系数变化事件的监听。比如,当调整窗口所处屏幕的显示大小缩放系数时,可以从此接口监听到这个行为。 4667 4668**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 4669 4670**系统能力:** SystemCapability.Window.SessionManager 4671 4672**参数:** 4673 4674| 参数名 | 类型 | 必填 | 说明 | 4675| -------- | --------------------------| ---- | ------------------------------------------------------------ | 4676| type | string | 是 | 监听事件,固定为'systemDensityChange',即本窗口所处屏幕的系统显示大小缩放系数变化的事件。 | 4677| callback | Callback<number> | 是 | 回调函数。当本窗口所处屏幕的系统显示大小缩放系数发生变化后的回调。回调函数返回number类型参数,表示当前窗口所处屏幕的系统显示大小缩放系数。 | 4678 4679**错误码:** 4680 4681 4682以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4683 4684| 错误码ID | 错误信息 | 4685| ------- | ------------------------------ | 4686| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4687| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4688| 1300002 | This window state is abnormal. | 4689 4690**示例:** 4691 4692```ts 4693const callback = (density: number) => { 4694 console.info('System density changed, density=' + JSON.stringify(density)); 4695} 4696try { 4697 windowClass.on('systemDensityChange', callback); 4698} catch (exception) { 4699 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4700} 4701``` 4702### off('systemDensityChange')<sup>15+</sup> 4703 4704off(type: 'systemDensityChange', callback?: Callback<number>): void 4705 4706关闭本窗口所处屏幕的系统显示大小缩放系数变化事件的监听。 4707 4708**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 4709 4710**系统能力:** SystemCapability.Window.SessionManager 4711 4712**参数:** 4713 4714| 参数名 | 类型 | 必填 | 说明 | 4715| -------- |----------------------------| ---- |--------------------------------------| 4716| type | string | 是 | 监听事件,固定为'systemDensityChange',即本窗口所处屏幕的系统显示大小缩放系数变化的事件。 | 4717| callback | Callback<number> | 否 | 回调函数。当本窗口所处屏幕的系统显示大小缩放系数发生变化后的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口所处屏幕的系统显示大小缩放系数变化事件的回调。 | 4718 4719**错误码:** 4720 4721以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4722 4723| 错误码ID | 错误信息 | 4724| ------- | ------------------------------ | 4725| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4726| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4727| 1300002 | This window state is abnormal. | 4728 4729**示例:** 4730 4731```ts 4732const callback = (density: number) => { 4733 // ... 4734} 4735try { 4736 // 通过on接口开启监听 4737 windowClass.on('systemDensityChange', callback); 4738 // 关闭指定callback的监听 4739 windowClass.off('systemDensityChange', callback); 4740 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4741 windowClass.off('systemDensityChange'); 4742} catch (exception) { 4743 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4744} 4745``` 4746 4747### on('noInteractionDetected')<sup>12+</sup> 4748 4749on(type: 'noInteractionDetected', timeout: number, callback: Callback<void>): void 4750 4751开启本窗口在指定超时时间内无交互事件的监听,交互事件支持物理键盘输入事件和屏幕触控点击事件,不支持软键盘输入事件。 4752 4753**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4754 4755**系统能力:** SystemCapability.Window.SessionManager 4756 4757**参数:** 4758 4759| 参数名 | 类型 | 必填 | 说明 | 4760| -------- | --------------------------| ---- | ------------------------------------------------------------ | 4761| type | string | 是 | 监听事件,固定为'noInteractionDetected',即本窗口在指定超时时间内无交互的事件。 | 4762| timeout | number | 是 | 指定本窗口在多长时间内无交互即回调,单位为秒(s)。该参数仅支持整数输入,负数和小数为非法参数。 | 4763| callback | Callback<void> | 是 | 回调函数。当本窗口在指定超时时间内无交互事件时的回调。 | 4764 4765**错误码:** 4766 4767以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4768 4769| 错误码ID | 错误信息 | 4770| ------- | ------------------------------ | 4771| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4772| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4773| 1300002 | This window state is abnormal. | 4774| 1300003 | This window manager service works abnormally. | 4775 4776**示例:** 4777 4778```ts 4779try { 4780 windowClass.on('noInteractionDetected', 60, () => { 4781 console.info('no interaction in 60s'); 4782 }); 4783} catch (exception) { 4784 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 4785} 4786``` 4787 4788### off('noInteractionDetected')<sup>12+</sup> 4789 4790off(type: 'noInteractionDetected', callback?: Callback<void>): void 4791 4792关闭本窗口在指定超时时间内无交互事件的监听,交互事件支持物理键盘输入事件和屏幕触控点击事件,不支持软键盘输入事件。 4793 4794**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4795 4796**系统能力:** SystemCapability.Window.SessionManager 4797 4798**参数:** 4799 4800| 参数名 | 类型 | 必填 | 说明 | 4801| -------- |----------------------------| ---- |--------------------------------------| 4802| type | string | 是 | 监听事件,固定为'noInteractionDetected',即本窗口在指定超时时间内无交互的事件。 | 4803| callback | Callback<void> | 否 | 回调函数,当本窗口在指定超时时间内无交互事件时的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口在指定超时时间内无交互事件的监听。 | 4804 4805**错误码:** 4806 4807以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4808 4809| 错误码ID | 错误信息 | 4810| ------- | ------------------------------ | 4811| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4812| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4813| 1300002 | This window state is abnormal. | 4814| 1300003 | This window manager service works abnormally. | 4815 4816**示例:** 4817 4818```ts 4819const callback = () => { 4820 // ... 4821} 4822try { 4823 windowClass.on('noInteractionDetected', 60, callback); 4824 windowClass.off('noInteractionDetected', callback); 4825 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4826 windowClass.off('noInteractionDetected'); 4827} catch (exception) { 4828 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4829} 4830``` 4831 4832### on('windowStatusChange')<sup>11+</sup> 4833 4834on(type: 'windowStatusChange', callback: Callback<WindowStatusType>): void 4835 4836开启窗口模式变化的监听,当窗口windowStatus发生变化时进行通知(此时窗口属性可能还没有更新)。 4837 4838**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4839 4840**系统能力:** SystemCapability.Window.SessionManager 4841 4842**参数:** 4843 4844| 参数名 | 类型 | 必填 | 说明 | 4845| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 4846| type | string | 是 | 监听事件,固定为'windowStatusChange',即窗口模式变化事件。 | 4847| callback | Callback<[WindowStatusType](#windowstatustype11)> | 是 | 回调函数。返回当前的窗口模式。 | 4848 4849**错误码:** 4850 4851以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4852 4853| 错误码ID | 错误信息 | 4854| ------- | ------------------------------ | 4855| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4856| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4857 4858**示例:** 4859 4860```ts 4861try { 4862 windowClass.on('windowStatusChange', (WindowStatusType) => { 4863 console.info('Succeeded in enabling the listener for window status changes. Data: ' + JSON.stringify(WindowStatusType)); 4864 }); 4865} catch (exception) { 4866 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4867} 4868``` 4869 4870### off('windowStatusChange')<sup>11+</sup> 4871 4872off(type: 'windowStatusChange', callback?: Callback<WindowStatusType>): void 4873 4874关闭窗口模式变化的监听。 4875 4876**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4877 4878**系统能力:** SystemCapability.Window.SessionManager 4879 4880**参数:** 4881 4882| 参数名 | 类型 | 必填 | 说明 | 4883| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 4884| type | string | 是 | 监听事件,固定为'windowStatusChange',即窗口模式变化事件。 | 4885| callback | Callback<[WindowStatusType](#windowstatustype11)> | 否 | 回调函数。返回当前的窗口模式。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有窗口模式变化的监听。 | 4886 4887**错误码:** 4888 4889以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4890 4891| 错误码ID | 错误信息 | 4892| ------- | ------------------------------ | 4893| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 4894| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4895 4896**示例:** 4897 4898```ts 4899const callback = (windowStatusType: window.WindowStatusType) => { 4900 // ... 4901} 4902try { 4903 windowClass.on('windowStatusChange', callback); 4904 windowClass.off('windowStatusChange', callback); 4905 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 4906 windowClass.off('windowStatusChange'); 4907} catch (exception) { 4908 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 4909} 4910``` 4911 4912### setWindowGrayScale<sup>12+</sup> 4913 4914setWindowGrayScale(grayScale: number): Promise<void> 4915 4916设置窗口灰阶,使用Promise异步回调。该接口需要在调用[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)使窗口加载页面内容后调用。 4917 4918**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4919 4920**系统能力:** SystemCapability.Window.SessionManager 4921 4922**参数:** 4923 4924| 参数名 | 类型 | 必填 | 说明 | 4925| --------- | ------ | -- | ---------------------------------------- | 4926| grayScale | number | 是 | 窗口灰阶。该参数为浮点数,取值范围为[0.0, 1.0]。0.0表示窗口图像无变化,1.0表示窗口图像完全转为灰度图像,0.0至1.0之间时效果呈线性变化。 | 4927 4928**返回值:** 4929 4930| 类型 | 说明 | 4931| ------------------- | ------------------------ | 4932| Promise<void> | 无返回结果的Promise对象。 | 4933 4934**错误码:** 4935 4936以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4937 4938| 错误码ID | 错误信息 | 4939| ------- | --------------------------------------------- | 4940| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4941| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4942| 1300002 | This window state is abnormal. | 4943| 1300003 | This window manager service works abnormally. | 4944 4945**示例:** 4946 4947```ts 4948import { BusinessError } from '@kit.BasicServicesKit'; 4949 4950windowClass?.setUIContent('pages/Index', (error: BusinessError) => { 4951 if (error.code) { 4952 console.error(`Failed to set the content. Cause code: ${error.code}`); 4953 return; 4954 } 4955 console.info('Succeeded in setting the content.'); 4956 let grayScale: number = 0.5; 4957 try { 4958 if (canIUse("SystemCapability.Window.SessionManager")) { 4959 let promise = windowClass?.setWindowGrayScale(grayScale); 4960 promise?.then(() => { 4961 console.info('Succeeded in setting the grayScale.'); 4962 }).catch((err: BusinessError) => { 4963 console.error(`Failed to set the grayScale. Cause code: ${err.code}, message: ${err.message}`); 4964 }); 4965 } 4966 } catch (exception) { 4967 console.error(`Failed to set the grayScale. Cause code: ${exception.code}, message: ${exception.message}`); 4968 } 4969}); 4970``` 4971 4972### on('windowTitleButtonRectChange')<sup>11+</sup> 4973 4974on(type: 'windowTitleButtonRectChange', callback: Callback<TitleButtonRect>): void 4975 4976开启窗口标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 4977 4978<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 4979 4980**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4981 4982**系统能力:** SystemCapability.Window.SessionManager 4983 4984**参数:** 4985 4986| 参数名 | 类型 | 必填 | 说明 | 4987| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 4988| type | string | 是 | 监听事件,固定为'windowTitleButtonRectChange',即标题栏上的最小化、最大化、关闭按钮矩形区域变化事件。 | 4989| callback | Callback<[TitleButtonRect](#titlebuttonrect11)> | 是 | 回调函数。返回当前标题栏上的最小化、最大化、关闭按钮矩形区域。 | 4990 4991**错误码:** 4992 4993以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 4994 4995| 错误码ID | 错误信息 | 4996| -------- | ------------------------------ | 4997| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4998| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 4999| 1300002 | This window state is abnormal. | 5000 5001**示例:** 5002 5003```ts 5004windowClass.setUIContent('pages/WindowPage').then(() => { 5005 try { 5006 windowClass?.on('windowTitleButtonRectChange', (titleButtonRect) => { 5007 console.info('Succeeded in enabling the listener for window title buttons area changes. Data: ' + JSON.stringify(titleButtonRect)); 5008 }); 5009 } catch (exception) { 5010 console.error(`Failed to enable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`); 5011 } 5012}) 5013``` 5014 5015### off('windowTitleButtonRectChange')<sup>11+</sup> 5016 5017off(type: 'windowTitleButtonRectChange', callback?: Callback<TitleButtonRect>): void 5018 5019关闭窗口标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 5020 5021<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 5022 5023**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5024 5025**系统能力:** SystemCapability.Window.SessionManager 5026 5027**参数:** 5028 5029| 参数名 | 类型 | 必填 | 说明 | 5030| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 5031| type | string | 是 | 监听事件,固定为'windowTitleButtonRectChange',即标题栏上的最小化、最大化、关闭按钮矩形区域变化事件。 | 5032| callback | Callback<[TitleButtonRect](#titlebuttonrect11)> | 否 | 回调函数。返回当前标题栏上的最小化、最大化、关闭按钮矩形区域。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有标题栏上的最小化、最大化、关闭按钮矩形区域变化的监听。 | 5033 5034**错误码:** 5035 5036以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5037 5038| 错误码ID | 错误信息 | 5039| -------- | ------------------------------ | 5040| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 5041| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5042| 1300002 | This window state is abnormal. | 5043 5044**示例:** 5045 5046```ts 5047windowClass.setUIContent('pages/WindowPage').then(() => { 5048 const callback = (titleButtonRect: window.TitleButtonRect) => { 5049 // ... 5050 } 5051 try { 5052 // 通过on接口开启监听 5053 windowClass?.on('windowTitleButtonRectChange', callback); 5054 // 关闭指定callback的监听 5055 windowClass?.off('windowTitleButtonRectChange', callback); 5056 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 5057 windowClass?.off('windowTitleButtonRectChange'); 5058 } catch (exception) { 5059 console.error(`Failed to disable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`); 5060 } 5061}) 5062``` 5063 5064### on('windowRectChange')<sup>12+</sup> 5065 5066on(type: 'windowRectChange', callback: Callback<RectChangeOptions>): void 5067 5068开启窗口矩形(窗口位置及窗口大小)变化的监听。 5069 5070**系统能力:** SystemCapability.Window.SessionManager 5071 5072**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5073 5074**参数:** 5075 5076| 参数名 | 类型 | 必填 | 说明 | 5077| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 5078| type | string | 是 | 监听事件,固定为'windowRectChange',即窗口矩形变化事件。 | 5079| callback | Callback<[RectChangeOptions](#rectchangeoptions12)> | 是 | 回调函数。返回当前窗口矩形变化值及变化原因。 | 5080 5081**错误码:** 5082 5083以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5084 5085| 错误码ID | 错误信息 | 5086| ------- | -------------------------------------------- | 5087| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5088| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5089| 1300002 | This window state is abnormal. | 5090| 1300003 | This window manager service works abnormally. | 5091 5092**示例:** 5093 5094```ts 5095windowClass.on('windowRectChange', (data: window.RectChangeOptions) => { 5096 console.info('Succeeded window rect changes. Data: ' + JSON.stringify(data)); 5097}); 5098``` 5099 5100### off('windowRectChange')<sup>12+</sup> 5101 5102off(type: 'windowRectChange', callback?: Callback<RectChangeOptions>): void 5103 5104关闭窗口矩形(窗口位置及窗口大小)变化的监听。 5105 5106**系统能力:** SystemCapability.Window.SessionManager 5107 5108**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5109 5110**参数:** 5111 5112| 参数名 | 类型 | 必填 | 说明 | 5113| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 5114| type | string | 是 | 监听事件,固定为'windowRectChange',即窗口矩形变化事件。 | 5115| callback | Callback<[RectChangeOptions](#rectchangeoptions12)> | 否 | 回调函数。返回当前的窗口矩形及变化原因。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有窗口矩形变化的监听。 | 5116 5117**错误码:** 5118 5119以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5120 5121| 错误码ID | 错误信息 | 5122| ------- | -------------------------------------------- | 5123| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 5124| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5125| 1300002 | This window state is abnormal. | 5126| 1300003 | This window manager service works abnormally. | 5127 5128**示例:** 5129 5130```ts 5131const callback = (rectChangeOptions: window.RectChangeOptions) => { 5132 // ... 5133} 5134windowClass.on('windowRectChange', callback); 5135windowClass.off('windowRectChange', callback); 5136// 如果通过on开启多个callback进行监听,同时关闭所有监听: 5137windowClass.off('windowRectChange'); 5138``` 5139 5140### on('subWindowClose')<sup>12+</sup> 5141 5142on(type: 'subWindowClose', callback: Callback<void>): void 5143 5144开启子窗口关闭事件的监听。此监听仅在点击系统提供的右上角关闭按钮关闭子窗时触发,其余关闭方式不触发回调。 5145 5146当重复注册窗口关闭事件的监听时,最后一次注册成功的监听事件生效。 5147 5148该接口触发的窗口关闭事件监听回调函数是同步执行,子窗口的异步关闭事件监听参考[on('windowWillClose')](#onwindowwillclose15)方法。 5149 5150如果存在[on('windowWillClose')](#onwindowwillclose15)监听事件,只响应[on('windowWillClose')](#onwindowwillclose15)接口。 5151 5152**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5153 5154**系统能力:** SystemCapability.Window.SessionManager 5155 5156**参数:** 5157 5158| 参数名 | 类型 | 必填 | 说明 | 5159| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 5160| type | string | 是 | 监听事件,固定为'subWindowClose',即子窗口关闭事件。 | 5161| callback | Callback<void> | 是 | 回调函数。当点击子窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑的返回值决定当前子窗是否继续关闭,如果返回boolean类型的true表示不关闭子窗,返回false或者其他非boolean类型表示关闭子窗。 | 5162 5163**错误码:** 5164 5165以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5166 5167| 错误码ID | 错误信息 | 5168| ------- | -------------------------------------------- | 5169| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 5170| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5171| 1300002 | This window state is abnormal. | 5172| 1300004 | Unauthorized operation. | 5173 5174**示例:** 5175 5176```ts 5177const callback = () => { 5178 // ... 5179 return true; 5180} 5181try { 5182 windowClass.on('subWindowClose', callback); 5183} catch (exception) { 5184 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 5185} 5186``` 5187 5188### off('subWindowClose')<sup>12+</sup> 5189 5190off(type: 'subWindowClose', callback?: Callback<void>): void 5191 5192关闭子窗口关闭事件的监听。 5193 5194**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5195 5196**系统能力:** SystemCapability.Window.SessionManager 5197 5198**参数:** 5199 5200| 参数名 | 类型 | 必填 | 说明 | 5201| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 5202| type | string | 是 | 监听事件,固定为'subWindowClose',即子窗口关闭事件。 | 5203| callback | Callback<void> | 否 | 回调函数。当点击子窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑的返回值决定当前子窗是否继续关闭,如果返回boolean类型的true表示不关闭子窗,返回false或者其他非boolean类型表示关闭子窗。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有子窗口关闭的监听。 | 5204 5205**错误码:** 5206 5207以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5208 5209| 错误码ID | 错误信息 | 5210| ------- | -------------------------------------------- | 5211| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 5212| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5213| 1300002 | This window state is abnormal. | 5214| 1300004 | Unauthorized operation. | 5215 5216**示例:** 5217 5218```ts 5219const callback = () => { 5220 // ... 5221 return true; 5222} 5223try { 5224 windowClass.on('subWindowClose', callback); 5225 windowClass.off('subWindowClose', callback); 5226 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 5227 windowClass.off('subWindowClose'); 5228} catch (exception) { 5229 console.error(`Failed to register or unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 5230} 5231``` 5232 5233### on('windowWillClose')<sup>15+</sup> 5234 5235on(type: 'windowWillClose', callback: Callback<void, Promise<boolean>>): void 5236 5237开启主窗口或子窗口关闭事件的监听。此监听仅能通过系统提供的窗口标题栏关闭按键触发,其余关闭窗口的方式不触发回调。 5238 5239该接口触发的回调函数是异步执行。子窗口的同步关闭事件监听参考[on('subWindowClose')](#onsubwindowclose12)方法。主窗口的同步关闭事件监听参考[on('windowStageClose')](#onwindowstageclose14)方法。 5240 5241<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> </br> 5242 5243**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 5244 5245**系统能力:** SystemCapability.Window.SessionManager 5246 5247**参数:** 5248 5249| 参数名 | 类型 | 必填 | 说明 | 5250| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 5251| type | string | 是 | 监听事件,固定为'windowWillClose',即窗口关闭事件。 | 5252| callback | Callback<void, Promise<boolean>> | 是 | 回调函数。当点击窗口系统提供的右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有Promise<boolean>类型的返回值。在返回的Promise函数里,执行resolve(true) 方法表示不关闭当前窗口,执行resolve(false) 方法或者reject方法均表示关闭当前窗口。| 5253 5254**错误码:** 5255 5256以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5257 5258| 错误码ID | 错误信息 | 5259| ------- | -------------------------------------------- | 5260| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 5261| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5262| 1300002 | This window state is abnormal. | 5263| 1300004 | Unauthorized operation. | 5264 5265**示例:** 5266 5267```ts 5268// EntryAbility.ets 5269import { UIAbility } from '@kit.AbilityKit'; 5270import { window } from '@kit.ArkUI'; 5271 5272export default class EntryAbility extends UIAbility { 5273 5274 onWindowStageCreate(windowStage: window.WindowStage) { 5275 console.info('onWindowStageCreate'); 5276 const callback = () => { 5277 // ... 5278 return new Promise<boolean>((resolve, reject) => { 5279 // 是否关闭该窗口 5280 let result: boolean = true; 5281 resolve(result); 5282 }); 5283 } 5284 try { 5285 let windowClass = windowStage.getMainWindowSync(); 5286 windowClass.on('windowWillClose', callback); 5287 } catch (exception) { 5288 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 5289 } 5290 } 5291} 5292``` 5293 5294### off('windowWillClose')<sup>15+</sup> 5295 5296off(type: 'windowWillClose', callback?: Callback<void, Promise<boolean>>): void 5297 5298关闭主窗口或子窗口关闭事件的监听。 5299 5300<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> </br> 5301 5302**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 5303 5304**系统能力:** SystemCapability.Window.SessionManager 5305 5306**参数:** 5307 5308| 参数名 | 类型 | 必填 | 说明 | 5309| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 5310| type | string | 是 | 监听事件,固定为'windowWillClose',即窗口关闭事件。 | 5311| callback | Callback<void, Promise<boolean>> | 否 | 回调函数。当点击窗口系统提供的右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有Promise<boolean>类型的返回值。在返回的Promise函数里,执行resolve(true) 方法表示不关闭当前窗口,执行resolve(false) 方法或者reject方法均表示关闭当前窗口。| 5312 5313**错误码:** 5314 5315以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5316 5317| 错误码ID | 错误信息 | 5318| ------- | -------------------------------------------- | 5319| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 5320| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5321| 1300002 | This window state is abnormal. | 5322| 1300004 | Unauthorized operation. | 5323 5324**示例:** 5325 5326```ts 5327// EntryAbility.ets 5328import { UIAbility } from '@kit.AbilityKit'; 5329import { window } from '@kit.ArkUI'; 5330 5331export default class EntryAbility extends UIAbility { 5332 5333 onWindowStageCreate(windowStage: window.WindowStage) { 5334 console.info('onWindowStageCreate'); 5335 try { 5336 const callback = () => { 5337 // ... 5338 return new Promise<boolean>((resolve, reject) => { 5339 // 是否关闭该窗口 5340 let result: boolean = true; 5341 resolve(result); 5342 }); 5343 } 5344 let windowClass = windowStage.getMainWindowSync(); 5345 windowClass.on('windowWillClose', callback); 5346 windowClass.off('windowWillClose', callback); 5347 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 5348 windowClass.off('windowWillClose'); 5349 } catch (exception) { 5350 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 5351 } 5352 } 5353} 5354``` 5355 5356### on('windowHighlightChange')<sup>15+</sup> 5357 5358on(type: 'windowHighlightChange', callback: Callback<boolean>): void 5359 5360开启窗口激活态变化事件的监听。 5361 5362**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 5363 5364**系统能力:** SystemCapability.Window.SessionManager 5365 5366**参数:** 5367 5368| 参数名 | 类型 | 必填 | 说明 | 5369| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 5370| type | string | 是 | 监听事件,固定为'windowHighlightChange',即窗口激活态变化事件。 | 5371| callback | Callback<boolean> | 是 | 回调函数。当本窗口的激活态发生变化时的回调。回调函数返回boolean类型参数。当返回参数为true表示激活态;false表示非激活态。 | 5372 5373**错误码:** 5374 5375以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5376 5377| 错误码ID | 错误信息 | 5378| ------- | -------------------------------------------- | 5379| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5380| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5381| 1300002 | This window state is abnormal. | 5382| 1300003 | This window manager service works abnormally. | 5383 5384**示例:** 5385 5386```ts 5387try { 5388 windowClass.on('windowHighlightChange', (data: boolean) => { 5389 console.info(`Window highlight Change: ${data}`); 5390 }); 5391} catch (exception) { 5392 console.error(`Failed to register callback. Cause code: ${exception.code}, message: ${exception.message}`); 5393} 5394``` 5395 5396### off('windowHighlightChange')<sup>15+</sup> 5397 5398off(type: 'windowHighlightChange', callback?: Callback<boolean>): void 5399 5400关闭窗口激活态变化事件的监听。 5401 5402**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 5403 5404**系统能力:** SystemCapability.Window.SessionManager 5405 5406**参数:** 5407 5408| 参数名 | 类型 | 必填 | 说明 | 5409| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | 5410| type | string | 是 | 监听事件,固定为'windowHighlightChange',即窗口激活态变化事件。 | 5411| callback | Callback<boolean> | 否 | 回调函数。当本窗口的激活态发生变化时的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有窗口激活态变化的监听。 | 5412 5413**错误码:** 5414 5415以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5416 5417| 错误码ID | 错误信息 | 5418| ------- | -------------------------------------------- | 5419| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5420| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 5421| 1300002 | This window state is abnormal. | 5422| 1300003 | This window manager service works abnormally. | 5423 5424**示例:** 5425 5426```ts 5427const callback = (data: boolean) => { 5428 // ... 5429} 5430try { 5431 // 通过on接口开启监听 5432 windowClass.on('windowHighlightChange', callback); 5433 // 关闭指定callback的监听 5434 windowClass.off('windowHighlightChange', callback); 5435 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 5436 windowClass.off('windowHighlightChange'); 5437} catch (exception) { 5438 console.error(`Failed to unregister callback. Cause code: ${exception.code}, message: ${exception.message}`); 5439} 5440``` 5441 5442### isWindowSupportWideGamut<sup>9+</sup> 5443 5444isWindowSupportWideGamut(callback: AsyncCallback<boolean>): void 5445 5446判断当前窗口是否支持广色域模式,使用callback异步回调。 5447 5448**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5449 5450**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5451 5452**参数:** 5453 5454| 参数名 | 类型 | 必填 | 说明 | 5455| -------- | ---------------------------- | -- | -------------------------------------------------------------------------------- | 5456| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 5457 5458**错误码:** 5459 5460以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 5461 5462| 错误码ID | 错误信息 | 5463| ------- | ------------------------------ | 5464| 1300002 | This window state is abnormal. | 5465 5466**示例:** 5467 5468```ts 5469import { BusinessError } from '@kit.BasicServicesKit'; 5470 5471windowClass.isWindowSupportWideGamut((err: BusinessError, data) => { 5472 const errCode: number = err.code; 5473 if (errCode) { 5474 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 5475 return; 5476 } 5477 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 5478}); 5479``` 5480 5481### isWindowSupportWideGamut<sup>9+</sup> 5482 5483isWindowSupportWideGamut(): Promise<boolean> 5484 5485判断当前窗口是否支持广色域模式,使用Promise异步回调。 5486 5487**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5488 5489**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5490 5491**返回值:** 5492 5493| 类型 | 说明 | 5494| ---------------------- | ------------------------------------------------------------------------------------ | 5495| Promise<boolean> | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 5496 5497**错误码:** 5498 5499以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 5500 5501| 错误码ID | 错误信息 | 5502| ------- | ------------------------------ | 5503| 1300002 | This window state is abnormal. | 5504 5505**示例:** 5506 5507```ts 5508import { BusinessError } from '@kit.BasicServicesKit'; 5509 5510let promise = windowClass.isWindowSupportWideGamut(); 5511promise.then((data) => { 5512 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 5513}).catch((err: BusinessError) => { 5514 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 5515}); 5516``` 5517 5518### setWindowColorSpace<sup>9+</sup> 5519 5520setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 5521 5522设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。 5523 5524**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5525 5526**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5527 5528**参数:** 5529 5530| 参数名 | 类型 | 必填 | 说明 | 5531| ---------- | ------------------------- | -- | ----------- | 5532| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 5533| callback | AsyncCallback<void> | 是 | 回调函数。 | 5534 5535**错误码:** 5536 5537以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5538 5539| 错误码ID | 错误信息 | 5540| ------- | ------------------------------ | 5541| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5542| 1300002 | This window state is abnormal. | 5543 5544**示例:** 5545 5546```ts 5547import { BusinessError } from '@kit.BasicServicesKit'; 5548 5549try { 5550 windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 5551 const errCode: number = err.code; 5552 if (errCode) { 5553 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 5554 return; 5555 } 5556 console.info('Succeeded in setting window colorspace.'); 5557 }); 5558} catch (exception) { 5559 console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`); 5560} 5561``` 5562 5563### setWindowColorSpace<sup>9+</sup> 5564 5565setWindowColorSpace(colorSpace:ColorSpace): Promise<void> 5566 5567设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。 5568 5569**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5570 5571**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5572 5573**参数:** 5574 5575| 参数名 | 类型 | 必填 | 说明 | 5576| ---------- | ------------------------- | -- | ------------- | 5577| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 5578 5579**返回值:** 5580 5581| 类型 | 说明 | 5582| ------------------- | ------------------------ | 5583| Promise<void> | 无返回结果的Promise对象。 | 5584 5585**错误码:** 5586 5587以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5588 5589| 错误码ID | 错误信息 | 5590| ------- | ------------------------------ | 5591| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5592| 1300002 | This window state is abnormal. | 5593 5594**示例:** 5595 5596```ts 5597import { BusinessError } from '@kit.BasicServicesKit'; 5598 5599try { 5600 let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT); 5601 promise.then(() => { 5602 console.info('Succeeded in setting window colorspace.'); 5603 }).catch((err: BusinessError) => { 5604 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 5605 }); 5606} catch (exception) { 5607 console.error(`Failed to set window colorspace. Cause code: ${exception.code}, message: ${exception.message}`); 5608} 5609``` 5610 5611### getWindowColorSpace<sup>9+</sup> 5612 5613getWindowColorSpace(): ColorSpace 5614 5615获取当前窗口色域模式。 5616 5617**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5618 5619**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5620 5621**返回值:** 5622 5623| 类型 | 说明 | 5624| ------------------------- | ------------- | 5625| [ColorSpace](#colorspace8) | 当前色域模式。 | 5626 5627**错误码:** 5628 5629以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 5630 5631| 错误码ID | 错误信息 | 5632| ------- | ------------------------------ | 5633| 1300002 | This window state is abnormal. | 5634 5635**示例:** 5636 5637```ts 5638let colorSpace = windowClass.getWindowColorSpace(); 5639``` 5640 5641### setWindowBackgroundColor<sup>9+</sup> 5642 5643setWindowBackgroundColor(color: string | ColorMetrics): void 5644 5645设置窗口的背景色。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 5646 5647**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5648 5649**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5650 5651**参数:** 5652 5653| 参数名 | 类型 | 必填 | 说明 | 5654| ----- | ------ | -- | ----------------------------------------------------------------------- | 5655| color | string \| [ColorMetrics](js-apis-arkui-graphics.md#colormetrics12)<sup>18+</sup> | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。<br>从API version 18开始,此参数支持ColorMetrics类型。| 5656 5657**错误码:** 5658 5659以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5660 5661| 错误码ID | 错误信息 | 5662| ------- | ------------------------------ | 5663| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5664| 1300002 | This window state is abnormal. | 5665 5666**示例:** 5667 5668```ts 5669import { BusinessError } from '@kit.BasicServicesKit'; 5670import { ColorMetrics } from '@kit.ArkUI'; 5671 5672let storage: LocalStorage = new LocalStorage(); 5673storage.setOrCreate('storageSimpleProp', 121); 5674windowClass.loadContent("pages/page2", storage, (err: BusinessError) => { 5675 let errCode: number = err.code; 5676 if (errCode) { 5677 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 5678 return; 5679 } 5680 console.info('Succeeded in loading the content.'); 5681 let color1: string = '#00ff33'; 5682 let color2: ColorMetrics = ColorMetrics.numeric(0xff112233); 5683 try { 5684 windowClass?.setWindowBackgroundColor(color1); 5685 windowClass?.setWindowBackgroundColor(color2); 5686 } catch (exception) { 5687 console.error(`Failed to set the background color. Cause code: ${exception.code}, message: ${exception.message}`); 5688 }; 5689}); 5690``` 5691 5692### setWindowBrightness<sup>9+</sup> 5693 5694setWindowBrightness(brightness: number, callback: AsyncCallback<void>): void 5695 5696允许应用主窗口设置屏幕亮度值,使用callback异步回调。 5697 5698非2in1设备,窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度; 56992in1设备,窗口设置屏幕亮度和控制中心调整屏幕亮度的优先级相同,窗口设置屏幕亮度生效后,控制中心也可以调整系统屏幕亮度。 5700 5701**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5702 5703**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5704 5705**参数:** 5706 5707| 参数名 | 类型 | 必填 | 说明 | 5708| ---------- | ------------------------- | -- |-------------------------------------------| 5709| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 5710| callback | AsyncCallback<void> | 是 | 回调函数。 | 5711 5712**错误码:** 5713 5714以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5715 5716| 错误码ID | 错误信息 | 5717| ------- | -------------------------------------------- | 5718| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5719| 1300002 | This window state is abnormal. | 5720| 1300003 | This window manager service works abnormally. | 5721 5722**示例:** 5723 5724```ts 5725// EntryAbility.ets 5726import { UIAbility } from '@kit.AbilityKit'; 5727import { BusinessError } from '@kit.BasicServicesKit'; 5728 5729export default class EntryAbility extends UIAbility { 5730 // ... 5731 onWindowStageCreate(windowStage: window.WindowStage): void { 5732 console.info('onWindowStageCreate'); 5733 let windowClass: window.Window | undefined = undefined; 5734 windowStage.getMainWindow((err: BusinessError, data) => { 5735 const errCode: number = err.code; 5736 if (errCode) { 5737 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 5738 return; 5739 } 5740 windowClass = data; 5741 let brightness: number = 1; 5742 try { 5743 windowClass.setWindowBrightness(brightness, (err: BusinessError) => { 5744 const errCode: number = err.code; 5745 if (errCode) { 5746 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 5747 return; 5748 } 5749 console.info('Succeeded in setting the brightness.'); 5750 }); 5751 } catch (exception) { 5752 console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`); 5753 } 5754 }); 5755 } 5756} 5757``` 5758 5759### setWindowBrightness<sup>9+</sup> 5760 5761setWindowBrightness(brightness: number): Promise<void> 5762 5763允许应用主窗口设置屏幕亮度值,使用Promise异步回调。 5764 5765非2in1设备,窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度; 57662in1设备,窗口设置屏幕亮度和控制中心调整屏幕亮度的优先级相同,窗口设置屏幕亮度生效后,控制中心也可以调整系统屏幕亮度。 5767 5768**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5769 5770**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5771 5772**参数:** 5773 5774| 参数名 | 类型 | 必填 | 说明 | 5775| ---------- | ------ | -- |----------------------------------------| 5776| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 5777 5778**返回值:** 5779 5780| 类型 | 说明 | 5781| ------------------- | ------------------------ | 5782| Promise<void> | 无返回结果的Promise对象。 | 5783 5784**错误码:** 5785 5786以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5787 5788| 错误码ID | 错误信息 | 5789| ------- | -------------------------------------------- | 5790| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5791| 1300002 | This window state is abnormal. | 5792| 1300003 | This window manager service works abnormally. | 5793 5794**示例:** 5795 5796```ts 5797// EntryAbility.ets 5798import { UIAbility } from '@kit.AbilityKit'; 5799import { BusinessError } from '@kit.BasicServicesKit'; 5800 5801export default class EntryAbility extends UIAbility { 5802 // ... 5803 onWindowStageCreate(windowStage: window.WindowStage): void { 5804 console.info('onWindowStageCreate'); 5805 let windowClass: window.Window | undefined = undefined; 5806 windowStage.getMainWindow((err: BusinessError, data) => { 5807 const errCode: number = err.code; 5808 if (errCode) { 5809 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 5810 return; 5811 } 5812 windowClass = data; 5813 let brightness: number = 1; 5814 try { 5815 let promise = windowClass.setWindowBrightness(brightness); 5816 promise.then(() => { 5817 console.info('Succeeded in setting the brightness.'); 5818 }).catch((err: BusinessError) => { 5819 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 5820 }); 5821 } catch (exception) { 5822 console.error(`Failed to set the brightness. Cause code: ${exception.code}, message: ${exception.message}`); 5823 } 5824 }); 5825 } 5826} 5827``` 5828 5829### setWindowFocusable<sup>9+</sup> 5830 5831setWindowFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 5832 5833设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用callback异步回调。 5834 5835**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5836 5837**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5838 5839**参数:** 5840 5841| 参数名 | 类型 | 必填 | 说明 | 5842| ----------- | ------------------------- | -- | ------------------------------------------------------- | 5843| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 5844| callback | AsyncCallback<void> | 是 | 回调函数。 | 5845 5846**错误码:** 5847 5848以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5849 5850| 错误码ID | 错误信息 | 5851| ------- | -------------------------------------------- | 5852| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5853| 1300002 | This window state is abnormal. | 5854| 1300003 | This window manager service works abnormally. | 5855 5856**示例:** 5857 5858```ts 5859import { BusinessError } from '@kit.BasicServicesKit'; 5860 5861let isFocusable: boolean = true; 5862try { 5863 windowClass.setWindowFocusable(isFocusable, (err: BusinessError) => { 5864 const errCode: number = err.code; 5865 if (errCode) { 5866 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 5867 return; 5868 } 5869 console.info('Succeeded in setting the window to be focusable.'); 5870 }); 5871} catch (exception) { 5872 console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`); 5873} 5874``` 5875 5876### setWindowFocusable<sup>9+</sup> 5877 5878setWindowFocusable(isFocusable: boolean): Promise<void> 5879 5880设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用Promise异步回调。 5881 5882**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5883 5884**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5885 5886**参数:** 5887 5888| 参数名 | 类型 | 必填 | 说明 | 5889| ----------- | ------- | -- | -------------------------------------------------------- | 5890| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 5891 5892**返回值:** 5893 5894| 类型 | 说明 | 5895| ------------------- | ------------------------ | 5896| Promise<void> | 无返回结果的Promise对象。 | 5897 5898**错误码:** 5899 5900以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5901 5902| 错误码ID | 错误信息 | 5903| ------- | -------------------------------------------- | 5904| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5905| 1300002 | This window state is abnormal. | 5906| 1300003 | This window manager service works abnormally. | 5907 5908**示例:** 5909 5910```ts 5911import { BusinessError } from '@kit.BasicServicesKit'; 5912 5913let isFocusable: boolean = true; 5914try { 5915 let promise = windowClass.setWindowFocusable(isFocusable); 5916 promise.then(() => { 5917 console.info('Succeeded in setting the window to be focusable.'); 5918 }).catch((err: BusinessError) => { 5919 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 5920 }); 5921} catch (exception) { 5922 console.error(`Failed to set the window to be focusable. Cause code: ${exception.code}, message: ${exception.message}`); 5923} 5924``` 5925 5926### setWindowKeepScreenOn<sup>9+</sup> 5927 5928setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 5929 5930设置屏幕是否为常亮状态,使用callback异步回调。 5931 5932规范使用该接口:仅在必要场景(导航、视频播放、绘画、游戏等场景)下,设置该属性为true;退出上述场景后,应当重置该属性为false;其他场景(无屏幕互动、音频播放等)下,不使用该接口;系统检测到非规范使用该接口时,可能会恢复自动灭屏功能。 5933 5934**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5935 5936**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5937 5938**参数:** 5939 5940| 参数名 | 类型 | 必填 | 说明 | 5941| -------------- | ------------------------- | -- | ---------------------------------------------------- | 5942| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 5943| callback | AsyncCallback<void> | 是 | 回调函数。 | 5944 5945**错误码:** 5946 5947以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 5948 5949| 错误码ID | 错误信息 | 5950| ------- | -------------------------------------------- | 5951| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5952| 1300002 | This window state is abnormal. | 5953| 1300003 | This window manager service works abnormally. | 5954 5955**示例:** 5956 5957```ts 5958import { BusinessError } from '@kit.BasicServicesKit'; 5959 5960let isKeepScreenOn: boolean = true; 5961try { 5962 windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 5963 const errCode: number = err.code; 5964 if (errCode) { 5965 console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 5966 return; 5967 } 5968 console.info('Succeeded in setting the screen to be always on.'); 5969 }); 5970} catch (exception) { 5971 console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`); 5972} 5973``` 5974 5975### setWindowKeepScreenOn<sup>9+</sup> 5976 5977setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 5978 5979设置屏幕是否为常亮状态,使用Promise异步回调。 5980 5981规范使用该接口:仅在必要场景(导航、视频播放、绘画、游戏等场景)下,设置该属性为true;退出上述场景后,应当重置该属性为false;其他场景(无屏幕互动、音频播放等)下,不使用该接口;系统检测到非规范使用该接口时,可能会恢复自动灭屏功能。 5982 5983**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5984 5985**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 5986 5987**参数:** 5988 5989| 参数名 | 类型 | 必填 | 说明 | 5990| -------------- | ------- | -- | --------------------------------------------------- | 5991| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 5992 5993**返回值:** 5994 5995| 类型 | 说明 | 5996| ------------------- | ------------------------ | 5997| Promise<void> | 无返回结果的Promise对象。 | 5998 5999**错误码:** 6000 6001以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6002 6003| 错误码ID | 错误信息 | 6004| ------- | -------------------------------------------- | 6005| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6006| 1300002 | This window state is abnormal. | 6007| 1300003 | This window manager service works abnormally. | 6008 6009**示例:** 6010 6011```ts 6012import { BusinessError } from '@kit.BasicServicesKit'; 6013 6014let isKeepScreenOn: boolean = true; 6015try { 6016 let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn); 6017 promise.then(() => { 6018 console.info('Succeeded in setting the screen to be always on.'); 6019 }).catch((err: BusinessError) => { 6020 console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 6021 }); 6022} catch (exception) { 6023 console.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`); 6024} 6025``` 6026 6027### setWindowPrivacyMode<sup>9+</sup> 6028 6029setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 6030 6031设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 6032 6033**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6034 6035**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6036 6037**需要权限:** ohos.permission.PRIVACY_WINDOW 6038 6039**参数:** 6040 6041| 参数名 | 类型 | 必填 | 说明 | 6042| ------------- | ------------------------- | -- | ------------------------------------------------------ | 6043| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 6044| callback | AsyncCallback<void> | 是 | 回调函数。 | 6045 6046**错误码:** 6047 6048以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6049 6050| 错误码ID | 错误信息 | 6051| ------- | ------------------------------ | 6052| 201 | Permission verification failed. The application does not have the permission required to call the API. | 6053| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6054| 1300002 | This window state is abnormal. | 6055 6056**示例:** 6057 6058```ts 6059import { BusinessError } from '@kit.BasicServicesKit'; 6060 6061let isPrivacyMode: boolean = true; 6062try { 6063 windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => { 6064 const errCode: number = err.code; 6065 if (errCode) { 6066 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 6067 return; 6068 } 6069 console.info('Succeeded in setting the window to privacy mode.'); 6070 }); 6071} catch (exception) { 6072 console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`); 6073} 6074``` 6075 6076### setWindowPrivacyMode<sup>9+</sup> 6077 6078setWindowPrivacyMode(isPrivacyMode: boolean): Promise<void> 6079 6080设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 6081 6082**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6083 6084**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6085 6086**需要权限:** ohos.permission.PRIVACY_WINDOW 6087 6088**参数:** 6089 6090| 参数名 | 类型 | 必填 | 说明 | 6091| ------------- | ------- | -- | ----------------------------------------------------- | 6092| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 6093 6094**返回值:** 6095 6096| 类型 | 说明 | 6097| ------------------- | ------------------------ | 6098| Promise<void> | 无返回结果的Promise对象。 | 6099 6100**错误码:** 6101 6102以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6103 6104| 错误码ID | 错误信息 | 6105| ------- | ------------------------------ | 6106| 201 | Permission verification failed. The application does not have the permission required to call the API. | 6107| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6108| 1300002 | This window state is abnormal. | 6109 6110**示例:** 6111 6112```ts 6113import { BusinessError } from '@kit.BasicServicesKit'; 6114 6115let isPrivacyMode: boolean = true; 6116try { 6117 let promise = windowClass.setWindowPrivacyMode(isPrivacyMode); 6118 promise.then(() => { 6119 console.info('Succeeded in setting the window to privacy mode.'); 6120 }).catch((err: BusinessError) => { 6121 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 6122 }); 6123} catch (exception) { 6124 console.error(`Failed to set the window to privacy mode. Cause code: ${exception.code}, message: ${exception.message}`); 6125} 6126``` 6127 6128### setWindowTouchable<sup>9+</sup> 6129 6130setWindowTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 6131 6132设置窗口是否为可触状态,使用callback异步回调。 6133 6134**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6135 6136**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6137 6138**参数:** 6139 6140| 参数名 | 类型 | 必填 | 说明 | 6141| ----------- | ------------------------- | -- | ----------------------------------------------- | 6142| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 6143| callback | AsyncCallback<void> | 是 | 回调函数。 | 6144 6145**错误码:** 6146 6147以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6148 6149| 错误码ID | 错误信息 | 6150| ------- | -------------------------------------------- | 6151| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6152| 1300002 | This window state is abnormal. | 6153| 1300003 | This window manager service works abnormally. | 6154 6155**示例:** 6156 6157```ts 6158import { BusinessError } from '@kit.BasicServicesKit'; 6159 6160let isTouchable = true; 6161try { 6162 windowClass.setWindowTouchable(isTouchable, (err: BusinessError) => { 6163 const errCode: number = err.code; 6164 if (errCode) { 6165 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 6166 return; 6167 } 6168 console.info('Succeeded in setting the window to be touchable.'); 6169 }); 6170} catch (exception) { 6171 console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 6172} 6173``` 6174 6175### setWindowTouchable<sup>9+</sup> 6176 6177setWindowTouchable(isTouchable: boolean): Promise<void> 6178 6179设置窗口是否为可触状态,使用Promise异步回调。 6180 6181**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6182 6183**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6184 6185**参数:** 6186 6187| 参数名 | 类型 | 必填 | 说明 | 6188| ----------- | ------- | -- | ----------------------------------------------- | 6189| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 6190 6191**返回值:** 6192 6193| 类型 | 说明 | 6194| ------------------- | ------------------------- | 6195| Promise<void> | 无返回结果的Promise对象。 | 6196 6197**错误码:** 6198 6199以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6200 6201| 错误码ID | 错误信息 | 6202| ------- | -------------------------------------------- | 6203| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6204| 1300002 | This window state is abnormal. | 6205| 1300003 | This window manager service works abnormally. | 6206 6207**示例:** 6208 6209```ts 6210import { BusinessError } from '@kit.BasicServicesKit'; 6211 6212let isTouchable: boolean = true; 6213try { 6214 let promise = windowClass.setWindowTouchable(isTouchable); 6215 promise.then(() => { 6216 console.info('Succeeded in setting the window to be touchable.'); 6217 }).catch((err: BusinessError) => { 6218 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 6219 }); 6220} catch (exception) { 6221 console.error(`Failed to set the window to be touchable. Cause code: ${exception.code}, message: ${exception.message}`); 6222} 6223``` 6224 6225### snapshot<sup>9+</sup> 6226 6227snapshot(callback: AsyncCallback<image.PixelMap>): void 6228 6229获取窗口截图,使用callback异步回调。 6230 6231**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6232 6233**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6234 6235**参数:** 6236 6237| 参数名 | 类型 | 必填 | 说明 | 6238| ----------- | ------------------------- | ---- | -------------------- | 6239| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | 是 | 回调函数。 | 6240 6241**错误码:** 6242 6243以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 6244 6245| 错误码ID | 错误信息 | 6246| ------- | ------------------------------ | 6247| 1300002 | This window state is abnormal. | 6248 6249**示例:** 6250 6251```ts 6252import { BusinessError } from '@kit.BasicServicesKit'; 6253import { image } from '@kit.ImageKit'; 6254 6255windowClass.snapshot((err: BusinessError, pixelMap: image.PixelMap) => { 6256 const errCode: number = err.code; 6257 if (errCode) { 6258 console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`); 6259 return; 6260 } 6261 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 6262 pixelMap.release(); // PixelMap使用完后及时释放内存 6263}); 6264``` 6265 6266### snapshot<sup>9+</sup> 6267 6268snapshot(): Promise<image.PixelMap> 6269 6270获取当前窗口截图。若当前窗口设置为隐私模式(可通过[setWindowPrivacyMode](#setwindowprivacymode9)接口设置),截图结果为白屏。 6271 6272**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6273 6274**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6275 6276**返回值:** 6277 6278| 类型 | 说明 | 6279| ------------------- | ------------------------- | 6280| Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise对象。返回当前窗口截图。 | 6281 6282**错误码:** 6283 6284以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 6285 6286| 错误码ID | 错误信息 | 6287| ------- | ------------------------------ | 6288| 1300002 | This window state is abnormal. | 6289 6290**示例:** 6291 6292```ts 6293import { BusinessError } from '@kit.BasicServicesKit'; 6294import { image } from '@kit.ImageKit'; 6295 6296let promise = windowClass.snapshot(); 6297promise.then((pixelMap: image.PixelMap) => { 6298 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 6299 pixelMap.release(); // PixelMap使用完后及时释放内存 6300}).catch((err: BusinessError) => { 6301 console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`); 6302}); 6303``` 6304 6305### snapshotIgnorePrivacy<sup>18+</sup> 6306 6307snapshotIgnorePrivacy(): Promise<image.PixelMap> 6308 6309获取当前窗口截图。即使当前窗口设置为隐私模式(可通过[setWindowPrivacyMode](#setwindowprivacymode9)接口设置),仍可调用本接口返回当前窗口截图。 6310 6311**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 6312 6313**系统能力:** SystemCapability.Window.SessionManager 6314 6315**返回值:** 6316 6317| 类型 | 说明 | 6318| ------------------- | ------------------------- | 6319| Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise对象。返回当前窗口截图。 | 6320 6321**错误码:** 6322 6323以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6324 6325| 错误码ID | 错误信息 | 6326| ------- | ------------------------------ | 6327| 801 | Capability not supported. Function snapshotIgnorePrivacy can not work correctly due to limited device capabilities. | 6328| 1300002 | This window state is abnormal. | 6329 6330**示例:** 6331 6332```ts 6333import { BusinessError } from '@kit.BasicServicesKit'; 6334import { image } from '@kit.ImageKit'; 6335 6336let promise = windowClass.snapshotIgnorePrivacy(); 6337promise.then((pixelMap: image.PixelMap) => { 6338 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 6339 pixelMap.release(); // PixelMap使用完后及时释放内存 6340}).catch((err: BusinessError) => { 6341 console.error(`Failed to snapshot window. Cause code: ${err.code}, message: ${err.message}`); 6342}); 6343``` 6344 6345### setAspectRatio<sup>10+</sup> 6346 6347setAspectRatio(ratio: number): Promise<void> 6348 6349设置窗口内容布局的比例,使用Promise异步回调。 6350 6351通过其他接口如[resize](#resize9)、[resizeAsync](#resizeasync12)设置窗口大小时,不受ratio约束。 6352 6353仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。 6354 6355**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6356 6357**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6358 6359**参数:** 6360 6361| 参数名 | 类型 | 必填 | 说明 | 6362| ------------------ | ------- | ---- |-------------------------------------------| 6363| ratio | number | 是 | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,受窗口最大最小尺寸限制,比例值下限为最小宽度/最大高度,上限为最大宽度/最小高度。窗口最大最小尺寸由[WindowLimits](#windowlimits11)和系统限制的交集决定,系统限制优先级高于[WindowLimits](#windowlimits11)。ratio的有效范围会随[WindowLimits](#windowlimits11)变化而变化。如果先设置了[WindowLimits](#windowlimits11),后设置的ratio与其冲突,会返回错误码;如果先设置了ratio,后设置的[WindowLimits](#windowlimits11)与其冲突,窗口的宽高比可能会不跟随设置的宽高比(ratio)。 | 6364 6365**返回值:** 6366 6367| 类型 | 说明 | 6368| ------------------- | ------------------------- | 6369| Promise<void> | 无返回结果的Promise对象。 | 6370 6371**错误码:** 6372 6373以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6374 6375| 错误码ID | 错误信息 | 6376| ------- | -------------------------------------------- | 6377| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6378| 1300002 | This window state is abnormal. | 6379| 1300004 | Unauthorized operation. | 6380 6381**示例:** 6382<!--code_no_check--> 6383```ts 6384// EntryAbility.ets 6385import { UIAbility } from '@kit.AbilityKit'; 6386import { BusinessError } from '@kit.BasicServicesKit'; 6387 6388export default class EntryAbility extends UIAbility { 6389 6390 // ... 6391 onWindowStageCreate(windowStage: window.WindowStage) { 6392 console.info('onWindowStageCreate'); 6393 let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 6394 if (!windowClass) { 6395 console.info('windowClass is null'); 6396 } 6397 try { 6398 let ratio = 1.0; 6399 let promise = windowClass.setAspectRatio(ratio); 6400 promise.then(() => { 6401 console.info('Succeeded in setting aspect ratio of window.'); 6402 }).catch((err: BusinessError) => { 6403 console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 6404 }); 6405 } catch (exception) { 6406 console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 6407 } 6408 } 6409} 6410``` 6411 6412### setAspectRatio<sup>10+</sup> 6413 6414setAspectRatio(ratio: number, callback: AsyncCallback<void>): void 6415 6416设置窗口内容布局的比例,使用callback异步回调。 6417 6418通过其他接口如[resize](#resize9)、[resizeAsync](#resizeasync12)设置窗口大小时,不受ratio约束。 6419 6420仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。 6421 6422**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6423 6424**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6425 6426**参数:** 6427 6428| 参数名 | 类型 | 必填 | 说明 | 6429| ------------------ | ------- | ---- |--------------------------------------------| 6430| ratio | number | 是 | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,受窗口最大最小尺寸限制,比例值下限为最小宽度/最大高度,上限为最大宽度/最小高度。窗口最大最小尺寸由[WindowLimits](#windowlimits11)和系统限制的交集决定,系统限制优先级高于[WindowLimits](#windowlimits11)。ratio的有效范围会随[WindowLimits](#windowlimits11)变化而变化。如果先设置了[WindowLimits](#windowlimits11),后设置的ratio与其冲突,会返回错误码;如果先设置了ratio,后设置的[WindowLimits](#windowlimits11)与其冲突,窗口的宽高比可能会不跟随设置的宽高比(ratio)。 | 6431| callback | AsyncCallback<void> | 是 | 回调函数。 | 6432 6433**错误码:** 6434 6435以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6436 6437| 错误码ID | 错误信息 | 6438| ------- | -------------------------------------------- | 6439| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6440| 1300002 | This window state is abnormal. | 6441| 1300004 | Unauthorized operation. | 6442 6443**示例:** 6444<!--code_no_check--> 6445```ts 6446// EntryAbility.ets 6447import { UIAbility } from '@kit.AbilityKit'; 6448import { BusinessError } from '@kit.BasicServicesKit'; 6449 6450export default class EntryAbility extends UIAbility { 6451 6452 // ... 6453 onWindowStageCreate(windowStage: window.WindowStage) { 6454 console.info('onWindowStageCreate'); 6455 let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 6456 if (!windowClass) { 6457 console.info('Failed to load the content. Cause: windowClass is null'); 6458 } 6459 try { 6460 let ratio = 1.0; 6461 windowClass.setAspectRatio(ratio, (err: BusinessError) => { 6462 const errCode: number = err.code; 6463 if (errCode) { 6464 console.error(`Failed to set the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 6465 return; 6466 } 6467 console.info('Succeeded in setting the aspect ratio of window.'); 6468 }); 6469 } catch (exception) { 6470 console.error(`Failed to set the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 6471 } 6472 } 6473} 6474 6475``` 6476 6477### resetAspectRatio<sup>10+</sup> 6478 6479resetAspectRatio(): Promise<void> 6480 6481取消设置窗口内容布局的比例,使用Promise异步回调。 6482 6483仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,调用后将清除持久化储存的比例信息。 6484 6485**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6486 6487**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6488 6489**返回值:** 6490 6491| 类型 | 说明 | 6492| ------------------- | ------------------------- | 6493| Promise<void> | 无返回结果的Promise对象。 | 6494 6495**错误码:** 6496 6497以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 6498 6499| 错误码ID | 错误信息 | 6500| ------- | -------------------------------------------- | 6501| 1300002 | This window state is abnormal. | 6502| 1300004 | Unauthorized operation. | 6503 6504**示例:** 6505<!--code_no_check--> 6506```ts 6507// EntryAbility.ets 6508import { UIAbility } from '@kit.AbilityKit'; 6509import { BusinessError } from '@kit.BasicServicesKit'; 6510 6511export default class EntryAbility extends UIAbility { 6512 6513 // ... 6514 onWindowStageCreate(windowStage: window.WindowStage) { 6515 console.info('onWindowStageCreate'); 6516 let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 6517 if (!windowClass) { 6518 console.info('Failed to load the content. Cause: windowClass is null'); 6519 } 6520 try { 6521 let promise = windowClass.resetAspectRatio(); 6522 promise.then(() => { 6523 console.info('Succeeded in resetting aspect ratio of window.'); 6524 }).catch((err: BusinessError) => { 6525 console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 6526 }); 6527 } catch (exception) { 6528 console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 6529 } 6530 } 6531} 6532``` 6533 6534### resetAspectRatio<sup>10+</sup> 6535 6536resetAspectRatio(callback: AsyncCallback<void>): void 6537 6538取消设置窗口内容布局的比例,使用callback异步回调。 6539 6540仅主窗可设置,且仅在自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)下生效,调用后将清除持久化储存的比例信息。 6541 6542**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6543 6544**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6545 6546**参数:** 6547 6548| 参数名 | 类型 | 必填 | 说明 | 6549| ------------------ | ------- | ---- | ------------------------------------------------------------ | 6550| callback | AsyncCallback<void> | 是 | 回调函数。 | 6551 6552**错误码:** 6553 6554以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 6555 6556| 错误码ID | 错误信息 | 6557| ------- | -------------------------------------------- | 6558| 1300002 | This window state is abnormal. | 6559| 1300004 | Unauthorized operation. | 6560 6561**示例:** 6562<!--code_no_check--> 6563```ts 6564// EntryAbility.ets 6565import { UIAbility } from '@kit.AbilityKit'; 6566import { BusinessError } from '@kit.BasicServicesKit'; 6567 6568export default class EntryAbility extends UIAbility { 6569 6570 // ... 6571 onWindowStageCreate(windowStage: window.WindowStage) { 6572 console.info('onWindowStageCreate'); 6573 let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 6574 if (!windowClass) { 6575 console.info('Failed to load the content. Cause: windowClass is null'); 6576 } 6577 try { 6578 windowClass.resetAspectRatio((err: BusinessError) => { 6579 const errCode: number = err.code; 6580 if (errCode) { 6581 console.error(`Failed to reset the aspect ratio of window. Cause code: ${err.code}, message: ${err.message}`); 6582 return; 6583 } 6584 console.info('Succeeded in resetting aspect ratio of window.'); 6585 }); 6586 } catch (exception) { 6587 console.error(`Failed to reset the aspect ratio of window. Cause code: ${exception.code}, message: ${exception.message}`); 6588 } 6589 } 6590} 6591``` 6592 6593### minimize<sup>11+</sup> 6594 6595minimize(callback: AsyncCallback<void>): void 6596 6597此接口根据调用对象不同,实现不同的功能: 6598 6599- 当调用对象为主窗口时,实现最小化功能,可在Dock栏中还原,2in1 设备上可以使用[restore()](#restore14)进行还原。 6600 6601- 当调用对象为子窗口或悬浮窗时,实现隐藏功能,不可在Dock栏中还原,可以使用[showWindow()](#showwindow9)进行还原。 6602 6603使用callback异步回调。 6604 6605**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6606 6607**系统能力:** SystemCapability.Window.SessionManager 6608 6609**参数:** 6610 6611| 参数名 | 类型 | 必填 | 说明 | 6612| -------- | ------------------------- | ---- | ---------- | 6613| callback | AsyncCallback<void> | 是 | 回调函数。 | 6614 6615**错误码:** 6616 6617以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6618 6619| 错误码ID | 错误信息 | 6620| ------- | ------------------------------ | 6621| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6622| 1300002 | This window state is abnormal. | 6623| 1300003 | This window manager service works abnormally. | 6624 6625**示例:** 6626 6627```ts 6628import { BusinessError } from '@kit.BasicServicesKit'; 6629 6630windowClass.minimize((err: BusinessError) => { 6631 const errCode: number = err.code; 6632 if (errCode) { 6633 console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`); 6634 return; 6635 } 6636 console.info('Succeeded in minimizing the window.'); 6637}); 6638``` 6639 6640### minimize<sup>11+</sup> 6641 6642minimize(): Promise<void> 6643 6644此接口根据调用对象不同,实现不同的功能: 6645 6646- 当调用对象为主窗口时,实现最小化功能,可在Dock栏中还原,2in1 设备上可以使用[restore()](#restore14)进行还原。 6647 6648- 当调用对象为子窗口或悬浮窗时,实现隐藏功能,不可在Dock栏中还原,可以使用[showWindow()](#showwindow9)进行还原。 6649 6650使用Promise异步回调。 6651 6652**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6653 6654**系统能力:** SystemCapability.Window.SessionManager 6655 6656**返回值:** 6657 6658| 类型 | 说明 | 6659| ------------------- | ------------------------- | 6660| Promise<void> | 无返回结果的Promise对象。 | 6661 6662**错误码:** 6663 6664以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6665 6666| 错误码ID | 错误信息 | 6667| ------- | ------------------------------ | 6668| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6669| 1300002 | This window state is abnormal. | 6670| 1300003 | This window manager service works abnormally. | 6671 6672**示例:** 6673 6674```ts 6675import { BusinessError } from '@kit.BasicServicesKit'; 6676 6677let promise = windowClass.minimize(); 6678promise.then(() => { 6679 console.info('Succeeded in minimizing the window.'); 6680}).catch((err: BusinessError) => { 6681 console.error(`Failed to minimize the window. Cause code: ${err.code}, message: ${err.message}`); 6682}); 6683``` 6684 6685### maximize<sup>12+</sup> 6686maximize(presentation?: MaximizePresentation): Promise<void> 6687 6688主窗口调用,实现最大化功能,使用Promise异步回调。 6689 6690<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 6691 6692**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6693 6694**系统能力:** SystemCapability.Window.SessionManager 6695 6696**参数:** 6697 6698| 参数名 | 类型 | 必填 | 说明 | 6699| ----- | ---------------------------- | -- | --------------------------------- | 6700| presentation | [MaximizePresentation](#maximizepresentation12) | 否 | 主窗口最大化时候的布局枚举。默认值window.MaximizePresentation.ENTER_IMMERSIVE,即默认最大化时进入沉浸式布局。 | 6701 6702**返回值:** 6703 6704| 类型 | 说明 | 6705| ------------------- | ------------------------- | 6706| Promise<void> | 无返回结果的Promise对象。 | 6707 6708**错误码:** 6709 6710以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6711 6712| 错误码ID | 错误信息 | 6713| ------- | ------------------------------ | 6714| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6715| 1300002 | This window state is abnormal. | 6716| 1300003 | This window manager service works abnormally. | 6717| 1300004 | Unauthorized operation. | 6718| 1300005 | This window stage is abnormal. | 6719 6720**示例:** 6721 6722```ts 6723// EntryAbility.ets 6724import { UIAbility } from '@kit.AbilityKit'; 6725import { BusinessError } from '@kit.BasicServicesKit'; 6726export default class EntryAbility extends UIAbility { 6727 // ... 6728 6729 onWindowStageCreate(windowStage: window.WindowStage) { 6730 console.info('onWindowStageCreate'); 6731 let windowClass: window.Window | undefined = undefined; 6732 windowStage.getMainWindow((err: BusinessError, data) => { 6733 const errCode: number = err.code; 6734 if (errCode) { 6735 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 6736 return; 6737 } 6738 windowClass = data; 6739 let promise = windowClass.maximize(); 6740 // let promise = windowClass.maximize(window.MaximizePresentation.ENTER_IMMERSIVE); 6741 promise.then(() => { 6742 console.info('Succeeded in maximizing the window.'); 6743 }).catch((err: BusinessError) => { 6744 console.error(`Failed to maximize the window. Cause code: ${err.code}, message: ${err.message}`); 6745 }); 6746 }); 6747 } 6748}; 6749``` 6750 6751### setResizeByDragEnabled<sup>14+</sup> 6752setResizeByDragEnabled(enable: boolean, callback: AsyncCallback<void>): void 6753 6754禁止/使能通过拖拽方式缩放主窗口或启用装饰的子窗口的功能。使用callback异步回调。 6755 6756**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 6757 6758**系统能力:** SystemCapability.Window.SessionManager 6759 6760**参数:** 6761 6762| 参数名 | 类型 | 必填 | 说明 | 6763| ----- | ---------------------------- | -- | --------------------------------- | 6764| enable | boolean | 是 | 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。 | 6765| callback | AsyncCallback<void> | 是 | 回调函数。 | 6766 6767**错误码:** 6768 6769以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6770 6771| 错误码ID | 错误信息 | 6772| ------- | ------------------------------ | 6773| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6774| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6775| 1300002 | This window state is abnormal. | 6776| 1300003 | This window manager service works abnormally. | 6777 6778**示例:** 6779 6780```ts 6781import { BusinessError } from '@kit.BasicServicesKit'; 6782 6783let enabled = false; 6784windowClass.setResizeByDragEnabled(enabled, (err) => { 6785 if (err.code) { 6786 console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${err.code}, message: ${err.message}`); 6787 return; 6788 } 6789 console.info('Succeeded in setting the function of disabling the resize by drag window.'); 6790}); 6791``` 6792 6793### setResizeByDragEnabled<sup>14+</sup> 6794setResizeByDragEnabled(enable: boolean): Promise<void> 6795 6796禁止/使能通过拖拽方式缩放主窗口或启用装饰的子窗口的功能。使用Promise异步回调。 6797 6798**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 6799 6800**系统能力:** SystemCapability.Window.SessionManager 6801 6802**参数:** 6803 6804| 参数名 | 类型 | 必填 | 说明 | 6805| ----- | ---------------------------- | -- | --------------------------------- | 6806| enable | boolean | 是 | 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。 | 6807 6808**返回值:** 6809 6810| 类型 | 说明 | 6811| ------------------- | ------------------------ | 6812| Promise<void> | 无返回结果的Promise对象。 | 6813 6814**错误码:** 6815 6816以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6817 6818| 错误码ID | 错误信息 | 6819| ------- | ------------------------------ | 6820| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6821| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6822| 1300002 | This window state is abnormal. | 6823| 1300003 | This window manager service works abnormally. | 6824 6825**示例:** 6826 6827```ts 6828import { BusinessError } from '@kit.BasicServicesKit'; 6829 6830let enabled = false; 6831let promise = windowClass.setResizeByDragEnabled(enabled); 6832promise.then(() => { 6833 console.info('Succeeded in setting the function of disabling the resize by drag window.'); 6834}).catch((err: BusinessError) => { 6835 console.error(`Failed to set the function of disabling the resize by drag window. Cause code: ${err.code}, message: ${err.message}`); 6836}); 6837``` 6838 6839### recover<sup>11+</sup> 6840 6841recover(): Promise<void> 6842 6843将主窗口从全屏、最大化、分屏模式下还原为浮动窗口,并恢复到进入该模式之前的大小和位置,已经是浮动窗口模式不可再还原。使用Promise异步回调。此接口仅在多窗层叠布局效果下生效。 6844 6845<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 6846 6847**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6848 6849**系统能力:** SystemCapability.Window.SessionManager 6850 6851**返回值:** 6852 6853| 类型 | 说明 | 6854| ------------------- | ------------------------- | 6855| Promise<void> | 无返回结果的Promise对象。 | 6856 6857**错误码:** 6858 6859以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6860 6861| 错误码ID | 错误信息 | 6862| ------- | ------------------------------ | 6863| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6864| 1300001 | Repeated operation. | 6865| 1300002 | This window state is abnormal. | 6866 6867**示例:** 6868 6869```ts 6870// EntryAbility.ets 6871import { UIAbility } from '@kit.AbilityKit'; 6872import { BusinessError } from '@kit.BasicServicesKit'; 6873 6874export default class EntryAbility extends UIAbility { 6875 // ... 6876 onWindowStageCreate(windowStage: window.WindowStage): void { 6877 console.info('onWindowStageCreate'); 6878 let windowClass: window.Window | undefined = undefined; 6879 windowStage.getMainWindow((err: BusinessError, data) => { 6880 const errCode: number = err.code; 6881 if (errCode) { 6882 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 6883 return; 6884 } 6885 windowClass = data; 6886 let promise = windowClass.recover(); 6887 promise.then(() => { 6888 console.info('Succeeded in recovering the window.'); 6889 }).catch((err: BusinessError) => { 6890 console.error(`Failed to recover the window. Cause code: ${err.code}, message: ${err.message}`); 6891 }); 6892 }); 6893 } 6894} 6895``` 6896 6897### restore<sup>14+</sup> 6898 6899restore(): Promise<void> 6900 6901将主窗口从最小化状态,恢复到前台显示,并恢复到进入该模式之前的大小和位置。使用Promise异步回调。 6902此接口仅在多窗层叠布局效果下生效,仅在主窗口为最小化状态且UIAbility生命周期为onForeground时生效。 6903 6904<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 6905 6906**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 6907 6908**系统能力:** SystemCapability.Window.SessionManager 6909 6910**返回值:** 6911 6912| 类型 | 说明 | 6913| ------------------- | ------------------------- | 6914| Promise<void> | 无返回结果的Promise对象。 | 6915 6916**错误码:** 6917 6918以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6919 6920| **错误码ID** | **错误信息** | 6921| ------------ | ------------------------------------------------------------ | 6922| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6923| 1300002 | This window state is abnormal. | 6924| 1300003 | This window manager service works abnormally. | 6925| 1300004 | Unauthorized operation. | 6926 6927**示例** 6928 6929```ts 6930// EntryAbility.ets 6931import { UIAbility } from '@kit.AbilityKit'; 6932import { BusinessError } from '@kit.BasicServicesKit'; 6933 6934export default class EntryAbility extends UIAbility { 6935 onWindowStageCreate(windowStage: window.WindowStage): void { 6936 try { 6937 let windowClass = windowStage.getMainWindowSync(); 6938 // 调用minimize, 使主窗最小化 6939 windowClass.minimize(); 6940 //设置延时函数延时5秒钟后对主窗进行恢复。 6941 setTimeout(()=>{ 6942 //调用restore()函数对主窗进行恢复。 6943 let promise = windowClass.restore(); 6944 promise.then(() => { 6945 console.info('Succeeded in restoring the window.'); 6946 }).catch((err: BusinessError) => { 6947 console.error(`Failed to restore the window. Cause code: ${err.code}, message: ${err.message}`); 6948 }); 6949 }, 5000); 6950 } catch (exception) { 6951 console.error(`Failed to restore the window. Cause code: ${exception.code}, message: ${exception.message}`); 6952 } 6953 } 6954} 6955``` 6956 6957### getWindowLimits<sup>11+</sup> 6958 6959getWindowLimits(): WindowLimits 6960 6961获取当前应用窗口的尺寸限制。 6962 6963**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6964 6965**系统能力:** SystemCapability.Window.SessionManager 6966 6967**返回值:** 6968 6969| 类型 | 说明 | 6970| ----------------------------- | ------------------ | 6971| [WindowLimits](#windowlimits11) | 当前窗口尺寸限制。 | 6972 6973**错误码:** 6974 6975以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 6976 6977| 错误码ID | 错误信息 | 6978| :------- | :----------------------------- | 6979| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 6980| 1300002 | This window state is abnormal. | 6981 6982**示例:** 6983 6984```ts 6985try { 6986 let windowLimits = windowClass.getWindowLimits(); 6987} catch (exception) { 6988 console.error(`Failed to obtain the window limits of window. Cause code: ${exception.code}, message: ${exception.message}`); 6989} 6990``` 6991 6992### setWindowLimits<sup>11+</sup> 6993 6994setWindowLimits(windowLimits: WindowLimits): Promise<WindowLimits> 6995 6996设置当前应用窗口的尺寸限制,使用Promise异步回调。 6997默认存在一个系统尺寸限制,系统尺寸限制由产品配置决定,不可修改。未调用setWindowLimits配置过WindowLimits时,使用[getWindowLimits](#getwindowlimits11)可获取系统限制。 6998 6999**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7000 7001**系统能力:** SystemCapability.Window.SessionManager 7002 7003**参数:** 7004 7005| 参数名 | 类型 | 必填 | 说明 | 7006| :----------- | :---------------------------- | :--- | :----------------------------- | 7007| windowLimits | [WindowLimits](#windowlimits11) | 是 | 目标窗口的尺寸限制,单位为px。 | 7008 7009**返回值:** 7010 7011| 类型 | 说明 | 7012| :------------------------------------------- | :---------------------------------- | 7013| Promise<[WindowLimits](#windowlimits11)> | Promise对象。返回设置后的尺寸限制,为入参与系统尺寸限制的交集。 | 7014 7015**错误码:** 7016 7017以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7018 7019| 错误码ID | 错误信息 | 7020| :------- | :-------------------------------------------- | 7021| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7022| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7023| 1300002 | This window state is abnormal. | 7024| 1300003 | This window manager service works abnormally. | 7025| 1300004 | Unauthorized operation. | 7026 7027**示例:** 7028 7029```ts 7030import { BusinessError } from '@kit.BasicServicesKit'; 7031try { 7032 let windowLimits: window.WindowLimits = { 7033 maxWidth: 1500, 7034 maxHeight: 1000, 7035 minWidth: 500, 7036 minHeight: 400 7037 }; 7038 let promise = windowClass.setWindowLimits(windowLimits); 7039 promise.then((data) => { 7040 console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data)); 7041 }).catch((err: BusinessError) => { 7042 console.error(`Failed to change the window limits. Cause code: ${err.code}, message: ${err.message}`); 7043 }); 7044} catch (exception) { 7045 console.error(`Failed to change the window limits. Cause code: ${exception.code}, message: ${exception.message}`); 7046} 7047``` 7048 7049### setWindowLimits<sup>15+</sup> 7050 7051setWindowLimits(windowLimits: WindowLimits, isForcible: boolean): Promise<WindowLimits> 7052 7053设置当前应用窗口的尺寸限制,使用Promise异步回调。 7054默认存在一个系统尺寸限制,系统尺寸限制由产品配置决定,不可修改。未调用setWindowLimits配置过WindowLimits时,使用[getWindowLimits](#getwindowlimits11)可获取系统限制。 7055此接口仅支持2in1设备。 7056 7057**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 7058 7059**系统能力:** SystemCapability.Window.SessionManager 7060 7061**参数:** 7062 7063| 参数名 | 类型 | 必填 | 说明 | 7064| :----------- | :---------------------------- | :--- | :----------------------------- | 7065| windowLimits | [WindowLimits](#windowlimits11) | 是 | 目标窗口的尺寸限制,单位为px。 | 7066| isForcible | boolean | 是 | 是否强制设置窗口的尺寸限制。<br>设置为true,表示窗口宽高最小值以系统限制值和40vp两者中的低数值为准,窗口宽高的最大值仍取决于系统限制。<br>设置为false,表示窗口宽高的最小值和最大值都取决于系统限制。| 7067 7068**返回值:** 7069 7070| 类型 | 说明 | 7071| :------------------------------------------- | :---------------------------------- | 7072| Promise<[WindowLimits](#windowlimits11)> | Promise对象。返回设置后的窗口尺寸限制。根据isForcible判断为入参与系统默认窗口尺寸限制的交集。 | 7073 7074**错误码:** 7075 7076以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7077 7078| 错误码ID | 错误信息 | 7079| :------- | :-------------------------------------------- | 7080| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7081| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7082| 1300002 | This window state is abnormal. | 7083| 1300003 | This window manager service works abnormally. | 7084| 1300004 | Unauthorized operation. | 7085 7086**示例:** 7087 7088```ts 7089import { BusinessError } from '@kit.BasicServicesKit'; 7090try { 7091 let windowLimits: window.WindowLimits = { 7092 maxWidth: 1500, 7093 maxHeight: 1000, 7094 minWidth: 100, 7095 minHeight: 100 7096 }; 7097 let promise = windowClass.setWindowLimits(windowLimits, true); 7098 promise.then((data) => { 7099 console.info('Succeeded in changing the window limits. Cause:' + JSON.stringify(data)); 7100 }).catch((err: BusinessError) => { 7101 console.error(`Failed to change the window limits. Cause code: ${err.code}, message: ${err.message}`); 7102 }); 7103} catch (exception) { 7104 console.error(`Failed to change the window limits. Cause code: ${exception.code}, message: ${exception.message}`); 7105} 7106``` 7107 7108### setWindowMask<sup>12+</sup> 7109 7110setWindowMask(windowMask: Array<Array<number>>): Promise<void>; 7111 7112设置异形窗口的掩码,使用Promise异步回调。异形窗口为非常规形状的窗口,掩码用于描述异形窗口的形状。此接口仅限子窗和全局悬浮窗可用。 7113当异形窗口大小发生变化时,实际的显示内容为掩码大小和窗口大小的交集部分。 7114 7115该接口只在多个线程操作同一个窗口时可能返回错误码1300002。窗口被销毁场景下错误码返回401。 7116 7117<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7118 7119**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7120 7121**系统能力:** SystemCapability.Window.SessionManager 7122 7123**参数:** 7124 7125| 参数名 | 类型 | 必填 | 说明 | 7126| :----------- | :---------------------------- | :--- | :----------------------------- | 7127| windowMask | Array<Array<number>> | 是 | 异形窗口的掩码,该参数仅支持宽高为窗口宽高、取值为整数0和整数1的二维数组输入,整数0代表所在像素透明,整数1代表所在像素不透明,宽高不符合的二维数组或二维数组取值不为整数0和整数1的二维数组为非法参数。 | 7128 7129**返回值:** 7130 7131| 类型 | 说明 | 7132| :------------------------------------------- | :---------------------------------- | 7133| Promise<void> | 无返回结果的Promise对象。 | 7134 7135**错误码:** 7136 7137以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7138 7139| 错误码ID | 错误信息 | 7140| :------- | :-------------------------------------------- | 7141| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7142| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7143| 1300002 | This window state is abnormal. | 7144| 1300003 | This window manager service works abnormally. | 7145| 1300004 | Unauthorized operation. | 7146 7147**示例:** 7148 7149```ts 7150import { BusinessError } from '@kit.BasicServicesKit'; 7151try { 7152 let windowMask: Array<Array<number>> = [ 7153 [0, 0, 0, 1, 0, 0, 0], 7154 [0, 0, 1, 1, 1, 0, 0], 7155 [0, 1, 1, 0, 1, 1, 0], 7156 [1, 1, 0, 0, 0, 1, 1] 7157 ]; 7158 let promise = windowClass.setWindowMask(windowMask); 7159 promise.then(() => { 7160 console.info('Succeeded in setting the window mask.'); 7161 }).catch((err: BusinessError) => { 7162 console.error(`Failed to set the window mask. Cause code: ${err.code}, message: ${err.message}`); 7163 }); 7164} catch (exception) { 7165 console.error(`Failed to set the window mask. Cause code: ${exception.code}, message: ${exception.message}`); 7166} 7167``` 7168 7169### keepKeyboardOnFocus<sup>11+</sup> 7170 7171keepKeyboardOnFocus(keepKeyboardFlag: boolean): void 7172 7173窗口获焦时保留由其他窗口创建的软键盘,仅支持系统窗口与应用子窗口。 7174 7175**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7176 7177**系统能力:** SystemCapability.Window.SessionManager 7178 7179**参数:** 7180 7181| 参数名 | 类型 | 必填 | 说明 | 7182| ---------------- | ------- | ---- | ------------------------------------------------------------ | 7183| keepKeyboardFlag | boolean | 是 | 是否保留其他窗口创建的软键盘。true表示保留;false表示不保留。| 7184 7185**错误码:** 7186 7187以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7188 7189| 错误码ID | 错误信息 | 7190| ------- | ---------------------------------------- | 7191| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7192| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7193| 1300002 | This window state is abnormal. | 7194| 1300004 | Unauthorized operation. | 7195 7196**示例:** 7197 7198```ts 7199try { 7200 windowClass.keepKeyboardOnFocus(true); 7201} catch (exception) { 7202 console.error(`Failed to keep keyboard onFocus. Cause code: ${exception.code}, message: ${exception.message}`); 7203} 7204``` 7205 7206### setWindowDecorVisible<sup>11+</sup> 7207 7208setWindowDecorVisible(isVisible: boolean): void 7209 7210设置窗口标题栏是否可见,对存在标题栏和三键区的窗口形态生效。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 7211 7212设置窗口标题栏不可见后,当主窗口进入全屏沉浸状态时,此时鼠标Hover到上方窗口标题栏热区上会显示悬浮标题栏。若想禁用悬浮标题栏显示,请使用[setTitleAndDockHoverShown()](#settitleanddockhovershown14)接口。 7213 7214**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7215 7216**系统能力:** SystemCapability.Window.SessionManager 7217 7218**参数:** 7219 7220| 参数名 | 类型 | 必填 | 说明 | 7221| --------- | ------- | ---- | --------------------------------------------- | 7222| isVisible | boolean | 是 | 设置标题栏是否可见,true为可见,false为隐藏。 | 7223 7224**错误码:** 7225 7226以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7227 7228| 错误码ID | 错误信息 | 7229| -------- | ------------------------------ | 7230| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7231| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7232| 1300002 | This window state is abnormal. | 7233| 1300004 | Unauthorized operation. | 7234 7235**示例:** 7236 7237```ts 7238import { BusinessError } from '@kit.BasicServicesKit'; 7239let storage: LocalStorage = new LocalStorage(); 7240storage.setOrCreate('storageSimpleProp', 121); 7241windowClass.loadContent("pages/page2", storage, (err: BusinessError) => { 7242 let errCode: number = err.code; 7243 if (errCode) { 7244 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 7245 return; 7246 } 7247 console.info('Succeeded in loading the content.'); 7248 let isVisible = false; 7249 // 调用setWindowDecorVisible接口 7250 try { 7251 windowClass?.setWindowDecorVisible(isVisible); 7252 } catch (exception) { 7253 console.error(`Failed to set the visibility of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 7254 } 7255}); 7256``` 7257 7258### getWindowDecorVisible<sup>18+</sup> 7259 7260getWindowDecorVisible(): boolean 7261 7262查询窗口标题栏是否可见。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 7263 7264<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7265 7266**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 7267 7268**系统能力:** SystemCapability.Window.SessionManager 7269 7270**返回值:** 7271 7272| 类型 | 说明 | 7273| ------ | ------------------------------------------------------------ | 7274| boolean | 返回当前窗口标题栏是否可见,true表示可见,false表示不可见。| 7275 7276**错误码:** 7277 7278以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7279 7280| 错误码ID | 错误信息 | 7281| -------- | ------------------------------ | 7282| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7283| 1300002 | This window state is abnormal. | 7284 7285**示例:** 7286 7287```ts 7288let isVisible: boolean | undefined = undefined; 7289windowClass.setUIContent('pages/WindowPage').then(() => { 7290 try { 7291 isVisible = windowClass?.getWindowDecorVisible(); 7292 } catch (exception) { 7293 console.error(`Failed to get the window decor visibility. Cause code: ${exception.code}, message: ${exception.message}`); 7294 } 7295}) 7296``` 7297 7298### setWindowTitle<sup>15+</sup> 7299 7300setWindowTitle(titleName: string): Promise<void> 7301 7302设置窗口标题,存在标题栏的窗口形态生效,使用Promise异步回调。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 7303 7304此接口仅支持2in1设备和平板设备。 7305 7306**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 7307 7308**系统能力:** SystemCapability.Window.SessionManager 7309 7310**参数:** 7311 7312| 参数名 | 类型 | 必填 | 说明 | 7313| --------- | ------- | ---- | --------------------------------------------- | 7314| titleName | string | 是 | 窗口标题。标题显示区域最右端不超过系统三键区域最左端,超过部分以省略号表示。 | 7315 7316**返回值:** 7317 7318| 类型 | 说明 | 7319| ------------------- | ------------------------ | 7320| Promise<void> | 无返回结果的Promise对象。 | 7321 7322**错误码:** 7323 7324以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7325 7326| 错误码ID | 错误信息 | 7327| -------- | ------------------------------ | 7328| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7329| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7330| 1300002 | This window state is abnormal. | 7331 7332**示例:** 7333 7334```ts 7335import { window } from '@kit.ArkUI'; 7336import { BusinessError } from '@kit.BasicServicesKit'; 7337 7338let windowClass: window.Window | undefined = undefined; 7339try { 7340 let promise = window.getLastWindow(this.context); 7341 promise.then((data) => { 7342 windowClass = data; 7343 let title = "title"; 7344 windowClass.setWindowTitle(title).then(() => { 7345 console.info('Succeeded in setting the window title.'); 7346 }).catch((err: BusinessError) => { 7347 console.error(`Failed to set the window title. Cause code: ${err.code}, message: ${err.message}`); 7348 }); 7349 }).catch((err: BusinessError) => { 7350 console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); 7351 }); 7352} catch (exception) { 7353 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`); 7354} 7355``` 7356 7357### setWindowTitleMoveEnabled<sup>14+</sup> 7358 7359setWindowTitleMoveEnabled(enabled: boolean): void 7360 7361禁止/使能主窗或子窗标题栏默认移动窗口和双击最大化的功能,当禁用标题栏默认移动窗口和双击最大化的功能时,可使用[startMoving()](#startmoving14)在应用热区中发起拖拽移动,使用[maximize()](#maximize12)实现最大化功能。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 7362 7363<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7364 7365**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 7366 7367**系统能力:** SystemCapability.Window.SessionManager 7368 7369**参数:** 7370 7371| 参数名 | 类型 | 必填 | 说明 | 7372| --------- | ------- | ---- | --------------------------------------------- | 7373| enabled | boolean | 是 | 是否使能标题栏默认移动窗口和双击最大化功能,true表示使能,false表示不使能。| 7374 7375**错误码:** 7376 7377以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7378 7379| 错误码ID | 错误信息 | 7380| -------- | ------------------------------ | 7381| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7382| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7383| 1300002 | This window state is abnormal. | 7384| 1300004 | Unauthorized operation. | 7385 7386**示例:** 7387 7388```ts 7389// EntryAbility.ets 7390import { UIAbility } from '@kit.AbilityKit'; 7391 7392export default class EntryAbility extends UIAbility { 7393 onWindowStageCreate(windowStage: window.WindowStage): void { 7394 try { 7395 windowStage.loadContent("pages/Index").then(() =>{ 7396 let windowClass = windowStage.getMainWindowSync(); 7397 let enabled = false; 7398 windowClass.setWindowTitleMoveEnabled(enabled); 7399 console.info(`Succeeded in setting the the window title move enabled: ${enabled}`); 7400 }); 7401 } catch (exception) { 7402 console.error(`Failed to set the window title move enabled. Cause code: ${exception.code}, message: ${exception.message}`); 7403 } 7404 } 7405} 7406``` 7407 7408### setSubWindowModal<sup>12+</sup> 7409 7410setSubWindowModal(isModal: boolean): Promise<void> 7411 7412设置子窗的模态属性是否启用,使用Promise异步回调。 7413 7414子窗口调用该接口时,设置子窗口模态属性是否启用。启用子窗口模态属性后,其父级窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态属性被禁用。 7415 7416子窗口之外的窗口调用该接口时,会报错。 7417 7418**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7419 7420**系统能力:** SystemCapability.Window.SessionManager 7421 7422**参数:** 7423 7424| 参数名 | 类型 | 必填 | 说明 | 7425| --------- | ------- | ---- | --------------------------------------------- | 7426| isModal | boolean | 是 | 设置子窗口模态属性是否启用,true为启用,false为不启用。 | 7427 7428 7429**返回值:** 7430 7431| 类型 | 说明 | 7432| ------------------- | ------------------------ | 7433| Promise<void> | 无返回结果的Promise对象。 | 7434 7435**错误码:** 7436 7437以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7438 7439| 错误码ID | 错误信息 | 7440| -------- | ------------------------------ | 7441| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7442| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7443| 1300002 | This window state is abnormal. | 7444| 1300004 | Unauthorized operation. | 7445 7446**示例:** 7447 7448```ts 7449// EntryAbility.ets 7450import { UIAbility } from '@kit.AbilityKit'; 7451import { BusinessError } from '@kit.BasicServicesKit'; 7452 7453export default class EntryAbility extends UIAbility { 7454 // ... 7455 onWindowStageCreate(windowStage: window.WindowStage): void { 7456 console.info('onWindowStageCreate'); 7457 let windowClass: window.Window | undefined = undefined; 7458 // 创建子窗 7459 try { 7460 let subWindow = windowStage.createSubWindow("testSubWindow"); 7461 subWindow.then((data) => { 7462 if (data == null) { 7463 console.error("Failed to create the subWindow. Cause: The data is empty"); 7464 return; 7465 } 7466 windowClass = data; 7467 let promise = windowClass.setSubWindowModal(true); 7468 promise.then(() => { 7469 console.info('Succeeded in setting subwindow modal'); 7470 }).catch((err: BusinessError) => { 7471 console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`); 7472 }); 7473 }); 7474 } catch (exception) { 7475 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 7476 } 7477 } 7478} 7479``` 7480 7481### setSubWindowModal<sup>14+</sup> 7482 7483setSubWindowModal(isModal: boolean, modalityType: ModalityType): Promise<void> 7484 7485设置子窗的模态类型,使用Promise异步回调。 7486 7487当子窗口模态类型为模窗口子窗时,其父级窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态类型被禁用。 7488 7489当子窗口模态类型为模应用子窗时,其父级窗口与该应用其他实例的窗口不能响应用户操作,直到子窗口关闭或者子窗口的模态类型被禁用。 7490 7491此接口仅支持设置子窗口模态类型,当需要禁用子窗口模态属性时,建议使用[setSubWindowModal<sup>12+</sup>](#setsubwindowmodal12)。 7492 7493子窗口之外的窗口调用该接口时,会报错。 7494 7495**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 7496 7497**系统能力:** SystemCapability.Window.SessionManager 7498 7499**参数:** 7500 7501| 参数名 | 类型 | 必填 | 说明 | 7502| --------- | ------- | ---- | --------------------------------------------- | 7503| isModal | boolean | 是 | 设置子窗口模态属性是否启用,true为启用,false为不启用。当前仅支持设置为true。 | 7504| modalityType | [ModalityType](#modalitytype14) | 是 | 子窗口模态类型。 | 7505 7506**返回值:** 7507 7508| 类型 | 说明 | 7509| ------------------- | ------------------------ | 7510| Promise<void> | 无返回结果的Promise对象。 | 7511 7512**错误码:** 7513 7514以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7515 7516| 错误码ID | 错误信息 | 7517| -------- | ------------------------------ | 7518| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7519| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7520| 1300002 | This window state is abnormal. | 7521| 1300004 | Unauthorized operation. | 7522 7523**示例:** 7524 7525```ts 7526// EntryAbility.ets 7527import { UIAbility } from '@kit.AbilityKit'; 7528import { BusinessError } from '@kit.BasicServicesKit'; 7529import { window } from '@kit.ArkUI'; 7530 7531export default class EntryAbility extends UIAbility { 7532 // ... 7533 onWindowStageCreate(windowStage: window.WindowStage): void { 7534 console.info('onWindowStageCreate'); 7535 let windowClass: window.Window | undefined = undefined; 7536 // 创建子窗 7537 try { 7538 let subWindow = windowStage.createSubWindow("testSubWindow"); 7539 subWindow.then((data) => { 7540 if (data == null) { 7541 console.error("Failed to create the subWindow. Cause: The data is empty"); 7542 return; 7543 } 7544 windowClass = data; 7545 let promise = windowClass.setSubWindowModal(true, window.ModalityType.WINDOW_MODALITY); 7546 promise.then(() => { 7547 console.info('Succeeded in setting subwindow modal'); 7548 }).catch((err: BusinessError) => { 7549 console.error(`Failed to set subwindow modal. Cause code: ${err.code}, message: ${err.message}`); 7550 }); 7551 }); 7552 } catch (exception) { 7553 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 7554 } 7555 } 7556} 7557``` 7558 7559### setWindowDecorHeight<sup>11+</sup> 7560 7561setWindowDecorHeight(height: number): void 7562 7563<!--RP1--> 7564设置窗口的标题栏高度,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 7565<!--RP1End--> 7566 7567当主窗口进入全屏沉浸状态时,此时鼠标Hover到窗口标题栏热区时,会显示悬浮标题栏,悬浮标题栏高度固定为37vp。 7568 7569**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7570 7571**系统能力:** SystemCapability.Window.SessionManager 7572 7573**参数:** 7574 7575| 参数名 | 类型 | 必填 | 说明 | 7576| ------ | ------ | ---- | ------------------------------------------------------------ | 7577| height | number | 是 |设置的窗口标题栏高度,仅支持具有窗口标题栏的窗口。该参数为整数,浮点数输入将向下取整,取值范围为[37,112],范围外为非法参数,单位为vp。 | 7578 7579**错误码:** 7580 7581以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7582 7583| 错误码ID | 错误信息 | 7584| -------- | ------------------------------ | 7585| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7586| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7587| 1300002 | This window state is abnormal. | 7588 7589**示例:** 7590 7591```ts 7592windowClass.setUIContent('pages/WindowPage').then(() => { 7593 let height: number = 50; 7594 try { 7595 windowClass?.setWindowDecorHeight(height); 7596 console.info(`Succeeded in setting the height of window decor: ${height}`); 7597 } catch (exception) { 7598 console.error(`Failed to set the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 7599 } 7600}) 7601``` 7602 7603### setDecorButtonStyle<sup>14+</sup> 7604 7605setDecorButtonStyle(dectorStyle: DecorButtonStyle): void 7606 7607设置装饰栏按钮样式,仅对主窗和使能窗口标题的子窗生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 7608 7609<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7610 7611**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 7612 7613**系统能力:** SystemCapability.Window.SessionManager 7614 7615**参数:** 7616 7617| 参数名 | 类型 | 必填 | 说明 | 7618| --------- | ------- | ---- | --------------------------------------------- | 7619| dectorStyle | [DecorButtonStyle](#decorbuttonstyle14) | 是 | 要设置的装饰栏按钮样式。 | 7620 7621**错误码:** 7622 7623以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7624 7625| 错误码ID | 错误信息 | 7626| -------- | ------------------------------ | 7627| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7628| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7629| 1300002 | This window state is abnormal. | 7630| 1300004 | Unauthorized operation. | 7631 7632**示例:** 7633 7634```ts 7635// EntryAbility.ets 7636import { UIAbility } from '@kit.AbilityKit'; 7637import { ConfigurationConstant } from '@kit.AbilityKit'; 7638 7639export default class EntryAbility extends UIAbility { 7640 onWindowStageCreate(windowStage: window.WindowStage): void { 7641 try { 7642 windowStage.loadContent("pages/Index").then(() =>{ 7643 let windowClass = windowStage.getMainWindowSync(); 7644 let colorMode : ConfigurationConstant.ColorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT; 7645 let style: window.DecorButtonStyle = { 7646 colorMode: colorMode, 7647 buttonBackgroundSize: 24, 7648 spacingBetweenButtons: 12, 7649 closeButtonRightMargin: 20 7650 }; 7651 windowClass.setDecorButtonStyle(style); 7652 console.info('Succeeded in setting the style of button. Data: ' + JSON.stringify(style)); 7653 }); 7654 } catch (exception) { 7655 console.error(`Failed to set the style of button. Cause code: ${exception.code}, message: ${exception.message}`); 7656 } 7657 } 7658} 7659``` 7660 7661### getDecorButtonStyle<sup>14+</sup> 7662 7663getDecorButtonStyle(): DecorButtonStyle 7664 7665获取装饰栏按钮样式,仅对主窗和使能窗口标题的子窗生效。 7666 7667<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7668 7669**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 7670 7671**系统能力:** SystemCapability.Window.SessionManager 7672 7673**返回值:** 7674 7675| 类型 | 说明 | 7676| ------------------------------------- | ------------------------------------------------------------ | 7677| [DecorButtonStyle](#decorbuttonstyle14) | 返回当前窗口装饰栏上的按钮样式,窗口装饰按钮区域位于窗口的右上角。 | 7678 7679**错误码:** 7680 7681以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7682 7683| 错误码ID | 错误信息 | 7684| -------- | ------------------------------ | 7685| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7686| 1300002 | This window state is abnormal. | 7687| 1300003 | This window manager service works abnormally. | 7688| 1300004 | Unauthorized operation. | 7689 7690**示例:** 7691 7692```ts 7693try { 7694 let decorButtonStyle = windowClass.getDecorButtonStyle(); 7695 console.info('Succeeded in getting the style of button. Data: ' + JSON.stringify(decorButtonStyle)); 7696} catch (exception) { 7697 console.error(`Failed to get the style of button. Cause code: ${exception.code}, message: ${exception.message}`); 7698} 7699``` 7700 7701### getWindowDecorHeight<sup>11+</sup> 7702 7703getWindowDecorHeight(): number 7704 7705<!--RP2--> 7706获取窗口的标题栏高度,仅在2in1设备中,对存在标题栏和三键区的窗口形态生效。如果使用Stage模型,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 7707<!--RP2End--> 7708 7709**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7710 7711**系统能力:** SystemCapability.Window.SessionManager 7712 7713**返回值:** 7714 7715| 类型 | 说明 | 7716| ------ | ------------------------------------------------------------ | 7717| number | 返回的窗口标题栏高度。该参数为整数,取值范围为[37,112],单位为vp。 | 7718 7719**错误码:** 7720 7721以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7722 7723| 错误码ID | 错误信息 | 7724| -------- | ------------------------------ | 7725| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7726| 1300002 | This window state is abnormal. | 7727 7728**示例:** 7729 7730```ts 7731windowClass.setUIContent('pages/WindowPage').then(() => { 7732 try { 7733 let height = windowClass?.getWindowDecorHeight(); 7734 console.info(`Succeeded in getting the height of window decor: ${height}`); 7735 } catch (exception) { 7736 console.error(`Failed to get the height of window decor. Cause code: ${exception.code}, message: ${exception.message}`); 7737 } 7738}) 7739``` 7740 7741### getTitleButtonRect<sup>11+</sup> 7742 7743getTitleButtonRect(): TitleButtonRect 7744 7745获取主窗口或启用装饰的子窗口的标题栏上的最小化、最大化、关闭按钮矩形区域。 7746 7747**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7748 7749**系统能力:** SystemCapability.Window.SessionManager 7750 7751**返回值:** 7752 7753| 类型 | 说明 | 7754| ------------------------------------- | ------------------------------------------------------------ | 7755| [TitleButtonRect](#titlebuttonrect11) | 标题栏上的最小化、最大化、关闭按钮矩形区域,该区域位置坐标相对窗口右上角。 | 7756 7757**错误码:** 7758 7759以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7760 7761| 错误码ID | 错误信息 | 7762| -------- | ------------------------------ | 7763| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7764| 1300002 | This window state is abnormal. | 7765 7766**示例:** 7767 7768```ts 7769// EntryAbility.ets 7770import { UIAbility } from '@kit.AbilityKit'; 7771import { BusinessError } from '@kit.BasicServicesKit'; 7772 7773export default class EntryAbility extends UIAbility { 7774 // ... 7775 onWindowStageCreate(windowStage: window.WindowStage): void { 7776 console.info('onWindowStageCreate'); 7777 let windowClass: window.Window | undefined = undefined; 7778 windowStage.getMainWindow((err: BusinessError, data) => { 7779 const errCode: number = err.code; 7780 if (errCode) { 7781 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7782 return; 7783 } 7784 windowClass = data; 7785 try { 7786 let titleButtonArea = windowClass.getTitleButtonRect(); 7787 console.info('Succeeded in obtaining the area of title buttons. Data: ' + JSON.stringify(titleButtonArea)); 7788 } catch (exception) { 7789 console.error(`Failed to get the area of title buttons. Cause code: ${exception.code}, message: ${exception.message}`); 7790 } 7791 }); 7792 } 7793} 7794``` 7795 7796### getWindowStatus<sup>12+</sup> 7797 7798getWindowStatus(): WindowStatusType 7799 7800获取当前应用窗口的模式。 7801 7802**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7803 7804**系统能力:** SystemCapability.Window.SessionManager 7805 7806**返回值:** 7807 7808| 类型 | 说明 | 7809| ------------------------------ | ----------------------------------------| 7810| [WindowStatusType](#windowstatustype11) | 当前窗口模式。 | 7811 7812**错误码:** 7813 7814以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7815 7816| 错误码ID | 错误信息 | 7817| ------- | ------------------------------ | 7818| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7819| 1300002 | This window state is abnormal. | 7820 7821**示例:** 7822 7823```ts 7824try { 7825 let windowStatusType = windowClass.getWindowStatus(); 7826} catch (exception) { 7827 console.error(`Failed to obtain the window status of window. Cause code: ${exception.code}, message: ${exception.message}`); 7828} 7829``` 7830 7831### isFocused<sup>12+</sup> 7832 7833isFocused(): boolean 7834 7835判断当前窗口是否已获焦。 7836 7837**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7838 7839**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7840 7841**返回值:** 7842 7843| 类型 | 说明 | 7844| ------- | ------------------------------------------------------------------ | 7845| boolean | 当前窗口是否已获焦。true表示当前窗口已获焦,false则表示当前窗口未获焦。 | 7846 7847**错误码:** 7848 7849以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 7850 7851| 错误码ID | 错误信息 | 7852| ------- | ------------------------------ | 7853| 1300002 | This window state is abnormal. | 7854 7855**示例:** 7856 7857```ts 7858try { 7859 let focus = windowClass.isFocused(); 7860 console.info('Succeeded in checking whether the window is focused. Data: ' + JSON.stringify(focus)); 7861} catch (exception) { 7862 console.error(`Failed to check whether the window is focused. Cause code: ${exception.code}, message: ${exception.message}`); 7863} 7864``` 7865 7866### createSubWindowWithOptions<sup>12+</sup> 7867 7868createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise<Window> 7869 7870创建主窗口、子窗口或悬浮窗下的子窗口,使用Promise异步回调。 7871 7872<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7873 7874**模型约束:** 此接口仅可在Stage模型下使用。 7875 7876**系统能力:** SystemCapability.Window.SessionManager 7877 7878**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7879 7880**参数:** 7881 7882| 参数名 | 类型 | 必填 | 说明 | 7883| ------ | ------ | ---- | -------------- | 7884| name | string | 是 | 子窗口的名字。 | 7885| options | [SubWindowOptions](#subwindowoptions11) | 是 | 子窗口参数。 | 7886 7887**返回值:** 7888 7889| 类型 | 说明 | 7890| -------------------------------- | ------------------------------------------------ | 7891| Promise<[Window](#window)> | Promise对象。返回当前Window下创建的子窗口对象。 | 7892 7893**错误码:** 7894 7895以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7896 7897| 错误码ID | 错误信息 | 7898| ------- | ------------------------------ | 7899| 401 | Parameter error. Possible cause: Incorrect parameter types. | 7900| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7901| 1300002 | This window state is abnormal. | 7902| 1300003 | This window manager service works abnormally. | 7903| 1300004 | Unauthorized operation. | 7904 7905**示例:** 7906 7907```ts 7908import { BusinessError } from '@kit.BasicServicesKit'; 7909 7910try { 7911 let options : window.SubWindowOptions = { 7912 title: 'title', 7913 decorEnabled: true, 7914 isModal: true 7915 }; 7916 let promise = windowClass.createSubWindowWithOptions('mySubWindow', options); 7917 promise.then((data) => { 7918 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 7919 }).catch((err: BusinessError) => { 7920 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 7921 }); 7922} catch (exception) { 7923 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 7924} 7925``` 7926 7927### setWindowTitleButtonVisible<sup>14+</sup> 7928 7929setWindowTitleButtonVisible(isMaximizeButtonVisible: boolean, isMinimizeButtonVisible: boolean, isCloseButtonVisible?: boolean): void 7930 7931设置主窗标题栏上的最大化、最小化、关闭按钮是否可见。 7932 7933<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7934 7935**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 7936 7937**系统能力:** SystemCapability.Window.SessionManager 7938 7939**参数:** 7940 7941| 参数名 | 类型 | 必填 | 说明 | 7942| --------- | ------- | ---- | --------------------------------------------- | 7943| isMaximizeButtonVisible | boolean | 是 | 设置最大化按钮是否可见,true为可见,false为隐藏。如果最大化按钮隐藏,那么在最大化场景下,也隐藏对应的还原按钮。 | 7944| isMinimizeButtonVisible | boolean | 是 | 设置最小化按钮是否可见,true为可见,false为隐藏。 | 7945| isCloseButtonVisible | boolean | 否 | 设置关闭按钮是否可见,true为可见,false为隐藏,默认值true。 | 7946 7947**错误码:** 7948 7949以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 7950 7951| 错误码ID | 错误信息 | 7952| -------- | ------------------------------ | 7953| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7954| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 7955| 1300002 | This window state is abnormal. | 7956| 1300004 | Unauthorized operation. | 7957 7958**示例:** 7959 7960```ts 7961// EntryAbility.ets 7962import { UIAbility } from '@kit.AbilityKit'; 7963import { BusinessError } from '@kit.BasicServicesKit'; 7964import { window } from '@kit.ArkUI'; 7965 7966export default class EntryAbility extends UIAbility { 7967 onWindowStageCreate(windowStage: window.WindowStage): void { 7968 // 加载主窗口对应的页面 7969 windowStage.loadContent('pages/Index', (err) => { 7970 let mainWindow: window.Window | undefined = undefined; 7971 // 获取应用主窗口。 7972 windowStage.getMainWindow().then( 7973 data => { 7974 mainWindow = data; 7975 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 7976 // 调用setWindowTitleButtonVisible接口,隐藏主窗标题栏最大化、最小化、关闭按钮。 7977 mainWindow.setWindowTitleButtonVisible(false, false, false); 7978 } 7979 ).catch((err: BusinessError) => { 7980 if(err.code){ 7981 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 7982 } 7983 }); 7984 }); 7985 } 7986} 7987``` 7988 7989### setWindowTopmost<sup>14+</sup> 7990 7991setWindowTopmost(isWindowTopmost: boolean): Promise<void> 7992 7993应用主窗口调用,实现将窗口置于其他应用窗口之上不被遮挡,使用Promise异步回调。 7994 7995应用可通过自定义快捷键实现主窗口的置顶和取消置顶。 7996 7997<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 7998 7999**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 8000 8001**系统能力:** SystemCapability.Window.SessionManager 8002 8003**需要权限:** ohos.permission.WINDOW_TOPMOST 8004 8005**参数:** 8006 8007| 参数名 | 类型 | 必填 | 说明 | 8008| --------- | ------- | ---- | --------------------------------------------- | 8009| isWindowTopmost | boolean | 是 | 设置主窗口置顶,true为置顶,false为取消置顶。 | 8010 8011 8012**错误码:** 8013 8014以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8015 8016| 错误码ID | 错误信息 | 8017| -------- | ------------------------------ | 8018| 201 | Permission verification failed. The application does not have the permission required to call the API. | 8019| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8020| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8021| 1300002 | This window state is abnormal. | 8022| 1300004 | Unauthorized operation. | 8023 8024**示例:** 8025 8026```ts 8027// ets/pages/Index.ets 8028import { window } from '@kit.ArkUI'; 8029import { common } from '@kit.AbilityKit'; 8030import { BusinessError } from '@kit.BasicServicesKit'; 8031 8032let windowClass: window.Window | undefined; 8033let keyUpEventAry: string[] = []; 8034 8035@Entry 8036@Component 8037struct Index { 8038 private context = (this.getUIContext()?.getHostContext() as common.UIAbilityContext); 8039 8040 build() { 8041 RelativeContainer() { 8042 Button("窗口置顶") 8043 .onClick(() => { 8044 try { 8045 let promiseCtx = window.getLastWindow(this.context); 8046 promiseCtx.then((data) => { 8047 windowClass = data; 8048 // true:窗口置顶,false:取消窗口置顶 8049 let isWindowTopmost: boolean = true; 8050 let promiseTopmost = windowClass.setWindowTopmost(isWindowTopmost); 8051 promiseTopmost.then(() => { 8052 console.info('Succeeded in setting the main window to be topmost.'); 8053 }).catch((err: BusinessError) => { 8054 console.error(`Failed to set the main window to be topmost. Cause code: ${err.code}, message: ${err.message}`); 8055 }); 8056 }) 8057 } catch (exception) { 8058 console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`) 8059 } 8060 }) 8061 } 8062 .height('100%') 8063 .width('100%') 8064 .onKeyEvent((event) => { 8065 if(event) { 8066 if(event.type === KeyType.Down) { 8067 keyUpEventAry = []; 8068 } 8069 if(event.type === KeyType.Up) { 8070 keyUpEventAry.push(event.keyText); 8071 // 自定义快捷键 ctrl+T 执行主窗口置顶、取消置顶的操作 8072 if(windowClass && keyUpEventAry.includes('KEYCODE_CTRL_LEFT') && keyUpEventAry.includes('KEYCODE_T')) { 8073 let isWindowTopmost: boolean = false; 8074 windowClass.setWindowTopmost(isWindowTopmost); 8075 } 8076 } 8077 } 8078 }) 8079 } 8080} 8081``` 8082 8083### raiseToAppTop<sup>14+</sup> 8084 8085raiseToAppTop(): Promise<void> 8086 8087应用子窗口调用,提升应用子窗口到顶层,只在当前应用同一个父窗口下的相同类型子窗范围内生效,对于自定义了zLevel属性的子窗口,只在当前应用同一个父窗口下相同zLevel值的子窗范围内生效。使用Promise异步回调。 8088 8089使用该接口需要先创建子窗口,并确保该子窗口调用[showWindow()](#showwindow9)并执行完毕。 8090 8091**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8092 8093**返回值:** 8094 8095| 类型 | 说明 | 8096| ------------------- | ------------------------- | 8097| Promise<void> | 无返回结果的Promise对象。 | 8098 8099**错误码:** 8100 8101以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8102 8103| 错误码ID | 错误信息 | 8104| ------- | ------------------------------ | 8105| 1300002 | This window state is abnormal. | 8106| 1300003 | This window manager service works abnormally. | 8107| 1300004 | Unauthorized operation. | 8108| 1300009 | The parent window is invalid. | 8109 8110**示例:** 8111 8112```ts 8113// EntryAbility.ets 8114import { window } from '@kit.ArkUI'; 8115import { UIAbility } from '@kit.AbilityKit'; 8116import { BusinessError } from '@kit.BasicServicesKit'; 8117 8118export default class EntryAbility extends UIAbility { 8119 // ... 8120 onWindowStageCreate(windowStage: window.WindowStage): void { 8121 console.info('onWindowStageCreate'); 8122 // 创建子窗 8123 try { 8124 let subWindowPromise = windowStage.createSubWindow("testSubWindow"); 8125 subWindowPromise.then((data) => { 8126 if (data == null) { 8127 console.error("Failed to create the subWindow. Cause: The data is empty"); 8128 return; 8129 } 8130 let showWindowPromise = data.showWindow(); 8131 showWindowPromise.then(() => { 8132 let raiseToTopPromise = data.raiseToAppTop(); 8133 raiseToTopPromise.then(() => { 8134 console.info('Succeeded in raising window to app top.'); 8135 }).catch((err: BusinessError)=>{ 8136 console.error(`Failed to raise window to app top. Cause code: ${err.code}, message: ${err.message}`); 8137 }); 8138 }); 8139 }); 8140 } catch (exception) { 8141 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 8142 } 8143 } 8144} 8145``` 8146 8147### setRaiseByClickEnabled<sup>14+</sup> 8148 8149setRaiseByClickEnabled(enable: boolean): Promise<void> 8150 8151禁止/使能子窗点击抬升功能。使用Promise异步回调。 8152 8153通常来说,点击一个子窗口,会将该子窗口显示抬升到应用内同一个父窗口下同类型子窗口的最上方,如果设置为false,那么点击子窗口的时候,不会将该子窗口进行抬升,而是保持不变。 8154 8155使用该接口需要先创建子窗口,并确保该子窗口调用[showWindow()](#showwindow9)并执行完毕。 8156 8157**系统能力:** SystemCapability.Window.SessionManager 8158 8159**参数:** 8160 8161| 参数名 | 类型 | 必填 | 说明 | 8162| -------- | ------------------------- | ---- | ---------- | 8163| enable | boolean | 是 | 设置子窗口点击抬升功能是否使能,true表示使能,false表示禁止。 | 8164 8165**返回值:** 8166 8167| 类型 | 说明 | 8168| ------------------- | ------------------------- | 8169| Promise<void> | 无返回结果的Promise对象。 | 8170 8171**错误码:** 8172 8173以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8174 8175| 错误码ID | 错误信息 | 8176| ------- | ------------------------------ | 8177| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8178| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8179| 1300002 | This window state is abnormal. | 8180| 1300003 | This window manager service works abnormally. | 8181| 1300004 | Unauthorized operation. | 8182| 1300009 | The parent window is invalid. | 8183 8184**示例:** 8185 8186```ts 8187// EntryAbility.ets 8188import { window } from '@kit.ArkUI'; 8189import { UIAbility } from '@kit.AbilityKit'; 8190import { BusinessError } from '@kit.BasicServicesKit'; 8191 8192export default class EntryAbility extends UIAbility { 8193 // ... 8194 onWindowStageCreate(windowStage: window.WindowStage): void { 8195 console.info('onWindowStageCreate'); 8196 // 创建子窗 8197 try { 8198 let subWindowPromise = windowStage.createSubWindow("testSubWindow"); 8199 subWindowPromise.then((data) => { 8200 if (data == null) { 8201 console.error("Failed to create the subWindow. Cause: The data is empty"); 8202 return; 8203 } 8204 let showWindowPromise = data.showWindow(); 8205 showWindowPromise.then(() => { 8206 let enabled = false; 8207 let setRaisePromise = data.setRaiseByClickEnabled(enabled); 8208 setRaisePromise.then(() => { 8209 console.info('Succeeded in disabling the raise-by-click function.'); 8210 }).catch((err: BusinessError)=>{ 8211 console.error(`Failed to disable the raise-by-click function. Cause code: ${err.code}, message: ${err.message}`); 8212 }); 8213 }); 8214 }); 8215 } catch (exception) { 8216 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 8217 } 8218 } 8219} 8220``` 8221 8222### enableLandscapeMultiWindow<sup>12+</sup> 8223 8224enableLandscapeMultiWindow(): Promise<void> 8225 8226应用部分界面支持横向布局时,在进入该界面时使能,使能后可支持进入横向多窗。不建议竖向布局界面使用。 8227 8228此接口只对应用主窗口生效,且需要在module.json5配置文件中[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中配置preferMultiWindowOrientation属性为"landscape_auto"。 8229 8230**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8231 8232**系统能力:** SystemCapability.Window.SessionManager 8233 8234**返回值:** 8235 8236| 类型 | 说明 | 8237| ------------------- | ------------------------- | 8238| Promise<void> | 无返回结果的Promise对象。 | 8239 8240**错误码:** 8241 8242以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 8243 8244| 错误码ID | 错误信息 | 8245| ------- | -------------------------------------------- | 8246| 1300002 | This window state is abnormal. | 8247| 1300003 | This window manager service works abnormally. | 8248 8249**示例:** 8250 8251```ts 8252// EntryAbility.ets 8253import { UIAbility } from '@kit.AbilityKit'; 8254import { BusinessError } from '@kit.BasicServicesKit'; 8255import { window } from '@kit.ArkUI'; 8256 8257export default class EntryAbility extends UIAbility { 8258 // ... 8259 onWindowStageCreate(windowStage: window.WindowStage): void { 8260 console.info('onWindowStageCreate'); 8261 let windowClass: window.Window | undefined = undefined; 8262 windowStage.getMainWindow((err: BusinessError, data) => { 8263 const errCode: number = err.code; 8264 if (errCode) { 8265 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8266 return; 8267 } 8268 windowClass = data; 8269 let promise = windowClass.enableLandscapeMultiWindow(); 8270 promise.then(() => { 8271 console.info('Succeeded in making multi-window become landscape.'); 8272 }).catch((err: BusinessError) => { 8273 console.error(`Failed to make multi-window become landscape. Cause code: ${err.code}, message: ${err.message}`); 8274 }); 8275 }); 8276 } 8277} 8278``` 8279 8280### disableLandscapeMultiWindow<sup>12+</sup> 8281 8282disableLandscapeMultiWindow(): Promise<void> 8283 8284应用部分界面支持横向布局时,在退出该界面时去使能,去使能后不支持进入横向多窗。 8285 8286此接口只对应用主窗口生效,且需要在module.json5配置文件中[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中配置preferMultiWindowOrientation属性为"landscape_auto"。 8287 8288**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8289 8290**系统能力:** SystemCapability.Window.SessionManager 8291 8292**返回值:** 8293 8294| 类型 | 说明 | 8295| ------------------- | ------------------------- | 8296| Promise<void> | 无返回结果的Promise对象。 | 8297 8298**错误码:** 8299 8300以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 8301 8302| 错误码ID | 错误信息 | 8303| ------- | -------------------------------------------- | 8304| 1300002 | This window state is abnormal. | 8305| 1300003 | This window manager service works abnormally. | 8306 8307**示例:** 8308 8309```ts 8310// EntryAbility.ets 8311import { UIAbility } from '@kit.AbilityKit'; 8312import { BusinessError } from '@kit.BasicServicesKit'; 8313import { window } from '@kit.ArkUI'; 8314 8315export default class EntryAbility extends UIAbility { 8316 // ... 8317 onWindowStageCreate(windowStage: window.WindowStage): void { 8318 console.info('onWindowStageCreate'); 8319 let windowClass: window.Window | undefined = undefined; 8320 windowStage.getMainWindow((err: BusinessError, data) => { 8321 const errCode: number = err.code; 8322 if (errCode) { 8323 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8324 return; 8325 } 8326 windowClass = data; 8327 let promise = windowClass.disableLandscapeMultiWindow(); 8328 promise.then(() => { 8329 console.info('Succeeded in making multi-window become not landscape.'); 8330 }).catch((err: BusinessError) => { 8331 console.error(`Failed to make multi-window become not landscape. Cause code: ${err.code}, message: ${err.message}`); 8332 }); 8333 }); 8334 } 8335} 8336``` 8337 8338### setDialogBackGestureEnabled<sup>12+</sup> 8339 8340setDialogBackGestureEnabled(enabled: boolean): Promise<void> 8341 8342设置模态窗口是否响应手势返回事件,非模态窗口调用返回错误码。 8343 8344**系统能力**:SystemCapability.Window.SessionManager 8345 8346**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8347 8348**参数:** 8349 8350| 参数名 | 类型 | 必填 | 说明 | 8351| ---------- | ------- | ---- | ------------------------------------------------------------ | 8352| enabled | boolean | 是 | 是否响应手势返回事件。<br>true表示响应手势返回事件,触发onBackPress回调;false表示不响应手势返回事件,不触发onBackPress回调。</br> | 8353 8354**返回值:** 8355 8356| 类型 | 说明 | 8357| ------------------- | ------------------------- | 8358| Promise<void> | 无返回结果的Promise对象。 | 8359 8360**错误码:** 8361 8362以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8363 8364| 错误码ID | 错误信息 | 8365| ------- | -------------------------------------------- | 8366| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8367| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8368| 1300002 | This window state is abnormal. | 8369| 1300003 | This window manager service works abnormally. | 8370| 1300004 | Unauthorized operation. | 8371 8372**示例:** 8373 8374```ts 8375// EntryAbility.ets 8376import { UIAbility } from '@kit.AbilityKit'; 8377import { BusinessError } from '@kit.BasicServicesKit'; 8378 8379export default class EntryAbility extends UIAbility { 8380 onWindowStageCreate(windowStage: window.WindowStage): void { 8381 console.info('onWindowStageCreate'); 8382 let windowClass: window.Window | undefined = undefined; 8383 let config: window.Configuration = { 8384 name: "test", 8385 windowType: window.WindowType.TYPE_DIALOG, 8386 ctx: this.context 8387 }; 8388 try { 8389 window.createWindow(config, (err: BusinessError, data) => { 8390 const errCode: number = err.code; 8391 if (errCode) { 8392 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 8393 return; 8394 } 8395 windowClass = data; 8396 windowClass.setUIContent("pages/Index"); 8397 let enabled = true; 8398 let promise = windowClass.setDialogBackGestureEnabled(enabled); 8399 promise.then(() => { 8400 console.info('Succeeded in setting dialog window to respond back gesture.'); 8401 }).catch((err: BusinessError) => { 8402 console.error(`Failed to set dialog window to respond back gesture. Cause code: ${err.code}, message: ${err.message}`); 8403 }); 8404 }); 8405 } catch (exception) { 8406 console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`); 8407 } 8408 } 8409} 8410``` 8411 8412```ts 8413// ets/pages/Index.ets 8414@Entry 8415@Component 8416struct Index { 8417 @State message: string = 'Hello World' 8418 build() { 8419 RelativeContainer() { 8420 Text(this.message) 8421 .id('HelloWorld') 8422 .fontSize(50) 8423 .fontWeight(FontWeight.Bold) 8424 } 8425 .height('100%') 8426 .width('100%') 8427 } 8428 8429 onBackPress(): boolean | void { 8430 console.info('Succeeded in setting dialog window to respond back gesture.'); 8431 return true; 8432 } 8433} 8434``` 8435 8436### startMoving<sup>14+</sup> 8437 8438startMoving(): Promise<void> 8439 8440开始移动窗口,使用Promise异步回调。 8441 8442仅在[onTouch](./arkui-ts/ts-universal-events-touch.md#touchevent)事件(其中,事件类型必须为TouchType.Down)的回调方法中调用此接口才会有移动效果,成功调用此接口后,窗口将跟随鼠标移动。 8443 8444<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 8445 8446仅对主窗、子窗、系统窗口生效,其它设备类型和窗口类型调用此接口会报错。 8447 8448**系统能力:** SystemCapability.Window.SessionManager 8449 8450**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 8451 8452**返回值:** 8453 8454| 类型 | 说明 | 8455| ------------------- | ------------------------- | 8456| Promise<void> | 无返回结果的Promise对象。 | 8457 8458**错误码:** 8459 8460以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8461 8462| 错误码ID | 错误信息 | 8463| -------- | -------------------------------------------- | 8464| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8465| 1300001 | Repeated operation. | 8466| 1300002 | This window state is abnormal. | 8467| 1300003 | This window manager service works abnormally. | 8468| 1300004 | Unauthorized operation. | 8469 8470**示例:** 8471 8472```ts 8473// ets/pages/Index.ets 8474import { BusinessError } from '@kit.BasicServicesKit'; 8475 8476@Entry 8477@Component 8478struct Index { 8479 build() { 8480 Row() { 8481 Column() { 8482 Blank('160') 8483 .color(Color.Blue) 8484 .onTouch((event: TouchEvent) => { 8485 if (event.type === TouchType.Down) { 8486 try { 8487 let windowClass: window.Window = window.findWindow("subWindow"); 8488 windowClass.startMoving().then(() => { 8489 console.info('Succeeded in starting moving window.') 8490 }).catch((err: BusinessError) => { 8491 console.error(`Failed to start moving. Cause code: ${err.code}, message: ${err.message}`); 8492 }); 8493 } catch (exception) { 8494 console.error(`Failed to start moving window. Cause code: ${exception.code}, message: ${exception.message}`); 8495 } 8496 } 8497 }) 8498 }.width('100%') 8499 }.height('100%').width('100%') 8500 } 8501} 8502``` 8503 8504### startMoving<sup>15+</sup> 8505 8506startMoving(offsetX: number, offsetY: number): Promise<void> 8507 8508指定鼠标在窗口内的位置并移动窗口,使用Promise异步回调。 8509 8510在同应用内窗口分合后,且鼠标保持按下状态直接移动新窗口,如果此时鼠标快速移动,窗口移动时鼠标可能会在窗口外。可以使用本接口指定窗口移动时鼠标在窗口内的位置,先移动窗口到鼠标位置,再开始移动窗口。 8511 8512仅在[onTouch](./arkui-ts/ts-universal-events-touch.md#touchevent)事件(其中,事件类型必须为TouchType.Down)的回调方法中调用此接口才会有移动效果,成功调用此接口后,窗口将跟随鼠标移动。 8513 8514<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 8515 8516**系统能力:** SystemCapability.Window.SessionManager 8517 8518**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 8519 8520**参数:** 8521 8522| 参数名 | 类型 | 必填 | 说明 | 8523| --------- | --------- | ------- |----------------------------------------------------| 8524| offsetX | number | 是 | 窗口移动时预期鼠标位置相对窗口左上角的x轴偏移量,单位为px,该参数仅支持整数输入,浮点数向下取整。负值为非法参数,大于窗口宽度为非法参数,窗口宽度可以在窗口属性[WindowProperties](#windowproperties)中获取。 | 8525| offsetY | number | 是 | 窗口移动时预期鼠标位置相对窗口左上角的y轴偏移量,单位为px,该参数仅支持整数输入,浮点数向下取整。负值为非法参数,大于窗口高度为非法参数,窗口高度可以在窗口属性[WindowProperties](#windowproperties)中获取。 | 8526 8527**返回值:** 8528 8529| 类型 | 说明 | 8530| ------------------- |----------------------------| 8531| Promise<void> | 无返回结果的Promise对象。 | 8532 8533**错误码:** 8534 8535以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8536 8537| 错误码ID | 错误信息 | 8538| ---- | -------------------------------------------- | 8539| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8540| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8541| 1300001 | Repeated operation. | 8542| 1300002 | This window state is abnormal. | 8543| 1300003 | This window manager service works abnormally. | 8544| 1300004 | Unauthorized operation. | 8545 8546**示例:** 8547 8548```ts 8549// ets/pages/Index.ets 8550import { BusinessError } from '@kit.BasicServicesKit'; 8551 8552@Entry 8553@Component 8554struct Index { 8555 build() { 8556 Row() { 8557 Column() { 8558 Blank('160') 8559 .color(Color.Blue) 8560 .onTouch((event: TouchEvent) => { 8561 if (event.type === TouchType.Down) { 8562 try { 8563 let windowClass: window.Window = window.findWindow("subWindow"); 8564 windowClass.startMoving(100, 50).then(() => { 8565 console.info('Succeeded in starting moving window.') 8566 }).catch((err: BusinessError) => { 8567 console.error(`Failed to start moving. Cause code: ${err.code}, message: ${err.message}`); 8568 }); 8569 } catch (exception) { 8570 console.error(`Failed to start moving window. Cause code: ${exception.code}, message: ${exception.message}`); 8571 } 8572 } 8573 }) 8574 }.width('100%') 8575 }.height('100%').width('100%') 8576 } 8577} 8578``` 8579 8580### stopMoving<sup>15+</sup> 8581 8582stopMoving(): Promise<void> 8583 8584在窗口拖拽移动过程中,通过此接口来停止窗口移动,使用Promise异步回调。 8585 8586<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 8587 8588**系统能力:** SystemCapability.Window.SessionManager 8589 8590**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 8591 8592**返回值:** 8593 8594| 类型 | 说明 | 8595| ------------------- | -------------------------| 8596| Promise<void> | 无返回结果的Promise对象。 | 8597 8598**错误码:** 8599 8600以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8601 8602| 错误码ID | 错误信息 | 8603| -------- | -------------------------------------------- | 8604| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8605| 1300002 | This window state is abnormal. | 8606| 1300003 | This window manager service works abnormally. | 8607| 1300004 | Unauthorized operation. | 8608 8609**示例:** 8610 8611```ts 8612// EntryAbility.ets 8613import { UIAbility } from '@kit.AbilityKit'; 8614import { window } from '@kit.ArkUI'; 8615import { BusinessError } from '@kit.BasicServicesKit'; 8616 8617export default class EntryAbility extends UIAbility { 8618 8619 onWindowStageCreate(windowStage: window.WindowStage) { 8620 try { 8621 let windowClass = windowStage.getMainWindowSync(); 8622 windowClass.on('windowRectChange', (data: window.RectChangeOptions) => { 8623 if (data.reason === window.RectChangeReason.MOVE) { 8624 windowClass.stopMoving().then(() => { 8625 console.info('Succeeded in stopping moving window.') 8626 }).catch((err: BusinessError) => { 8627 console.error(`Failed to stop moving. Cause code: ${err.code}, message: ${err.message}`); 8628 }); 8629 } 8630 }); 8631 } catch (exception) { 8632 console.error(`Failed to stop moving window. Cause code: ${exception.code}, message: ${exception.message}`); 8633 } 8634 } 8635} 8636``` 8637 8638### setGestureBackEnabled<sup>13+<sup> 8639 8640setGestureBackEnabled(enabled: boolean): Promise<void> 8641 8642设置当前窗口是否禁用返回手势功能,仅主窗全屏模式下生效,2in1设备下不生效。 8643禁用返回手势功能后,当前应用会禁用手势热区,侧滑返回功能失效;切换到其他应用或者回到桌面后,手势热区恢复,侧滑返回功能正常。 8644开启返回手势功能后,当前应用会恢复手势热区,侧滑返回功能正常。 8645 8646**系统能力:** SystemCapability.Window.SessionManager 8647 8648**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 8649 8650**参数:** 8651 8652| 参数名 | 类型 | 必填 | 说明 | 8653| ---------- | --------- | -------- | --------------------------------------------- | 8654| enabled | boolean | 是 | true时开启返回手势功能,false时禁用返回手势功能。 | 8655 8656**返回值:** 8657 8658| 类型 | 说明 | 8659| ------------------- | ------------------------- | 8660| Promise<void> | 无返回结果的Promise对象。 | 8661 8662**错误码:** 8663 8664以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8665 8666| 错误码ID | 错误信息 | 8667| -------- | ------------------------------------------------------------------------------------------------------------ | 8668| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8669| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8670| 1300002 | This window state is abnormal. | 8671| 1300003 | This window manager service works abnormally. | 8672| 1300004 | Unauthorized operation. | 8673 8674**示例:** 8675 8676```ts 8677// EntryAbility.ets 8678import { UIAbility } from '@kit.AbilityKit'; 8679import { BusinessError } from '@kit.BasicServicesKit'; 8680import { window } from '@kit.ArkUI'; 8681 8682export default class EntryAbility extends UIAbility { 8683 // ... 8684 onWindowStageCreate(windowStage: window.WindowStage): void { 8685 console.info('onWindowStageCreate'); 8686 let windowClass: window.Window | undefined = undefined; 8687 windowStage.getMainWindow((err: BusinessError, data) => { 8688 const errCode: number = err.code; 8689 if (errCode) { 8690 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8691 return; 8692 } 8693 windowClass = data; 8694 8695 // 设置当前窗口禁用返回手势功能 8696 try { 8697 let gestureBackEnabled: boolean = false; 8698 let promise = windowClass.setGestureBackEnabled(gestureBackEnabled); 8699 promise.then(() => { 8700 console.info(`Succeeded in setting gesture back disabled`); 8701 }).catch((err: BusinessError) => { 8702 console.error(`Failed to set gesture back disabled, Cause code: ${err.code}, message: ${err.message}`); 8703 }); 8704 } catch(exception) { 8705 console.error(`Failed to set gesture back disabled, Cause code: ${exception.code}, message: ${exception.message}`); 8706 } 8707 }); 8708 } 8709} 8710``` 8711 8712### isGestureBackEnabled<sup>13+<sup> 8713 8714isGestureBackEnabled(): boolean 8715 8716获取当前窗口是否禁用返回手势功能,仅主窗全屏模式下生效,2in1设备不生效。 8717 8718**系统能力:** SystemCapability.Window.SessionManager 8719 8720**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 8721 8722**返回值:** 8723 8724| 类型 | 说明 | 8725| ------------------- | --------------------------------------------- | 8726| boolean | 是否已经禁用返回手势。true表示未禁用返回手势功能,false表示已禁用返回手势功能。 | 8727 8728**错误码:** 8729 8730以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8731 8732| 错误码ID | 错误信息 | 8733| -------- | ------------------------------------------------------------------------------------------------------------ | 8734| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8735| 1300002 | This window state is abnormal. | 8736| 1300003 | This window manager service works abnormally. | 8737| 1300004 | Unauthorized operation. | 8738 8739**示例:** 8740 8741```ts 8742// EntryAbility.ets 8743import { UIAbility } from '@kit.AbilityKit'; 8744import { BusinessError } from '@kit.BasicServicesKit'; 8745import { window } from '@kit.ArkUI'; 8746 8747export default class EntryAbility extends UIAbility { 8748 // ... 8749 onWindowStageCreate(windowStage: window.WindowStage): void { 8750 console.info('onWindowStageCreate'); 8751 let windowClass: window.Window | undefined = undefined; 8752 windowStage.getMainWindow((err: BusinessError, data) => { 8753 const errCode: number = err.code; 8754 if (errCode) { 8755 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 8756 return; 8757 } 8758 windowClass = data; 8759 8760 // 获取当前窗口是否禁用返回手势功能 8761 try { 8762 let gestureBackEnabled: boolean = windowClass.isGestureBackEnabled(); 8763 console.info(`Succeeded in obtaining gesture back enabled status: ${gestureBackEnabled}`); 8764 } catch (exception) { 8765 console.error(`Failed to get gesture back enabled status. Cause code: ${exception.code}, message: ${exception.message}`); 8766 } 8767 }); 8768 } 8769} 8770``` 8771 8772### setWindowShadowRadius<sup>17+</sup> 8773 8774setWindowShadowRadius(radius: number): void 8775 8776设置子窗或悬浮窗窗口边缘阴影的模糊半径,此接口仅支持在2in1设备或平板设备上使用。 8777 8778**系统能力:** SystemCapability.Window.SessionManager 8779 8780**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。 8781 8782**参数:** 8783 8784| 参数名 | 类型 | 必填 | 说明 | 8785| ------- | ------ | ---- |-------------------------------------------------------------| 8786| radius | number | 是 | 表示窗口边缘阴影的模糊半径。该参数为浮点数,单位为px,取值范围为[0.0, +∞),取值为0.0时表示关闭窗口边缘阴影。 | 8787 8788**错误码:** 8789 8790以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8791 8792| 错误码ID | 错误信息 | 8793| ------- | ------------------------------ | 8794| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8795| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8796| 1300002 | This window state is abnormal. | 8797| 1300004 | Unauthorized operation. | 8798 8799**示例:** 8800 8801```ts 8802try { 8803 windowClass.setWindowShadowRadius(4.0); 8804} catch (exception) { 8805 console.error(`Failed to set shadow. Cause code: ${exception.code}, message: ${exception.message}`); 8806} 8807``` 8808 8809### setWindowCornerRadius<sup>17+</sup> 8810 8811setWindowCornerRadius(cornerRadius: number): Promise<void> 8812 8813设置子窗或悬浮窗的圆角半径值,使用Promise异步回调。 8814 8815<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 8816 8817圆角半径值过大将会导致三键(最大化、最小化、关闭按钮)位置被裁切,且会导致热区不易识别,请根据窗口大小设置合适的圆角半径值。 8818 8819在调用此接口之前调用[getWindowCornerRadius()](#getwindowcornerradius17)接口可以获得窗口默认圆角半径值。 8820 8821**系统能力**:SystemCapability.Window.SessionManager 8822 8823**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。 8824 8825**参数:** 8826 8827| 参数名 | 类型 | 必填 | 说明 | 8828| ----------- | ------- | ---- |----------------------------------------------------| 8829| cornerRadius | number | 是 | 表示窗口圆角的半径值。该参数为浮点数,单位为vp,取值范围为[0.0, +∞),取值为0.0时表示没有窗口圆角。 | 8830 8831**返回值:** 8832 8833| 类型 | 说明 | 8834| ---------------------- | ------------------------------------------------------------------------------------ | 8835| Promise<void> | 无返回结果的Promise对象。 | 8836 8837**错误码:** 8838 8839以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8840 8841| 错误码ID | 错误信息 | 8842| ------- | ------------------------------ | 8843| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8844| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8845| 1300002 | This window state is abnormal. | 8846| 1300003 | This window manager service works abnormally. | 8847| 1300004 | Unauthorized operation. | 8848 8849**示例:** 8850 8851```ts 8852import { BusinessError } from '@kit.BasicServicesKit'; 8853 8854try{ 8855 let promise = windowClass.setWindowCornerRadius(1.0); 8856 promise.then(() => { 8857 console.info('Succeeded in setting window corner radius.'); 8858 }).catch((err: BusinessError) => { 8859 console.error(`Failed to set window corner radius. Cause code: ${err.code}, message: ${err.message}`); 8860 }); 8861} catch (exception) { 8862 console.error(`Failed to set corner radius. Cause code: ${exception.code}, message: ${exception.message}`); 8863} 8864 8865``` 8866 8867### getWindowCornerRadius<sup>17+</sup> 8868 8869getWindowCornerRadius(): number 8870 8871获取子窗或悬浮窗的圆角半径值,在未调用[setWindowCornerRadius()](#setwindowcornerradius17)接口设置窗口圆角半径值之前,调用此接口可获取窗口默认圆角半径值。 8872 8873<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 8874 8875**系统能力**:SystemCapability.Window.SessionManager 8876 8877**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。 8878 8879**返回值:** 8880 8881| 类型 | 说明 | 8882| ---------------------- | ------------------------------------------------------------------------------------ | 8883| number | 当前子窗或悬浮窗的圆角半径值,单位为vp。 | 8884 8885**错误码:** 8886 8887以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8888 8889| 错误码ID | 错误信息 | 8890| ------- | ------------------------------ | 8891| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8892| 1300002 | This window state is abnormal. | 8893| 1300004 | Unauthorized operation. | 8894 8895**示例:** 8896 8897```ts 8898try { 8899 let cornerRadius = windowClass.getWindowCornerRadius(); 8900} catch (exception) { 8901 console.error(`Failed to get corner radius. Cause code: ${exception.code}, message: ${exception.message}`); 8902} 8903``` 8904 8905### setExclusivelyHighlighted<sup>15+<sup> 8906 8907setExclusivelyHighlighted(exclusivelyHighlighted: boolean): Promise<void> 8908 8909设置窗口独占激活态属性。独占激活态表示窗口获焦时,会导致当前父子窗口链中处于激活态的其他窗口失去激活态。使用Promise异步回调。 8910 8911此接口对主窗、模态窗、dialog窗口不生效。 8912 8913**系统能力:** SystemCapability.Window.SessionManager 8914 8915**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 8916 8917**参数:** 8918 8919| 参数名 | 类型 | 必填 | 说明 | 8920| ----------- | ------- | -- | -------------------------------------------------------- | 8921| exclusivelyHighlighted | boolean | 是 | 窗口是否独占激活态。true表示独占激活态;false表示不独占激活态。 | 8922 8923**返回值:** 8924 8925| 类型 | 说明 | 8926| ---------------------- | ------------------------------------------------------------------------------------ | 8927| Promise<void> | 无返回结果的Promise对象。 | 8928 8929**错误码:** 8930 8931以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8932 8933| 错误码ID | 错误信息 | 8934| -------- | ------------------------------------------------------------------------------------------------------------ | 8935| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8936| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8937| 1300002 | This window state is abnormal. | 8938| 1300003 | This window manager service works abnormally. | 8939| 1300004 | Unauthorized operation. | 8940 8941**示例:** 8942 8943```ts 8944import { BusinessError } from '@kit.BasicServicesKit'; 8945 8946let exclusivelyHighlighted: boolean = true; 8947try { 8948 let promise = windowClass.setExclusivelyHighlighted(exclusivelyHighlighted); 8949 promise.then(() => { 8950 console.info('Succeeded in setting the window to be exclusively highlight.'); 8951 }).catch((err: BusinessError) => { 8952 console.error(`Failed to set the window to be exclusively highlight. Cause code: ${err.code}, message: ${err.message}`); 8953 }); 8954} catch (exception) { 8955 console.error(`Failed to set the window to be exclusively highlight. Cause code: ${exception.code}, message: ${exception.message}`); 8956} 8957``` 8958 8959### isWindowHighlighted<sup>18+<sup> 8960 8961isWindowHighlighted(): boolean 8962 8963获取当前窗口是否为激活态。为准确获取激活态,需要在[WindowEventType](#windoweventtype10)生命周期处于WINDOW_ACTIVE之后调用。 8964 8965可使用[on('windowHighlightChange')](#onwindowhighlightchange15)监听对应状态变更,再执行对应具体业务。 8966 8967**系统能力:** SystemCapability.Window.SessionManager 8968 8969**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 8970 8971**返回值:** 8972 8973| 类型 | 说明 | 8974| ------------------- | --------------------------------------------- | 8975| boolean | 当前窗口是否为激活态。true表示当前窗口为激活态,false表示当前窗口非激活态。 | 8976 8977**错误码:** 8978 8979以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 8980 8981| 错误码ID | 错误信息 | 8982| -------- | ------------------------------------------------------------------------------------------------------------ | 8983| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 8984| 1300002 | This window state is abnormal. | 8985 8986**示例:** 8987 8988```ts 8989import { BusinessError } from '@kit.BasicServicesKit'; 8990 8991try { 8992 let isHighlighted = windowClass.isWindowHighlighted(); 8993 console.info(`Succeeded in getting the window highlight status: ${isHighlighted}`); 8994} catch (exception) { 8995 console.error(`Failed to get the window highlight status.. Cause code: ${exception.code}, message: ${exception.message}`); 8996} 8997``` 8998 8999### setFollowParentMultiScreenPolicy<sup>17+<sup> 9000 9001setFollowParentMultiScreenPolicy(enabled: boolean): Promise<void> 9002 9003设置子窗口在其父窗口处于拖拽移动或拖拽缩放过程时,该子窗口是否支持跨多个屏幕同时显示。使用Promise异步回调。 9004 9005通过监听父窗口大小位置变化,对子窗口调用[moveWindowTo()](#movewindowto9)等接口实现子窗口跟随父窗口布局时,此时子窗口默认不支持跨多个屏幕同时显示。 9006 9007对子窗口调用此接口后可以使能子窗口在跟随父窗口布局过程中跨多个屏幕同时显示。 9008 9009<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 9010 9011**系统能力:** SystemCapability.Window.SessionManager 9012 9013**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。 9014 9015**参数:** 9016 9017| 参数名 | 类型 | 必填 | 说明 | 9018| ----------- | ------- | -- | -------------------------------------------------------- | 9019| enabled | boolean | 是 | 设置子窗口在其父窗口处于拖拽移动或拖拽缩放过程时,该子窗口是否支持跨多个屏幕同时显示。true表示支持;false表示不支持。 | 9020 9021**返回值:** 9022 9023| 类型 | 说明 | 9024| ---------------------- | ------------------------------------------------------------------------------------ | 9025| Promise<void> | 无返回结果的Promise对象。 | 9026 9027**错误码:** 9028 9029以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 9030 9031| 错误码ID | 错误信息 | 9032| -------- | ------------------------------------------------------------------------------------------------------------ | 9033| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9034| 801 | Capability not supported.Function setFollowParentMultiScreenPolicy can not work correctly due to limited device capabilities.| 9035| 1300002 | This window state is abnormal. | 9036| 1300003 | This window manager service works abnormally. | 9037| 1300004 | Unauthorized operation. | 9038 9039**示例:** 9040 9041```ts 9042import { BusinessError } from '@kit.BasicServicesKit'; 9043 9044try { 9045 let windowClass: window.Window = window.findWindow("subWindow"); 9046 let enabled: boolean = true; 9047 let promise = windowClass?.setFollowParentMultiScreenPolicy(enabled); 9048 promise.then(() => { 9049 console.info('Succeeded in setting the sub window supports multi-screen simultaneous display') 9050 }).catch((err: BusinessError) => { 9051 console.error(`Failed to set the sub window supports multi-screen simultaneous display. Cause code: ${err.code}, message: ${err.message}`); 9052 }); 9053} catch (exception) { 9054 console.error(`Failed to set the sub window supports multi-screen simultaneous display. Cause code: ${exception.code}, message: ${exception.message}`); 9055} 9056``` 9057 9058### setFollowParentWindowLayoutEnabled<sup>17+</sup> 9059 9060setFollowParentWindowLayoutEnabled(enabled: boolean): Promise<void> 9061 9062设置子窗或模态窗口(即WindowType为TYPE_DIALOG的窗口)的布局信息(position和size)是否跟随主窗,使用Promise异步回调。 9063 90641、只支持主窗的一级子窗或模态窗口使用该接口。 9065 90662、当子窗或模态窗口调用该接口后,立即使其布局信息与主窗完全一致并保持,除非传入false再次调用该接口,否则效果将持续。 9067 90683、当子窗或模态窗口调用该接口后,再调用moveTo、resize等修改布局信息的接口将不生效。 9069 90704、当子窗或模态窗口不再使用该功能后,不保证子窗或模态窗口的布局信息(position和size)为确定的值,需要应用重新进行设置。 9071 9072**模型约束:** 此接口仅可在Stage模型下使用。 9073 9074**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。 9075 9076**系统能力:** SystemCapability.Window.SessionManager 9077 9078**参数:** 9079 9080| 参数名 | 类型 | 必填 | 说明 | 9081| --- | --- | --- | --- | 9082| enabled | boolean | 是 | 设置是否启用跟随主窗布局。true表示启用,false表示不启用。| 9083 9084**返回值:** 9085 9086| 类型 | 说明 | 9087| --- | --- | 9088| Promise<void> | 无返回结果的Promise对象。 | 9089 9090**错误码:** 9091 9092以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 9093 9094| 错误码ID | 错误信息 | 9095| --- | --- | 9096| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9097| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 9098| 1300002 | This window state is abnormal. | 9099| 1300003 | This window manager service works abnormally. | 9100| 1300004 | Unauthorized operation. | 9101 9102**示例:** 9103```ts 9104// EntryAbility.ets 9105import { window } from '@kit.ArkUI'; 9106import { BusinessError } from '@kit.BasicServicesKit'; 9107import { UIAbility } from '@kit.AbilityKit'; 9108 9109export default class EntryAbility extends UIAbility { 9110 onWindowStageCreate(windowStage: window.WindowStage): void { 9111 windowStage.loadContent('pages/Index', (loadError) => { 9112 if (loadError.code) { 9113 console.error(`Failed to load the content. Cause code: ${loadError.code}, message: ${loadError.message}`); 9114 return; 9115 } 9116 console.info("Succeeded in loading the content."); 9117 windowStage.createSubWindow("subWindow").then((subWindow: window.Window) => { 9118 if (subWindow == null) { 9119 console.error("Failed to create the subWindow. Cause: The data is empty"); 9120 return; 9121 } 9122 subWindow.setFollowParentWindowLayoutEnabled(true).then(() => { 9123 console.info("after set follow parent window layout") 9124 }).catch((error: BusinessError) => { 9125 console.error(`setFollowParentWindowLayoutEnabled failed. ${error.code} ${error.message}`); 9126 }) 9127 }).catch((error: BusinessError) => { 9128 console.error(`createSubWindow failed. ${error.code} ${error.message}`); 9129 }) 9130 }); 9131 } 9132} 9133``` 9134 9135### setWindowSystemBarProperties<sup>(deprecated)</sup> 9136 9137setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 9138 9139设置主窗口三键导航栏、状态栏的属性,使用callback异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 9140 9141子窗口调用后不生效。 9142 9143> **说明:** 9144> 9145> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowSystemBarProperties](#setwindowsystembarproperties9)。 9146 9147**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9148 9149**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 9150 9151**参数:** 9152 9153| 参数名 | 类型 | 必填 | 说明 | 9154| ------------------- | ------------------------------------------- | ---- | ---------------------- | 9155| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 三键导航栏、状态栏的属性。 | 9156| callback | AsyncCallback<void> | 是 | 回调函数。 | 9157 9158**错误码:** 9159 9160以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 9161 9162| 错误码ID | 错误信息 | 9163| -------- | ------------------------------------------------------------------------------------------------------------ | 9164| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9165| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 9166| 1300002 | This window state is abnormal. | 9167| 1300003 | This window manager service works abnormally. | 9168 9169**示例:** 9170 9171```ts 9172// EntryAbility.ets 9173import { UIAbility } from '@kit.AbilityKit'; 9174import { BusinessError } from '@kit.BasicServicesKit'; 9175 9176export default class EntryAbility extends UIAbility { 9177 // ... 9178 onWindowStageCreate(windowStage: window.WindowStage): void { 9179 console.info('onWindowStageCreate'); 9180 let windowClass: window.Window | undefined = undefined; 9181 windowStage.getMainWindow((err: BusinessError, data) => { 9182 const errCode: number = err.code; 9183 if (errCode) { 9184 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9185 return; 9186 } 9187 windowClass = data; 9188 let SystemBarProperties: window.SystemBarProperties = { 9189 statusBarColor: '#ff00ff', 9190 navigationBarColor: '#00ff00', 9191 //以下两个属性从API Version8开始支持 9192 statusBarContentColor: '#ffffff', 9193 navigationBarContentColor: '#00ffff' 9194 }; 9195 try { 9196 windowClass.setWindowSystemBarProperties(SystemBarProperties, (err: BusinessError) => { 9197 const errCode: number = err.code; 9198 if (errCode) { 9199 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 9200 return; 9201 } 9202 console.info('Succeeded in setting the system bar properties.'); 9203 }); 9204 } catch (exception) { 9205 console.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); 9206 } 9207 }); 9208 } 9209} 9210``` 9211 9212### setSubWindowZLevel<sup>18+</sup> 9213 9214setSubWindowZLevel(zLevel: number): Promise<void> 9215 9216设置当前子窗口层级级别,设置了模态属性的子窗不支持。使用Promise异步回调。 9217 9218通过该接口改变子窗口的显示层级时,不会发生焦点切换。推荐使用[shiftAppWindowFocus()](#windowshiftappwindowfocus11)进行焦点切换。 9219 9220**系统能力:** SystemCapability.Window.SessionManager 9221 9222**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 9223 9224**参数:** 9225 9226| 参数名 | 类型 | 必填 | 说明 | 9227| :----------- | :---------------------------- | :--- | :----------------------------- | 9228| zLevel | number | 是 | 子窗口层级级别。默认值为0,取值范围为[-10000, 10000],该参数仅支持整数输入,浮点数输入将向下取整。 | 9229 9230**返回值:** 9231 9232| 类型 | 说明 | 9233| ------------------- | ------------------------- | 9234| Promise<void> | 无返回结果的Promise对象。 | 9235 9236**错误码:** 9237 9238以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 9239 9240| 错误码ID | 错误信息 | 9241| ------- | --------------------------------------------- | 9242| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 3. Parameter verification failed.| 9243| 801 | Capability not supported. Function setSubWindowZLevel can not work correctly due to limited device capabilities. | 9244| 1300002 | This window state is abnormal. | 9245| 1300003 | This window manager service works abnormally. | 9246| 1300004 | Unauthorized operation. | 9247| 1300009 | The parent window is invalid. | 9248 9249**示例:** 9250 9251```ts 9252// EntryAbility.ets 9253import { window } from '@kit.ArkUI'; 9254import { UIAbility } from '@kit.AbilityKit'; 9255import { BusinessError } from '@kit.BasicServicesKit'; 9256 9257export default class EntryAbility extends UIAbility { 9258 // ... 9259 onWindowStageCreate(windowStage: window.WindowStage): void { 9260 console.info('onWindowStageCreate'); 9261 // 创建子窗 9262 try { 9263 let subWindowPromise = windowStage.createSubWindow('testSubWindow'); 9264 subWindowPromise.then((subWindow) => { 9265 if (subWindow == null) { 9266 console.error('Failed to create the sub window. Cause: The sub window is null'); 9267 return; 9268 } 9269 let zLevelPromise = subWindow.setSubWindowZLevel(1); 9270 zLevelPromise.then(() => { 9271 console.info('Succeeded in setting sub window zLevel.'); 9272 }).catch((err: BusinessError) => { 9273 console.error(`Failed to set sub window zLevel. Cause code: ${err.code}, message: ${err.message}`); 9274 }); 9275 }); 9276 } catch (err) { 9277 console.error(`Failed to create the sub window. Cause code: ${err.code}, message: ${err.message}`); 9278 } 9279 } 9280} 9281``` 9282 9283### getSubWindowZLevel<sup>18+</sup> 9284 9285getSubWindowZLevel(): number 9286 9287获取当前子窗口层级级别。不支持主窗、系统窗调用。 9288 9289**系统能力:** SystemCapability.Window.SessionManager 9290 9291**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 9292 9293**返回值:** 9294 9295| 类型 | 说明 | 9296| ------------------- | --------------------------------------------- | 9297| number | 当前子窗口层级级别。 | 9298 9299**错误码:** 9300 9301以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 9302 9303| 错误码ID | 错误信息 | 9304| -------- | ------------------------------------------------------------------------------------------------------------ | 9305| 801 | Capability not supported. Function getSubWindowZLevel can not work correctly due to limited device capabilities. | 9306| 1300002 | This window state is abnormal. | 9307| 1300004 | Unauthorized operation. | 9308 9309**示例:** 9310 9311```ts 9312// EntryAbility.ets 9313import { window } from '@kit.ArkUI'; 9314import { UIAbility } from '@kit.AbilityKit'; 9315 9316export default class EntryAbility extends UIAbility { 9317 // ... 9318 onWindowStageCreate(windowStage: window.WindowStage): void { 9319 console.info('onWindowStageCreate'); 9320 // 创建子窗 9321 try { 9322 let subWindowPromise = windowStage.createSubWindow('testSubWindow'); 9323 subWindowPromise.then((subWindow) => { 9324 if (subWindow == null) { 9325 console.error('Failed to create the sub window. Cause: The sub window is null'); 9326 return; 9327 } 9328 try { 9329 let subWindowZLevel = subWindow.getSubWindowZLevel(); 9330 console.info(`Succeeded in getting sub window zLevel: ${subWindowZLevel}`); 9331 } catch (err) { 9332 console.error(`Failed to get sub window zLevel. Cause code: ${err.code}, message: ${err.message}`); 9333 } 9334 }); 9335 } catch (err) { 9336 console.error(`Failed to create the sub window. Cause code: ${err.code}, message: ${err.message}`); 9337 } 9338 } 9339} 9340``` 9341 9342### setWindowSystemBarEnable<sup>(deprecated)</sup> 9343 9344setWindowSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 9345 9346设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用callback异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 9347 9348调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。非全屏模式(悬浮窗、分屏等场景)下配置不生效。 9349 9350> **说明:** 9351> 9352> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowSystemBarEnable](#setwindowsystembarenable9)。 9353 9354**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 9355 9356**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9357 9358**参数:** 9359 9360| 参数名 | 类型 | 必填 | 说明 | 9361| -------- | ----------------------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------- | 9362| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 9363| callback | AsyncCallback<void> | 是 | 回调函数。 | 9364 9365**错误码:** 9366 9367以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 9368 9369| 错误码ID | 错误信息 | 9370| -------- | ------------------------------------------------------------------------------------------------------------ | 9371| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9372| 1300002 | This window state is abnormal. | 9373| 1300003 | This window manager service works abnormally. | 9374 9375**示例:** 9376 9377```ts 9378// 此处以不显示三键导航栏、状态栏、底部导航条为例 9379// EntryAbility.ets 9380import { UIAbility } from '@kit.AbilityKit'; 9381import { BusinessError } from '@kit.BasicServicesKit'; 9382 9383export default class EntryAbility extends UIAbility { 9384 // ... 9385 onWindowStageCreate(windowStage: window.WindowStage): void { 9386 console.info('onWindowStageCreate'); 9387 let windowClass: window.Window | undefined = undefined; 9388 windowStage.getMainWindow((err: BusinessError, data) => { 9389 const errCode: number = err.code; 9390 if (errCode) { 9391 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9392 return; 9393 } 9394 windowClass = data; 9395 let names: Array<'status' | 'navigation'> = []; 9396 try { 9397 windowClass.setWindowSystemBarEnable(names, (err: BusinessError) => { 9398 const errCode: number = err.code; 9399 if (errCode) { 9400 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 9401 return; 9402 } 9403 console.info('Succeeded in setting the system bar to be invisible.'); 9404 }); 9405 } catch (exception) { 9406 console.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); 9407 } 9408 }); 9409 } 9410} 9411``` 9412 9413### setWindowLayoutFullScreen<sup>(deprecated)</sup> 9414 9415setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 9416 9417设置主窗口或子窗口的布局是否为沉浸式布局,使用callback异步回调。 9418沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 9419非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 9420 9421> **说明:** 9422> 9423> 从API version 9开始支持,从API version 12开始废弃,推荐使用Promise方式的[setWindowLayoutFullScreen](#setwindowlayoutfullscreen9)。 9424 9425**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9426 9427**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 9428 9429**参数:** 9430 9431| 参数名 | 类型 | 必填 | 说明 | 9432| ------------------ | ------------------------- | ---- | ------------------------------------------------------------------------------------------------------------- | 9433| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 9434| callback | AsyncCallback<void> | 是 | 回调函数。 | 9435 9436**错误码:** 9437 9438以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 9439 9440| 错误码ID | 错误信息 | 9441| -------- | ------------------------------------------------------------------------------------------------------------ | 9442| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9443| 1300002 | This window state is abnormal. | 9444| 1300003 | This window manager service works abnormally. | 9445 9446**示例:** 9447 9448```ts 9449// EntryAbility.ets 9450import { UIAbility } from '@kit.AbilityKit'; 9451import { BusinessError } from '@kit.BasicServicesKit'; 9452 9453export default class EntryAbility extends UIAbility { 9454 // ... 9455 onWindowStageCreate(windowStage: window.WindowStage): void { 9456 console.info('onWindowStageCreate'); 9457 let windowClass: window.Window | undefined = undefined; 9458 windowStage.getMainWindow((err: BusinessError, data) => { 9459 const errCode: number = err.code; 9460 if (errCode) { 9461 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9462 return; 9463 } 9464 windowClass = data; 9465 let isLayoutFullScreen = true; 9466 try { 9467 windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 9468 const errCode: number = err.code; 9469 if (errCode) { 9470 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 9471 return; 9472 } 9473 console.info('Succeeded in setting the window layout to full-screen mode.'); 9474 }); 9475 } catch (exception) { 9476 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`); 9477 } 9478 }); 9479 } 9480} 9481``` 9482 9483### show<sup>(deprecated)</sup> 9484 9485show(callback: AsyncCallback<void>): void 9486 9487显示当前窗口,使用callback异步回调。 9488 9489> **说明:** 9490> 9491> 从API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9)。 9492 9493**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9494 9495**参数:** 9496 9497| 参数名 | 类型 | 必填 | 说明 | 9498| -------- | ------------------------- | ---- | ---------- | 9499| callback | AsyncCallback<void> | 是 | 回调函数。 | 9500 9501**示例:** 9502 9503```ts 9504import { BusinessError } from '@kit.BasicServicesKit'; 9505 9506windowClass.show((err: BusinessError) => { 9507 const errCode: number = err.code; 9508 if (errCode) { 9509 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 9510 return; 9511 } 9512 console.info('Succeeded in showing the window.'); 9513}); 9514``` 9515 9516### show<sup>(deprecated)</sup> 9517 9518show(): Promise<void> 9519 9520显示当前窗口,使用Promise异步回调。 9521 9522> **说明:** 9523> 9524> 从API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9-1)。 9525 9526**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9527 9528**返回值:** 9529 9530| 类型 | 说明 | 9531| ------------------- | ------------------------- | 9532| Promise<void> | 无返回结果的Promise对象。 | 9533 9534**示例:** 9535 9536```ts 9537import { BusinessError } from '@kit.BasicServicesKit'; 9538 9539let promise = windowClass.show(); 9540promise.then(() => { 9541 console.info('Succeeded in showing the window.'); 9542}).catch((err: BusinessError) => { 9543 console.error(`Failed to show the window. Cause code: ${err.code}, message: ${err.message}`); 9544}); 9545``` 9546 9547### destroy<sup>(deprecated)</sup> 9548 9549destroy(callback: AsyncCallback<void>): void 9550 9551销毁当前窗口,使用callback异步回调。 9552 9553> **说明:** 9554> 9555> 从API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9)。 9556 9557**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9558 9559**参数:** 9560 9561| 参数名 | 类型 | 必填 | 说明 | 9562| -------- | ------------------------- | ---- | ---------- | 9563| callback | AsyncCallback<void> | 是 | 回调函数。 | 9564 9565**示例:** 9566 9567```ts 9568import { BusinessError } from '@kit.BasicServicesKit'; 9569 9570windowClass.destroy((err: BusinessError) => { 9571 const errCode: number = err.code; 9572 if (err.code) { 9573 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 9574 return; 9575 } 9576 console.info('Succeeded in destroying the window.'); 9577}); 9578``` 9579 9580### destroy<sup>(deprecated)</sup> 9581 9582destroy(): Promise<void> 9583 9584销毁当前窗口,使用Promise异步回调。 9585 9586> **说明:** 9587> 9588> 从API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9-1)。 9589 9590**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9591 9592**返回值:** 9593 9594| 类型 | 说明 | 9595| ------------------- | ------------------------- | 9596| Promise<void> | 无返回结果的Promise对象。 | 9597 9598**示例:** 9599 9600```ts 9601import { BusinessError } from '@kit.BasicServicesKit'; 9602 9603let promise = windowClass.destroy(); 9604promise.then(() => { 9605 console.info('Succeeded in destroying the window.'); 9606}).catch((err: BusinessError) => { 9607 console.error(`Failed to destroy the window. Cause code: ${err.code}, message: ${err.message}`); 9608}); 9609``` 9610 9611### moveTo<sup>(deprecated)</sup> 9612 9613moveTo(x: number, y: number, callback: AsyncCallback<void>): void 9614 9615移动窗口位置,使用callback异步回调。 9616 9617全屏模式窗口不支持该操作。 9618 9619> **说明:** 9620> 9621> 从API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9)。 9622 9623**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9624 9625**参数:** 9626 9627| 参数名 | 类型 | 必填 | 说明 | 9628| -------- | ------------------------- | ---- | ------------------------------------------------- | 9629| x | number | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 9630| y | number | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 9631| callback | AsyncCallback<void> | 是 | 回调函数。 | 9632 9633**示例:** 9634 9635```ts 9636import { BusinessError } from '@kit.BasicServicesKit'; 9637 9638windowClass.moveTo(300, 300, (err: BusinessError) => { 9639 const errCode: number = err.code; 9640 if (errCode) { 9641 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 9642 return; 9643 } 9644 console.info('Succeeded in moving the window.'); 9645}); 9646``` 9647 9648### moveTo<sup>(deprecated)</sup> 9649 9650moveTo(x: number, y: number): Promise<void> 9651 9652移动窗口位置,使用Promise异步回调。 9653 9654全屏模式窗口不支持该操作。 9655 9656> **说明:** 9657> 9658> 从API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9-1)。 9659 9660**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9661 9662**参数:** 9663 9664| 参数名 | 类型 | 必填 | 说明 | 9665| ------ | ------ | ---- | ------------------------------------------------- | 9666| x | number | 是 | 窗口在x轴方向移动到的坐标位置,单位为px,值为正表示位置在x轴右侧;值为负表示位置在x轴左侧;值为0表示位置在x轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 9667| y | number | 是 | 窗口在y轴方向移动到的坐标位置,单位为px,值为正表示位置在y轴下侧;值为负表示位置在y轴上侧;值为0表示位置在y轴坐标原点。该参数仅支持整数输入,浮点数输入将向下取整。 | 9668 9669**返回值:** 9670 9671| 类型 | 说明 | 9672| ------------------- | ------------------------- | 9673| Promise<void> | 无返回结果的Promise对象。 | 9674 9675**示例:** 9676 9677```ts 9678import { BusinessError } from '@kit.BasicServicesKit'; 9679 9680let promise = windowClass.moveTo(300, 300); 9681promise.then(() => { 9682 console.info('Succeeded in moving the window.'); 9683}).catch((err: BusinessError) => { 9684 console.error(`Failed to move the window. Cause code: ${err.code}, message: ${err.message}`); 9685}); 9686``` 9687 9688### resetSize<sup>(deprecated)</sup> 9689 9690resetSize(width: number, height: number, callback: AsyncCallback<void>): void 9691 9692改变当前窗口大小,使用callback异步回调。 9693 9694应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 9695应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 9696 9697系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 9698 9699设置的宽度与高度受到此约束限制,规则: 9700若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 9701若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 9702 9703全屏模式窗口不支持该操作。 9704 9705> **说明:** 9706> 9707> 从API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9)。 9708 9709**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9710 9711**参数:** 9712 9713| 参数名 | 类型 | 必填 | 说明 | 9714| -------- | ------------------------- | ---- | -------------------------- | 9715| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 9716| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 9717| callback | AsyncCallback<void> | 是 | 回调函数。 | 9718 9719**示例:** 9720 9721```ts 9722import { BusinessError } from '@kit.BasicServicesKit'; 9723 9724windowClass.resetSize(500, 1000, (err: BusinessError) => { 9725 const errCode: number = err.code; 9726 if (errCode) { 9727 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 9728 return; 9729 } 9730 console.info('Succeeded in changing the window size.'); 9731}); 9732``` 9733 9734### resetSize<sup>(deprecated)</sup> 9735 9736resetSize(width: number, height: number): Promise<void> 9737 9738改变当前窗口大小,使用Promise异步回调。 9739 9740应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 1920],默认高度范围:[240, 1920],单位为vp。 9741应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准,具体尺寸限制范围可以通过[getWindowLimits](#getwindowlimits11)接口进行查询。 9742 9743系统窗口存在大小限制,宽度范围:(0, 1920],高度范围:(0, 1920],单位为vp。 9744 9745设置的宽度与高度受到此约束限制,规则: 9746若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 9747若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 9748 9749全屏模式窗口不支持该操作。 9750 9751> **说明:** 9752> 9753> 从API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9-1)。 9754 9755**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9756 9757**参数:** 9758 9759| 参数名 | 类型 | 必填 | 说明 | 9760| ------ | ------ | ---- | -------------------------- | 9761| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 9762| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入,浮点数输入将向下取整,负值为非法参数。 | 9763 9764**返回值:** 9765 9766| 类型 | 说明 | 9767| ------------------- | ------------------------- | 9768| Promise<void> | 无返回结果的Promise对象。 | 9769 9770**示例:** 9771 9772```ts 9773import { BusinessError } from '@kit.BasicServicesKit'; 9774 9775let promise = windowClass.resetSize(500, 1000); 9776promise.then(() => { 9777 console.info('Succeeded in changing the window size.'); 9778}).catch((err: BusinessError) => { 9779 console.error(`Failed to change the window size. Cause code: ${err.code}, message: ${err.message}`); 9780}); 9781``` 9782 9783### getProperties<sup>(deprecated)</sup> 9784 9785getProperties(callback: AsyncCallback<WindowProperties>): void 9786 9787获取当前窗口的属性,使用callback异步回调,返回WindowProperties。 9788 9789> **说明:** 9790> 9791> 从API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。 9792 9793**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9794 9795**参数:** 9796 9797| 参数名 | 类型 | 必填 | 说明 | 9798| -------- | ---------------------------------------------------------- | ---- | ---------------------------- | 9799| callback | AsyncCallback<[WindowProperties](#windowproperties)> | 是 | 回调函数。返回当前窗口属性。 | 9800 9801**示例:** 9802 9803```ts 9804import { BusinessError } from '@kit.BasicServicesKit'; 9805 9806windowClass.getProperties((err: BusinessError, data) => { 9807 const errCode: number = err.code; 9808 if (errCode) { 9809 console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`); 9810 return; 9811 } 9812 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 9813}); 9814``` 9815 9816### getProperties<sup>(deprecated)</sup> 9817 9818getProperties(): Promise<WindowProperties> 9819 9820获取当前窗口的属性,使用Promise异步回调,返回WindowProperties。 9821 9822> **说明:** 9823> 9824> 从API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。 9825 9826**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9827 9828**返回值:** 9829 9830| 类型 | 说明 | 9831| ---------------------------------------------------- | ------------------------------- | 9832| Promise<[WindowProperties](#windowproperties)> | Promise对象。返回当前窗口属性。 | 9833 9834**示例:** 9835 9836```ts 9837import { BusinessError } from '@kit.BasicServicesKit'; 9838 9839let promise = windowClass.getProperties(); 9840promise.then((data) => { 9841 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 9842}).catch((err: BusinessError) => { 9843 console.error(`Failed to obtain the window properties. Cause code: ${err.code}, message: ${err.message}`); 9844}); 9845``` 9846 9847### getAvoidArea<sup>(deprecated)</sup> 9848 9849getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback<[AvoidArea](#avoidarea7)>): void 9850 9851获取当前窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 9852 9853> **说明:** 9854> 9855> 从API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。 9856 9857**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9858 9859**参数:** 9860 9861| 参数名 | 类型 | 必填 | 说明 | 9862| -------- |-----------------------------------------------| ---- | ------------------------------------------------------------ | 9863| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。| 9864| callback | AsyncCallback<[AvoidArea](#avoidarea7)> | 是 | 回调函数。返回窗口内容规避区域。 | 9865 9866**示例:** 9867 9868```ts 9869import { BusinessError } from '@kit.BasicServicesKit'; 9870 9871let type = window.AvoidAreaType.TYPE_SYSTEM; 9872windowClass.getAvoidArea(type, (err: BusinessError, data) => { 9873 const errCode: number = err.code; 9874 if (errCode) { 9875 console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`); 9876 return; 9877 } 9878 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 9879}); 9880``` 9881 9882### getAvoidArea<sup>(deprecated)</sup> 9883 9884getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise<[AvoidArea](#avoidarea7)> 9885 9886获取当前窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 9887 9888> **说明:** 9889> 9890> 从API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。 9891 9892**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9893 9894**参数:** 9895 9896| 参数名 | 类型 | 必填 | 说明 | 9897| ------ |----------------------------------| ---- | ------------------------------------------------------------ | 9898| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。 | 9899 9900**返回值:** 9901 9902| 类型 | 说明 | 9903|-----------------------------------------| ----------------------------------- | 9904| Promise<[AvoidArea](#avoidarea7)> | Promise对象。返回窗口内容规避区域。 | 9905 9906**示例:** 9907 9908```ts 9909import { BusinessError } from '@kit.BasicServicesKit'; 9910 9911let type = window.AvoidAreaType.TYPE_SYSTEM; 9912let promise = windowClass.getAvoidArea(type); 9913promise.then((data) => { 9914 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 9915}).catch((err: BusinessError) => { 9916 console.error(`Failed to obtain the area. Cause code: ${err.code}, message: ${err.message}`); 9917}); 9918``` 9919 9920### setFullScreen<sup>(deprecated)</sup> 9921 9922setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void 9923 9924设置主窗口或子窗口的布局是否为全屏布局,使用callback异步回调。 9925全屏布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 9926非全屏布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 9927 9928> **说明:** 9929> 9930> 从API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)实现全屏。 9931 9932**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9933 9934**参数:** 9935 9936| 参数名 | 类型 | 必填 | 说明 | 9937| ------------ | ------------------------- | ---- | ---------------------------------------------- | 9938| isFullScreen | boolean | 是 | 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。 | 9939| callback | AsyncCallback<void> | 是 | 回调函数。 | 9940 9941**示例:** 9942 9943```ts 9944// EntryAbility.ets 9945import { UIAbility } from '@kit.AbilityKit'; 9946import { BusinessError } from '@kit.BasicServicesKit'; 9947 9948export default class EntryAbility extends UIAbility { 9949 // ... 9950 onWindowStageCreate(windowStage: window.WindowStage): void { 9951 console.info('onWindowStageCreate'); 9952 let windowClass: window.Window | undefined = undefined; 9953 windowStage.getMainWindow((err: BusinessError, data) => { 9954 const errCode: number = err.code; 9955 if (errCode) { 9956 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 9957 return; 9958 } 9959 windowClass = data; 9960 let isFullScreen: boolean = true; 9961 windowClass.setFullScreen(isFullScreen, (err: BusinessError) => { 9962 const errCode: number = err.code; 9963 if (errCode) { 9964 console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 9965 return; 9966 } 9967 console.info('Succeeded in enabling the full-screen mode.'); 9968 }); 9969 }); 9970 } 9971} 9972``` 9973 9974### setFullScreen<sup>(deprecated)</sup> 9975 9976setFullScreen(isFullScreen: boolean): Promise<void> 9977 9978设置主窗口或子窗口的布局是否为全屏布局,使用Promise异步回调。 9979全屏布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 9980非全屏布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 9981 9982> **说明:** 9983> 9984> 从API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)实现全屏。 9985 9986**系统能力:** SystemCapability.WindowManager.WindowManager.Core 9987 9988**参数:** 9989 9990| 参数名 | 类型 | 必填 | 说明 | 9991| ------------ | ------- | ---- | ---------------------------------------------- | 9992| isFullScreen | boolean | 是 | 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。 | 9993 9994**返回值:** 9995 9996| 类型 | 说明 | 9997| ------------------- | ------------------------- | 9998| Promise<void> | 无返回结果的Promise对象。 | 9999 10000**示例:** 10001 10002```ts 10003// EntryAbility.ets 10004import { UIAbility } from '@kit.AbilityKit'; 10005import { BusinessError } from '@kit.BasicServicesKit'; 10006 10007export default class EntryAbility extends UIAbility { 10008 // ... 10009 onWindowStageCreate(windowStage: window.WindowStage): void { 10010 console.info('onWindowStageCreate'); 10011 let windowClass: window.Window | undefined = undefined; 10012 windowStage.getMainWindow((err: BusinessError, data) => { 10013 const errCode: number = err.code; 10014 if (errCode) { 10015 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10016 return; 10017 } 10018 windowClass = data; 10019 let isFullScreen: boolean = true; 10020 let promise = windowClass.setFullScreen(isFullScreen); 10021 promise.then(() => { 10022 console.info('Succeeded in enabling the full-screen mode.'); 10023 }).catch((err: BusinessError) => { 10024 console.error(`Failed to enable the full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 10025 }); 10026 }); 10027 } 10028} 10029``` 10030 10031### setLayoutFullScreen<sup>(deprecated)</sup> 10032 10033setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 10034 10035设置主窗口或子窗口的布局是否为沉浸式布局,使用callback异步回调。 10036沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 10037非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 10038 10039> **说明:** 10040> 10041> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)。 10042 10043**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10044 10045**参数:** 10046 10047| 参数名 | 类型 | 必填 | 说明 | 10048| ------------------ | ------------------------- | ---- | ------------------------------------------------------------ | 10049| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 10050| callback | AsyncCallback<void> | 是 | 回调函数。 | 10051 10052**示例:** 10053 10054```ts 10055// EntryAbility.ets 10056import { UIAbility } from '@kit.AbilityKit'; 10057import { BusinessError } from '@kit.BasicServicesKit'; 10058 10059export default class EntryAbility extends UIAbility { 10060 // ... 10061 onWindowStageCreate(windowStage: window.WindowStage): void { 10062 console.info('onWindowStageCreate'); 10063 let windowClass: window.Window | undefined = undefined; 10064 windowStage.getMainWindow((err: BusinessError, data) => { 10065 const errCode: number = err.code; 10066 if (errCode) { 10067 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10068 return; 10069 } 10070 windowClass = data; 10071 let isLayoutFullScreen: boolean = true; 10072 windowClass.setLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 10073 const errCode: number = err.code; 10074 if (errCode) { 10075 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 10076 return; 10077 } 10078 console.info('Succeeded in setting the window layout to full-screen mode.'); 10079 }); 10080 }); 10081 } 10082} 10083``` 10084 10085### setLayoutFullScreen<sup>(deprecated)</sup> 10086 10087setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 10088 10089设置主窗口或子窗口的布局是否为沉浸式布局,使用Promise异步回调。 10090沉浸式布局生效时,布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 10091非沉浸式布局生效时,布局避让状态栏与导航栏,组件不会与其重叠。 10092 10093> **说明:** 10094> 10095> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)。 10096 10097**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10098 10099**参数:** 10100 10101| 参数名 | 类型 | 必填 | 说明 | 10102| ------------------ | ------- | ---- | ------------------------------------------------------------ | 10103| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 10104 10105**返回值:** 10106 10107| 类型 | 说明 | 10108| ------------------- | ------------------------- | 10109| Promise<void> | 无返回结果的Promise对象。 | 10110 10111**示例:** 10112 10113```ts 10114// EntryAbility.ets 10115import { UIAbility } from '@kit.AbilityKit'; 10116import { BusinessError } from '@kit.BasicServicesKit'; 10117 10118export default class EntryAbility extends UIAbility { 10119 // ... 10120 onWindowStageCreate(windowStage: window.WindowStage): void { 10121 console.info('onWindowStageCreate'); 10122 let windowClass: window.Window | undefined = undefined; 10123 windowStage.getMainWindow((err: BusinessError, data) => { 10124 const errCode: number = err.code; 10125 if (errCode) { 10126 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10127 return; 10128 } 10129 windowClass = data; 10130 let isLayoutFullScreen: boolean = true; 10131 let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen); 10132 promise.then(() => { 10133 console.info('Succeeded in setting the window layout to full-screen mode.'); 10134 }).catch((err: BusinessError) => { 10135 console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); 10136 }); 10137 }); 10138 } 10139} 10140``` 10141 10142### setSystemBarEnable<sup>(deprecated)</sup> 10143 10144setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 10145 10146设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用callback异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 10147 10148调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。非全屏模式(悬浮窗、分屏等场景)下配置不生效。 10149 10150> **说明:** 10151> 10152> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)。 10153 10154**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10155 10156**参数:** 10157 10158| 参数名 | 类型 | 必填 | 说明 | 10159| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 10160| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏和底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 10161| callback | AsyncCallback<void> | 是 | 回调函数。 | 10162 10163 10164**示例:** 10165 10166```ts 10167// 此处以不显示三键导航栏、状态栏、底部导航条为例 10168// EntryAbility.ets 10169import { UIAbility } from '@kit.AbilityKit'; 10170import { BusinessError } from '@kit.BasicServicesKit'; 10171 10172export default class EntryAbility extends UIAbility { 10173 // ... 10174 onWindowStageCreate(windowStage: window.WindowStage): void { 10175 console.info('onWindowStageCreate'); 10176 let windowClass: window.Window | undefined = undefined; 10177 windowStage.getMainWindow((err: BusinessError, data) => { 10178 const errCode: number = err.code; 10179 if (errCode) { 10180 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10181 return; 10182 } 10183 windowClass = data; 10184 let names: Array<'status' | 'navigation'> = []; 10185 windowClass.setSystemBarEnable(names, (err: BusinessError) => { 10186 const errCode: number = err.code; 10187 if (errCode) { 10188 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 10189 return; 10190 } 10191 console.info('Succeeded in setting the system bar to be invisible.'); 10192 }); 10193 }); 10194 } 10195} 10196``` 10197 10198### setSystemBarEnable<sup>(deprecated)</sup> 10199 10200setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 10201 10202设置主窗口三键导航栏、状态栏、底部导航条的可见模式,状态栏与底部导航条通过status控制、三键导航栏通过navigation控制,使用Promise异步回调。从API version 12开始,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 10203 10204调用生效后返回并不表示三键导航栏、状态栏和底部导航条的显示或隐藏已完成。子窗口调用后不生效。非全屏模式(悬浮窗、分屏等场景)下配置不生效。 10205 10206> **说明:** 10207> 10208> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)。 10209 10210**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10211 10212**参数:** 10213 10214| 参数名 | 类型 | 必填 | 说明 | 10215| ------ | ---------------------------- | ---- | ------------------------ | 10216| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏、三键导航栏、底部导航条是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 10217 10218**返回值:** 10219 10220| 类型 | 说明 | 10221| ------------------- | ------------------------- | 10222| Promise<void> | 无返回结果的Promise对象。 | 10223 10224 10225**示例:** 10226 10227```ts 10228// 此处以不显示三键导航栏、状态栏、底部导航条为例 10229// EntryAbility.ets 10230import { UIAbility } from '@kit.AbilityKit'; 10231import { BusinessError } from '@kit.BasicServicesKit'; 10232 10233export default class EntryAbility extends UIAbility { 10234 // ... 10235 onWindowStageCreate(windowStage: window.WindowStage): void { 10236 console.info('onWindowStageCreate'); 10237 let windowClass: window.Window | undefined = undefined; 10238 windowStage.getMainWindow((err: BusinessError, data) => { 10239 const errCode: number = err.code; 10240 if (errCode) { 10241 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10242 return; 10243 } 10244 windowClass = data; 10245 let names: Array<'status' | 'navigation'> = []; 10246 let promise = windowClass.setSystemBarEnable(names); 10247 promise.then(() => { 10248 console.info('Succeeded in setting the system bar to be invisible.'); 10249 }).catch((err: BusinessError) => { 10250 console.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`); 10251 }); 10252 }); 10253 } 10254} 10255``` 10256 10257### setSystemBarProperties<sup>(deprecated)</sup> 10258 10259setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 10260 10261设置主窗口三键导航栏、状态栏的属性,使用callback异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 10262 10263子窗口调用后不生效。非全屏模式(悬浮窗、分屏等场景)下配置不生效。 10264 10265> **说明:** 10266> 10267> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9)。 10268 10269**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10270 10271**参数:** 10272 10273| 参数名 | 类型 | 必填 | 说明 | 10274| ------------------- | ------------------------------------------- | ---- | ---------------------- | 10275| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 三键导航栏、状态栏的属性。 | 10276| callback | AsyncCallback<void> | 是 | 回调函数。 | 10277 10278**示例:** 10279 10280```ts 10281// EntryAbility.ets 10282import { UIAbility } from '@kit.AbilityKit'; 10283import { BusinessError } from '@kit.BasicServicesKit'; 10284 10285export default class EntryAbility extends UIAbility { 10286 // ... 10287 onWindowStageCreate(windowStage: window.WindowStage): void { 10288 console.info('onWindowStageCreate'); 10289 let windowClass: window.Window | undefined = undefined; 10290 windowStage.getMainWindow((err: BusinessError, data) => { 10291 const errCode: number = err.code; 10292 if (errCode) { 10293 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10294 return; 10295 } 10296 windowClass = data; 10297 let SystemBarProperties: window.SystemBarProperties = { 10298 statusBarColor: '#ff00ff', 10299 navigationBarColor: '#00ff00', 10300 //以下两个属性从API Version8开始支持 10301 statusBarContentColor: '#ffffff', 10302 navigationBarContentColor: '#00ffff' 10303 }; 10304 windowClass.setSystemBarProperties(SystemBarProperties, (err) => { 10305 const errCode: number = err.code; 10306 if (errCode) { 10307 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 10308 return; 10309 } 10310 console.info('Succeeded in setting the system bar properties.'); 10311 }); 10312 }); 10313 } 10314} 10315``` 10316 10317### setSystemBarProperties<sup>(deprecated)</sup> 10318 10319setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 10320 10321设置主窗口三键导航栏、状态栏的属性,使用Promise异步回调,<!--RP5-->该接口在2in1设备上调用不生效。<!--RP5End--> 10322 10323子窗口调用后不生效。 10324 10325> **说明:** 10326> 10327> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9-1)。 10328 10329**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10330 10331**参数:** 10332 10333| 参数名 | 类型 | 必填 | 说明 | 10334| ------------------- | ------------------------------------------- | ---- | ---------------------- | 10335| systemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 三键导航栏、状态栏的属性。 | 10336 10337**返回值:** 10338 10339| 类型 | 说明 | 10340| ------------------- | ------------------------- | 10341| Promise<void> | 无返回结果的Promise对象。 | 10342 10343**示例:** 10344 10345```ts 10346// EntryAbility.ets 10347import { UIAbility } from '@kit.AbilityKit'; 10348import { BusinessError } from '@kit.BasicServicesKit'; 10349 10350export default class EntryAbility extends UIAbility { 10351 // ... 10352 onWindowStageCreate(windowStage: window.WindowStage): void { 10353 console.info('onWindowStageCreate'); 10354 let windowClass: window.Window | undefined = undefined; 10355 windowStage.getMainWindow((err: BusinessError, data) => { 10356 const errCode: number = err.code; 10357 if (errCode) { 10358 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 10359 return; 10360 } 10361 windowClass = data; 10362 let SystemBarProperties: window.SystemBarProperties = { 10363 statusBarColor: '#ff00ff', 10364 navigationBarColor: '#00ff00', 10365 //以下两个属性从API Version8开始支持 10366 statusBarContentColor: '#ffffff', 10367 navigationBarContentColor: '#00ffff' 10368 }; 10369 let promise = windowClass.setSystemBarProperties(SystemBarProperties); 10370 promise.then(() => { 10371 console.info('Succeeded in setting the system bar properties.'); 10372 }).catch((err: BusinessError) => { 10373 console.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); 10374 }); 10375 }); 10376 } 10377} 10378``` 10379 10380### loadContent<sup>(deprecated)</sup> 10381 10382loadContent(path: string, callback: AsyncCallback<void>): void 10383 10384为当前窗口加载具体页面内容,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 10385 10386> **说明:** 10387> 10388> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9)。 10389 10390**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10391 10392**参数:** 10393 10394| 参数名 | 类型 | 必填 | 说明 | 10395| -------- | ------------------------- | ---- | -------------------- | 10396| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 10397| callback | AsyncCallback<void> | 是 | 回调函数。 | 10398 10399**示例:** 10400 10401```ts 10402import { BusinessError } from '@kit.BasicServicesKit'; 10403 10404windowClass.loadContent('pages/page2/page3', (err: BusinessError) => { 10405 const errCode: number = err.code; 10406 if (errCode) { 10407 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 10408 return; 10409 } 10410 console.info('Succeeded in loading the content.'); 10411}); 10412``` 10413 10414### loadContent<sup>(deprecated)</sup> 10415 10416loadContent(path: string): Promise<void> 10417 10418为当前窗口加载具体页面内容,使用Promise异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 10419 10420> **说明:** 10421> 10422> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9-1)。 10423 10424**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10425 10426**参数:** 10427 10428| 参数名 | 类型 | 必填 | 说明 | 10429| ------ | ------ | ---- | -------------------- | 10430| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 10431 10432**返回值:** 10433 10434| 类型 | 说明 | 10435| ------------------- | ------------------------- | 10436| Promise<void> | 无返回结果的Promise对象。 | 10437 10438**示例:** 10439 10440```ts 10441import { BusinessError } from '@kit.BasicServicesKit'; 10442 10443let promise = windowClass.loadContent('pages/page2/page3'); 10444promise.then(() => { 10445 console.info('Succeeded in loading the content.'); 10446}).catch((err: BusinessError) => { 10447 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 10448}); 10449``` 10450 10451### isShowing<sup>(deprecated)</sup> 10452 10453isShowing(callback: AsyncCallback<boolean>): void 10454 10455判断当前窗口是否已显示,使用callback异步回调。 10456 10457> **说明:** 10458> 10459> 从API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。 10460 10461**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10462 10463**参数:** 10464 10465| 参数名 | 类型 | 必填 | 说明 | 10466| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 10467| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 | 10468 10469**示例:** 10470 10471```ts 10472import { BusinessError } from '@kit.BasicServicesKit'; 10473 10474windowClass.isShowing((err: BusinessError, data) => { 10475 const errCode: number = err.code; 10476 if (errCode) { 10477 console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`); 10478 return; 10479 } 10480 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 10481}); 10482``` 10483 10484### isShowing<sup>(deprecated)</sup> 10485 10486isShowing(): Promise<boolean> 10487 10488判断当前窗口是否已显示,使用Promise异步回调。 10489 10490> **说明:** 10491> 10492> 从API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。 10493 10494**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10495 10496**返回值:** 10497 10498| 类型 | 说明 | 10499| ---------------------- | ------------------------------------------------------------ | 10500| Promise<boolean> | Promise对象。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 | 10501 10502**示例:** 10503 10504```ts 10505import { BusinessError } from '@kit.BasicServicesKit'; 10506 10507let promise = windowClass.isShowing(); 10508promise.then((data) => { 10509 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 10510}).catch((err: BusinessError) => { 10511 console.error(`Failed to check whether the window is showing. Cause code: ${err.code}, message: ${err.message}`); 10512}); 10513``` 10514 10515### on('systemAvoidAreaChange')<sup>(deprecated)</sup> 10516 10517on(type: 'systemAvoidAreaChange', callback: Callback<AvoidArea>): void 10518 10519开启当前窗口系统规避区变化的监听。 10520 10521> **说明:** 10522> 10523> 从API version 7开始支持,从API version 9开始废弃,推荐使用[on('avoidAreaChange')](#onavoidareachange9)。 10524 10525**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10526 10527**参数:** 10528 10529| 参数名 | 类型 | 必填 | 说明 | 10530| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 10531| type | string | 是 | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 | 10532| callback | Callback<[AvoidArea](#avoidarea7)> | 是 | 回调函数。返回当前规避区。 | 10533 10534 10535**示例:** 10536 10537```ts 10538windowClass.on('systemAvoidAreaChange', (data) => { 10539 console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data)); 10540}); 10541``` 10542 10543### off('systemAvoidAreaChange')<sup>(deprecated)</sup> 10544 10545off(type: 'systemAvoidAreaChange', callback?: Callback<AvoidArea>): void 10546 10547关闭当前窗口系统规避区变化的监听。 10548 10549> **说明:** 10550> 10551> 从API version 7开始支持,从API version 9开始废弃,推荐使用[off('avoidAreaChange')](#offavoidareachange9)。 10552 10553**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10554 10555**参数:** 10556 10557| 参数名 | 类型 | 必填 | 说明 | 10558| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 10559| type | string | 是 | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 | 10560| callback | Callback<[AvoidArea](#avoidarea7)> | 否 | 回调函数。返回当前规避区。若传入参数,则关闭该监听。若未传入参数,则关闭所有系统规避区变化的监听。 | 10561 10562**示例:** 10563 10564```ts 10565const callback = (avoidArea: window.AvoidArea) => { 10566 // ... 10567} 10568windowClass.on('systemAvoidAreaChange', callback); 10569windowClass.off('systemAvoidAreaChange', callback); 10570// 如果通过on开启多个callback进行监听,同时关闭所有监听: 10571windowClass.off('systemAvoidAreaChange'); 10572``` 10573 10574### isSupportWideGamut<sup>(deprecated)</sup> 10575 10576isSupportWideGamut(callback: AsyncCallback<boolean>): void 10577 10578判断当前窗口是否支持广色域模式,使用callback异步回调。 10579 10580> **说明:** 10581> 10582> 从API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9)。 10583 10584**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10585 10586**参数:** 10587 10588| 参数名 | 类型 | 必填 | 说明 | 10589| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 10590| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 10591 10592**示例:** 10593 10594```ts 10595import { BusinessError } from '@kit.BasicServicesKit'; 10596 10597windowClass.isSupportWideGamut((err: BusinessError, data) => { 10598 const errCode: number = err.code; 10599 if (errCode) { 10600 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 10601 return; 10602 } 10603 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 10604}); 10605``` 10606 10607### isSupportWideGamut<sup>(deprecated)</sup> 10608 10609isSupportWideGamut(): Promise<boolean> 10610 10611判断当前窗口是否支持广色域模式,使用Promise异步回调。 10612 10613> **说明:** 10614> 10615> 从API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9-1)。 10616 10617**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10618 10619**返回值:** 10620 10621| 类型 | 说明 | 10622| ---------------------- | ------------------------------------------------------------ | 10623| Promise<boolean> | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 10624 10625**示例:** 10626 10627```ts 10628import { BusinessError } from '@kit.BasicServicesKit'; 10629 10630let promise = windowClass.isSupportWideGamut(); 10631promise.then((data) => { 10632 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 10633}).catch((err: BusinessError) => { 10634 console.error(`Failed to check whether the window support WideGamut. Cause code: ${err.code}, message: ${err.message}`); 10635}); 10636``` 10637 10638### setColorSpace<sup>(deprecated)</sup> 10639 10640setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 10641 10642设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。 10643 10644> **说明:** 10645> 10646> 从API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9)。 10647 10648**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10649 10650**参数:** 10651 10652| 参数名 | 类型 | 必填 | 说明 | 10653| ---------- | ------------------------- | ---- | ------------ | 10654| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 10655| callback | AsyncCallback<void> | 是 | 回调函数。 | 10656 10657 10658**示例:** 10659 10660```ts 10661import { BusinessError } from '@kit.BasicServicesKit'; 10662 10663windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 10664 const errCode: number = err.code; 10665 if (errCode) { 10666 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 10667 return; 10668 } 10669 console.info('Succeeded in setting window colorspace.'); 10670}); 10671``` 10672 10673### setColorSpace<sup>(deprecated)</sup> 10674 10675setColorSpace(colorSpace:ColorSpace): Promise<void> 10676 10677设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。 10678 10679> **说明:** 10680> 10681> 从API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9-1)。 10682 10683**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10684 10685**参数:** 10686 10687| 参数名 | 类型 | 必填 | 说明 | 10688| ---------- | ------------------------- | ---- | -------------- | 10689| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 10690 10691**返回值:** 10692 10693| 类型 | 说明 | 10694| ------------------- | ------------------------- | 10695| Promise<void> | 无返回结果的Promise对象。 | 10696 10697 10698**示例:** 10699 10700```ts 10701import { BusinessError } from '@kit.BasicServicesKit'; 10702 10703let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT); 10704promise.then(() => { 10705 console.info('Succeeded in setting window colorspace.'); 10706}).catch((err: BusinessError) => { 10707 console.error(`Failed to set window colorspace. Cause code: ${err.code}, message: ${err.message}`); 10708}); 10709``` 10710 10711### getColorSpace<sup>(deprecated)</sup> 10712 10713getColorSpace(callback: AsyncCallback<ColorSpace>): void 10714 10715获取当前窗口色域模式,使用callback异步回调。 10716 10717> **说明:** 10718> 10719> 从API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。 10720 10721**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10722 10723**参数:** 10724 10725| 参数名 | 类型 | 必填 | 说明 | 10726| -------- | ---------------------------------------------- | ---- | ---------------------------------------------------------- | 10727| callback | AsyncCallback<[ColorSpace](#colorspace8)> | 是 | 回调函数。当获取成功,err为undefined,data为当前色域模式。 | 10728 10729**示例:** 10730 10731```ts 10732import { BusinessError } from '@kit.BasicServicesKit'; 10733 10734windowClass.getColorSpace((err: BusinessError, data) => { 10735 const errCode: number = err.code; 10736 if (errCode) { 10737 console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`); 10738 return; 10739 } 10740 console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data)); 10741}); 10742``` 10743 10744### getColorSpace<sup>(deprecated)</sup> 10745 10746getColorSpace(): Promise<ColorSpace> 10747 10748获取当前窗口色域模式,使用Promise异步回调。 10749 10750> **说明:** 10751> 10752> 从API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。 10753 10754**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10755 10756**返回值:** 10757 10758| 类型 | 说明 | 10759| ---------------------------------------- | ------------------------------- | 10760| Promise<[ColorSpace](#colorspace8)> | Promise对象。返回当前色域模式。 | 10761 10762**示例:** 10763 10764```ts 10765import { BusinessError } from '@kit.BasicServicesKit'; 10766 10767let promise = windowClass.getColorSpace(); 10768promise.then((data) => { 10769 console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data)); 10770}).catch((err: BusinessError) => { 10771 console.error(`Failed to get window colorspace. Cause code: ${err.code}, message: ${err.message}`); 10772}); 10773``` 10774 10775### setBackgroundColor<sup>(deprecated)</sup> 10776 10777setBackgroundColor(color: string, callback: AsyncCallback<void>): void 10778 10779设置窗口的背景色,使用callback异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 10780 10781> **说明:** 10782> 10783> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。 10784 10785**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10786 10787**参数:** 10788 10789| 参数名 | 类型 | 必填 | 说明 | 10790| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 10791| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 | 10792| callback | AsyncCallback<void> | 是 | 回调函数。 | 10793 10794 10795**示例:** 10796 10797```ts 10798import { BusinessError } from '@kit.BasicServicesKit'; 10799 10800let color: string = '#00ff33'; 10801windowClass.setBackgroundColor(color, (err: BusinessError) => { 10802 const errCode: number = err.code; 10803 if (errCode) { 10804 console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`); 10805 return; 10806 } 10807 console.info('Succeeded in setting the background color.'); 10808}); 10809``` 10810 10811### setBackgroundColor<sup>(deprecated)</sup> 10812 10813setBackgroundColor(color: string): Promise<void> 10814 10815设置窗口的背景色,使用Promise异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 10816 10817> **说明:** 10818> 10819> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。 10820 10821**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10822 10823**参数:** 10824 10825| 参数名 | 类型 | 必填 | 说明 | 10826| ------ | ------ | ---- | ------------------------------------------------------------ | 10827| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`'#00FF00'`或`'#FF00FF00'`。 | 10828 10829**返回值:** 10830 10831| 类型 | 说明 | 10832| ------------------- | ------------------------- | 10833| Promise<void> | 无返回结果的Promise对象。 | 10834 10835 10836**示例:** 10837 10838```ts 10839import { BusinessError } from '@kit.BasicServicesKit'; 10840 10841let color: string = '#00ff33'; 10842let promise = windowClass.setBackgroundColor(color); 10843promise.then(() => { 10844 console.info('Succeeded in setting the background color.'); 10845}).catch((err: BusinessError) => { 10846 console.error(`Failed to set the background color. Cause code: ${err.code}, message: ${err.message}`); 10847}); 10848``` 10849 10850### setBrightness<sup>(deprecated)</sup> 10851 10852setBrightness(brightness: number, callback: AsyncCallback<void>): void 10853 10854允许应用窗口设置屏幕亮度值,使用callback异步回调。 10855 10856当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 10857 10858> **说明:** 10859> 10860> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9)。 10861 10862**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10863 10864**参数:** 10865 10866| 参数名 | 类型 | 必填 | 说明 | 10867| ---------- | ------------------------- | ---- |---------------------------------------| 10868| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 10869| callback | AsyncCallback<void> | 是 | 回调函数。 | 10870 10871 10872**示例:** 10873 10874```ts 10875import { BusinessError } from '@kit.BasicServicesKit'; 10876 10877let brightness: number = 1; 10878windowClass.setBrightness(brightness, (err: BusinessError) => { 10879 const errCode: number = err.code; 10880 if (errCode) { 10881 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 10882 return; 10883 } 10884 console.info('Succeeded in setting the brightness.'); 10885}); 10886``` 10887 10888### setBrightness<sup>(deprecated)</sup> 10889 10890setBrightness(brightness: number): Promise<void> 10891 10892允许应用窗口设置屏幕亮度值,使用Promise异步回调。 10893 10894当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 10895 10896> **说明:** 10897> 10898> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9-1)。 10899 10900**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10901 10902**参数:** 10903 10904| 参数名 | 类型 | 必填 | 说明 | 10905| ---------- | ------ | ---- |------------------------------------------| 10906| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 10907 10908**返回值:** 10909 10910| 类型 | 说明 | 10911| ------------------- | ------------------------- | 10912| Promise<void> | 无返回结果的Promise对象。 | 10913 10914 10915**示例:** 10916 10917```ts 10918import { BusinessError } from '@kit.BasicServicesKit'; 10919 10920let brightness: number = 1; 10921let promise = windowClass.setBrightness(brightness); 10922promise.then(() => { 10923 console.info('Succeeded in setting the brightness.'); 10924}).catch((err: BusinessError) => { 10925 console.error(`Failed to set the brightness. Cause code: ${err.code}, message: ${err.message}`); 10926}); 10927``` 10928 10929### setDimBehind<sup>(deprecated)</sup> 10930 10931setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void 10932 10933窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用callback异步回调。 10934 10935> **说明:** 10936> 10937> 该接口不支持使用。从API version 7开始支持,从API version 9开始废弃。 10938 10939**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10940 10941**参数:** 10942 10943| 参数名 | 类型 | 必填 | 说明 | 10944| -------------- | ------------------------- | ---- |----------------------------------------| 10945| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为[0.0, 1.0],取1.0时表示最暗。 | 10946| callback | AsyncCallback<void> | 是 | 回调函数。 | 10947 10948**示例:** 10949 10950```ts 10951import { BusinessError } from '@kit.BasicServicesKit'; 10952 10953windowClass.setDimBehind(0.5, (err: BusinessError) => { 10954 const errCode: number = err.code; 10955 if (errCode) { 10956 console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`); 10957 return; 10958 } 10959 console.info('Succeeded in setting the dimness.'); 10960}); 10961``` 10962 10963### setDimBehind<sup>(deprecated)</sup> 10964 10965setDimBehind(dimBehindValue: number): Promise<void> 10966 10967窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用Promise异步回调。 10968 10969> **说明:** 10970> 10971> 该接口不支持使用。从API version 7开始支持,从API version 9开始废弃。 10972 10973**系统能力:** SystemCapability.WindowManager.WindowManager.Core 10974 10975**参数:** 10976 10977| 参数名 | 类型 | 必填 | 说明 | 10978| -------------- | ------ | ---- | -------------------------------------------------- | 10979| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 | 10980 10981**返回值:** 10982 10983| 类型 | 说明 | 10984| ------------------- | ------------------------- | 10985| Promise<void> | 无返回结果的Promise对象。 | 10986 10987**示例:** 10988 10989```ts 10990import { BusinessError } from '@kit.BasicServicesKit'; 10991 10992let promise = windowClass.setDimBehind(0.5); 10993promise.then(() => { 10994 console.info('Succeeded in setting the dimness.'); 10995}).catch((err: BusinessError) => { 10996 console.error(`Failed to set the dimness. Cause code: ${err.code}, message: ${err.message}`); 10997}); 10998``` 10999 11000### setFocusable<sup>(deprecated)</sup> 11001 11002setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 11003 11004设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从操作前的获焦窗口切换到该窗口,使用callback异步回调。 11005 11006> **说明:** 11007> 11008> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9)。 11009 11010**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11011 11012**参数:** 11013 11014| 参数名 | 类型 | 必填 | 说明 | 11015| ----------- | ------------------------- | ---- | ---------------------------- | 11016| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 11017| callback | AsyncCallback<void> | 是 | 回调函数。 | 11018 11019 11020**示例:** 11021 11022```ts 11023import { BusinessError } from '@kit.BasicServicesKit'; 11024 11025let isFocusable: boolean = true; 11026windowClass.setFocusable(isFocusable, (err: BusinessError) => { 11027 const errCode: number = err.code; 11028 if (errCode) { 11029 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 11030 return; 11031 } 11032 console.info('Succeeded in setting the window to be focusable.'); 11033}); 11034``` 11035 11036### setFocusable<sup>(deprecated)</sup> 11037 11038setFocusable(isFocusable: boolean): Promise<void> 11039 11040设置使用点击或其他方式使该窗口获焦的场景时,该窗口是否支持窗口焦点从点击前的获焦窗口切换到该窗口,使用Promise异步回调。 11041 11042> **说明:** 11043> 11044> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9-1)。 11045 11046**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11047 11048**参数:** 11049 11050| 参数名 | 类型 | 必填 | 说明 | 11051| ----------- | ------- | ---- | ---------------------------- | 11052| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 11053 11054**返回值:** 11055 11056| 类型 | 说明 | 11057| ------------------- | ------------------------- | 11058| Promise<void> | 无返回结果的Promise对象。 | 11059 11060 11061**示例:** 11062 11063```ts 11064import { BusinessError } from '@kit.BasicServicesKit'; 11065 11066let isFocusable: boolean = true; 11067let promise = windowClass.setFocusable(isFocusable); 11068promise.then(() => { 11069 console.info('Succeeded in setting the window to be focusable.'); 11070}).catch((err: BusinessError) => { 11071 console.error(`Failed to set the window to be focusable. Cause code: ${err.code}, message: ${err.message}`); 11072}); 11073``` 11074 11075### setKeepScreenOn<sup>(deprecated)</sup> 11076 11077setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 11078 11079设置屏幕是否为常亮状态,使用callback异步回调。 11080 11081> **说明:** 11082> 11083> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9)。 11084 11085**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11086 11087**参数:** 11088 11089| 参数名 | 类型 | 必填 | 说明 | 11090| -------------- | ------------------------- | ---- | ------------------------ | 11091| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 11092| callback | AsyncCallback<void> | 是 | 回调函数。 | 11093 11094 11095**示例:** 11096 11097```ts 11098import { BusinessError } from '@kit.BasicServicesKit'; 11099 11100let isKeepScreenOn: boolean = true; 11101windowClass.setKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 11102 const errCode: number = err.code; 11103 if (errCode) { 11104 console.error(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 11105 return; 11106 } 11107 console.info('Succeeded in setting the screen to be always on.'); 11108}); 11109``` 11110 11111### setKeepScreenOn<sup>(deprecated)</sup> 11112 11113setKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 11114 11115设置屏幕是否为常亮状态,使用Promise异步回调。 11116 11117> **说明:** 11118> 11119> 从API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9-1)。 11120 11121**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11122 11123**参数:** 11124 11125| 参数名 | 类型 | 必填 | 说明 | 11126| -------------- | ------- | ---- | ------------------------ | 11127| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 11128 11129**返回值:** 11130 11131| 类型 | 说明 | 11132| ------------------- | ------------------------- | 11133| Promise<void> | 无返回结果的Promise对象。 | 11134 11135**示例:** 11136 11137```ts 11138import { BusinessError } from '@kit.BasicServicesKit'; 11139 11140let isKeepScreenOn: boolean = true; 11141let promise = windowClass.setKeepScreenOn(isKeepScreenOn); 11142promise.then(() => { 11143 console.info('Succeeded in setting the screen to be always on.'); 11144}).catch((err: BusinessError) => { 11145 console.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`); 11146}); 11147``` 11148 11149### setOutsideTouchable<sup>(deprecated)</sup> 11150 11151setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void 11152 11153设置是否允许可点击子窗口之外的区域,使用callback异步回调。 11154 11155> **说明:** 11156> 11157> 从API version 7开始支持,从API version 9开始废弃。 11158> 11159> 从API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。 11160 11161**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11162 11163**参数:** 11164 11165| 参数名 | 类型 | 必填 | 说明 | 11166| --------- | ------------------------- | ---- | ---------------- | 11167| touchable | boolean | 是 | 设置是否可点击。true表示可点击;false表示不可点击。 | 11168| callback | AsyncCallback<void> | 是 | 回调函数。 | 11169 11170**示例:** 11171 11172```ts 11173import { BusinessError } from '@kit.BasicServicesKit'; 11174 11175windowClass.setOutsideTouchable(true, (err: BusinessError) => { 11176 const errCode: number = err.code; 11177 if (errCode) { 11178 console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`); 11179 return; 11180 } 11181 console.info('Succeeded in setting the area to be touchable.'); 11182}); 11183``` 11184 11185### setOutsideTouchable<sup>(deprecated)</sup> 11186 11187setOutsideTouchable(touchable: boolean): Promise<void> 11188 11189设置是否允许可点击子窗口之外的区域,使用Promise异步回调。 11190 11191> **说明:** 11192> 11193> 从API version 7开始支持,从API version 9开始废弃。 11194> 11195> 从API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。 11196 11197**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11198 11199**参数:** 11200 11201| 参数名 | 类型 | 必填 | 说明 | 11202| --------- | ------- | ---- | ---------------- | 11203| touchable | boolean | 是 | 设置是否可点击。true表示可点击;false表示不可点击。 | 11204 11205**返回值:** 11206 11207| 类型 | 说明 | 11208| ------------------- | ------------------------- | 11209| Promise<void> | 无返回结果的Promise对象。 | 11210 11211**示例:** 11212 11213```ts 11214import { BusinessError } from '@kit.BasicServicesKit'; 11215 11216let promise = windowClass.setOutsideTouchable(true); 11217promise.then(() => { 11218 console.info('Succeeded in setting the area to be touchable.'); 11219}).catch((err: BusinessError) => { 11220 console.error(`Failed to set the area to be touchable. Cause code: ${err.code}, message: ${err.message}`); 11221}); 11222``` 11223 11224### setPrivacyMode<sup>(deprecated)</sup> 11225 11226setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 11227 11228设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 11229 11230> **说明:** 11231> 11232> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9)。 11233 11234**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11235 11236**参数:** 11237 11238| 参数名 | 类型 | 必填 | 说明 | 11239| ------------- | ------------------------- | ---- | -------------------- | 11240| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 11241| callback | AsyncCallback<void> | 是 | 回调函数。 | 11242 11243**示例:** 11244 11245```ts 11246import { BusinessError } from '@kit.BasicServicesKit'; 11247 11248let isPrivacyMode: boolean = true; 11249windowClass.setPrivacyMode(isPrivacyMode, (err: BusinessError) => { 11250 const errCode: number = err.code; 11251 if (errCode) { 11252 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 11253 return; 11254 } 11255 console.info('Succeeded in setting the window to privacy mode.'); 11256}); 11257``` 11258 11259### setPrivacyMode<sup>(deprecated)</sup> 11260 11261setPrivacyMode(isPrivacyMode: boolean): Promise<void> 11262 11263设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 11264 11265> **说明:** 11266> 11267> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9-1)。 11268 11269**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11270 11271**参数:** 11272 11273| 参数名 | 类型 | 必填 | 说明 | 11274| ------------- | ------- | ---- | -------------------- | 11275| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 11276 11277**返回值:** 11278 11279| 类型 | 说明 | 11280| ------------------- | ------------------------- | 11281| Promise<void> | 无返回结果的Promise对象。 | 11282 11283**示例:** 11284 11285```ts 11286import { BusinessError } from '@kit.BasicServicesKit'; 11287 11288let isPrivacyMode: boolean = true; 11289let promise = windowClass.setPrivacyMode(isPrivacyMode); 11290promise.then(() => { 11291 console.info('Succeeded in setting the window to privacy mode.'); 11292}).catch((err: BusinessError) => { 11293 console.error(`Failed to set the window to privacy mode. Cause code: ${err.code}, message: ${err.message}`); 11294}); 11295``` 11296 11297### setTouchable<sup>(deprecated)</sup> 11298 11299setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 11300 11301设置窗口是否为可触状态,使用callback异步回调。 11302 11303> **说明:** 11304> 11305> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9)。 11306 11307**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11308 11309**参数:** 11310 11311| 参数名 | 类型 | 必填 | 说明 | 11312| ----------- | ------------------------- | ---- | -------------------- | 11313| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 11314| callback | AsyncCallback<void> | 是 | 回调函数。 | 11315 11316 11317**示例:** 11318 11319```ts 11320import { BusinessError } from '@kit.BasicServicesKit'; 11321 11322let isTouchable = true; 11323windowClass.setTouchable(isTouchable, (err: BusinessError) => { 11324 const errCode: number = err.code; 11325 if (errCode) { 11326 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 11327 return; 11328 } 11329 console.info('Succeeded in setting the window to be touchable.'); 11330}); 11331``` 11332 11333### setTouchable<sup>(deprecated)</sup> 11334 11335setTouchable(isTouchable: boolean): Promise<void> 11336 11337设置窗口是否为可触状态,使用Promise异步回调。 11338 11339> **说明:** 11340> 11341> 从API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9-1)。 11342 11343**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11344 11345**参数:** 11346 11347| 参数名 | 类型 | 必填 | 说明 | 11348| ----------- | ------- | ---- | -------------------- | 11349| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 11350 11351**返回值:** 11352 11353| 类型 | 说明 | 11354| ------------------- | ------------------------- | 11355| Promise<void> | 无返回结果的Promise对象。 | 11356 11357 11358**示例:** 11359 11360```ts 11361import { BusinessError } from '@kit.BasicServicesKit'; 11362 11363let isTouchable = true; 11364let promise = windowClass.setTouchable(isTouchable); 11365promise.then(() => { 11366 console.info('Succeeded in setting the window to be touchable.'); 11367}).catch((err: BusinessError) => { 11368 console.error(`Failed to set the window to be touchable. Cause code: ${err.code}, message: ${err.message}`); 11369}); 11370``` 11371 11372## WindowStageEventType<sup>9+</sup> 11373 11374WindowStage生命周期。 11375 11376**模型约束:** 此接口仅可在Stage模型下使用。 11377 11378**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11379 11380**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11381 11382| 名称 | 值 | 说明 | 11383| ---------- | ------ | ---------- | 11384| SHOWN | 1 | 切到前台,例如点击应用图标启动,无论是首次启动还是从后台启动均会触发。 | 11385| ACTIVE | 2 | 获焦状态,例如应用窗口处理点击事件后的状态、应用启动后的状态。 | 11386| INACTIVE | 3 | 失焦状态,例如打开新应用或点击其他窗口后,原获焦窗口的状态。 | 11387| HIDDEN | 4 | 切到后台,例如应用上滑退出、应用窗口关闭。 | 11388| RESUMED<sup>11+</sup> | 5 | 前台可交互状态,例如应用打开后,可以与用户交互的状态。 | 11389| PAUSED<sup>11+</sup> | 6 | 前台不可交互状态,例如从屏幕底部上划,应用进入到多任务界面后的状态。 | 11390 11391## ModalityType<sup>14+</sup> 11392 11393子窗口模态类型枚举。 11394 11395**系统能力:** SystemCapability.Window.SessionManager 11396 11397**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 11398 11399| 名称 | 值 | 说明 | 11400| -------------------- | ------ | ---------- | 11401| WINDOW_MODALITY | 0 | 模态子窗类型为模窗口子窗,当仅需要其父级窗口不响应用户操作时,可选此参数。 | 11402| APPLICATION_MODALITY | 1 | 模态子窗类型为模应用子窗,除其父级窗口外还需要该应用其他实例的窗口不响应用户操作时,可选此参数。<br> 此接口仅支持在2in1设备下使用。 | 11403 11404## SubWindowOptions<sup>11+</sup> 11405 11406子窗口创建参数。 11407 11408**系统能力:** SystemCapability.Window.SessionManager 11409 11410| 名称 | 类型 | 只读 | 可选 | 说明 | 11411| ---------- | ---- | ---- | ---- | ----------- | 11412| title<sup>11+</sup> | string | 否 | 否 | 子窗口标题。标题显示区域最右端不超过系统三键区域最左端,超过部分以省略号表示。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 11413| decorEnabled<sup>11+</sup> | boolean | 否 | 否 | 子窗口是否显示装饰。true表示子窗口显示装饰,false表示子窗口不显示装饰。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 11414| isModal<sup>12+</sup> | boolean | 否 | 是 | 子窗口是否启用模态属性。true表示子窗口启用模态属性,false表示子窗口禁用模态属性。不设置,则默认为false。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 11415| modalityType<sup>14+</sup> | [ModalityType](#modalitytype14) | 否 | 是 | 子窗口模态类型,仅当子窗口启用模态属性时生效。WINDOW_MODALITY表示子窗口模态类型为模窗口子窗,APPLICATION_MODALITY表示子窗口模态类型为模应用子窗。不设置,则默认为WINDOW_MODALITY。<br>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 | 11416| windowRect<sup>18+</sup> | [Rect](#rect7) | 否 | 是 | 子窗口矩形区域,其中子窗存在大小限制,具体参考[resize()](#resize9)方法。不设置,此窗口在显示时默认为全屏大小。<br>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。| 11417| zLevel<sup>18+</sup> | number | 否 | 是 | 子窗口层级级别,仅当子窗口未启用模态属性,即未设置isModal时生效。该参数是整数,取值范围为[-10000, 10000],浮点数输入将向下取整。不设置,则默认为0。<br>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。| 11418 11419## WindowStage<sup>9+</sup> 11420 11421窗口管理器。管理各个基本窗口单元,即[Window](#window)实例。 11422 11423下列API示例中都需在[onWindowStageCreate()](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate)函数中使用WindowStage的实例调用对应方法。 11424 11425### getMainWindow<sup>9+</sup> 11426 11427getMainWindow(callback: AsyncCallback<Window>): void 11428 11429获取该WindowStage实例下的主窗口,使用callback异步回调。 11430 11431**模型约束:** 此接口仅可在Stage模型下使用。 11432 11433**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11434 11435**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11436 11437**参数:** 11438 11439| 参数名 | 类型 | 必填 | 说明 | 11440| -------- | -------------------------------------- | ---- | --------------------------------------------- | 11441| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前WindowStage下的主窗口对象。 | 11442 11443**错误码:** 11444 11445以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 11446 11447| 错误码ID | 错误信息 | 11448| ------- | ------------------------------ | 11449| 1300002 | This window state is abnormal. | 11450| 1300005 | This window stage is abnormal. | 11451 11452**示例:** 11453 11454```ts 11455// EntryAbility.ets 11456import { UIAbility } from '@kit.AbilityKit'; 11457import { BusinessError } from '@kit.BasicServicesKit'; 11458 11459export default class EntryAbility extends UIAbility { 11460 // ... 11461 11462 onWindowStageCreate(windowStage: window.WindowStage) { 11463 console.info('onWindowStageCreate'); 11464 let windowClass: window.Window | undefined = undefined; 11465 windowStage.getMainWindow((err: BusinessError, data) => { 11466 const errCode: number = err.code; 11467 if (errCode) { 11468 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 11469 return; 11470 } 11471 windowClass = data; 11472 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 11473 }); 11474 } 11475}; 11476``` 11477 11478### getMainWindow<sup>9+</sup> 11479 11480getMainWindow(): Promise<Window> 11481 11482获取该WindowStage实例下的主窗口,使用Promise异步回调。 11483 11484**模型约束:** 此接口仅可在Stage模型下使用。 11485 11486**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11487 11488**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11489 11490**返回值:** 11491 11492| 类型 | 说明 | 11493| -------------------------------- | ------------------------------------------------ | 11494| Promise<[Window](#window)> | Promise对象。返回当前WindowStage下的主窗口对象。 | 11495 11496**错误码:** 11497 11498以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 11499 11500| 错误码ID | 错误信息 | 11501| ------- | ------------------------------ | 11502| 1300002 | This window state is abnormal. | 11503| 1300005 | This window stage is abnormal. | 11504 11505**示例:** 11506 11507```ts 11508// EntryAbility.ets 11509import { UIAbility } from '@kit.AbilityKit'; 11510import { BusinessError } from '@kit.BasicServicesKit'; 11511 11512export default class EntryAbility extends UIAbility { 11513 // ... 11514 11515 onWindowStageCreate(windowStage: window.WindowStage) { 11516 console.info('onWindowStageCreate'); 11517 let windowClass: window.Window | undefined = undefined; 11518 let promise = windowStage.getMainWindow(); 11519 promise.then((data) => { 11520 windowClass = data; 11521 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 11522 }).catch((err: BusinessError) => { 11523 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 11524 }); 11525 } 11526}; 11527``` 11528 11529### getMainWindowSync<sup>9+</sup> 11530 11531getMainWindowSync(): Window 11532 11533获取该WindowStage实例下的主窗口。 11534 11535**模型约束:** 此接口仅可在Stage模型下使用。 11536 11537**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11538 11539**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11540 11541**返回值:** 11542 11543| 类型 | 说明 | 11544| ----------------- | --------------------------------- | 11545| [Window](#window) | 返回当前WindowStage下的主窗口对象。 | 11546 11547**错误码:** 11548 11549以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 11550 11551| 错误码ID | 错误信息 | 11552| ------- | ------------------------------ | 11553| 1300002 | This window state is abnormal. | 11554| 1300005 | This window stage is abnormal. | 11555 11556**示例:** 11557<!--code_no_check--> 11558```ts 11559// EntryAbility.ets 11560import { UIAbility } from '@kit.AbilityKit'; 11561 11562export default class EntryAbility extends UIAbility { 11563 // ... 11564 11565 onWindowStageCreate(windowStage: window.WindowStage) { 11566 console.info('onWindowStageCreate'); 11567 try { 11568 let windowClass = windowStage.getMainWindowSync(); 11569 } catch (exception) { 11570 console.error(`Failed to obtain the main window. Cause code: ${exception.code}, message: ${exception.message}`); 11571 } 11572 } 11573}; 11574``` 11575 11576### createSubWindow<sup>9+</sup> 11577 11578createSubWindow(name: string, callback: AsyncCallback<Window>): void 11579 11580创建该WindowStage实例下的子窗口,使用callback异步回调。 11581 11582**模型约束:** 此接口仅可在Stage模型下使用。 11583 11584**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11585 11586**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11587 11588**参数:** 11589 11590| 参数名 | 类型 | 必填 | 说明 | 11591| -------- | -------------------------------------- | ---- | --------------------------------------------- | 11592| name | string | 是 | 子窗口的名字。 | 11593| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前WindowStage下的子窗口对象。 | 11594 11595**错误码:** 11596 11597以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11598 11599| 错误码ID | 错误信息 | 11600| ------- | ------------------------------ | 11601| 401 | Parameter error. Possible cause: Incorrect parameter types. | 11602| 1300002 | This window state is abnormal. | 11603| 1300005 | This window stage is abnormal. | 11604 11605**示例:** 11606 11607```ts 11608// EntryAbility.ets 11609import { UIAbility } from '@kit.AbilityKit'; 11610import { BusinessError } from '@kit.BasicServicesKit'; 11611 11612export default class EntryAbility extends UIAbility { 11613 // ... 11614 11615 onWindowStageCreate(windowStage: window.WindowStage) { 11616 console.info('onWindowStageCreate'); 11617 let windowClass: window.Window | undefined = undefined; 11618 try { 11619 windowStage.createSubWindow('mySubWindow', (err: BusinessError, data) => { 11620 const errCode: number = err.code; 11621 if (errCode) { 11622 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 11623 return; 11624 } 11625 windowClass = data; 11626 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 11627 if (!windowClass) { 11628 console.info('Failed to load the content. Cause: windowClass is null'); 11629 } 11630 else { 11631 (windowClass as window.Window).resize(500, 1000); 11632 } 11633 }); 11634 } catch (exception) { 11635 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 11636 } 11637 } 11638}; 11639``` 11640 11641### createSubWindow<sup>9+</sup> 11642 11643createSubWindow(name: string): Promise<Window> 11644 11645创建该WindowStage实例下的子窗口,使用Promise异步回调。 11646 11647**模型约束:** 此接口仅可在Stage模型下使用。 11648 11649**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11650 11651**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11652 11653**参数:** 11654 11655| 参数名 | 类型 | 必填 | 说明 | 11656| ------ | ------ | ---- | -------------- | 11657| name | string | 是 | 子窗口的名字。 | 11658 11659**返回值:** 11660 11661| 类型 | 说明 | 11662| -------------------------------- | ------------------------------------------------ | 11663| Promise<[Window](#window)> | Promise对象。返回当前WindowStage下的子窗口对象。 | 11664 11665**错误码:** 11666 11667以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11668 11669| 错误码ID | 错误信息 | 11670| ------- | ------------------------------ | 11671| 401 | Parameter error. Possible cause: Incorrect parameter types. | 11672| 1300002 | This window state is abnormal. | 11673| 1300005 | This window stage is abnormal. | 11674 11675**示例:** 11676 11677```ts 11678// EntryAbility.ets 11679import { UIAbility } from '@kit.AbilityKit'; 11680import { BusinessError } from '@kit.BasicServicesKit'; 11681 11682export default class EntryAbility extends UIAbility { 11683 // ... 11684 11685 onWindowStageCreate(windowStage: window.WindowStage) { 11686 console.info('onWindowStageCreate'); 11687 let windowClass: window.Window | undefined = undefined; 11688 try { 11689 let promise = windowStage.createSubWindow('mySubWindow'); 11690 promise.then((data) => { 11691 windowClass = data; 11692 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 11693 }).catch((err: BusinessError) => { 11694 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 11695 }); 11696 } catch (exception) { 11697 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 11698 } 11699 } 11700}; 11701``` 11702 11703### createSubWindowWithOptions<sup>11+</sup> 11704 11705createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise<Window> 11706 11707创建该WindowStage实例下的子窗口,使用Promise异步回调。 11708 11709**模型约束:** 此接口仅可在Stage模型下使用。 11710 11711**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 11712 11713**系统能力:** SystemCapability.Window.SessionManager 11714 11715**参数:** 11716 11717| 参数名 | 类型 | 必填 | 说明 | 11718| ------ | ------ | ---- | -------------- | 11719| name | string | 是 | 子窗口的名字。 | 11720| options | [SubWindowOptions](#subwindowoptions11) | 是 | 子窗口参数。 | 11721 11722**返回值:** 11723 11724| 类型 | 说明 | 11725| -------------------------------- | ------------------------------------------------ | 11726| Promise<[Window](#window)> | Promise对象。返回当前WindowStage下创建的子窗口对象。 | 11727 11728**错误码:** 11729 11730以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11731 11732| 错误码ID | 错误信息 | 11733| ------- | ------------------------------ | 11734| 401 | Parameter error. Possible cause: Incorrect parameter types. | 11735| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 11736| 1300002 | This window state is abnormal. | 11737| 1300005 | This window stage is abnormal. | 11738 11739**示例:** 11740 11741```ts 11742// EntryAbility.ets 11743import { UIAbility } from '@kit.AbilityKit'; 11744import { BusinessError } from '@kit.BasicServicesKit'; 11745 11746export default class EntryAbility extends UIAbility { 11747 // ... 11748 11749 onWindowStageCreate(windowStage: window.WindowStage) { 11750 console.info('onWindowStageCreate'); 11751 let windowClass: window.Window | undefined = undefined; 11752 try { 11753 let options : window.SubWindowOptions = { 11754 title: 'title', 11755 decorEnabled: true 11756 }; 11757 let promise = windowStage.createSubWindowWithOptions('mySubWindow', options); 11758 promise.then((data) => { 11759 windowClass = data; 11760 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 11761 }).catch((err: BusinessError) => { 11762 console.error(`Failed to create the subwindow. Cause code: ${err.code}, message: ${err.message}`); 11763 }); 11764 } catch (exception) { 11765 console.error(`Failed to create the subwindow. Cause code: ${exception.code}, message: ${exception.message}`); 11766 } 11767 } 11768}; 11769``` 11770 11771### getSubWindow<sup>9+</sup> 11772 11773getSubWindow(callback: AsyncCallback<Array<Window>>): void 11774 11775获取该WindowStage实例下的所有子窗口,使用callback异步回调。 11776 11777**模型约束:** 此接口仅可在Stage模型下使用。 11778 11779**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11780 11781**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11782 11783**参数:** 11784 11785| 参数名 | 类型 | 必填 | 说明 | 11786| -------- | --------------------------------------------------- | ---- | ------------------------------------------------- | 11787| callback | AsyncCallback<Array<[Window](#window)>> | 是 | 回调函数。返回当前WindowStage下的所有子窗口对象。 | 11788 11789**错误码:** 11790 11791以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 11792 11793| 错误码ID | 错误信息 | 11794| ------- | ------------------------------ | 11795| 1300005 | This window stage is abnormal. | 11796 11797**示例:** 11798<!--code_no_check--> 11799```ts 11800// EntryAbility.ets 11801import { UIAbility } from '@kit.AbilityKit'; 11802import { BusinessError } from '@kit.BasicServicesKit'; 11803 11804export default class EntryAbility extends UIAbility { 11805 // ... 11806 11807 onWindowStageCreate(windowStage: window.WindowStage) { 11808 console.info('onWindowStageCreate'); 11809 let windowClass: window.Window[] = []; 11810 windowStage.getSubWindow((err: BusinessError, data) => { 11811 const errCode: number = err.code; 11812 if (errCode) { 11813 console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`); 11814 return; 11815 } 11816 windowClass = data; 11817 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 11818 }); 11819 } 11820}; 11821``` 11822 11823### getSubWindow<sup>9+</sup> 11824 11825getSubWindow(): Promise<Array<Window>> 11826 11827获取该WindowStage实例下的所有子窗口,使用Promise异步回调。 11828 11829**模型约束:** 此接口仅可在Stage模型下使用。 11830 11831**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11832 11833**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11834 11835**返回值:** 11836 11837| 类型 | 说明 | 11838| --------------------------------------------- | ---------------------------------------------------- | 11839| Promise<Array<[Window](#window)>> | Promise对象。返回当前WindowStage下的所有子窗口对象。 | 11840 11841**错误码:** 11842 11843以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 11844 11845| 错误码ID | 错误信息 | 11846| ------- | ------------------------------ | 11847| 1300005 | This window stage is abnormal. | 11848 11849**示例:** 11850<!--code_no_check--> 11851```ts 11852// EntryAbility.ets 11853import { UIAbility } from '@kit.AbilityKit'; 11854import { BusinessError } from '@kit.BasicServicesKit'; 11855 11856export default class EntryAbility extends UIAbility { 11857 // ... 11858 11859 onWindowStageCreate(windowStage: window.WindowStage) { 11860 console.info('onWindowStageCreate'); 11861 let windowClass: window.Window[] = []; 11862 let promise = windowStage.getSubWindow(); 11863 promise.then((data) => { 11864 windowClass = data; 11865 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 11866 }).catch((err: BusinessError) => { 11867 console.error(`Failed to obtain the subwindow. Cause code: ${err.code}, message: ${err.message}`); 11868 }); 11869 } 11870}; 11871``` 11872 11873### loadContent<sup>9+</sup> 11874 11875loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 11876 11877为当前WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 11878 11879**模型约束:** 此接口仅可在Stage模型下使用。 11880 11881**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11882 11883**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11884 11885**参数:** 11886 11887| 参数名 | 类型 | 必填 | 说明 | 11888| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 11889| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 11890| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 11891| callback | AsyncCallback<void> | 是 | 回调函数。 | 11892 11893**错误码:** 11894 11895以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11896 11897| 错误码ID | 错误信息 | 11898| ------- | ------------------------------ | 11899| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11900| 1300002 | This window state is abnormal. | 11901| 1300005 | This window stage is abnormal. | 11902 11903**示例:** 11904 11905```ts 11906// EntryAbility.ets 11907import { UIAbility } from '@kit.AbilityKit'; 11908import { BusinessError } from '@kit.BasicServicesKit'; 11909 11910export default class EntryAbility extends UIAbility { 11911 // ... 11912 11913 storage: LocalStorage = new LocalStorage(); 11914 11915 onWindowStageCreate(windowStage: window.WindowStage) { 11916 this.storage.setOrCreate('storageSimpleProp', 121); 11917 console.info('onWindowStageCreate'); 11918 try { 11919 windowStage.loadContent('pages/page2', this.storage, (err: BusinessError) => { 11920 const errCode: number = err.code; 11921 if (errCode) { 11922 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 11923 return; 11924 } 11925 console.info('Succeeded in loading the content.'); 11926 }); 11927 } catch (exception) { 11928 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 11929 } 11930 } 11931}; 11932``` 11933 11934### loadContent<sup>9+</sup> 11935 11936loadContent(path: string, storage?: LocalStorage): Promise<void> 11937 11938为当前WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 11939 11940**模型约束:** 此接口仅可在Stage模型下使用。 11941 11942**系统能力:** SystemCapability.WindowManager.WindowManager.Core 11943 11944**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11945 11946**参数:** 11947 11948| 参数名 | 类型 | 必填 | 说明 | 11949| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 11950| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 11951| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 否 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 11952 11953**返回值:** 11954 11955| 类型 | 说明 | 11956| ------------------- | ------------------------- | 11957| Promise<void> | 无返回结果的Promise对象。 | 11958 11959**错误码:** 11960 11961以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 11962 11963| 错误码ID | 错误信息 | 11964| ------- | ------------------------------ | 11965| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 11966| 1300002 | This window state is abnormal. | 11967| 1300005 | This window stage is abnormal. | 11968 11969**示例:** 11970 11971```ts 11972// EntryAbility.ets 11973import { UIAbility } from '@kit.AbilityKit'; 11974import { BusinessError } from '@kit.BasicServicesKit'; 11975 11976export default class EntryAbility extends UIAbility { 11977 // ... 11978 11979 storage: LocalStorage = new LocalStorage(); 11980 11981 onWindowStageCreate(windowStage: window.WindowStage) { 11982 this.storage.setOrCreate('storageSimpleProp', 121); 11983 console.info('onWindowStageCreate'); 11984 try { 11985 let promise = windowStage.loadContent('pages/page2', this.storage); 11986 promise.then(() => { 11987 console.info('Succeeded in loading the content.'); 11988 }).catch((err: BusinessError) => { 11989 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 11990 }); 11991 } catch (exception) { 11992 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 11993 } 11994 ; 11995 } 11996}; 11997``` 11998 11999### loadContent<sup>9+</sup> 12000 12001loadContent(path: string, callback: AsyncCallback<void>): void 12002 12003为当前WindowStage的主窗口加载具体页面内容,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 12004 12005**模型约束:** 此接口仅可在Stage模型下使用。 12006 12007**系统能力:** SystemCapability.WindowManager.WindowManager.Core 12008 12009**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 12010 12011**参数:** 12012 12013| 参数名 | 类型 | 必填 | 说明 | 12014| -------- | ------------------------- | ---- | -------------------- | 12015| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 12016| callback | AsyncCallback<void> | 是 | 回调函数。 | 12017 12018**错误码:** 12019 12020以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12021 12022| 错误码ID | 错误信息 | 12023| ------- | ------------------------------ | 12024| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 12025| 1300002 | This window state is abnormal. | 12026| 1300005 | This window stage is abnormal. | 12027 12028**示例:** 12029 12030```ts 12031// EntryAbility.ets 12032import { UIAbility } from '@kit.AbilityKit'; 12033import { BusinessError } from '@kit.BasicServicesKit'; 12034 12035export default class EntryAbility extends UIAbility { 12036 // ... 12037 12038 onWindowStageCreate(windowStage: window.WindowStage) { 12039 console.info('onWindowStageCreate'); 12040 try { 12041 windowStage.loadContent('pages/page2', (err: BusinessError) => { 12042 const errCode: number = err.code; 12043 if (errCode) { 12044 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 12045 return; 12046 } 12047 console.info('Succeeded in loading the content.'); 12048 }); 12049 } catch (exception) { 12050 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 12051 } 12052 } 12053}; 12054``` 12055 12056### loadContentByName<sup>11+</sup> 12057 12058loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback<void>): void 12059 12060为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 12061 12062**模型约束:** 此接口仅可在Stage模型下使用。 12063 12064**系统能力:** SystemCapability.WindowManager.WindowManager.Core 12065 12066**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 12067 12068**参数:** 12069 12070| 参数名 | 类型 | 必填 | 说明 | 12071| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 12072| name | string | 是 | 命名路由页面的名称。 | 12073| storage | [LocalStorage](../../ui/state-management/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 12074| callback | AsyncCallback<void> | 是 | 回调函数。 | 12075 12076**错误码:** 12077 12078以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12079 12080| 错误码ID | 错误信息 | 12081| -------- | --------------------------------------------- | 12082| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 12083| 1300002 | This window state is abnormal. | 12084| 1300003 | This window manager service works abnormally. | 12085 12086**示例:** 12087 12088<!--code_no_check--> 12089```ts 12090// EntryAbility.ets 12091import { UIAbility } from '@kit.AbilityKit'; 12092import { BusinessError } from '@kit.BasicServicesKit'; 12093import * as Index from '../pages/Index'; // 导入命名路由页面 12094 12095export default class EntryAbility extends UIAbility { 12096 // ... 12097 12098 storage: LocalStorage = new LocalStorage(); 12099 12100 onWindowStageCreate(windowStage: window.WindowStage) { 12101 console.info('onWindowStageCreate'); 12102 this.storage.setOrCreate('storageSimpleProp', 121); 12103 try { 12104 windowStage.loadContentByName(Index.entryName, this.storage, (err: BusinessError) => { 12105 const errCode: number = err.code; 12106 if (errCode) { 12107 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 12108 return; 12109 } 12110 console.info('Succeeded in loading the content.'); 12111 }); 12112 } catch (exception) { 12113 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 12114 } 12115 } 12116}; 12117``` 12118<!--code_no_check--> 12119```ts 12120// ets/pages/Index.ets 12121export const entryName : string = 'Index'; 12122@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 12123@Component 12124export struct Index { 12125 @State message: string = 'Hello World' 12126 build() { 12127 Row() { 12128 Column() { 12129 Text(this.message) 12130 .fontSize(50) 12131 .fontWeight(FontWeight.Bold) 12132 } 12133 .width('100%') 12134 } 12135 .height('100%') 12136 } 12137} 12138``` 12139 12140### loadContentByName<sup>11+</sup> 12141 12142loadContentByName(name: string, callback: AsyncCallback<void>): void 12143 12144为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,使用callback异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 12145 12146**模型约束:** 此接口仅可在Stage模型下使用。 12147 12148**系统能力:** SystemCapability.WindowManager.WindowManager.Core 12149 12150**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 12151 12152**参数:** 12153 12154| 参数名 | 类型 | 必填 | 说明 | 12155| -------- | ------------------------- | ---- | ---------------- | 12156| name | string | 是 | 命名路由页面的名称。 | 12157| callback | AsyncCallback<void> | 是 | 回调函数。 | 12158 12159**错误码:** 12160 12161以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12162 12163| 错误码ID | 错误信息 | 12164| -------- | --------------------------------------------- | 12165| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 12166| 1300002 | This window state is abnormal. | 12167| 1300003 | This window manager service works abnormally. | 12168 12169**示例:** 12170 12171<!--code_no_check--> 12172```ts 12173// EntryAbility.ets 12174import { UIAbility } from '@kit.AbilityKit'; 12175import { BusinessError } from '@kit.BasicServicesKit'; 12176import * as Index from '../pages/Index'; // 导入命名路由页面 12177 12178export default class EntryAbility extends UIAbility { 12179 // ... 12180 12181 onWindowStageCreate(windowStage: window.WindowStage) { 12182 console.info('onWindowStageCreate'); 12183 try { 12184 windowStage.loadContentByName(Index.entryName, (err: BusinessError) => { 12185 const errCode: number = err.code; 12186 if (errCode) { 12187 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 12188 return; 12189 } 12190 console.info('Succeeded in loading the content.'); 12191 }); 12192 } catch (exception) { 12193 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 12194 } 12195 } 12196}; 12197``` 12198<!--code_no_check--> 12199```ts 12200// ets/pages/Index.ets 12201export const entryName : string = 'Index'; 12202@Entry({routeName: entryName}) 12203@Component 12204export struct Index { 12205 @State message: string = 'Hello World' 12206 build() { 12207 Row() { 12208 Column() { 12209 Text(this.message) 12210 .fontSize(50) 12211 .fontWeight(FontWeight.Bold) 12212 } 12213 .width('100%') 12214 } 12215 .height('100%') 12216 } 12217} 12218``` 12219 12220### loadContentByName<sup>11+</sup> 12221 12222loadContentByName(name: string, storage?: LocalStorage): Promise<void>; 12223 12224为当前WindowStage加载[命名路由](../../ui/arkts-routing.md#命名路由)页面,通过LocalStorage传递状态属性给加载的页面,使用promise异步回调。建议在UIAbility启动过程中使用该接口,多次调用该接口会先销毁旧的页面内容(即UIContent)再加载新的页面内容,请谨慎使用。 12225 12226**模型约束:** 此接口仅可在Stage模型下使用。 12227 12228**系统能力:** SystemCapability.WindowManager.WindowManager.Core 12229 12230**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 12231 12232**参数:** 12233 12234| 参数名 | 类型 | 必填 | 说明 | 12235| ------- | ------------ | ---- | ------------------------------------------------------------ | 12236| name | string | 是 | 命名路由页面的名称。 | 12237| storage | LocalStorage | 否 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 12238 12239**错误码:** 12240 12241以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12242 12243| 错误码ID | 错误信息 | 12244| -------- | --------------------------------------------- | 12245| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 12246| 1300002 | This window state is abnormal. | 12247| 1300003 | This window manager service works abnormally. | 12248 12249**示例:** 12250 12251<!--code_no_check--> 12252```ts 12253// EntryAbility.ets 12254import { UIAbility } from '@kit.AbilityKit'; 12255import { BusinessError } from '@kit.BasicServicesKit'; 12256import * as Index from '../pages/Index'; // 导入命名路由页面 12257 12258export default class EntryAbility extends UIAbility { 12259 // ... 12260 12261 storage: LocalStorage = new LocalStorage(); 12262 12263 onWindowStageCreate(windowStage: window.WindowStage) { 12264 console.info('onWindowStageCreate'); 12265 this.storage.setOrCreate('storageSimpleProp', 121); 12266 try { 12267 let promise = windowStage.loadContentByName(Index.entryName, this.storage); 12268 promise.then(() => { 12269 console.info('Succeeded in loading the content.'); 12270 }).catch((err: BusinessError) => { 12271 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 12272 }); 12273 } catch (exception) { 12274 console.error(`Failed to load the content. Cause code: ${exception.code}, message: ${exception.message}`); 12275 } 12276 } 12277}; 12278``` 12279<!--code_no_check--> 12280```ts 12281// ets/pages/Index.ets 12282export const entryName : string = 'Index'; 12283@Entry({routeName: entryName, storage : LocalStorage.getShared()}) 12284@Component 12285export struct Index { 12286 @State message: string = 'Hello World' 12287 build() { 12288 Row() { 12289 Column() { 12290 Text(this.message) 12291 .fontSize(50) 12292 .fontWeight(FontWeight.Bold) 12293 } 12294 .width('100%') 12295 } 12296 .height('100%') 12297 } 12298} 12299``` 12300 12301### on('windowStageEvent')<sup>9+</sup> 12302 12303on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void 12304 12305开启WindowStage生命周期变化的监听。 12306 12307**模型约束:** 此接口仅可在Stage模型下使用。 12308 12309**系统能力:** SystemCapability.WindowManager.WindowManager.Core 12310 12311**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 12312 12313**参数:** 12314 12315| 参数名 | 类型 | 必填 | 说明 | 12316| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 12317| eventType | string | 是 | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 | 12318| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | 是 | 回调函数。返回当前的WindowStage生命周期状态。 | 12319 12320**错误码:** 12321 12322以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12323 12324| 错误码ID | 错误信息 | 12325| ------- | ------------------------------ | 12326| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 12327| 1300002 | This window state is abnormal. | 12328| 1300005 | This window stage is abnormal. | 12329 12330**示例:** 12331 12332```ts 12333// EntryAbility.ets 12334import { UIAbility } from '@kit.AbilityKit'; 12335 12336export default class EntryAbility extends UIAbility { 12337 // ... 12338 12339 onWindowStageCreate(windowStage: window.WindowStage) { 12340 console.info('onWindowStageCreate'); 12341 try { 12342 windowStage.on('windowStageEvent', (data) => { 12343 console.info('Succeeded in enabling the listener for window stage event changes. Data: ' + 12344 JSON.stringify(data)); 12345 }); 12346 } catch (exception) { 12347 console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`); 12348 } 12349 } 12350}; 12351``` 12352 12353### off('windowStageEvent')<sup>9+</sup> 12354 12355off(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType>): void 12356 12357关闭WindowStage生命周期变化的监听。 12358 12359**模型约束:** 此接口仅可在Stage模型下使用。 12360 12361**系统能力:** SystemCapability.WindowManager.WindowManager.Core 12362 12363**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 12364 12365**参数:** 12366 12367| 参数名 | 类型 | 必填 | 说明 | 12368| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 12369| eventType | string | 是 | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 | 12370| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | 否 | 回调函数。返回当前的WindowStage生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有WindowStage生命周期变化的监听。 | 12371 12372**错误码:** 12373 12374以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12375 12376| 错误码ID | 错误信息 | 12377| ------- | ------------------------------ | 12378| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 12379| 1300002 | This window state is abnormal. | 12380| 1300005 | This window stage is abnormal. | 12381 12382**示例:** 12383 12384```ts 12385// EntryAbility.ets 12386import { UIAbility } from '@kit.AbilityKit'; 12387 12388export default class EntryAbility extends UIAbility { 12389 // ... 12390 12391 onWindowStageCreate(windowStage: window.WindowStage) { 12392 console.info('onWindowStageCreate'); 12393 const callback = (windowStageEventType: window.WindowStageEventType) => { 12394 // ... 12395 } 12396 try { 12397 windowStage.on('windowStageEvent', callback); 12398 } catch (exception) { 12399 console.error(`Failed to enable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`); 12400 } 12401 try { 12402 windowStage.off('windowStageEvent', callback); 12403 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 12404 windowStage.off('windowStageEvent'); 12405 } catch (exception) { 12406 console.error(`Failed to disable the listener for window stage event changes. Cause code: ${exception.code}, message: ${exception.message}`); 12407 } 12408 } 12409}; 12410``` 12411 12412### on('windowStageClose')<sup>14+</sup> 12413 12414on(eventType: 'windowStageClose', callback: Callback<void>): void 12415 12416开启点击主窗三键区的关闭按钮监听事件。点击主窗口的三键区域的关闭键时触发该回调函数,将不执行注册的[UIAbility.onPrepareToTerminate](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonpreparetoterminate10)生命周期回调函数。 12417 12418当重复注册窗口关闭事件的监听时,最后一次注册成功的监听事件生效。 12419 12420触发的回调函数是同步执行,主窗口的异步关闭事件监听参考[on('windowWillClose')](#onwindowwillclose15)方法。 12421 12422如果存在[on('windowWillClose')](#onwindowwillclose15)监听事件,只响应[on('windowWillClose')](#onwindowwillclose15)接口。 12423 12424<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 12425 12426**模型约束:** 此接口仅可在Stage模型下使用。 12427 12428**系统能力:** SystemCapability.Window.SessionManager 12429 12430**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 12431 12432**参数:** 12433 12434| 参数名 | 类型 | 必填 | 说明 | 12435| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 12436| eventType | string | 是 | 监听事件,固定为'windowStageClose',即开启主窗三键区的关闭按钮监听。| 12437| callback | Callback<void> | 是 | 回调函数。当点击主窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前主窗是否继续关闭,true表示不关闭,false表示关闭。| 12438 12439**错误码:** 12440 12441以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12442 12443| 错误码ID | 错误信息 | 12444| ------- | ------------------------------ | 12445| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 12446| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12447| 1300002 | This window state is abnormal. | 12448 12449**示例:** 12450 12451```ts 12452// EntryAbility.ets 12453import { UIAbility } from '@kit.AbilityKit'; 12454import { window } from '@kit.ArkUI'; 12455 12456export default class EntryAbility extends UIAbility { 12457 // ... 12458 12459 onWindowStageCreate(windowStage: window.WindowStage) { 12460 console.info('onWindowStageCreate'); 12461 try { 12462 windowStage.on('windowStageClose', () => { 12463 console.info('Succeeded in enabling the listener for window stage close event.'); 12464 return false; 12465 }); 12466 } catch (exception) { 12467 console.error(`Failed to enable the listener for window stage close event. Cause code: ${exception.code}, message: ${exception.message}`); 12468 } 12469 } 12470}; 12471``` 12472 12473### off('windowStageClose')<sup>14+</sup> 12474 12475off(eventType: 'windowStageClose', callback?: Callback<void>): void 12476 12477关闭主窗口关闭事件的监听。 12478 12479<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 12480 12481**模型约束:** 此接口仅可在Stage模型下使用。 12482 12483**系统能力:** SystemCapability.Window.SessionManager 12484 12485**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 12486 12487**参数:** 12488 12489| 参数名 | 类型 | 必填 | 说明 | 12490| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 12491| eventType | string | 是 | 监听事件,固定为'windowStageClose',即关闭主窗口关闭事件的监听。 | 12492| callback | Callback<void> | 否 | 回调函数。当点击主窗口右上角关闭按钮事件发生时的回调。该回调函数不返回任何参数。回调函数内部逻辑需要有boolean类型的返回值,该返回值决定当前主窗是否继续关闭,true表示不关闭,false表示关闭。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有主窗口关闭的监听。 | 12493 12494**错误码:** 12495 12496以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12497 12498| 错误码ID | 错误信息 | 12499| ------- | ------------------------------ | 12500| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 12501| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12502| 1300002 | This window state is abnormal. | 12503 12504**示例:** 12505 12506```ts 12507// EntryAbility.ets 12508import { UIAbility } from '@kit.AbilityKit'; 12509import { window } from '@kit.ArkUI'; 12510 12511export default class EntryAbility extends UIAbility { 12512 // ... 12513 12514 onWindowStageCreate(windowStage: window.WindowStage) { 12515 console.info('onWindowStageCreate'); 12516 const callback = () => { 12517 // ... 12518 return false; 12519 } 12520 try { 12521 windowStage.on('windowStageClose', callback); 12522 windowStage.off('windowStageClose', callback); 12523 windowStage.off('windowStageClose'); 12524 } catch (exception) { 12525 console.error(`Failed to disable the listener for window stage close changes. Cause code: ${exception.code}, message: ${exception.message}`); 12526 } 12527 } 12528}; 12529``` 12530 12531### setDefaultDensityEnabled<sup>12+</sup> 12532 12533setDefaultDensityEnabled(enabled: boolean): void 12534 12535设置应用是否使用系统默认Density。 12536 12537不调用此接口进行设置,则表示不使用系统默认Density,即窗口会跟随系统显示大小变化重新布局。 12538 12539**模型约束:** 此接口仅可在Stage模型下使用。 12540 12541**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 12542 12543**系统能力:** SystemCapability.Window.SessionManager 12544 12545**参数:** 12546 12547| 参数名 | 类型 | 必填 | 说明 | 12548| ---------------- | ------- | ---- | ---------------------------- | 12549| enabled | boolean | 是 | 是否设置应用使用系统默认Density。true表示使用系统默认Density,窗口不跟随系统显示大小变化重新布局;false表示不使用系统默认Density,窗口跟随系统显示大小变化重新布局。 | 12550 12551**错误码:** 12552 12553以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12554 12555| 错误码ID | 错误信息 | 12556| ------- | ------------------------------ | 12557| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 12558| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12559| 1300002 | This window state is abnormal. | 12560| 1300005 | This window stage is abnormal. | 12561 12562**示例:** 12563 12564```ts 12565// EntryAbility.ets 12566import { UIAbility } from '@kit.AbilityKit'; 12567 12568export default class EntryAbility extends UIAbility { 12569 // ... 12570 12571 onWindowStageCreate(windowStage: window.WindowStage) { 12572 console.info('onWindowStageCreate'); 12573 try { 12574 windowStage.setDefaultDensityEnabled(true); 12575 } catch (exception) { 12576 console.error(`Failed to set default density enabled. Cause code: ${exception.code}, message: ${exception.message}`); 12577 } 12578 } 12579}; 12580``` 12581 12582### setCustomDensity<sup>15+</sup> 12583 12584setCustomDensity(density: number): void 12585 12586支持应用主窗口自定义其显示大小缩放系数,子窗会跟随主窗生效。当存在同时使用该接口和[setDefaultDensityEnabled(true)](#setdefaultdensityenabled12)时,以最终调用的结果设置效果为准。 12587 12588**模型约束:** 此接口仅可在Stage模型下使用。 12589 12590**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 12591 12592**系统能力:** SystemCapability.Window.SessionManager 12593 12594**参数:** 12595 12596| 参数名 | 类型 | 必填 | 说明 | 12597| ---------------- | ------- | ---- | ---------------------------- | 12598| density | number | 是 | 自定义显示大小缩放系数。该参数为浮点数,取值范围为[0.5, 4.0]或-1.0。4.0表示窗口可显示的最大显示大小缩放系数,-1.0表示窗口使用系统显示大小缩放系数。 | 12599 12600**错误码:** 12601 12602以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12603 12604| 错误码ID | 错误信息 | 12605| ------- | ------------------------------ | 12606| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 12607| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12608| 1300002 | This window state is abnormal. | 12609| 1300005 | This window stage is abnormal. | 12610 12611**示例:** 12612 12613```ts 12614// EntryAbility.ets 12615import { UIAbility } from '@kit.AbilityKit'; 12616 12617export default class EntryAbility extends UIAbility { 12618 // ... 12619 12620 onWindowStageCreate(windowStage: window.WindowStage) { 12621 console.info('onWindowStageCreate'); 12622 try { 12623 windowStage.setCustomDensity(-1.0); 12624 } catch (exception) { 12625 console.error(`Failed to set custom density. Cause code: ${exception.code}, message: ${exception.message}`); 12626 } 12627 } 12628}; 12629``` 12630 12631### setWindowModal<sup>14+</sup> 12632 12633setWindowModal(isModal: boolean): Promise<void> 12634 12635设置主窗的模态属性是否启用,使用Promise异步回调。 12636 12637主窗口调用该接口时,设置主窗口模态属性是否启用。启用主窗口模态属性后,其相同应用进程下的其他主窗口以及其他主窗口的子窗口不能响应用户操作,直到该主窗口关闭或者主窗口的模态属性被禁用。 12638 12639<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 12640 12641**模型约束:** 此接口仅可在Stage模型下使用。 12642 12643**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 12644 12645**系统能力:** SystemCapability.Window.SessionManager 12646 12647**参数:** 12648 12649| 参数名 | 类型 | 必填 | 说明 | 12650| --------- | ------- | ---- | --------------------------------------------- | 12651| isModal | boolean | 是 | 设置主窗口模态属性是否启用,true为启用,false为不启用。 | 12652 12653 12654**返回值:** 12655 12656| 类型 | 说明 | 12657| ------------------- | ------------------------ | 12658| Promise<void> | 无返回结果的Promise对象。 | 12659 12660**错误码:** 12661 12662以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12663 12664| 错误码ID | 错误信息 | 12665| -------- | ------------------------------ | 12666| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 12667| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12668| 1300002 | This window state is abnormal. | 12669| 1300003 | This window manager service works abnormally. | 12670 12671**示例:** 12672 12673```ts 12674// EntryAbility.ets 12675import { UIAbility } from '@kit.AbilityKit'; 12676import { BusinessError } from '@kit.BasicServicesKit'; 12677 12678export default class EntryAbility extends UIAbility { 12679 // ... 12680 onWindowStageCreate(windowStage: window.WindowStage): void { 12681 console.info('onWindowStageCreate'); 12682 try { 12683 let promise = windowStage.setWindowModal(true); 12684 promise.then(() => { 12685 console.info('Succeeded in setting window modal'); 12686 }).catch((err: BusinessError) => { 12687 console.error(`Failed to set window modal. Cause code: ${err.code}, message: ${err.message}`); 12688 }); 12689 } catch (exception) { 12690 console.error(`Failed to set window modal. Cause code: ${exception.code}, message: ${exception.message}`); 12691 } 12692 } 12693} 12694``` 12695 12696### removeStartingWindow<sup>14+</sup> 12697 12698removeStartingWindow(): Promise<void> 12699 12700支持应用控制启动页消失时机。 12701 12702此接口只对应用主窗口生效,且需要在module.json5配置文件[abilities](../../quick-start/module-configuration-file.md#abilities标签)标签中的metadata标签下配置"enable.remove.starting.window"为"true"才会生效。 12703 12704在标签配置为"true"的情况下,系统提供了启动页超时保护机制,若5s内未调用此接口,系统将自动移除启动页。 12705 12706若标签配置为"false"或未配置标签,则此接口不生效,启动页将会在应用首帧渲染完成后自动移除。 12707 12708**模型约束:** 此接口仅可在Stage模型下使用。 12709 12710**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 12711 12712**系统能力:** SystemCapability.Window.SessionManager 12713 12714**返回值:** 12715 12716| 类型 | 说明 | 12717| ------------------- | ------------------------- | 12718| Promise<void> | 无返回结果的Promise对象。 | 12719 12720**错误码:** 12721 12722以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12723 12724| 错误码ID | 错误信息 | 12725| ------- | ------------------------------ | 12726| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12727| 1300002 | This window state is abnormal. | 12728| 1300003 | This window manager service works abnormally. | 12729 12730**示例:** 12731 12732```ts 12733// EntryAbility.ets 12734import { UIAbility } from '@kit.AbilityKit'; 12735import { BusinessError } from '@kit.BasicServicesKit'; 12736 12737export default class EntryAbility extends UIAbility { 12738 // ... 12739 12740 onWindowStageCreate(windowStage: window.WindowStage) { 12741 console.info('onWindowStageCreate'); 12742 windowStage.removeStartingWindow().then(() => { 12743 console.info('Succeeded in removing starting window.'); 12744 }).catch((err: BusinessError) => { 12745 console.error(`Failed to remove starting window. Cause code: ${err.code}, message: ${err.message}`); 12746 }); 12747 } 12748}; 12749``` 12750 12751### setWindowRectAutoSave<sup>14+</sup> 12752 12753setWindowRectAutoSave(enabled: boolean): Promise<void> 12754 12755设置是否启用最后关闭的主窗尺寸的记忆功能,使用Promise异步回调,仅对2in1设备生效。 12756 12757启用记忆功能后,在同一个UIAbility下,记忆最后关闭的主窗口的尺寸;此主窗口再次启动时,以记忆的尺寸按照规则进行打开。 12758 12759层叠规则: 1、当前实例是自由窗口时,打开下一实例窗口层叠时,大小要跟随。2、当前实例是最大化或全屏窗口时,打开下一个实例窗口层叠时,保持最大化。 12760 12761记忆规则: 12762|上一次窗口状态|记忆规则| 12763|-------------|-------| 12764|自由窗口|保留自由窗口的大小/位置,超出工作区回弹| 12765|二分屏窗口|保留二分屏之前自由窗口的大小/位置| 12766|最大化窗口|保留最大化| 12767|沉浸式窗口|保留沉浸式之前自由窗口的大小/位置| 12768|最小化窗口|保留最小化之前自由窗口的大小/位置| 12769 12770**模型约束:** 此接口仅可在Stage模型下使用。 12771 12772**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 12773 12774**系统能力:** SystemCapability.Window.SessionManager 12775 12776**参数:** 12777 12778| 参数名 | 类型 | 必填 | 说明 | 12779| --------- | ------- | ---- | --------------------------------------------- | 12780| enabled | boolean | 是 | 设置是否启用主窗尺寸的记忆功能,true为启用,false为不启用。 | 12781 12782 12783**返回值:** 12784 12785| 类型 | 说明 | 12786| ------------------- | ------------------------ | 12787| Promise<void> | 无返回结果的Promise对象。 | 12788 12789**错误码:** 12790 12791以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12792 12793| 错误码ID | 错误信息 | 12794| -------- | ------------------------------ | 12795| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 12796| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12797| 1300002 | This window state is abnormal. | 12798| 1300003 | This window manager service works abnormally. | 12799 12800**示例:** 12801 12802```ts 12803// EntryAbility.ets 12804import { UIAbility } from '@kit.AbilityKit'; 12805import { BusinessError } from '@kit.BasicServicesKit'; 12806 12807export default class EntryAbility extends UIAbility { 12808 // ... 12809 onWindowStageCreate(windowStage: window.WindowStage): void { 12810 console.info('onWindowStageCreate'); 12811 try { 12812 let promise = windowStage.setWindowRectAutoSave(true); 12813 promise.then(() => { 12814 console.info('Succeeded in setting window rect auto-save'); 12815 }).catch((err: BusinessError) => { 12816 console.error(`Failed to set window rect auto-save. Cause code: ${err.code}, message: ${err.message}`); 12817 }); 12818 } catch (exception) { 12819 console.error(`Failed to set window rect auto-save. Cause code: ${exception.code}, message: ${exception.message}`); 12820 } 12821 } 12822} 12823``` 12824 12825### setWindowRectAutoSave<sup>17+</sup> 12826 12827setWindowRectAutoSave(enabled: boolean, isSaveBySpecifiedFlag: boolean): Promise<void> 12828 12829设置是否启用主窗的尺寸记忆功能,使用Promise异步回调,仅对2in1设备生效。 12830 12831在同一个UIAbility下,可记忆最后关闭的主窗口尺寸,也可针对每个主窗口尺寸单独进行记忆。只有在UIAbility启动模式为specified,且isSaveBySpecifiedFlag设置为true时,才能针对每个主窗口尺寸进行单独记忆。 12832 12833启用记忆功能后,记忆主窗口关闭时的尺寸;对应主窗口再次启动时,以记忆的尺寸按照规则进行打开。 12834 12835记忆规则: 12836|上一次窗口状态|记忆规则| 12837|-------------|-------| 12838|自由窗口|保留自由窗口的大小/位置,超出工作区回弹。| 12839|二分屏窗口|保留二分屏之前自由窗口的大小/位置。| 12840|最大化窗口|保留最大化。| 12841|沉浸式窗口|保留沉浸式之前自由窗口的大小/位置。| 12842|最小化窗口|保留最小化之前自由窗口的大小/位置。| 12843 12844**模型约束:** 此接口仅可在Stage模型下使用。 12845 12846**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。 12847 12848**系统能力:** SystemCapability.Window.SessionManager 12849 12850**参数:** 12851 12852| 参数名 | 类型 | 必填 | 说明 | 12853| --------- | ------- | ---- | --------------------------------------------- | 12854| enabled | boolean | 是 | 设置是否启用主窗的尺寸记忆功能,true为启用,false为不启用。 | 12855| isSaveBySpecifiedFlag | boolean | 是 | 设置specified模式下是否启用对窗口进行单独记忆,true为启用,false为不启用。 | 12856 12857 12858**返回值:** 12859 12860| 类型 | 说明 | 12861| ------------------- | ------------------------ | 12862| Promise<void> | 无返回结果的Promise对象。 | 12863 12864**错误码:** 12865 12866以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12867 12868| 错误码ID | 错误信息 | 12869| -------- | ------------------------------ | 12870| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 12871| 801 | Capability not supported. Function setWindowRectAutoSave can not work correctly due to limited device capabilities. | 12872| 1300002 | This window state is abnormal. | 12873| 1300003 | This window manager service works abnormally. | 12874 12875**示例:** 12876 12877```ts 12878// EntryAbility.ets 12879import { UIAbility } from '@kit.AbilityKit'; 12880import { BusinessError } from '@kit.BasicServicesKit'; 12881 12882export default class EntryAbility extends UIAbility { 12883 // ... 12884 onWindowStageCreate(windowStage: window.WindowStage): void { 12885 console.info('onWindowStageCreate'); 12886 try { 12887 let promise = windowStage.setWindowRectAutoSave(true, true); 12888 promise.then(() => { 12889 console.info('Succeeded in setting window rect auto-save'); 12890 }).catch((err: BusinessError) => { 12891 console.error(`Failed to set window rect auto-save. Cause code: ${err.code}, message: ${err.message}`); 12892 }); 12893 } catch (exception) { 12894 console.error(`Failed to set window rect auto-save. Cause code: ${exception.code}, message: ${exception.message}`); 12895 } 12896 } 12897} 12898``` 12899 12900### isWindowRectAutoSave<sup>14+</sup> 12901 12902isWindowRectAutoSave(): Promise<boolean> 12903 12904判断当前主窗口是否已经启用尺寸记忆,使用Promise异步回调,仅对2in1设备生效。 12905 12906**模型约束:** 此接口仅可在Stage模型下使用。 12907 12908**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 12909 12910**系统能力:** SystemCapability.Window.SessionManager 12911 12912**返回值:** 12913 12914| 类型 | 说明 | 12915| ---------------------- | ------------------------------------------------------------------------------------ | 12916| Promise<boolean> | Promise对象。返回true表示当前窗口启用尺寸记忆,返回false表示当前窗口禁用尺寸记忆。 | 12917 12918**错误码:** 12919 12920以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 12921 12922| 错误码ID | 错误信息 | 12923| ------- | ------------------------------ | 12924| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12925| 1300002 | This window state is abnormal. | 12926 12927**示例:** 12928 12929```ts 12930// EntryAbility.ets 12931import { UIAbility } from '@kit.AbilityKit'; 12932import { BusinessError } from '@kit.BasicServicesKit'; 12933 12934export default class EntryAbility extends UIAbility { 12935 // ... 12936 onWindowStageCreate(windowStage: window.WindowStage): void { 12937 console.info('onWindowStageCreate'); 12938 try { 12939 let promise = windowStage.isWindowRectAutoSave(); 12940 promise.then((data) => { 12941 console.info('Succeeded in checking whether the window support the rect auto-save. Data: ' + JSON.stringify(data)); 12942 }).catch((err: BusinessError) => { 12943 console.error(`Failed to check whether the window support the rect auto-save. Cause code: ${err.code}, message: ${err.message}`); 12944 }); 12945 } catch (exception) { 12946 console.error(`Failed to check whether the window support the rect auto-save. Cause code: ${exception.code}, message: ${exception.message}`); 12947 } 12948 } 12949} 12950``` 12951 12952### setSupportedWindowModes<sup>15+</sup> 12953 12954setSupportedWindowModes(supportedWindowModes: Array<bundleManager.SupportWindowMode>): Promise<void> 12955 12956设置主窗的窗口支持模式,使用Promise异步回调。 12957 12958<!--RP6-->此接口仅可在2in1设备下使用。<!--RP6End--> 12959 12960**模型约束:** 此接口仅可在Stage模型下使用。 12961 12962**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 12963 12964**系统能力:** SystemCapability.Window.SessionManager 12965 12966**参数:** 12967 12968| 参数名 | 类型 | 必填 | 说明 | 12969| --------- | ------- | ---- | --------------------------------------------- | 12970| supportedWindowModes | Array<[bundleManager.SupportWindowMode](../apis-ability-kit/js-apis-bundleManager.md#supportwindowmode)> | 是 | 设置主窗的窗口支持模式。<br>- FULL_SCREEN:支持全屏模式。<br>- FLOATING:支持悬浮窗模式。<br>- SPLIT:支持分屏模式。需要配合FULL_SCREEN或FLOATING一起使用,不支持仅配置SPLIT。<br> 注:数组中SupportWindowMode字段取值不应该与该UIAbility对应的[module.json5配置文件](../../quick-start/module-configuration-file.md)中[abilities标签](../../quick-start/module-configuration-file.md#abilities标签)的supportWindowMode字段取值或者[StartOptions](../apis-ability-kit/js-apis-app-ability-startOptions.md)中[属性](../apis-ability-kit/js-apis-app-ability-startOptions.md#属性)的supportWindowModes字段取值冲突。当取值冲突时,最终以该参数设置的窗口支持模式为准。| 12971 12972**返回值:** 12973 12974| 类型 | 说明 | 12975| ------------------- | ------------------------ | 12976| Promise<void> | 无返回结果的Promise对象。 | 12977 12978**错误码:** 12979 12980以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 12981 12982| 错误码ID | 错误信息 | 12983| -------- | ------------------------------ | 12984| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 12985| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 12986| 1300002 | This window state is abnormal. | 12987| 1300003 | This window manager service works abnormally. | 12988 12989**示例:** 12990 12991```ts 12992// EntryAbility.ets 12993import { UIAbility, bundleManager } from '@kit.AbilityKit'; 12994import { BusinessError } from '@kit.BasicServicesKit'; 12995 12996export default class EntryAbility extends UIAbility { 12997 // ... 12998 onWindowStageCreate(windowStage: window.WindowStage): void { 12999 console.info('onWindowStageCreate'); 13000 try { 13001 let promise = windowStage.setSupportedWindowModes([ 13002 bundleManager.SupportWindowMode.FULL_SCREEN, 13003 bundleManager.SupportWindowMode.SPLIT, 13004 bundleManager.SupportWindowMode.FLOATING 13005 ]); 13006 promise.then(() => { 13007 console.info('Succeeded in setting window support modes'); 13008 }).catch((err: BusinessError) => { 13009 console.error(`Failed to set window support modes. Cause code: ${err.code}, message: ${err.message}`); 13010 }); 13011 } catch (exception) { 13012 console.error(`Failed to set window support modes. Cause code: ${exception.code}, message: ${exception.message}`); 13013 } 13014 } 13015} 13016``` 13017