MiniX自绘渲染跨平台框架
  • 框架说明
  • 声明式开发范式
  • 内置Api
指南
接口
  • Minix CLI
示例
  • 类Web框架

    • 框架说明
    • 类Web开发范式
    • 内置Api
  • 指南
  • 组件
  • 接口
  • 示例
  • 规范
  • DophinHybrid

    • 快速上手 (opens new window)
    • UI 组件库 (opens new window)
    • jsBridge 接口 (opens new window)
  • DolphinWeex

    • 快速上手 (opens new window)
    • UI 组件库 (opens new window)
    • jsBridge 接口 (opens new window)
  • 发布消息
  • 常见问题
  • 更新日志
  • 框架说明
  • 声明式开发范式
  • 内置Api
指南
接口
  • Minix CLI
示例
  • 类Web框架

    • 框架说明
    • 类Web开发范式
    • 内置Api
  • 指南
  • 组件
  • 接口
  • 示例
  • 规范
  • DophinHybrid

    • 快速上手 (opens new window)
    • UI 组件库 (opens new window)
    • jsBridge 接口 (opens new window)
  • DolphinWeex

    • 快速上手 (opens new window)
    • UI 组件库 (opens new window)
    • jsBridge 接口 (opens new window)
  • 发布消息
  • 常见问题
  • 更新日志
  • 接口参考

    • UI 界面

    • 图形图像

      • @ohos.window (窗口)
        • 导入模块
        • WindowType
        • AvoidAreaType
        • WindowMode
        • WindowLayoutMode
        • SystemBarProperties
        • Orientation
        • BlurStyle
        • SystemBarRegionTint
        • SystemBarTintState
        • Rect
        • AvoidArea
        • Size
        • WindowProperties
        • ColorSpace
        • ScaleOptions
        • RotateOptions
        • TranslateOptions
        • window.create
        • window.create
        • window.create
        • window.create
        • window.find
        • window.find
        • window.getTopWindow
        • window.getTopWindow
        • window.getTopWindow
        • window.getTopWindow
        • window.minimizeAll
        • window.minimizeAll
        • window.toggleShownStateForAllAppWindows
        • window.toggleShownStateForAllAppWindows
        • window.setWindowLayoutMode
        • window.setWindowLayoutMode
        • on('systemBarTintChange')
        • off('systemBarTintChange')
        • Window
        • WindowStageEventType
        • WindowStage
        • TransitionContext
        • TransitionController
    • 媒体

    • 资源管理

    • 语言基础类库

    • 网络管理

    • 数据管理

    • 设备管理

    • 公共事件与通知

# @ohos.window (窗口)

窗口提供管理窗口的一些基础能力,包括对当前窗口的创建、销毁、各属性设置,以及对各窗口间的管理调度。

该模块提供以下窗口相关的常用功能:

  • Window:当前窗口实例,窗口管理器管理的基本单元。
  • WindowStage:窗口管理器。管理各个基本窗口单元。

说明:

本模块首批接口从 API version 6 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

# 导入模块

import window from "@ohos.window";
1

# WindowType7+

窗口类型枚举。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 值 说明
TYPE_APP 0 表示应用子窗口。
模型约束: 此接口仅可在 FA 模型下使用。
TYPE_SYSTEM_ALERT 1 表示系统告警窗口。
TYPE_INPUT_METHOD9+ 2 表示输入法窗口。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。
TYPE_STATUS_BAR9+ 3 表示状态栏窗口。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。
TYPE_PANEL9+ 4 表示通知栏。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。
TYPE_KEYGUARD9+ 5 表示锁屏。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。
TYPE_VOLUME_OVERLAY9+ 6 表示音量条。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。
TYPE_NAVIGATION_BAR9+ 7 表示导航栏窗口。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。
TYPE_FLOAT9+ 8 表示悬浮窗。
模型约束: 此接口仅可在 Stage 模型下使用。
需要权限: ohos.permission.SYSTEM_FLOAT_WINDOW
TYPE_WALLPAPER9+ 9 表示壁纸。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。
TYPE_DESKTOP9+ 10 表示桌面。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。
TYPE_LAUNCHER_RECENT9+ 11 表示多任务中心。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。
TYPE_LAUNCHER_DOCK9+ 12 表示桌面 Dock 栏。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。
TYPE_VOICE_INTERACTION9+ 13 表示智慧语音。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。
TYPE_POINTER9+ 14 表示鼠标。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。
TYPE_FLOAT_CAMERA9+ 15 表示相机类型悬浮窗。
模型约束: 此接口仅可在 Stage 模型下使用。
需要权限: ohos.permission.SYSTEM_FLOAT_WINDOW
TYPE_DIALOG9+ 16 表示模态窗口。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。
TYPE_SCREENSHOT9+ 17 表示截屏窗口。
模型约束: 此接口仅可在 Stage 模型下使用。
系统接口: 此接口为系统接口。

# AvoidAreaType7+

窗口内容需要规避区域的类型枚举。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 值 说明
TYPE_SYSTEM 0 表示系统默认区域。一般包括状态栏、导航栏和 Dock 栏,各设备系统定义可能不同。
TYPE_CUTOUT 1 表示刘海屏区域。
TYPE_SYSTEM_GESTURE9+ 2 表示手势区域。
TYPE_KEYBOARD9+ 3 表示软键盘区域。

# WindowMode7+

窗口模式枚举。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 值 说明
UNDEFINED 1 表示 APP 未定义窗口模式。
FULLSCREEN 2 表示 APP 全屏模式。
PRIMARY 3 表示 APP 分屏多窗口主要模式。
SECONDARY 4 表示 APP 分屏多窗口次要模式。
FLOATING 5 表示 APP 自由悬浮形式窗口模式。

# WindowLayoutMode9+

窗口布局模式枚举。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 值 说明
WINDOW_LAYOUT_MODE_CASCADE 0 表示使用层叠布局模式。
WINDOW_LAYOUT_MODE_TILE 1 表示使用平铺布局模式。

# SystemBarProperties

状态栏、导航栏的属性。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 参数类型 可读 可写 必填 说明
statusBarColor string 否 是 否 状态栏背景颜色,为十六进制 RGB 或 ARGB 颜色,不区分大小写,例如#00FF00或#FF00FF00。默认值:#0x66000000。
isStatusBarLightIcon7+ boolean 否 是 否 状态栏图标是否为高亮状态。true 表示高亮;false 表示不高亮。默认值:false。
statusBarContentColor8+ string 否 是 否 状态栏文字颜色。当设置此属性后, isStatusBarLightIcon属性设置无效。默认值:0xE5FFFFFF。
navigationBarColor string 否 是 否 导航栏背景颜色,为十六进制 RGB 或 ARGB 颜色,不区分大小写,例如#00FF00或#FF00FF00。默认值:#0x66000000。
isNavigationBarLightIcon7+ boolean 否 是 否 导航栏图标是否为高亮状态。true 表示高亮;false 表示不高亮。默认值:false。
navigationBarContentColor8+ string 否 是 否 导航栏文字颜色。当设置此属性后, isNavigationBarLightIcon属性设置无效。默认值:#0xE5FFFFFF。

# Orientation9+

窗口显示方向类型枚举。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 值 说明
UNSPECIFIED 0 表示未定义方向模式,由系统判定。
PORTRAIT 1 表示竖屏显示模式。
LANDSCAPE 2 表示横屏显示模式。
PORTRAIT_INVERTED 3 表示反向竖屏显示模式。
LANDSCAPE_INVERTED 4 表示反向横屏显示模式。
AUTO_ROTATION 5 表示传感器自动旋转模式。
AUTO_ROTATION_PORTRAIT 6 表示传感器自动竖向旋转模式。
AUTO_ROTATION_LANDSCAPE 7 表示传感器自动横向旋转模式。
AUTO_ROTATION_RESTRICTED 8 表示受开关控制的自动旋转模式。
AUTO_ROTATION_PORTRAIT_RESTRICTED 9 表示受开关控制的自动竖向旋转模式。
AUTO_ROTATION_LANDSCAPE_RESTRICTED 10 表述受开关控制的自动横向旋转模式。
LOCKED 11 表示锁定模式。

# BlurStyle9+

窗口模糊类型枚举。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 值 说明
OFF 0 表示关闭模糊。
THIN 1 表示较薄的模糊类型。
REGULAR 2 表示适中的模糊类型。
THICK 3 表示较厚的模糊类型。

# SystemBarRegionTint8+

单个导航栏或状态栏回调信息。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 参数类型 可读 可写 说明
type WindowType 是 否 当前属性改变的系统栏类型,仅支持类型为导航栏、状态栏的系统栏。
isEnable boolean 是 否 当前系统栏是否显示。
region Rect 是 否 当前系统栏的位置及大小。
backgroundColor string 是 否 系统栏背景颜色,为十六进制 RGB 或 ARGB 颜色,不区分大小写,例如#00FF00或#FF00FF00。
contentColor string 是 否 系统栏文字颜色。

# SystemBarTintState8+

当前系统栏回调信息集合。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 参数类型 可读 可写 说明
displayId number 是 否 当前物理屏幕 id。
regionTint Array<SystemBarRegionTint> 是 否 当前已改变的所有系统栏信息。

# Rect7+

窗口矩形区域。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 参数类型 可读 可写 说明
left number 是 是 矩形区域的左边界。
top number 是 是 矩形区域的上边界。
width number 是 是 矩形区域的宽度。
height number 是 是 矩形区域的高度。

# AvoidArea7+

窗口内容规避区域。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 参数类型 可读 可写 说明
visible9+ boolean 是 是 规避区域是否可见。
leftRect Rect 是 是 屏幕左侧的矩形区。
topRect Rect 是 是 屏幕顶部的矩形区。
rightRect Rect 是 是 屏幕右侧的矩形区。
bottomRect Rect 是 是 屏幕底部的矩形区。

# Size7+

窗口大小。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 参数类型 可读 可写 说明
width number 是 是 窗口宽度。
height number 是 是 窗口高度。

# WindowProperties

窗口属性。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 参数类型 可读 可写 说明
windowRect7+ Rect 是 是 窗口尺寸。
type7+ WindowType 是 是 窗口类型。
isFullScreen boolean 是 是 是否全屏,默认为 false。
isLayoutFullScreen7+ boolean 是 是 窗口是否为沉浸式,默认为 false。
focusable7+ boolean 是 否 窗口是否可聚焦,默认为 true。
touchable7+ boolean 是 否 窗口是否可触摸,默认为 true。
brightness number 是 是 屏幕亮度, 取值范围为 0~1,1 表示最大亮度值。
dimBehindValue(deprecated) number 是 是 靠后窗口的暗度值,取值范围为 0~1,1 表示最暗。
- 说明: 从 API version 9 开始废弃。
- 从 API version 7 开始支持
isKeepScreenOn boolean 是 是 屏幕是否常亮,默认为 false。
isPrivacyMode7+ boolean 是 是 隐私模式,默认为 false。
isRoundCorner(deprecated) boolean 是 是 窗口是否为圆角。默认为 false。
- 说明: 从 API version 9 开始废弃。
- 从 API version 7 开始支持
isTransparent7+ boolean 是 是 窗口是否透明。默认为 false。
id9+ number 是 否 窗口 ID,默认值为 0.0。

# ColorSpace8+

色域模式。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 默认值 说明
DEFAULT 0 默认色域模式。
WIDE_GAMUT 1 广色域模式。

# ScaleOptions9+

缩放参数。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.WindowManager.WindowManager.Core

名称 参数类型 可读 可写 说明
x number 否 是 X 轴的缩放参数,默认值为 1.0。
y number 否 是 Y 轴的缩放参数,默认值为 1.0。
pivotX number 否 是 缩放中心点 X 轴坐标,默认值为 0.5, 取值范围 0.0~1.0。
pivotY number 否 是 缩放中心点 Y 轴坐标,默认值为 0.5, 取值范围 0.0~1.0。

# RotateOptions9+

旋转参数。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.WindowManager.WindowManager.Core

名称 参数类型 可读 可写 说明
x number 否 是 绕 X 轴的旋转角度,默认值为 0.0。
y number 否 是 绕 Y 轴的旋转角度,默认值为 0.0。
z number 否 是 绕 Z 轴的旋转角度,默认值为 0.0。
pivotX number 否 是 旋转中心点 X 轴坐标,默认值为 0.5, 取值范围 0.0~1.0。
pivotY number 否 是 旋转中心点 Y 轴坐标,默认值为 0.5, 取值范围 0.0~1.0。

# TranslateOptions9+

平移参数。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.WindowManager.WindowManager.Core

名称 参数类型 可读 可写 说明
x number 否 是 X 轴的平移参数,默认值为 0.0。
y number 否 是 Y 轴的平移参数,默认值为 0.0。
z number 否 是 Z 轴的平移参数,默认值为 0.0。

# window.create7+

create(id: string, type: WindowType, callback: AsyncCallback<Window>): void

创建子窗口,使用 callback 异步回调。

模型约束: 此接口仅可在 FA 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
id string 是 窗口 id。
type WindowType 是 窗口类型。
callback AsyncCallback<Window> 是 回调函数。返回当前创建的子窗口对象。

示例:

let windowClass = null;
window.create("first", window.WindowType.TYPE_APP, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to create the subWindow. Cause: " + JSON.stringify(err)
    );
    return;
  }
  windowClass = data;
  console.info(
    "Succeeded in creating the subWindow. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13

# window.create7+

create(id: string, type: WindowType): Promise<Window>

创建子窗口,使用 Promise 异步回调。

模型约束: 此接口仅可在 FA 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
id string 是 窗口 id。
type WindowType 是 窗口类型。

返回值:

类型 说明
Promise<Window> Promise 对象。返回当前创建的子窗口对象。

示例:

let windowClass = null;
let promise = window.create("first", window.WindowType.TYPE_APP);
promise
  .then((data) => {
    windowClass = data;
    console.info(
      "Succeeded in creating the subWindow. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to create the subWindow. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# window.create8+

create(ctx: Context, id: string, type: WindowType, callback: AsyncCallback<Window>): void

创建子窗口,使用 callback 异步回调,其中 Context 详见Context。

从 API version 9 开始,当 Context 为ServiceExtensionContext时,创建系统窗口,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
ctx Context 是 当前应用上下文信息。
API version 8 的 Context 定义见Context。
API version 9 的 Context 定义见Context。
id string 是 窗口 id。
type WindowType 是 窗口类型。
callback AsyncCallback<Window> 是 回调函数。返回当前创建的子窗口对象。

示例:

let windowClass = null;
window.create(
  this.context,
  "alertWindow",
  window.WindowType.TYPE_SYSTEM_ALERT,
  (err, data) => {
    if (err.code) {
      console.error(
        "Failed to create the window. Cause: " + JSON.stringify(err)
      );
      return;
    }
    windowClass = data;
    console.info(
      "Succeeded in creating the window. Data: " + JSON.stringify(data)
    );
    windowClass.resetSize(500, 1000);
  }
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# window.create8+

create(ctx: Context, id: string, type: WindowType): Promise<Window>

创建子窗口,使用 Promise 异步回调,其中 Context 详见Context。

从 API version 9 开始,当 Context 为ServiceExtensionContext时,创建系统窗口,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
ctx Context 是 当前应用上下文信息。
API version 8 的 Context 定义见Context。
API version 9 的 Context 定义见Context。
id string 是 窗口 id。
type WindowType 是 窗口类型。

返回值:

类型 说明
Promise<Window> Promise 对象。返回当前创建的子窗口对象。

示例:

let windowClass = null;
let promise = window.create(
  this.context,
  "alertWindow",
  window.WindowType.TYPE_SYSTEM_ALERT
);
promise
  .then((data) => {
    windowClass = data;
    console.info(
      "Succeeded in creating the window. Data:" + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error("Failed to create the Window. Cause:" + JSON.stringify(err));
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# window.find7+

find(id: string, callback: AsyncCallback<Window>): void

查找 id 所对应的窗口,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
id string 是 窗口 id。
callback AsyncCallback<Window> 是 回调函数。返回当前查找到的窗口对象。

示例:

let windowClass = null;
window.find("alertWindow", (err, data) => {
  if (err.code) {
    console.error("Failed to find the Window. Cause: " + JSON.stringify(err));
    return;
  }
  windowClass = data;
  console.info(
    "Succeeded in finding the window. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11

# window.find7+

find(id: string): Promise<Window>

查找 id 所对应的窗口,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
id string 是 窗口 id。

返回值:

类型 说明
Promise<Window> Promise 对象。返回当前查找的窗口对象。

示例:

let windowClass = null;
let promise = window.find("alertWindow");
promise
  .then((data) => {
    windowClass = data;
    console.info(
      "Succeeded in finding the window. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error("Failed to find the Window. Cause: " + JSON.stringify(err));
  });
1
2
3
4
5
6
7
8
9
10
11
12

# window.getTopWindow

getTopWindow(callback: AsyncCallback<Window>): void

获取当前应用内最后显示的窗口,使用 callback 异步回调。

模型约束: 此接口仅可在 FA 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<Window> 是 回调函数。返回当前应用内最后显示的窗口对象。

示例:

let windowClass = null;
window.getTopWindow((err, data) => {
  if (err.code) {
    console.error(
      "Failed to obtain the top window. Cause: " + JSON.stringify(err)
    );
    return;
  }
  windowClass = data;
  console.info(
    "Succeeded in obtaining the top window. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13

# window.getTopWindow

getTopWindow(): Promise<Window>

获取当前应用内最后显示的窗口,使用 Promise 异步回调。

模型约束: 此接口仅可在 FA 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<Window> Promise 对象。返回当前应用内最后显示的窗口对象。

示例:

let windowClass = null;
let promise = window.getTopWindow();
promise
  .then((data) => {
    windowClass = data;
    console.info(
      "Succeeded in obtaining the top window. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to obtain the top window. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# window.getTopWindow8+

getTopWindow(ctx: Context, callback: AsyncCallback<Window>): void

获取当前应用内最后显示的窗口,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
ctx Context 是 当前应用上下文信息。
API version 8 的 Context 定义见Context。
API version 9 的 Context 定义见Context。
callback AsyncCallback<Window> 是 回调函数。返回当前应用内最后显示的窗口对象。

示例:

let windowClass = null;
window.getTopWindow(this.context, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to obtain the top window. Cause: " + JSON.stringify(err)
    );
    return;
  }
  windowClass = data;
  console.info(
    "Succeeded in obtaining the top window. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13

# window.getTopWindow8+

getTopWindow(ctx: Context): Promise<Window>

获取当前应用内最后显示的窗口,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
ctx Context 是 当前应用上下文信息。
API version 8 的 Context 定义见Context。
API version 9 的 Context 定义见Context。

返回值:

类型 说明
Promise<Window> Promise 对象。返回当前应用内最后显示的窗口对象。

示例:

let windowClass = null;
let promise = window.getTopWindow(this.context);
promise
  .then((data) => {
    windowClass = data;
    console.info(
      "Succeeded in obtaining the top window. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to obtain the top window. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# window.minimizeAll9+

minimizeAll(id: number, callback: AsyncCallback<void>): void

最小化某显示设备下的所有窗口。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
id number 是 显示设备Display的 ID 号
callback AsyncCallback<void> 是 回调信息。

示例:

import display from "@ohos.display";
import window from "@ohos.window";

let displayClass = null;
display.getDefaultDisplay((err, data) => {
  if (err.code) {
    return;
  }
  displayClass = data;
  window.minimizeAll(displayClass.id, (err, data) => {
    if (err.code) {
      console.error(
        "Failed to minimize all windows. Cause: " + JSON.stringify(err)
      );
      return;
    }
    console.info("Succeeded in minimizing all windows.");
  });
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# window.minimizeAll9+

minimizeAll(id: number): Promise<void>

最小化某显示设备下的所有窗口。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
id number 是 显示设备Display的 ID 号

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

import display from "@ohos.display";
import window from "@ohos.window";

let displayClass = null;
display.getDefaultDisplay((err, data) => {
  if (err.code) {
    return;
  }
  displayClass = data;
  let promise = window.minimizeAll(displayClass.id);
  promise
    .then((data) => {
      console.info("Succeeded in minimizing all windows.");
    })
    .catch((err) => {
      console.error(
        "Failed to minimize all windows. Cause: " + JSON.stringify(err)
      );
    });
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# window.toggleShownStateForAllAppWindows9+

toggleShownStateForAllAppWindows(callback: AsyncCallback<void>): void

多窗口快速切换时隐藏或者恢复应用窗口。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 是 回调信息。

示例:

window.toggleShownStateForAllAppWindows((err, data) => {
  if (err.code) {
    console.error(
      "Failed to toggle shown state for all app windows. Cause: " +
        JSON.stringify(err)
    );
    return;
  }
  console.info("Succeeded in toggling shown state for all app windows.");
});
1
2
3
4
5
6
7
8
9
10

# window.toggleShownStateForAllAppWindows9+

toggleShownStateForAllAppWindows(): Promise<void>

多窗口快速切换时隐藏或者恢复应用窗口。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let promise = window.toggleShownStateForAllAppWindows();
promise
  .then((data) => {
    console.info(
      "Succeeded in toggling shown state for all app windows. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to toggle shown state for all app windows. Cause: " +
        JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# window.setWindowLayoutMode9+

setWindowLayoutMode(mode: WindowLayoutMode, callback: AsyncCallback<void>): void

设置窗口布局模式。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
mode WindowLayoutMode 是 设置的窗口布局模式
callback AsyncCallback<void> 是 回调信息。

示例:

window.setWindowLayoutMode(
  window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE,
  (data) => {
    console.info(
      "Succeeded in setting window layout mode. Data: " + JSON.stringify(data)
    );
  }
);
1
2
3
4
5
6
7
8

# window.setWindowLayoutMode9+

setWindowLayoutMode(mode: WindowLayoutMode): Promise<void>

设置窗口布局模式。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
mode WindowLayoutMode 是 设置的窗口布局模式

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let promise = window.setWindowLayoutMode(
  window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE
);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting window layout mode. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to set window layout mode. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# on('systemBarTintChange')8+

on(type: 'systemBarTintChange', callback: Callback<SystemBarTintState>): void

开启状态栏、导航栏属性变化的监听。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。
callback Callback<SystemBarTintState> 是 回调函数。返回当前的状态栏、导航栏信息集合。

示例:

window.on("systemBarTintChange", (data) => {
  console.info(
    "Succeeded in enabling the listener for systemBarTint changes. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6

# off('systemBarTintChange')8+

off(type: 'systemBarTintChange', callback?: Callback<SystemBarTintState >): void

关闭状态栏、导航栏属性变化的监听。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。
callback Callback<SystemBarTintState> 否 回调函数。返回当前的状态栏、导航栏信息集合。

示例:

window.off("systemBarTintChange");
1

# Window

当前窗口实例,窗口管理器管理的基本单元。

下列 API 示例中都需先使用getTopWindow()、create()、find()中的任一方法获取到 Window 实例,再通过此实例调用对应方法。

# hide7+

hide (callback: AsyncCallback<void>): void

隐藏当前窗口,使用 callback 异步回调。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 是 回调函数。

示例:

windowClass.hide((err, data) => {
  if (err.code) {
    console.error("Failed to hide the window. Cause: " + JSON.stringify(err));
    return;
  }
  console.info("Succeeded in hiding the window. data: " + JSON.stringify(data));
});
1
2
3
4
5
6
7

# hide7+

hide(): Promise<void>

隐藏当前窗口,使用 Promise 异步回调。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let promise = windowClass.hide();
promise
  .then((data) => {
    console.info(
      "Succeeded in hiding the window. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error("Failed to hide the window. Cause: " + JSON.stringify(err));
  });
1
2
3
4
5
6
7
8
9
10

# hideWithAnimation9+

hideWithAnimation(callback: AsyncCallback<void>): void

隐藏当前窗口,过程中播放动画,使用 callback 异步回调。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 是 回调函数。

示例:

windowClass.hideWithAnimation((err, data) => {
  if (err.code) {
    console.error(
      "Failed to hide the window with animation. Cause: " + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in hiding the window with animation. data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12

# hideWithAnimation9+

hideWithAnimation(): Promise<void>

隐藏当前窗口,过程中播放动画,使用 Promise 异步回调。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let promise = windowClass.hideWithAnimation();
promise
  .then((data) => {
    console.info(
      "Succeeded in hiding the window with animation. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to hide the window with animation. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13

# show7+

show(callback: AsyncCallback<void>): void

显示当前窗口,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 是 回调函数。

示例:

windowClass.show((err, data) => {
  if (err.code) {
    console.error("Failed to show the window. Cause: " + JSON.stringify(err));
    return;
  }
  console.info(
    "Succeeded in showing the window. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9

# show7+

show(): Promise<void>

显示当前窗口,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let promise = windowClass.show();
promise
  .then((data) => {
    console.info(
      "Succeeded in showing the window. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error("Failed to show the window. Cause: " + JSON.stringify(err));
  });
1
2
3
4
5
6
7
8
9
10

# showWithAnimation9+

showWithAnimation(callback: AsyncCallback<void>): void

显示当前窗口,过程中播放动画,使用 callback 异步回调。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 是 回调函数。

示例:

windowClass.showWithAnimation((err, data) => {
  if (err.code) {
    console.error(
      "Failed to show the window with animation. Cause: " + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in showing the window with animation. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12

# showWithAnimation9+

showWithAnimation(): Promise<void>

显示当前窗口,过程中播放动画,使用 Promise 异步回调。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let promise = windowClass.showWithAnimation();
promise
  .then((data) => {
    console.info(
      "Succeeded in showing the window with animation. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to show the window with animation. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13

# destroy7+

destroy(callback: AsyncCallback<void>): void

销毁当前窗口,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 是 回调函数。

示例:

windowClass.destroy((err, data) => {
  if (err.code) {
    console.error("Failed to destroy the window. Cause:" + JSON.stringify(err));
    return;
  }
  console.info(
    "Succeeded in destroying the window. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9

# destroy7+

destroy(): Promise<void>

销毁当前窗口,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let promise = windowClass.destroy();
promise
  .then((data) => {
    console.info(
      "Succeeded in destroying the window. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to destroy the window. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12

# moveTo7+

moveTo(x: number, y: number, callback: AsyncCallback<void>): void

移动窗口位置,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
x number 是 窗口在 x 轴方向移动的值,值为正表示右移,单位为 px。
y number 是 窗口在 y 轴方向移动的值,值为正表示下移,单位为 px。
callback AsyncCallback<void> 是 回调函数。

示例:

windowClass.moveTo(300, 300, (err, data) => {
  if (err.code) {
    console.error("Failed to move the window. Cause:" + JSON.stringify(err));
    return;
  }
  console.info("Succeeded in moving the window. Data: " + JSON.stringify(data));
});
1
2
3
4
5
6
7

# moveTo7+

moveTo(x: number, y: number): Promise<void>

移动窗口位置,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
x number 是 窗口在 x 轴方向移动的值,值为正表示右移,单位为 px。
y number 是 窗口在 y 轴方向移动的值,值为正表示下移,单位为 px。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let promise = windowClass.moveTo(300, 300);
promise
  .then((data) => {
    console.info(
      "Succeeded in moving the window. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error("Failed to move the window. Cause: " + JSON.stringify(err));
  });
1
2
3
4
5
6
7
8
9
10

# resetSize7+

resetSize(width: number, height: number, callback: AsyncCallback<void>): void

改变当前窗口大小,使用 callback 异步回调。

应用主窗口与子窗口存在大小限制,宽度范围:[320,2560],高度范围:[240,2560],单位为 vp。

系统窗口存在大小限制,宽度范围:[0,2560],高度范围:[0,2560],单位为 vp。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
width number 是 目标窗口的宽度,单位为 px。
height number 是 目标窗口的高度,单位为 px。
callback AsyncCallback<void> 是 回调函数。

示例:

windowClass.resetSize(500, 1000, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to change the window size. Cause:" + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in changing the window size. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11

# resetSize7+

resetSize(width: number, height: number): Promise<void>

改变当前窗口大小,使用 Promise 异步回调。

应用主窗口与子窗口存在大小限制,宽度范围:[320,2560],高度范围:[240,2560],单位为 vp。

系统窗口存在大小限制,宽度范围:[0,2560],高度范围:[0,2560],单位为 vp。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
width number 是 目标窗口的宽度,单位为 px。
height number 是 目标窗口的高度,单位为 px。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let promise = windowClass.resetSize(500, 1000);
promise
  .then((data) => {
    console.info(
      "Succeeded in changing the window size. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to change the window size. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12

# setWindowType(deprecated)

setWindowType(type: WindowType, callback: AsyncCallback<void>): void

设置窗口类型,使用 callback 异步回调。

系统接口: 此接口为系统接口。

说明: 从 API version 9 开始废弃。

从 API version 7 开始支持。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type WindowType 是 窗口类型。
callback AsyncCallback<void> 是 回调函数。

示例:

let type = window.WindowType.TYPE_APP;
windowClass.setWindowType(type, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to set the window type. Cause: " + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in setting the window type. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12

# setWindowType(deprecated)

setWindowType(type: WindowType): Promise<void>

设置窗口类型,使用 Promise 异步回调。

系统接口: 此接口为系统接口。

说明: 从 API version 9 开始废弃。

从 API version 7 开始支持。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type WindowType 是 窗口类型。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let type = window.WindowType.TYPE_APP;
let promise = windowClass.setWindowType(type);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting the window type. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to set the window type. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13

# getProperties

getProperties(callback: AsyncCallback<WindowProperties>): void

获取当前窗口的属性,使用 callback 异步回调,返回 WindowProperties。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<WindowProperties> 是 回调函数。返回当前窗口属性。

示例:

windowClass.getProperties((err, data) => {
  if (err.code) {
    console.error(
      "Failed to obtain the window properties. Cause: " + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in obtaining the window properties. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12

# getProperties

getProperties(): Promise<WindowProperties>

获取当前窗口的属性,使用 Promise 异步回调,返回 WindowProperties。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<WindowProperties> Promise 对象。返回当前窗口属性。

示例:

let promise = windowClass.getProperties();
promise
  .then((data) => {
    console.info(
      "Succeeded in obtaining the window properties. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to obtain the window properties. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13

# getAvoidArea7+

getAvoidArea(type: AvoidAreaType, callback: AsyncCallback<AvoidArea>): void

获取窗口内容规避的区域,如系统的系统栏区域、凹凸区域。使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type AvoidAreaType 是 表示规避区类型。type 为 TYPE_SYSTEM,表示系统默认区域。type 为 TYPE_CUTOUT,表示刘海屏区域。type 为 TYPE_SYSTEM_GESTURE,表示手势区域。type 为 TYPE_KEYBOARD,表示软键盘区域。
callback AsyncCallback<AvoidArea> 是 回调函数。返回窗口内容规避区域。

示例:

let type = window.AvoidAreaType.TYPE_SYSTEM;
windowClass.getAvoidArea(type, (err, data) => {
  if (err.code) {
    console.error("Failed to obtain the area. Cause:" + JSON.stringify(err));
    return;
  }
  console.info("Succeeded in obtaining the area. Data:" + JSON.stringify(data));
});
1
2
3
4
5
6
7
8

# getAvoidArea7+

getAvoidArea(type: AvoidAreaType): Promise<AvoidArea>

获取窗口内容规避的区域,如系统的系统栏区域、凹凸区域。使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type AvoidAreaType 是 表示规避区类型。type 为 TYPE_SYSTEM,表示系统默认区域。type 为 TYPE_CUTOUT,表示刘海屏区域。type 为 TYPE_SYSTEM_GESTURE,表示手势区域。type 为 TYPE_KEYBOARD,表示软键盘区域。

返回值:

类型 说明
Promise<AvoidArea> Promise 对象。返回窗口内容规避区域。

示例:

let type = window.AvoidAreaType.TYPE_SYSTEM;
let promise = windowClass.getAvoidArea(type);
promise
  .then((data) => {
    console.info(
      "Succeeded in obtaining the area. Data:" + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error("Failed to obtain the area. Cause:" + JSON.stringify(err));
  });
1
2
3
4
5
6
7
8
9
10
11

# setFullScreen

setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void

设置是否为全屏状态,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isFullScreen boolean 是 是否设为全屏状态,且全屏状态隐藏状态栏导航栏。
callback AsyncCallback<void> 是 回调函数。

示例:

let isFullScreen = true;
windowClass.setFullScreen(isFullScreen, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to enable the full-screen mode. Cause: " + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in enabling the full-screen mode. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12

# setFullScreen

setFullScreen(isFullScreen: boolean): Promise<void>

设置是否为全屏状态,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isFullScreen boolean 是 是否设为全屏状态,且全屏状态隐藏状态栏导航栏。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let isFullScreen = true;
let promise = windowClass.setFullScreen(isFullScreen);
promise
  .then((data) => {
    console.info(
      "Succeeded in enabling the full-screen mode. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to enable the full-screen mode. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# setLayoutFullScreen7+

setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void

设置窗口的布局是否为全屏显示状态,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isLayoutFullScreen boolean 是 窗口的布局是否为全屏显示状态,且全屏状态下状态栏、导航栏仍然显示。
callback AsyncCallback<void> 是 回调函数。

示例:

let isLayoutFullScreen = true;
windowClass.setLayoutFullScreen(isLayoutFullScreen, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to set the window layout to full-screen mode. Cause:" +
        JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in setting the window layout to full-screen mode. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# setLayoutFullScreen7+

setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void>

设置窗口的布局是否为全屏显示状态,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isLayoutFullScreen boolean 是 窗口的布局是否为全屏显示状态,且全屏状态下状态栏、导航栏仍然显示。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let isLayoutFullScreen = true;
let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting the window layout to full-screen mode. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to set the window layout to full-screen mode. Cause:" +
        JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# setSystemBarEnable7+

setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void

设置导航栏、状态栏的可见模式,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
names Array 是 设置状态栏和导航栏是否显示。
例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。
callback AsyncCallback<void> 是 回调函数。

示例:

// 此处以不显示导航栏、状态栏为例
let names = [];
windowClass.setSystemBarEnable(names, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to set the system bar to be invisible. Cause:" +
        JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in setting the system bar to be invisible. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# setSystemBarEnable7+

setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void>

设置导航栏、状态栏的可见模式,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
names Array 是 设置状态栏和导航栏是否显示。
例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

// 此处以不显示导航栏、状态栏为例
let names = [];
let promise = windowClass.setSystemBarEnable(names);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting the system bar to be invisible. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to set the system bar to be invisible. Cause:" +
        JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# setSystemBarProperties

setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void

设置窗口内导航栏、状态栏的属性,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
SystemBarProperties SystemBarProperties 是 导航栏、状态栏的属性。
callback AsyncCallback<void> 是 回调函数。

示例:

let SystemBarProperties = {
  statusBarColor: "#ff00ff",
  navigationBarColor: "#00ff00",
  //以下两个属性从API Version8开始支持
  statusBarContentColor: "#ffffff",
  navigationBarContentColor: "#00ffff",
};
windowClass.setSystemBarProperties(SystemBarProperties, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to set the system bar properties. Cause: " + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in setting the system bar properties. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# setSystemBarProperties

setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void>

设置窗口内导航栏、状态栏的属性,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
SystemBarProperties SystemBarProperties 是 导航栏、状态栏的属性。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let SystemBarProperties = {
  statusBarColor: "#ff00ff",
  navigationBarColor: "#00ff00",
  //以下两个属性从API Version8开始支持
  statusBarContentColor: "#ffffff",
  navigationBarContentColor: "#00ffff",
};
let promise = windowClass.setSystemBarProperties(SystemBarProperties);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting the system bar properties. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to set the system bar properties. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# setPreferredOrientation9+

setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void

设置窗口的显示方向属性,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
Orientation Orientation 是 窗口显示方向的属性。
callback AsyncCallback<void> 是 回调函数。

示例:

let orientation = window.Orientation.AUTO_ROTATION;
windowClass.setPreferredOrientation(orientation, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to set window orientation. Cause: " + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in setting window orientation. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12

# setPreferredOrientation9+

setPreferredOrientation(orientation: Orientation): Promise<void>

设置窗口的显示方向属性,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
Orientation Orientation 是 窗口显示方向的属性。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let orientation = window.Orientation.AUTO_ROTATION;
let promise = windowClass.setPreferredOrientation(orientation);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting the window orientation. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to set the window orientation. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# loadContent7+

loadContent(path: string, callback: AsyncCallback<void>): void

为当前窗口加载具体页面内容,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
path string 是 设置加载页面的路径。
callback AsyncCallback<void> 是 回调函数。

示例:

windowClass.loadContent("pages/page2/page2", (err, data) => {
  if (err.code) {
    console.error("Failed to load the content. Cause:" + JSON.stringify(err));
    return;
  }
  console.info(
    "Succeeded in loading the content. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9

# loadContent7+

loadContent(path: string): Promise<void>

为当前窗口加载具体页面内容,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
path string 是 设置加载页面的路径。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let promise = windowClass.loadContent("pages/page2/page2");
promise
  .then((data) => {
    console.info(
      "Succeeded in loading the content. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error("Failed to load the content. Cause: " + JSON.stringify(err));
  });
1
2
3
4
5
6
7
8
9
10

# loadContent9+

loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void

为当前窗口加载与 LocalStorage 相关联的具体页面内容,使用 callback 异步回调。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
path string 是 设置加载页面的路径。
storage LocalStorage 是 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。
callback AsyncCallback<void> 是 回调函数。

示例:

class myAbility extends Ability {
  storage: LocalStorage;
  onWindowStageCreate(windowStage) {
    this.storage = new LocalStorage();
    this.storage.setOrCreate("storageSimpleProp", 121);
    console.log("onWindowStageCreate");
    windowStage.loadContent("pages/page2", this.storage, (err, data) => {
      if (err.code) {
        console.error(
          "Failed to load the content. Cause:" + JSON.stringify(err)
        );
        return;
      }
      console.info(
        "Succeeded in loading the content. Data: " + JSON.stringify(data)
      );
    });
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# loadContent9+

loadContent(path: string, storage: LocalStorage): Promise<void>

为当前窗口加载与 LocalStorage 相关联的具体页面内容,使用 Promise 异步回调。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
path string 是 设置加载页面的路径。
storage LocalStorage 是 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

class myAbility extends Ability {
  storage: LocalStorage;
  onWindowStageCreate(windowStage) {
    this.storage = new LocalStorage();
    this.storage.setOrCreate("storageSimpleProp", 121);
    console.log("onWindowStageCreate");
    let windowClass = null;
    let promise = windowStage.loadContent("pages/page2", this.storage);
    promise
      .then((data) => {
        windowClass = data;
        console.info(
          "Succeeded in loading the content. Data: " + JSON.stringify(data)
        );
      })
      .catch((err) => {
        console.error(
          "Failed to load the content. Cause:" + JSON.stringify(err)
        );
      });
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

# isShowing7+

isShowing(callback: AsyncCallback<boolean>): void

判断当前窗口是否已显示,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<boolean> 是 回调函数。返回 true 表示当前窗口已显示,返回 false 则表示当前窗口未显示。

示例:

windowClass.isShowing((err, data) => {
  if (err.code) {
    console.error(
      "Failed to check whether the window is showing. Cause:" +
        JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in checking whether the window is showing. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13

# isShowing7+

isShowing(): Promise<boolean>

判断当前窗口是否已显示,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<boolean> Promise 对象。返回 true 表示当前窗口已显示,返回 false 则表示当前窗口未显示。

示例:

let promise = windowClass.isShowing();
promise
  .then((data) => {
    console.info(
      "Succeeded in checking whether the window is showing. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to check whether the window is showing. Cause: " +
        JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# on('windowSizeChange')7+

on(type: 'windowSizeChange', callback: Callback<Size>): void

开启窗口尺寸变化的监听。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。
callback Callback<Size> 是 回调函数。返回当前的窗口尺寸。

示例:

windowClass.on("windowSizeChange", (data) => {
  console.info(
    "Succeeded in enabling the listener for window size changes. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6

# off('windowSizeChange')7+

off(type: 'windowSizeChange', callback?: Callback<Size >): void

关闭窗口尺寸变化的监听。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。
callback Callback<Size> 否 回调函数。返回当前的窗口尺寸。

示例:

windowClass.off("windowSizeChange");
1

# on('systemAvoidAreaChange')(deprecated)

on(type: 'systemAvoidAreaChange', callback: Callback<AvoidArea>): void

开启系统规避区变化的监听。

说明: 从 API version 9 开始废弃,推荐使用on('avoidAreaChange')。

从 API version 7 开始支持。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。
callback Callback<AvoidArea> 是 回调函数。返回当前规避区。

示例:

windowClass.on("systemAvoidAreaChange", (data) => {
  console.info(
    "Succeeded in enabling the listener for system avoid area changes. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6

# off('systemAvoidAreaChange')(deprecated)

off(type: 'systemAvoidAreaChange', callback?: Callback<AvoidArea>): void

关闭系统规避区变化的监听。

说明: 从 API version 9 开始废弃,推荐使用off('avoidAreaChange')。

从 API version 7 开始支持。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。
callback Callback<AvoidArea> 否 回调函数。返回当前规避区。

示例:

windowClass.off("systemAvoidAreaChange");
1

# on('avoidAreaChange')9+

on(type: 'avoidAreaChange', callback: Callback<{AvoidAreaType, AvoidArea}>): void

开启系统规避区变化的监听。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。
callback Callback<{AvoidAreaType, AvoidArea}> 是 回调函数。返回当前规避区以及规避区类型。

示例:

windowClass.on("avoidAreaChange", (data) => {
  console.info(
    "Succeeded in enabling the listener for system avoid area changes. type:" +
      JSON.stringify(data.type) +
      ", area: " +
      JSON.stringify(data.area)
  );
});
1
2
3
4
5
6
7
8

# off('avoidAreaChange')9+

off(type: 'avoidAreaChange', callback: Callback<{AvoidAreaType, AvoidArea}>): void

关闭系统规避区变化的监听。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。
callback Callback<{AvoidAreaType, AvoidArea}> 否 回调函数。返回当前规避区以及规避区类型。

示例:

windowClass.off("avoidAreaChange");
1

# on('keyboardHeightChange')7+

on(type: 'keyboardHeightChange', callback: Callback<number>): void

开启键盘高度变化的监听。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。
callback Callback<number> 是 回调函数。返回当前的键盘高度。

示例:

windowClass.on("keyboardHeightChange", (data) => {
  console.info(
    "Succeeded in enabling the listener for keyboard height changes. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6

# off('keyboardHeightChange')7+

off(type: 'keyboardHeightChange', callback?: Callback<number>): void

关闭键盘高度变化的监听。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。
callback Callback<number> 否 回调函数。返回当前的键盘高度。

示例:

windowClass.off("keyboardHeightChange");
1

# on('touchOutside')9+

on(type: 'touchOutside', callback: Callback<void>): void

开启本窗口区域范围外的点击事件的监听。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。
callback Callback<void> 是 回调函数。当点击事件发生在本窗口范围之外的回调。

示例:

windowClass.on("touchOutside", () => {
  console.info("touch outside");
});
1
2
3

# off('touchOutside')9+

off(type: 'touchOutside', callback?: Callback<void>): void

关闭本窗口区域范围外的点击事件的监听。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。
callback Callback<number> 否 回调函数。当点击事件发生在本窗口范围之外的回调。

示例:

windowClass.off("touchOutside");
1

# on('screenshot')9+

on(type: 'screenshot', callback: Callback<void>): void

开启截屏事件的监听。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'screenshot',即截屏事件。
callback Callback<void> 是 回调函数。发生截屏事件时的回调。

示例:

windowClass.on("screenshot", () => {
  console.info("screenshot happened");
});
1
2
3

# off('screenshot')9+

off(type: 'screenshot', callback?: Callback<void>): void

关闭截屏事件的监听。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'screenshot',即截屏事件。
callback Callback<void> 否 回调函数。发生截屏事件时的回调。

示例:

let callback = () => {
  console.info("screenshot happened");
};
windowClass.on("screenshot", callback);
windowClass.off("screenshot", callback);

// 如果通过on开启多个callback进行监听,同时关闭所有监听:
windowClass.off("screenshot");
1
2
3
4
5
6
7
8

# on('dialogTargetTouch')9+

on(type: 'dialogTargetTouch', callback: Callback<void>): void

开启模态窗口目标窗口的点击事件的监听。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'dialogTargetTouch',即模态窗口目标窗口的点击事件。
callback Callback<void> 是 回调函数。当点击事件发生在模态窗口目标窗口的回调。

示例:

windowClass.on("dialogTargetTouch", () => {
  console.info("touch dialog target");
});
1
2
3

# off('dialogTargetTouch')9+

off(type: 'dialogTargetTouch', callback?: Callback<void>): void

关闭模态窗口目标窗口的点击事件的监听。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'dialogTargetTouch',即模态窗口目标窗口的点击事件。
callback Callback<void> 否 回调函数。当点击事件发生在模态窗口目标窗口的回调。

示例:

windowClass.off("dialogTargetTouch");
1

# bindDialogTarget9+

bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>, callback: AsyncCallback<void>): void

绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用 callback 异步回调。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
token rpc.RemoteObject 是 目标窗口 token 值。
deathCallback Callback<void> 是 模态窗口销毁监听。
callback AsyncCallback<void> 是 回调函数。

示例:

class MyDeathRecipient {
  onRemoteDied() {
    console.log("server died");
  }
}
class TestRemoteObject extends rpc.RemoteObject {
  constructor(descriptor) {
    super(descriptor);
  }
  addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
    return true;
  }
  removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
    return true;
  }
  isObjectDead(): boolean {
    return false;
  }
}
let token = new TestRemoteObject("testObject");
windowClass.bindDialogTarget(
  token,
  () => {
    console.info("Dialog Window Need Destroy.");
  },
  (err, data) => {
    if (err.code) {
      console.error(
        "Failed to bind dialog target. Cause:" + JSON.stringify(err)
      );
      return;
    }
    console.info(
      "Succeeded in binding dialog target. Data:" + JSON.stringify(data)
    );
  }
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

# bindDialogTarget9+

bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>): Promise<void>

绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用 Promise 异步回调。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
token rpc.RemoteObject 是 目标窗口 token 值。
deathCallback Callback<void> 是 模态窗口销毁监听。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

class MyDeathRecipient {
  onRemoteDied() {
    console.log("server died");
  }
}
class TestRemoteObject extends rpc.RemoteObject {
  constructor(descriptor) {
    super(descriptor);
  }
  addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
    return true;
  }
  removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
    return true;
  }
  isObjectDead(): boolean {
    return false;
  }
}
let token = new TestRemoteObject("testObject");
let promise = windowClass.bindDialogTarget(token, () => {
  console.info("Dialog Window Need Destroy.");
});
promise
  .then((data) => {
    console.info(
      "Succeeded in binding dialog target. Data:" + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error("Failed to bind dialog target. Cause:" + JSON.stringify(err));
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

# isSupportWideGamut8+

isSupportWideGamut(callback: AsyncCallback<boolean>): void

判断当前窗口是否支持广色域模式,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<boolean> 是 回调函数。返回 true 表示当前窗口支持广色域模式,返回 false 则表示当前窗口不支持广色域模式。

示例:

windowClass.isSupportWideGamut((err, data) => {
  if (err.code) {
    console.error(
      "Failed to check whether the window support WideGamut. Cause:" +
        JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in checking whether the window support WideGamut Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13

# isSupportWideGamut8+

isSupportWideGamut(): Promise<boolean>

判断当前窗口是否支持广色域模式,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<boolean> Promise 对象。返回 true 表示当前窗口支持广色域模式,返回 false 则表示当前窗口不支持广色域模式。

示例:

let promise = windowClass.isSupportWideGamut();
promise
  .then((data) => {
    console.info(
      "Succeeded in checking whether the window support WideGamut. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to check whether the window support WideGamut. Cause: " +
        JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# setColorSpace8+

setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void

设置当前窗口为广色域模式或默认色域模式,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
colorSpace ColorSpace 是 设置色域模式
callback AsyncCallback<void> 是 回调函数。

示例:

windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to set window colorspace. Cause:" + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in setting window colorspace. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11

# setColorSpace8+

setColorSpace(colorSpace:ColorSpace): Promise<void>

设置当前窗口为广色域模式或默认色域模式,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
colorSpace ColorSpace 是 设置色域模式。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting window colorspace. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to set window colorspace. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12

# getColorSpace8+

getColorSpace(callback: AsyncCallback<ColorSpace>): void

获取当前窗口色域模式,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<ColorSpace> 是 回调函数。当获取成功,err 为 undefined,data 为当前色域模式。

示例:

windowClass.getColorSpace((err, data) => {
  if (err.code) {
    console.error(
      "Failed to get window colorspace. Cause:" + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in getting window colorspace. Cause:" + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11

# getColorSpace8+

getColorSpace(): Promise<ColorSpace>

获取当前窗口色域模式,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<ColorSpace> Promise 对象。返回当前色域模式。

示例:

let promise = windowClass.getColorSpace();
promise
  .then((data) => {
    console.info(
      "Succeeded in getting window color space. Cause:" + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to get window colorspace. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12

# setBackgroundColor

setBackgroundColor(color: string, callback: AsyncCallback<void>): void

设置窗口的背景色,使用 callback 异步回调。Stage 模型下,该接口需要在loadContent之后使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
color string 是 需要设置的背景色,为十六进制颜色,不区分大小写,例如#00FF00或#FF00FF00。
callback AsyncCallback<void> 是 回调函数。

示例:

let color = "#00ff33";
windowClass.setBackgroundColor(color, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to set the background color. Cause: " + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in setting the background color. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12

# setBackgroundColor

setBackgroundColor(color: string): Promise<void>

设置窗口的背景色,使用 Promise 异步回调。Stage 模型下,该接口需要在loadContent之后使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
color string 是 需要设置的背景色,为十六进制颜色,不区分大小写,例如#00FF00或#FF00FF00。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let color = "#00ff33";
let promise = windowClass.setBackgroundColor(color);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting the background color. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to set the background color. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13

# setWakeUpScreen()9+

setWakeUpScreen(wakeUp: boolean): void;

窗口唤醒屏幕。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
wakeUp boolean 是 是否设置唤醒屏幕。

示例:

let wakeUp = true;
windowClass.setWakeUpScreen(wakeUp);
1
2

# setBrightness

setBrightness(brightness: number, callback: AsyncCallback<void>): void

设置屏幕亮度值,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
brightness number 是 屏幕亮度值,值为 0-1 之间。1 表示最亮。
callback AsyncCallback<void> 是 回调函数。

示例:

let brightness = 1;
windowClass.setBrightness(brightness, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to set the brightness. Cause: " + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in setting the brightness. Data: " + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12

# setBrightness

setBrightness(brightness: number): Promise<void>

设置屏幕亮度值,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
brightness number 是 屏幕亮度值,值为 0-1 之间。1 表示最亮。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let brightness = 1;
let promise = windowClass.setBrightness(brightness);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting the brightness. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to set the brightness. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13

# setDimBehind(deprecated)

setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void

窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用 callback 异步回调。

说明: 该接口不支持使用。

从 API version 9 开始废弃。从 API Version 7 开始支持。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
dimBehindValue number 是 表示靠后的窗口的暗度值,取值范围为 0-1,1 表示最暗。
callback AsyncCallback<void> 是 回调函数。

示例:

windowClass.setDimBehind(0.5, (err, data) => {
  if (err.code) {
    console.error("Failed to set the dimness. Cause: " + JSON.stringify(err));
    return;
  }
  console.info(
    "Succeeded in setting the dimness. Data:" + JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9

# setDimBehind(deprecated)

setDimBehind(dimBehindValue: number): Promise<void>

窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用 Promise 异步回调。

说明: 该接口不支持使用。

从 API version 9 开始废弃。从 API Version 7 开始支持。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
dimBehindValue number 是 表示靠后的窗口的暗度值,取值范围为 0-1,1 表示最暗。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let promise = windowClass.setDimBehind(0.5);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting the dimness. Data: " + JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error("Failed to set the dimness. Cause: " + JSON.stringify(err));
  });
1
2
3
4
5
6
7
8
9
10

# setFocusable7+

setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void

设置点击时是否支持切换焦点窗口,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isFocusable boolean 是 点击时是否支持切换焦点窗口。
callback AsyncCallback<void> 是 回调函数。

示例:

let isFocusable = true;
windowClass.setFocusable(isFocusable, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to set the window to be focusable. Cause:" + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in setting the window to be focusable. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13

# setFocusable7+

setFocusable(isFocusable: boolean): Promise<void>

设置点击时是否支持切换焦点窗口,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isFocusable boolean 是 点击时是否支持切换焦点窗口。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let isFocusable = true;
let promise = windowClass.setFocusable(isFocusable);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting the window to be focusable. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to set the window to be focusable. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# setKeepScreenOn

setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void

设置屏幕是否为常亮状态,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isKeepScreenOn boolean 是 设置屏幕是否为常亮状态。
callback AsyncCallback<void> 是 回调函数。

示例:

let isKeepScreenOn = true;
windowClass.setKeepScreenOn(isKeepScreenOn, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to set the screen to be always on. Cause: " + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in setting the screen to be always on. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13

# setKeepScreenOn

setKeepScreenOn(isKeepScreenOn: boolean): Promise<void>

设置屏幕是否为常亮状态,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isKeepScreenOn boolean 是 设置屏幕是否为常亮状态。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let isKeepScreenOn = true;
let promise = windowClass.setKeepScreenOn(isKeepScreenOn);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting the screen to be always on. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.info(
      "Failed to set the screen to be always on. Cause:  " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# setOutsideTouchable(deprecated)

setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void

设置是否允许可点击子窗口之外的区域,使用 callback 异步回调。

说明: 该接口不支持使用。

从 API version 9 开始废弃。从 API Version 7 开始支持。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
touchable boolean 是 设置是否可点击。
callback AsyncCallback<void> 是 回调函数。

示例:

windowClass.setOutsideTouchable(true, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to set the area to be touchable. Cause: " + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in setting the area to be touchable. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12

# setOutsideTouchable(deprecated)

setOutsideTouchable(touchable: boolean): Promise<void>

设置是否允许可点击子窗口之外的区域,使用 Promise 异步回调。。

说明: 该接口不支持使用。

从 API version 9 开始废弃。从 API version 7 开始支持。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
touchable boolean 是 设置是否可点击。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let promise = windowClass.setOutsideTouchable(true);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting the area to be touchable. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to set the area to be touchable. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13

# setPrivacyMode7+

setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void

设置窗口是否为隐私模式,使用 callback 异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isPrivacyMode boolean 是 窗口是否为隐私模式。
callback AsyncCallback<void> 是 回调函数。

示例:

let isPrivacyMode = true;
windowClass.setPrivacyMode(isPrivacyMode, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to set the window to privacy mode. Cause:" + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in setting the window to privacy mode. Data:" +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13

# setPrivacyMode7+

setPrivacyMode(isPrivacyMode: boolean): Promise<void>

设置窗口是否为隐私模式,使用 Promise 异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isPrivacyMode boolean 是 窗口是否为隐私模式。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let isPrivacyMode = true;
let promise = windowClass.setPrivacyMode(isPrivacyMode);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting the window to privacy mode. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to set the window to privacy mode. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# setSnapshotSkip9+

setSnapshotSkip(isSkip: boolean): void

截屏录屏是否忽略当前窗口。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isSkip boolean 是 截屏录屏是否忽略当前窗口,默认为 false。
true 表示忽略当前窗口,false 表示不忽略当前窗口。
let isSkip = true;
windowClass.setSnapshotSkip(isSkip);
1
2

# setTouchable7+

setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void

设置窗口是否为可触状态,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isTouchable boolean 是 窗口是否为可触状态。
callback AsyncCallback<void> 是 回调函数。

示例:

let isTouchable = true;
windowClass.setTouchable(isTouchable, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to set the window to be touchable. Cause:" + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in setting the window to be touchable. Data:" +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13

# setTouchable7+

setTouchable(isTouchable: boolean): Promise<void>

设置窗口是否为可触状态,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isTouchable boolean 是 窗口是否为可触状态。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let isTouchable = true;
let promise = windowClass.setTouchable(isTouchable);
promise
  .then((data) => {
    console.info(
      "Succeeded in setting the window to be touchable. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to set the window to be touchable. Cause: " + JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# setForbidSplitMove9+

setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback<void>): void

设置窗口在分屏模式下是否被禁止移动,使用 callback 异步回调。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isForbidSplitMove boolean 是 窗口在分屏模式下是否被禁止移动。
callback AsyncCallback<void> 是 回调函数。

示例:

let isForbidSplitMove = true;
windowClass.setForbidSplitMove(isForbidSplitMove, (err, data) => {
  if (err.code) {
    console.error(
      "Failed to forbid window moving in split screen mode. Cause:" +
        JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in forbidding window moving in split screen mode. Data:" +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# setForbidSplitMove9+

setForbidSplitMove(isForbidSplitMove: boolean): Promise<void>

设置窗口在分屏模式下是否被禁止移动,使用 Promise 异步回调。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isForbidSplitMove boolean 是 窗口在分屏模式下是否被禁止移动。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

let isForbidSplitMove = true;
let promise = windowClass.setForbidSplitMove(isForbidSplitMove);
promise
  .then((data) => {
    console.info(
      "Succeeded in forbidding window moving in split screen mode. Data: " +
        JSON.stringify(data)
    );
  })
  .catch((err) => {
    console.error(
      "Failed to forbid window moving in split screen mode. Cause: " +
        JSON.stringify(err)
    );
  });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# snapshot9+

snapshot(callback: AsyncCallback<image.PixelMap>): void

获取窗口截图,使用 callback 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<image.PixelMap> 是 回调函数。

示例:

windowClass.snapshot((err, data) => {
  if (err.code) {
    console.error("Failed to snapshot window. Cause:" + JSON.stringify(err));
    return;
  }
  console.info(
    "Succeeded in snapshotting window. Pixel bytes number: " +
      pixelMap.getPixelBytesNumber()
  );
  data.release(); // PixelMap使用完后及时释放内存
});
1
2
3
4
5
6
7
8
9
10
11

# snapshot9+

snapshot(): Promise<image.PixelMap>

获取窗口截图,使用 Promise 异步回调。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<image.PixelMap> Promise 对象。返回当前窗口截图。

示例:

let promise = windowClass.snapshot();
promise
  .then((pixelMap) => {
    console.info(
      "Succeeded in snapshotting window. Pixel bytes number: " +
        pixelMap.getPixelBytesNumber()
    );
    pixelMap.release(); // PixelMap使用完后及时释放内存
  })
  .catch((err) => {
    console.error("Failed to snapshot window. Cause:" + JSON.stringify(err));
  });
1
2
3
4
5
6
7
8
9
10
11
12

# setBlur9+

setBlur(radius: number): void

设置窗口模糊。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
radius number 是 表示窗口模糊的半径值,取值范围为大于等于 0,0 表示关闭窗口模糊。

示例:

windowClass.setBlur(4.0);
1

# setBackdropBlur9+

setBackdropBlur(radius: number): void

设置窗口背景模糊。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
radius number 是 表示窗口背景模糊的半径值,取值范围为大于等于 0,0 表示关闭窗口背景模糊。

示例:

windowClass.setBackdropBlur(4.0);
1

# setBackdropBlurStyle9+

setBackdropBlurStyle(blurStyle: BlurStyle): void

设置窗口背景模糊类型。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
blurStyle BlurStyle 是 表示窗口背景模糊类型。

示例:

windowClass.setBackdropBlurStyle(window.BlurType.THIN);
1

# setShadow9+

setShadow(radius: number, color?: string, offsetX?: number, offsetY?: number): void

设置窗口边缘阴影。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
radius number 是 表示窗口边缘阴影的模糊半径,取值范围为大于等于 0,0 表示关闭窗口边缘阴影。
color string 否 表示窗口边缘阴影的颜色,为十六进制颜色,不区分大小写,例如#00FF00或#FF00FF00。
offsetX number 否 表示窗口边缘阴影的 X 轴的偏移量,单位为 px。
offsetY number 否 表示窗口边缘阴影的 Y 轴的偏移量,单位为 px。

示例:

windowClass.setShadow(4.0, "#FF00FF00", 2, 3);
1

# setCornerRadius9+

setCornerRadius(cornerRadius: number): void

设置窗口圆角半径。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
radius number 是 表示窗口圆角的半径值,取值范围为大于等于 0,0 表示没有窗口圆角。

示例:

windowClass.setCornerRadius(4.0);
1

# opacity9+

opacity(opacity: number): void

设置窗口透明度。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
opacity number 是 透明度,范围 0.0~1.0。

示例:

windowClass.opacity(0.5);
1

# scale9+

scale(scaleOptions: ScaleOptions): void

设置窗口缩放参数。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
scaleOptions ScaleOptions 是 缩放参数。

示例:

let obj : window.ScaleOptions = {
  x : 2.0,
  y : 1.0,
  pivotX = 0.5;
  pivotY = 0.5;
}
windowClass.scale(obj);
1
2
3
4
5
6
7

# rotate9+

rotate(rotateOptions: RotateOptions): void

设置窗口旋转参数。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
rotateOptions RotateOptions 是 旋转参数。

示例:

let obj : window.RotateOptions = {
  x : 1.0,
  y : 1.0,
  z : 45.0,
  pivotX = 0.5;
  pivotY = 0.5;
}
windowClass.rotate(obj);
1
2
3
4
5
6
7
8

# translate9+

translate(translateOptions: TranslateOptions): void

设置窗口平移参数。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
translateOptions TranslateOptions 是 平移参数。

示例:

let obj: window.TranslateOptions = {
  x: 100.0,
  y: 0.0,
  z: 0.0,
};
windowClass.translate(obj);
1
2
3
4
5
6

# getTransitionController9+

getTransitionController(): TransitionController

获取窗口属性转换控制器。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
TransitionController 属性转换控制器。

示例:

let controller = windowClass.getTransitionController(); // 获取属性转换控制器
controller.animationForHidden = (context: window.TransitionContext) => {
  let toWindow = context.toWindow;
  animateTo(
    {
      duration: 1000, // 动画时长
      tempo: 0.5, // 播放速率
      curve: Curve.EaseInOut, // 动画曲线
      delay: 0, // 动画延迟
      iterations: 1, // 播放次数
      playMode: PlayMode.Normal, // 动画模式
      onFinish: () => {
        context.completeTransition(true);
      },
    },
    () => {
      let obj: window.TranslateOptions = {
        x: 100.0,
        y: 0.0,
        z: 0.0,
      };
      toWindow.translate(obj); // 设置动画过程中的属性转换
      console.info("toWindow translate end");
    }
  );
  console.info("complete transition end");
};
windowClass.hideWithAnimation((err, data) => {
  if (err.code) {
    console.error(
      "Failed to show the window with animation. Cause: " + JSON.stringify(err)
    );
    return;
  }
  console.info(
    "Succeeded in showing the window with animation. Data: " +
      JSON.stringify(data)
  );
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

# WindowStageEventType9+

WindowStage 生命周期。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

名称 默认值 说明
FOREGROUND 1 切到前台。
ACTIVE 2 获焦状态。
INACTIVE 3 失焦状态。
BACKGROUND 4 切到后台。

# WindowStage9+

窗口管理器。管理各个基本窗口单元,即Window实例。

下列 API 示例中都需在onWindowStageCreate()函数中使用 WindowStage 的实例调用对应方法。

# getMainWindow9+

getMainWindow(callback: AsyncCallback<Window>): void

获取该 WindowStage 实例下的主窗口,使用 callback 异步回调。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<Window> 是 回调函数。返回当前 WindowStage 下的主窗口对象。

示例:

import Ability from "@ohos.application.Ability";
class myAbility extends Ability {
  onWindowStageCreate(windowStage) {
    console.log("onWindowStageCreate");
    let windowClass = null;
    windowStage.getMainWindow((err, data) => {
      if (err.code) {
        console.error(
          "Failed to obtain the main window. Cause: " + JSON.stringify(err)
        );
        return;
      }
      windowClass = data;
      console.info(
        "Succeeded in obtaining the main window. Data: " + JSON.stringify(data)
      );
    });
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# getMainWindow9+

getMainWindow(): Promise<Window>

获取该 WindowStage 实例下的主窗口,使用 Promise 异步回调。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<Window> Promise 对象。返回当前 WindowStage 下的主窗口对象。

示例:

import Ability from "@ohos.application.Ability";
class myAbility extends Ability {
  onWindowStageCreate(windowStage) {
    console.log("onWindowStageCreate");
    let windowClass = null;
    let promise = windowStage.getMainWindow();
    promise
      .then((data) => {
        windowClass = data;
        console.info(
          "Succeeded in obtaining the main window. Data: " +
            JSON.stringify(data)
        );
      })
      .catch((err) => {
        console.error(
          "Failed to obtain the main window. Cause: " + JSON.stringify(err)
        );
      });
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# createSubWindow9+

createSubWindow(name: string, callback: AsyncCallback<Window>): void

创建该 WindowStage 实例下的子窗口,使用 callback 异步回调。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
name String 是 子窗口的名字。
callback AsyncCallback<Window> 是 回调函数。返回当前 WindowStage 下的子窗口对象。

示例:

import Ability from "@ohos.application.Ability";
class myAbility extends Ability {
  onWindowStageCreate(windowStage) {
    console.log("onWindowStageCreate");
    let windowClass = null;
    windowStage.createSubWindow("mySubWindow", (err, data) => {
      if (err.code) {
        console.error(
          "Failed to create the subwindow. Cause: " + JSON.stringify(err)
        );
        return;
      }
      windowClass = data;
      console.info(
        "Succeeded in creating the subwindow. Data: " + JSON.stringify(data)
      );
      windowClass.resetSize(500, 1000);
    });
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# createSubWindow9+

createSubWindow(name: string): Promise<Window>

创建该 WindowStage 实例下的子窗口,使用 Promise 异步回调。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
name String 是 子窗口的名字。

返回值:

类型 说明
Promise<Window> Promise 对象。返回当前 WindowStage 下的子窗口对象。

示例:

import Ability from "@ohos.application.Ability";
class myAbility extends Ability {
  onWindowStageCreate(windowStage) {
    console.log("onWindowStageCreate");
    let windowClass = null;
    let promise = windowStage.createSubWindow("mySubWindow");
    promise
      .then((data) => {
        windowClass = data;
        console.info(
          "Succeeded in creating the subwindow. Data: " + JSON.stringify(data)
        );
      })
      .catch((err) => {
        console.error(
          "Failed to create the subwindow. Cause: " + JSON.stringify(err)
        );
      });
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# getSubWindow9+

getSubWindow(callback: AsyncCallback<Array<Window>>): void

获取该 WindowStage 实例下的所有子窗口,使用 callback 异步回调。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<Array<Window>> 是 回调函数。返回当前 WindowStage 下的所有子窗口对象。

示例:

import Ability from "@ohos.application.Ability";
class myAbility extends Ability {
  onWindowStageCreate(windowStage) {
    console.log("onWindowStageCreate");
    let windowClass = null;
    windowStage.getSubWindow((err, data) => {
      if (err.code) {
        console.error(
          "Failed to obtain the subwindow. Cause: " + JSON.stringify(err)
        );
        return;
      }
      windowClass = data;
      console.info(
        "Succeeded in obtaining the subwindow. Data: " + JSON.stringify(data)
      );
    });
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# getSubWindow9+

getSubWindow(): Promise<Array<Window>>

获取该 WindowStage 实例下的所有子窗口,使用 Promise 异步回调。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

返回值:

类型 说明
Promise<Array<Window>> Promise 对象。返回当前 WindowStage 下的所有子窗口对象。

示例:

import Ability from "@ohos.application.Ability";
class myAbility extends Ability {
  onWindowStageCreate(windowStage) {
    console.log("onWindowStageCreate");
    let windowClass = null;
    let promise = windowStage.getSubWindow();
    promise
      .then((data) => {
        windowClass = data;
        console.info(
          "Succeeded in obtaining the subwindow. Data: " + JSON.stringify(data)
        );
      })
      .catch((err) => {
        console.error(
          "Failed to obtain the subwindow. Cause: " + JSON.stringify(err)
        );
      });
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# loadContent9+

loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void

为当前 WindowStage 的主窗口加载与 LocalStorage 相关联的具体页面内容,使用 callback 异步回调。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
path string 是 设置加载页面的路径。
storage LocalStorage 是 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。
callback AsyncCallback<void> 是 回调函数。

示例:

import Ability from "@ohos.application.Ability";
class myAbility extends Ability {
  storage: LocalStorage;
  onWindowStageCreate(windowStage) {
    this.storage = new LocalStorage();
    this.storage.setOrCreate("storageSimpleProp", 121);
    console.log("onWindowStageCreate");
    windowStage.loadContent("pages/page2", this.storage, (err, data) => {
      if (err.code) {
        console.error(
          "Failed to load the content. Cause:" + JSON.stringify(err)
        );
        return;
      }
      console.info(
        "Succeeded in loading the content. Data: " + JSON.stringify(data)
      );
    });
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# loadContent9+

loadContent(path: string, storage?: LocalStorage): Promise<void>

为当前 WindowStage 的主窗口加载与 LocalStorage 相关联的具体页面内容,使用 Promise 异步回调。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
path string 是 设置加载页面的路径。
storage LocalStorage 否 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。

返回值:

类型 说明
Promise<void> 无返回结果的 Promise 对象。

示例:

import Ability from "@ohos.application.Ability";
class myAbility extends Ability {
  storage: LocalStorage;
  onWindowStageCreate(windowStage) {
    this.storage = new LocalStorage();
    this.storage.setOrCreate("storageSimpleProp", 121);
    console.log("onWindowStageCreate");
    let windowClass = null;
    let promise = windowStage.loadContent("pages/page2", this.storage);
    promise
      .then((data) => {
        windowClass = data;
        console.info(
          "Succeeded in loading the content. Data: " + JSON.stringify(data)
        );
      })
      .catch((err) => {
        console.error(
          "Failed to load the content. Cause:" + JSON.stringify(err)
        );
      });
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

# loadContent9+

loadContent(path: string, callback: AsyncCallback<void>): void

为当前 WindowStage 的主窗口加载具体页面内容,使用 callback 异步回调。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
path string 是 设置加载页面的路径。
callback AsyncCallback<void> 是 回调函数。

示例:

import Ability from "@ohos.application.Ability";
class myAbility extends Ability {
  onWindowStageCreate(windowStage) {
    console.log("onWindowStageCreate");
    windowStage.loadContent("pages/page2", (err, data) => {
      if (err.code) {
        console.error(
          "Failed to load the content. Cause:" + JSON.stringify(err)
        );
        return;
      }
      console.info(
        "Succeeded in loading the content. Data: " + JSON.stringify(data)
      );
    });
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# on('windowStageEvent')9+

on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void

开启 WindowStage 生命周期变化的监听。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'windowStageEvent',即 WindowStage 生命周期变化事件。
callback Callback<WindowStageEventType> 是 回调函数。返回当前的 WindowStage 生命周期状态。

示例:

import Ability from "@ohos.application.Ability";
class myAbility extends Ability {
  onWindowStageCreate(windowStage) {
    console.log("onWindowStageCreate");
    windowStage.on("windowStageEvent", (data) => {
      console.info(
        "Succeeded in enabling the listener for window stage event changes. Data: " +
          JSON.stringify(data)
      );
    });
  }
}
1
2
3
4
5
6
7
8
9
10
11
12

# off('windowStageEvent')9+

off(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType>): void

关闭 WindowStage 生命周期变化的监听。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
type string 是 监听事件,固定为'windowStageEvent',即 WindowStage 生命周期变化事件。
callback Callback<WindowStageEventType> 否 回调函数。返回当前的 WindowStage 生命周期状态。

示例:

import Ability from "@ohos.application.Ability";
class myAbility extends Ability {
  onWindowStageCreate(windowStage) {
    console.log("onWindowStageCreate");
    windowStage.off("windowStageEvent");
  }
}
1
2
3
4
5
6
7

# disableWindowDecor()9+

disableWindowDecor(): void

禁止窗口装饰。

模型约束: 此接口仅可在 Stage 模型下使用。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

示例:

import Ability from "@ohos.application.Ability";
class myAbility extends Ability {
  onWindowStageCreate(windowStage) {
    console.log("disableWindowDecor");
    windowStage.disableWindowDecor();
  }
}
1
2
3
4
5
6
7

# setShowOnLockScreen()9+

setShowOnLockScreen(showOnLockScreen: boolean): void

设置应用显示在锁屏之上。

系统接口: 此接口为系统接口。

模型约束: 此接口仅可在 Stage 模型下使用。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
showOnLockScreen boolean 是 是否设置应用显示在锁屏之上。

示例:

import Ability from "@ohos.application.Ability";
class myAbility extends Ability {
  onWindowStageCreate(windowStage) {
    console.log("onWindowStageCreate");
    windowStage.setShowOnLockScreen(true);
  }
}
1
2
3
4
5
6
7

# TransitionContext9+

属性转换的上下文信息。

# 属性

系统接口: 此接口为系统接口。

系统能力:SystemCapability.WindowManager.WindowManager.Core

名称 参数类型 可读 可写 说明
toWindow9+ Window 是 是 动画的目标窗口。

# completeTransition9+

completeTransition(isCompleted: boolean): void

设置属性转换的最终完成状态。该函数需要在动画函数animateTo()执行后设置。

系统接口: 此接口为系统接口。

系统能力:SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
isCompleted boolean 是 窗口属性转换是否完成。true:完成本次转换;false:撤销本次转换。

示例:

let controller = windowClass.getTransitionController();
controller.animationForShown = (context: window.TransitionContext) => {
  let toWindow = context.toWindow;
  animateTo(
    {
      duration: 1000, // 动画时长
      tempo: 0.5, // 播放速率
      curve: Curve.EaseInOut, // 动画曲线
      delay: 0, // 动画延迟
      iterations: 1, // 播放次数
      playMode: PlayMode.Normal, // 动画模式
    },
    () => {
      let obj: window.TranslateOptions = {
        x: 100.0,
        y: 0.0,
        z: 0.0,
      };
      toWindow.translate(obj);
      console.info("toWindow translate end");
    }
  );
  context.completeTransition(true);
  console.info("complete transition end");
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# TransitionController9+

属性转换控制器。

# animationForShown9+

animationForShown(context: TransitionContext): void

窗口显示时的自定义动画配置。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
context TransitionContext 是 属性转换时的上下文。

示例:

let controller = windowClass.getTransitionController();
controller.animationForShown = (context: window.TransitionContext) => {
  let toWindow = context.toWindow;
  animateTo(
    {
      duration: 1000, // 动画时长
      tempo: 0.5, // 播放速率
      curve: Curve.EaseInOut, // 动画曲线
      delay: 0, // 动画延迟
      iterations: 1, // 播放次数
      playMode: PlayMode.Normal, // 动画模式
      onFinish: () => {
        context.completeTransition(true);
      },
    },
    () => {
      let obj: window.TranslateOptions = {
        x: 100.0,
        y: 0.0,
        z: 0.0,
      };
      toWindow.translate(obj);
      console.info("toWindow translate end");
    }
  );
  console.info("complete transition end");
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

# animationForHidden9+

animationForHidden(context: TransitionContext): void

窗口隐藏时的自定义动画配置。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.WindowManager.WindowManager.Core

参数:

参数名 类型 必填 说明
context TransitionContext 是 属性转换时的上下文。

示例:

let controller = windowClass.getTransitionController();
controller.animationForHidden = (context: window.TransitionContext) => {
  let toWindow = context.toWindow;
  animateTo(
    {
      duration: 1000, // 动画时长
      tempo: 0.5, // 播放速率
      curve: Curve.EaseInOut, // 动画曲线
      delay: 0, // 动画延迟
      iterations: 1, // 播放次数
      playMode: PlayMode.Normal, // 动画模式
      onFinish: () => {
        context.completeTransition(true);
      },
    },
    () => {
      let obj: window.TranslateOptions = {
        x: 100.0,
        y: 0.0,
        z: 0.0,
      };
      toWindow.translate(obj);
      console.info("toWindow translate end");
    }
  );
  console.info("complete transition end");
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27