harmony 鸿蒙@ohos.window (窗口)

  • 2022-08-09
  • 浏览 (926)

@ohos.window (窗口)

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

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

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

说明:

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

导入模块

import window from '@ohos.window';

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模型下使用。
系统接口: 此接口为系统接口。
TYPE_DIALOG10+ 16 表示模态窗口。
模型约束: 此接口仅可在Stage模型下使用。
TYPE_SCREENSHOT9+ 17 表示截屏窗口。
模型约束: 此接口仅可在Stage模型下使用。
系统接口: 此接口为系统接口。
TYPE_SYSTEM_TOAST11+ 18 表示顶层提示窗口。
模型约束: 此接口仅可在Stage模型下使用。
系统接口: 此接口为系统接口。

Configuration9+

创建子窗口或系统窗口时的参数。

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

|名称|类型|必填|说明 | |———-|————————–|–|—————————————————————————–| |name |string |是|窗口名字。 | |windowType|WindowType|是|窗口类型。 | |ctx |BaseContext|否|当前应用上下文信息。不设置,则默认为空。
FA模型下不需要使用该参数,即可创建子窗口。
Stage模型下需要使用该参数,用于创建系统窗口。| |displayId|number |否|当前物理屏幕id。不设置,则默认为-1,该参数应为整数。 | |parentId |number |否|父窗口id。不设置,则默认为-1,该参数应为整数。 |

AvoidAreaType7+

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

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

名称 说明
TYPE_SYSTEM 0 表示系统默认区域。一般包括状态栏、导航栏,各设备系统定义可能不同。
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 当前系统栏是否显示。true表示显示;false表示不显示。
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 矩形区域的左边界,单位为px,该参数为整数。
top number 矩形区域的上边界,单位为px,该参数应为整数。
width number 矩形区域的宽度,单位为px,该参数应为整数。
height number 矩形区域的高度,单位为px,该参数应为整数。

AvoidArea7+

窗口内容规避区域。

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

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

Size7+

窗口大小。

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

名称 类型 可读 可写 说明
width number 窗口宽度,单位为px,该参数应为整数。
height number 窗口高度,单位为px,该参数应为整数。

WindowProperties

窗口属性。

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

名称 类型 可读 可写 说明
windowRect7+ Rect 窗口尺寸。
type7+ WindowType 窗口类型。
isFullScreen boolean 是否全屏,默认为false。true表示全屏;false表示非全屏。
isLayoutFullScreen7+ boolean 窗口是否为沉浸式,默认为false。true表示沉浸式;false表示非沉浸式。
focusable7+ boolean 窗口是否可聚焦,默认为true。true表示可聚焦;false表示不可聚焦。
touchable7+ boolean 窗口是否可触摸,默认为true。true表示可触摸;false表示不可触摸。
brightness number 屏幕亮度。该参数为浮点数,可设置的亮度范围为[0.0, 1.0],其取1.0时表示最大亮度值。如果窗口没有设置亮度值,表示亮度跟随系统,此时获取到的亮度值为-1。
dimBehindValue(deprecated) number 靠后窗口的暗度值。该参数为浮点数,取值范围为[0.0, 1.0],其取1.0表示最暗。
- 说明: 从API version 9开始废弃。
- 从 API version 7开始支持。
isKeepScreenOn boolean 屏幕是否常亮,默认为false。true表示常亮;false表示不常亮。
isPrivacyMode7+ boolean 隐私模式,默认为false。true表示模式开启;false表示模式关闭。
isRoundCorner(deprecated) boolean 窗口是否为圆角。默认为false。true表示圆角;false表示非圆角。
- 说明: 从API version 9开始废弃。
- 从 API version 7开始支持。
isTransparent7+ boolean 窗口是否透明。默认为false。true表示透明;false表示不透明。
id9+ number 窗口ID,默认值为0,该参数应为整数。

ColorSpace8+

色域模式。

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

名称 说明
DEFAULT 0 默认SRGB色域模式。
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。

WindowEventType10+

窗口生命周期。

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

名称 说明
WINDOW_SHOWN 1 切到前台。
WINDOW_ACTIVE 2 获焦状态。
WINDOW_INACTIVE 3 失焦状态。
WINDOW_HIDDEN 4 切到后台。

window.createWindow9+

createWindow(config: Configuration, callback: AsyncCallback&lt;Window&gt;): void

创建子窗口或者系统窗口,使用callback异步回调。

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

参数:

|参数名|类型|必填|说明| |——–|————————————–|–|———————————| |config |Configuration |是|创建窗口时的参数。 | |callback|AsyncCallback&lt;Window&gt;|是|回调函数。返回当前创建的窗口对象。|

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300001 Repeated operation.
1300006 This window context is abnormal.
1300008 The operation is on invalid display.
1300009 The parent window is invalid.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let config: window.Configuration = {
  name: "alertWindow",
  windowType: window.WindowType.TYPE_SYSTEM_ALERT
};
try {
  window.createWindow(config, (err: BusinessError, data) => {
    const errCode: number = err.code;
    if (errCode) {
      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);
  });
} catch (exception) {
  console.error('Failed to create the window. Cause: ' + JSON.stringify(exception));
}

window.createWindow9+

createWindow(config: Configuration): Promise&lt;Window&gt;

创建子窗口或者系统窗口,使用Promise异步回调。

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

参数:

|参数名|类型|必填|说明| |——|——————————–|–|——————| |config|Configuration|是|创建窗口时的参数。|

返回值:

类型 说明
Promise&lt;Window&gt; Promise对象。返回当前创建的窗口对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300001 Repeated operation.
1300006 This window context is abnormal.
1300008 The operation is on invalid display.
1300009 The parent window is invalid.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let config: window.Configuration = {
  name: "alertWindow",
  windowType: window.WindowType.TYPE_SYSTEM_ALERT
};
try {
  let promise = window.createWindow(config);
  promise.then((data) => {
    windowClass = data;
    console.info('Succeeded in creating the window. Data:' + JSON.stringify(data));
  }).catch((err: BusinessError) => {
    console.error('Failed to create the Window. Cause:' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to create the window. Cause: ' + JSON.stringify(exception));
}

window.findWindow9+

findWindow(name: string): Window

查找name所对应的窗口。

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

参数:

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

返回值:

类型 说明
Window 当前查找的窗口对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

let windowClass: window.Window = window.findWindow("test");
try {
  windowClass = window.findWindow('alertWindow');
} catch (exception) {
  console.error('Failed to find the Window. Cause: ' + JSON.stringify(exception));
}

window.getLastWindow9+

getLastWindow(ctx: BaseContext, callback: AsyncCallback&lt;Window&gt;): void

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

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

参数:

|参数名|类型|必填|说明| |——–|————————————–|–|—————————————-| |ctx |BaseContext|是|当前应用上下文信息。| |callback|AsyncCallback&lt;Window&gt;|是|回调函数。返回当前应用内最后显示的窗口对象。|

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300006 This window context is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
try {
  class BaseContext {
      stageMode: boolean = false;
    }
    let context: BaseContext = { stageMode: false };
  window.getLastWindow(context, (err: BusinessError, data) => {
    const errCode: number = err.code;
    if (errCode) {
      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));
  });
} catch (exception) {
  console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception));
}

window.getLastWindow9+

getLastWindow(ctx: BaseContext): Promise&lt;Window&gt;

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

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

参数:

参数名 类型 必填 说明
ctx BaseContext 当前应用上下文信息。

返回值:

类型 说明
Promise&lt;Window&gt; Promise对象。返回当前应用内最后显示的窗口对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300006 This window context is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
class BaseContext {
  stageMode: boolean = false;
}
let context: BaseContext = { stageMode: false };
try {
  let promise = window.getLastWindow(context);
  promise.then((data) => {
    windowClass = data;
    console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
  }).catch((err: BusinessError) => {
    console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception));
}

window.minimizeAll9+

minimizeAll(id: number, callback: AsyncCallback&lt;void&gt;): void

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

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

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

参数:

参数名 类型 必填 说明
id number 显示设备Display的ID号,该参数仅支持整数输入。
callback AsyncCallback&lt;void&gt; 回调信息。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300003 This window manager service works abnormally.

示例:

import display from '@ohos.display'
import { BusinessError } from '@ohos.base';

let displayClass: display.Display|null = null;
try {
  displayClass = display.getDefaultDisplaySync();

  try {
    window.minimizeAll(displayClass.id, (err: BusinessError) => {
      const errCode: number = err.code;
      if (errCode) {
        console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(err));
        return;
      }
      console.info('Succeeded in minimizing all windows.');
    });
  } catch (exception) {
    console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(exception));
  }
} catch (exception) {
  console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
}

window.minimizeAll9+

minimizeAll(id: number): Promise&lt;void&gt;

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

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

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

参数:

参数名 类型 必填 说明
id number 显示设备Display的ID号,该参数仅支持整数输入。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300003 This window manager service works abnormally.

示例:

import display from '@ohos.display'
import { BusinessError } from '@ohos.base';

let displayClass: display.Display|null = null;
try {
  displayClass = display.getDefaultDisplaySync();

  try {
    let promise = window.minimizeAll(displayClass.id);
    promise.then(() => {
      console.info('Succeeded in minimizing all windows.');
    }).catch((err: BusinessError) => {
      console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(err));
    });
  } catch (exception) {
    console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(exception));
  }
} catch (exception) {
  console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
}

window.toggleShownStateForAllAppWindows9+

toggleShownStateForAllAppWindows(callback: AsyncCallback&lt;void&gt;): void

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

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

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

参数:

参数名 类型 必填 说明
callback AsyncCallback&lt;void&gt; 回调信息。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

window.toggleShownStateForAllAppWindows((err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    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.');
});

window.toggleShownStateForAllAppWindows9+

toggleShownStateForAllAppWindows(): Promise&lt;void&gt;

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

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

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let promise = window.toggleShownStateForAllAppWindows();
promise.then(() => {
  console.info('Succeeded in toggling shown state for all app windows.');
}).catch((err: BusinessError) => {
  console.error('Failed to toggle shown state for all app windows. Cause: ' + JSON.stringify(err));
});

window.setWindowLayoutMode9+

setWindowLayoutMode(mode: WindowLayoutMode, callback: AsyncCallback&lt;void&gt;): void

设置窗口布局模式。

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

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

参数:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

try {
  window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(err));
      return;
    }
    console.info('Succeeded in setting window layout mode.');
  });
} catch (exception) {
  console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(exception));
}

window.setWindowLayoutMode9+

setWindowLayoutMode(mode: WindowLayoutMode): Promise&lt;void&gt;

设置窗口布局模式。

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

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

try {
  let promise = window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE);
  promise.then(() => {
    console.info('Succeeded in setting window layout mode.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(exception));
}

window.on(‘systemBarTintChange’)8+

on(type: ‘systemBarTintChange’, callback: Callback&lt;SystemBarTintState&gt;): void

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

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

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

参数:

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

示例:

try {
  window.on('systemBarTintChange', (data) => {
    console.info('Succeeded in enabling the listener for systemBarTint changes. Data: ' + JSON.stringify(data));
  });
} catch (exception) {
  console.error('Failed to enable the listener for systemBarTint changes. Cause: ' + JSON.stringify(exception));
}

window.off(‘systemBarTintChange’)8+

off(type: ‘systemBarTintChange’, callback?: Callback&lt;SystemBarTintState &gt;): void

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

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

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’systemBarTintChange’,即导航栏、状态栏属性变化事件。
callback Callback&lt;SystemBarTintState&gt; 回调函数。返回当前的状态栏、导航栏信息集合。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有状态栏、导航栏属性变化的监听。

示例:

try {
  window.off('systemBarTintChange');
} catch (exception) {
  console.error('Failed to disable the listener for systemBarTint changes. Cause: ' + JSON.stringify(exception));
}

window.on(‘gestureNavigationEnabledChange’)10+

on(type: ‘gestureNavigationEnabledChange’, callback: Callback&lt;boolean&gt;): void

添加手势导航启用状态变化的监听。

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

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’gestureNavigationEnabledChange’,即手势导航启用状态变化事件。
callback Callback&lt;boolean&gt; 回调函数。返回当前手势导航的启用状态。true表示手势导航状态变化为启用;false表示手势导航状态变化为禁用。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

try {
  window.on('gestureNavigationEnabledChange', (data) => {
    console.info('Succeeded in enabling the listener for gesture navigation status changes. Data: ' + JSON.stringify(data));
  });
} catch (exception) {
  console.error('Failed to enable the listener for gesture navigation status changes. Cause: ' + JSON.stringify(exception));
}

window.off(‘gestureNavigationEnabledChange’)10+

off(type: ‘gestureNavigationEnabledChange’, callback?: Callback&lt;boolean&gt;): void

移除手势导航启用状态变化的监听。

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

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

参数:

|参数名 |类型 |必填|说明 | |——–|———————–|–|————————————————————| |type |string |是|监听事件,固定为’gestureNavigationEnabledChange’,即手势导航启用状态变化事件。| |callback|Callback&lt;boolean&gt;|否|已注册的回调函数。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有手势导航启用状态变化的监听。|

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

try {
  window.off('gestureNavigationEnabledChange');
} catch (exception) {
  console.error('Failed to disable the listener for gesture navigation status changes. Cause: ' + JSON.stringify(exception));
}

window.on(‘waterMarkFlagChange’)10+

on(type: ‘waterMarkFlagChange’, callback: Callback&lt;boolean&gt;): void

添加水印启用状态变化的监听。

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

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’waterMarkFlagChange’,即水印启用状态变化事件。
callback Callback&lt;boolean&gt; 回调函数。返回当前水印的启用状态。true表示当前已启用水印;false表示当前未启用水印。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300003 This window manager service works abnormally.

示例:

try {
  window.on('waterMarkFlagChange', (data) => {
    console.info('Succeeded in enabling the listener for watermark flag changes. Data: ' + JSON.stringify(data));
  });
} catch (exception) {
  console.error('Failed to enable the listener for watermark flag changes. Cause: ' + JSON.stringify(exception));
}

window.off(‘waterMarkFlagChange’)10+

off(type: ‘waterMarkFlagChange’, callback?: Callback&lt;boolean&gt;): void

移除水印启用状态变化的监听。

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

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

参数:

|参数名 |类型 |必填|说明 | |——–|———————–|–|————————————————————| |type |string |是|监听事件,固定为’waterMarkFlagChange’,即水印启用状态变化事件。| |callback|Callback&lt;boolean&gt;|否|已注册的回调函数。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有水印启用状态变化的监听。|

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300003 This window manager service works abnormally.

示例:

try {
  window.off('waterMarkFlagChange');
} catch (exception) {
  console.error('Failed to disable the listener for watermark flag changes. Cause: ' + JSON.stringify(exception));
}

window.setGestureNavigationEnabled10+

setGestureNavigationEnabled(enable: boolean, callback: AsyncCallback&lt;void&gt;): void

设置手势导航启用状态。使用callback异步回调。

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

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

参数:

参数名 类型 必填 说明
enable boolean 设置手势导航启用状态。true表示启用手势导航;false表示禁用手势导航。
callback AsyncCallback&lt;void&gt; 回调信息。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

try {
  window.setGestureNavigationEnabled(true, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(err));
      return;
    }
    console.info('Succeeded in setting gesture navigation enabled.');
  });
} catch (exception) {
  console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(exception));
}

window.setGestureNavigationEnabled10+

setGestureNavigationEnabled(enable: boolean): Promise&lt;void&gt;

设置手势导航启用状态。使用Promise异步回调。

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

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

参数:

参数名 类型 必填 说明
enable boolean 设置手势导航启用状态。true表示启用手势导航;false表示禁用手势导航。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

try {
  let promise = window.setGestureNavigationEnabled(true);
  promise.then(() => {
    console.info('Succeeded in setting gesture navigation enabled.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(exception));
}

window.setWaterMarkImage10+

setWaterMarkImage(pixelMap: image.PixelMap, enable: boolean, callback: AsyncCallback&lt;void&gt;): void

设置水印图片显示状态。使用callback异步回调。

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

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

参数:

参数名 类型 必填 说明
pixelMap image.PixelMap 水印图片。
enable boolean 设置是否显示水印图片。true显示水印图片;false表示不显示水印图片。
callback AsyncCallback&lt;void&gt; 回调信息。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300003 This window manager service works abnormally.

示例:

import image from '@ohos.multimedia.image';
import { BusinessError } from '@ohos.base';

let enable: boolean = true;
let color: ArrayBuffer = new ArrayBuffer(0);
let initializationOptions: image.InitializationOptions = {
  size: {
    height: 100,
    width: 100
  }
};
image.createPixelMap(color, initializationOptions).then((pixelMap: image.PixelMap) => {
  console.info('Succeeded in creating pixelmap.');
  try {
    window.setWaterMarkImage(pixelMap, enable, (err: BusinessError) => {
      const errCode: number = err.code;
      if (errCode) {
        console.error('Failed to show watermark image. Cause: ' + JSON.stringify(err));
        return;
      }
      console.info('Succeeded in showing watermark image.');
    });
  } catch (exception) {
    console.error('Failed to show watermark image. Cause: ' + JSON.stringify(exception));
  }
}).catch((err: BusinessError) => {
  console.error('Failed to create PixelMap. Cause: ' + JSON.stringify(err));
});

window.setWaterMarkImage10+

setWaterMarkImage(pixelMap: image.PixelMap, enable: boolean): Promise&lt;void&gt;

设置水印图片显示状态。使用Promise异步回调。

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

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

参数:

参数名 类型 必填 说明
pixelMap image.PixelMap 水印图片。
enable boolean 设置是否显示水印图片。true显示水印图片;false表示不显示水印图片。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300003 This window manager service works abnormally.

示例:

import image from '@ohos.multimedia.image';
import { BusinessError } from '@ohos.base';

let enable: boolean = true;
let color: ArrayBuffer = new ArrayBuffer(0);
let initializationOptions: image.InitializationOptions = {
  size: {
    height: 100,
    width: 100
  }
};
image.createPixelMap(color, initializationOptions).then((pixelMap: image.PixelMap) => {
  console.info('Succeeded in creating pixelmap.');
  try {
    let promise = window.setWaterMarkImage(pixelMap, enable);
    promise.then(() => {
      console.info('Succeeded in showing watermark image.');
    }).catch((err: BusinessError) => {
      console.error('Failed to show watermark image. Cause: ' + JSON.stringify(err));
    });
  } catch (exception) {
    console.error('Failed to show watermark image. Cause: ' + JSON.stringify(exception));
  }
}).catch((err: BusinessError) => {
  console.error('Failed to create PixelMap. Cause: ' + JSON.stringify(err));
});

window.create(deprecated)

create(id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用createWindow()

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

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

参数:

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

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
window.create('first', window.WindowType.TYPE_APP, (err: BusinessError, data) => {
  const errCode: number = err.code;
  if (errCode) {
    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));
});

window.create(deprecated)

create(id: string, type: WindowType): Promise&lt;Window&gt;

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用createWindow()

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

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

参数:

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

返回值:

类型 说明
Promise&lt;Window&gt; Promise对象。返回当前创建的子窗口对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
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: BusinessError) => {
  console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err));
});

window.create(deprecated)

create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用createWindow()

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

参数:

参数名 类型 必填 说明
ctx BaseContext 当前应用上下文信息。
id string 窗口id。
type WindowType 窗口类型。
callback AsyncCallback&lt;Window&gt; 回调函数。返回当前创建的子窗口对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
window.create('alertWindow', window.WindowType.TYPE_SYSTEM_ALERT, (err: BusinessError, data) => {
  const errCode: number = err.code;
  if (errCode) {
    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);
});

window.create(deprecated)

create(ctx: BaseContext, id: string, type: WindowType): Promise&lt;Window&gt;

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用createWindow()

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

参数:

参数名 类型 必填 说明
ctx BaseContext 当前应用上下文信息。
id string 窗口id。
type WindowType 窗口类型。

返回值:

类型 说明
Promise&lt;Window&gt; Promise对象。返回当前创建的子窗口对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = window.create('alertWindow', window.WindowType.TYPE_SYSTEM_ALERT);
promise.then((data) => {
  windowClass = data;
  console.info('Succeeded in creating the window. Data:' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error('Failed to create the Window. Cause:' + JSON.stringify(err));
});

window.find(deprecated)

find(id: string, callback: AsyncCallback&lt;Window&gt;): void

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用findWindow()

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

参数:

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

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
window.find('alertWindow', (err: BusinessError, data) => {
  const errCode: number = err.code;
  if (errCode) {
    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));
});

window.find(deprecated)

find(id: string): Promise&lt;Window&gt;

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用findWindow()

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

参数:

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

返回值:

类型 说明
Promise&lt;Window&gt; Promise对象。返回当前查找的窗口对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = window.find('alertWindow');
promise.then((data) => {
  windowClass = data;
  console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error('Failed to find the Window. Cause: ' + JSON.stringify(err));
});

window.getTopWindow(deprecated)

getTopWindow(callback: AsyncCallback&lt;Window&gt;): void

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

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐使用getLastWindow()

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

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

参数:

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

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
window.getTopWindow((err: BusinessError, data) => {
  const errCode: number = err.code;
  if (errCode) {
    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));
});

window.getTopWindow(deprecated)

getTopWindow(): Promise&lt;Window&gt;

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

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐使用getLastWindow()

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

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

返回值:

类型 说明
Promise&lt;Window&gt; Promise对象。返回当前应用内最后显示的窗口对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = window.getTopWindow();
promise.then((data)=> {
    windowClass = data;
    console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
}).catch((err: BusinessError)=>{
    console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
});

window.getTopWindow(deprecated)

getTopWindow(ctx: BaseContext, callback: AsyncCallback&lt;Window&gt;): void

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

说明:

从 API version 8开始支持,从API version 9开始废弃,推荐使用getLastWindow()

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

参数:

参数名 类型 必填 说明
ctx BaseContext 当前应用上下文信息。
callback AsyncCallback&lt;Window&gt; 回调函数。返回当前应用内最后显示的窗口对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = window.getTopWindow();
promise.then((data) => {
  windowClass = data;
  console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
});

window.getTopWindow(deprecated)

getTopWindow(ctx: BaseContext): Promise&lt;Window&gt;

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

说明:

从 API version 8开始支持,从API version 9开始废弃,推荐使用getLastWindow()

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

参数:

参数名 类型 必填 说明
ctx BaseContext 当前应用上下文信息。

返回值:

类型 说明
Promise&lt;Window&gt; Promise对象。返回当前应用内最后显示的窗口对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = window.getTopWindow();
promise.then((data) => {
  windowClass = data;
  console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
});

Window

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

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

hide7+

hide (callback: AsyncCallback&lt;void&gt;): void

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

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

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

参数:

参数名 类型 必填 说明
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.hide((err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to hide the window. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in hiding the window.');
});

hide7+

hide(): Promise&lt;void&gt;

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

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

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.hide();
promise.then(() => {
  console.info('Succeeded in hiding the window.');
}).catch((err: BusinessError) => {
  console.error('Failed to hide the window. Cause: ' + JSON.stringify(err));
});

hideWithAnimation9+

hideWithAnimation(callback: AsyncCallback&lt;void&gt;): void

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

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

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

参数:

参数名 类型 必填 说明
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300004 Unauthorized operation.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.hideWithAnimation((err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to hide the window with animation. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in hiding the window with animation.');
});

hideWithAnimation9+

hideWithAnimation(): Promise&lt;void&gt;

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

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

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300004 Unauthorized operation.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.hideWithAnimation();
promise.then(() => {
  console.info('Succeeded in hiding the window with animation.');
}).catch((err: BusinessError) => {
  console.error('Failed to hide the window with animation. Cause: ' + JSON.stringify(err));
});

showWindow9+

showWindow(callback: AsyncCallback&lt;void&gt;): void

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

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

参数:

|参数名|类型|必填|说明| |——–|————————-|–|———| |callback|AsyncCallback&lt;void&gt;|是|回调函数。|

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.showWindow((err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in showing the window.');
});

showWindow9+

showWindow(): Promise&lt;void&gt;

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

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.showWindow();
promise.then(() => {
  console.info('Succeeded in showing the window.');
}).catch((err: BusinessError) => {
  console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
});

showWithAnimation9+

showWithAnimation(callback: AsyncCallback&lt;void&gt;): void

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

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

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

参数:

参数名 类型 必填 说明
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300004 Unauthorized operation.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.showWithAnimation((err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in showing the window with animation.');
});

showWithAnimation9+

showWithAnimation(): Promise&lt;void&gt;

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

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

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300004 Unauthorized operation.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.showWithAnimation();
promise.then(() => {
  console.info('Succeeded in showing the window with animation.');
}).catch((err: BusinessError) => {
  console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err));
});

destroyWindow9+

destroyWindow(callback: AsyncCallback&lt;void&gt;): void

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

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

参数:

|参数名|类型|必填|说明| |——–|————————-|–|———| |callback|AsyncCallback&lt;void&gt;|是|回调函数。|

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.destroyWindow((err) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to destroy the window. Cause:' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in destroying the window.');
});

destroyWindow9+

destroyWindow(): Promise&lt;void&gt;

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

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.destroyWindow();
promise.then(() => {
  console.info('Succeeded in destroying the window.');
}).catch((err: BusinessError) => {
  console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err));
});

moveWindowTo9+

moveWindowTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void

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

全屏模式窗口不支持该操作。

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

参数:

|参数名|类型|必填|说明| |——–|————————-|–|———————————————| |x |number |是|窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入。| |y |number |是|窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入。| |callback|AsyncCallback&lt;void&gt;|是|回调函数。 |

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.moveWindowTo(300, 300, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error('Failed to move the window. Cause:' + JSON.stringify(err));
      return;
    }
    console.info('Succeeded in moving the window.');
  });
} catch (exception) {
  console.error('Failed to move the window. Cause:' + JSON.stringify(exception));
}

moveWindowTo9+

moveWindowTo(x: number, y: number): Promise&lt;void&gt;

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

全屏模式窗口不支持该操作。

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

参数:

|参数名|类型|必填|说明| |–|—–|–|———————————————| |x|number|是|窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入。| |y|number|是|窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入。|

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

try {
  let windowClass: window.Window = window.findWindow("test");
  let promise = windowClass.moveWindowTo(300, 300);
  promise.then(() => {
    console.info('Succeeded in moving the window.');
  }).catch((err: BusinessError) => {
    console.error('Failed to move the window. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to move the window. Cause:' + JSON.stringify(exception));
}

resize9+

resize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void

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

应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 2560],默认高度范围:[240, 2560],单位为vp。 应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准。

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

设置的宽度与高度受到此约束限制,规则: 若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。

全屏模式窗口不支持该操作。

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

参数:

|参数名|类型|必填|说明| |——–|————————-|–|————————| |width |number |是|目标窗口的宽度,单位为px,该参数仅支持整数输入。| |height |number |是|目标窗口的高度,单位为px,该参数仅支持整数输入。| |callback|AsyncCallback&lt;void&gt;|是|回调函数。 |

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.resize(500, 1000, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error('Failed to change the window size. Cause:' + JSON.stringify(err));
      return;
    }
    console.info('Succeeded in changing the window size.');
  });
} catch (exception) {
  console.error('Failed to change the window size. Cause:' + JSON.stringify(exception));
}

resize9+

resize(width: number, height: number): Promise&lt;void&gt;

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

应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 2560],默认高度范围:[240, 2560],单位为vp。 应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准。

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

设置的宽度与高度受到此约束限制,规则: 若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。

全屏模式窗口不支持该操作。

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

参数:

|参数名|类型|必填|说明| |——|——|–|————————| |width|number|是|目标窗口的宽度,单位为px,该参数仅支持整数输入。| |height|number|是|目标窗口的高度,单位为px,该参数仅支持整数输入。|

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

try {
  let windowClass: window.Window = window.findWindow("test");
  let promise = windowClass.resize(500, 1000);
  promise.then(() => {
    console.info('Succeeded in changing the window size.');
  }).catch((err: BusinessError) => {
    console.error('Failed to change the window size. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to change the window size. Cause: ' + JSON.stringify(exception));
}

setWindowMode9+

setWindowMode(mode: WindowMode, callback: AsyncCallback&lt;void&gt;): void

设置窗口模式,使用callback异步回调。

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

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

参数:

|参数名|类型|必填|说明| |——–|————————–|–|———| |mode |WindowMode|是|窗口模式。| |callback|AsyncCallback&lt;void&gt;|是|回调函数。|

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let mode = window.WindowMode.FULLSCREEN;
try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.setWindowMode(mode, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error('Failed to set the window mode. Cause: ' + JSON.stringify(err));
      return;
    }
    console.info('Succeeded in setting the window mode.');
  });
} catch (exception) {
  console.error('Failed to set the window mode. Cause: ' + JSON.stringify(exception));
}

setWindowMode9+

setWindowMode(mode: WindowMode): Promise&lt;void&gt;

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

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

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

参数:

|参数名|类型|必填|说明| |——–|————————–|–|———| |mode |WindowMode|是|窗口模式。|

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let mode = window.WindowMode.FULLSCREEN;
try {
  let windowClass: window.Window = window.findWindow("test");
  let promise = windowClass.setWindowMode(mode);
  promise.then(() => {
    console.info('Succeeded in setting the window mode.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set the window mode. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set the window mode. Cause: ' + JSON.stringify(exception));
}

getWindowProperties9+

getWindowProperties(): WindowProperties

获取当前窗口的属性,返回WindowProperties。

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

返回值:

类型 说明
WindowProperties 当前窗口属性。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

try {
  let windowClass: window.Window = window.findWindow("test");
  let properties = windowClass.getWindowProperties();
} catch (exception) {
  console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(exception));
}

getWindowAvoidArea9+

getWindowAvoidArea(type: AvoidAreaType): AvoidArea

获取窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。

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

参数:

|参数名|类型|必填|说明| |—-|———————————-|–|————————————————————| |type|AvoidAreaType|是|表示规避区类型。|

返回值:

类型 说明
AvoidArea 窗口内容规避区域。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

let type = window.AvoidAreaType.TYPE_SYSTEM;
try {
  let windowClass: window.Window = window.findWindow("test");
  let avoidArea = windowClass.getWindowAvoidArea(type);
} catch (exception) {
  console.error('Failed to obtain the area. Cause:' + JSON.stringify(exception));
}

setWindowLayoutFullScreen9+

setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void

设置窗口的布局是否为沉浸式布局,使用callback异步回调。 沉浸式布局是指布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 非沉浸式布局是指布局避让状态栏与导航栏,组件不会与其重叠。

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

参数:

|参数名|类型|必填|说明| |——————|————————-|–|———| |isLayoutFullScreen|boolean |是|窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。| |callback |AsyncCallback&lt;void&gt;|是|回调函数。|

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let isLayoutFullScreen = true;
try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      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.');
  });
} catch (exception) {
  console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception));
}

setWindowLayoutFullScreen9+

setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise&lt;void&gt;

设置窗口的布局是否为沉浸式布局,使用Promise异步回调。 沉浸式布局是指布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 非沉浸式布局是指布局避让状态栏与导航栏,组件不会与其重叠。

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

参数:

|参数名|类型|必填|说明| |——————|——-|–|————————————————————————————————| |isLayoutFullScreen|boolean|是|窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。|

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let isLayoutFullScreen = true;
try {
  let windowClass: window.Window = window.findWindow("test");
  let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen);
  promise.then(() => {
    console.info('Succeeded in setting the window layout to full-screen mode.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception));
}

setWindowSystemBarEnable9+

setWindowSystemBarEnable(names: Array<‘status’|‘navigation’>, callback: AsyncCallback&lt;void&gt;): void

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

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

参数:

|参数名|类型|必填|说明| |——–|—————————-|–|———| |names |Array<‘status’|‘navigation’>|是|设置窗口全屏模式时状态栏和导航栏是否显示。
例如,需全部显示,该参数设置为[‘status’,&nbsp;‘navigation’];不设置,则默认不显示。| |callback|AsyncCallback&lt;void&gt;|是|回调函数。|

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

// 此处以不显示导航栏、状态栏为例
import { BusinessError } from '@ohos.base';

let names: Array<'status'|'navigation'> = [];
try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.setWindowSystemBarEnable(names, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      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.');
  });
} catch (exception) {
  console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception));
}

setWindowSystemBarEnable9+

setWindowSystemBarEnable(names: Array<‘status’|‘navigation’>): Promise&lt;void&gt;

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

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

参数:

|参数名|类型|必填|说明| |—–|—————————-|–|———————————| |names|Array<‘status’|‘navigation’>|是|设置窗口全屏模式时状态栏和导航栏是否显示。
例如,需全部显示,该参数设置为[‘status’,&nbsp;‘navigation’];不设置,则默认不显示。|

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

// 此处以不显示导航栏、状态栏为例
import { BusinessError } from '@ohos.base';

let names: Array<'status'|'navigation'> = [];
try {
  let windowClass: window.Window = window.findWindow("test");
  let promise = windowClass.setWindowSystemBarEnable(names);
  promise.then(() => {
    console.info('Succeeded in setting the system bar to be invisible.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception));
}

setWindowSystemBarProperties9+

setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback&lt;void&gt;): void

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

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

参数:

参数名 类型 必填 说明
SystemBarProperties SystemBarProperties 导航栏、状态栏的属性。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let SystemBarProperties: window.SystemBarProperties = {
  statusBarColor: '#ff00ff',
  navigationBarColor: '#00ff00',
  //以下两个属性从API Version8开始支持
  statusBarContentColor: '#ffffff',
  navigationBarContentColor: '#00ffff'
};
try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.setWindowSystemBarProperties(SystemBarProperties, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
      return;
    }
    console.info('Succeeded in setting the system bar properties.');
  });
} catch (exception) {
  console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(exception));
}

setWindowSystemBarProperties9+

setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise&lt;void&gt;

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

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let SystemBarProperties: window.SystemBarProperties = {
  statusBarColor: '#ff00ff',
  navigationBarColor: '#00ff00',
  //以下两个属性从API Version8开始支持
  statusBarContentColor: '#ffffff',
  navigationBarContentColor: '#00ffff'
};
try {
  let windowClass: window.Window = window.findWindow("test");
  let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties);
  promise.then(() => {
    console.info('Succeeded in setting the system bar properties.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(exception));
}

setPreferredOrientation9+

setPreferredOrientation(orientation: Orientation, callback: AsyncCallback&lt;void&gt;): void

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

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

参数:

参数名 类型 必填 说明
Orientation Orientation 窗口显示方向的属性。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let orientation = window.Orientation.AUTO_ROTATION;
try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.setPreferredOrientation(orientation, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error('Failed to set window orientation. Cause: ' + JSON.stringify(err));
      return;
    }
    console.info('Succeeded in setting window orientation.');
  });
} catch (exception) {
  console.error('Failed to set window orientation. Cause: ' + JSON.stringify(exception));
}

setPreferredOrientation9+

setPreferredOrientation(orientation: Orientation): Promise&lt;void&gt;

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

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let orientation = window.Orientation.AUTO_ROTATION;
try {
  let windowClass: window.Window = window.findWindow("test");
  let promise = windowClass.setPreferredOrientation(orientation);
  promise.then(() => {
    console.info('Succeeded in setting the window orientation.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set the window orientation. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set window orientation. Cause: ' + JSON.stringify(exception));
}

getUIContext10+

getUIContext(): UIContext

获取UIContext实例。

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

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

返回值:

类型 说明
UIContext 返回UIContext实例对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';
import { UIContext } from '@ohos.arkui.UIContext';

export default class EntryAbility extends UIAbility {
  onWindowStageCreate(windowStage: window.WindowStage) {
    // 为主窗口加载对应的目标页面。
    windowStage.loadContent("pages/page2", (err: BusinessError) => {
      let errCode: number = err.code;
      if (errCode) {
        console.error('Failed to load the content. Cause:' + JSON.stringify(err));
        return;
      }
      console.info('Succeeded in loading the content.');
      // 获取应用主窗口。
      let windowClass: window.Window = window.findWindow("test");
      windowStage.getMainWindow((err: BusinessError, data) => {
        let errCode: number = err.code;
        if (errCode) {
          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));
        // 获取UIContext实例。
        let uiContext: UIContext|null = null;
        uiContext = windowClass.getUIContext();
      })
    });
  }
};

setUIContent9+

setUIContent(path: string, callback: AsyncCallback&lt;void&gt;): void

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

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

参数:

|参数名|类型|必填|说明| |——–|————————-|–|——————–| |path |string |是|设置加载页面的路径。| |callback|AsyncCallback&lt;void&gt;|是|回调函数。 |

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.setUIContent('pages/page2/page2', (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error('Failed to load the content. Cause:' + JSON.stringify(err));
      return;
    }
    console.info('Succeeded in loading the content.');
  });
} catch (exception) {
  console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
}

setUIContent9+

setUIContent(path: string): Promise&lt;void&gt;

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

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

try {
  let windowClass: window.Window = window.findWindow("test");
  let promise = windowClass.setUIContent('pages/page2/page2');
  promise.then(() => {
    console.info('Succeeded in loading the content.');
  }).catch((err: BusinessError) => {
    console.error('Failed to load the content. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to load the content. Cause: ' + JSON.stringify(exception));
}

loadContent9+

loadContent(path: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void

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

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

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

参数:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    let windowClass: window.Window = window.findWindow("test");
    let storage: LocalStorage = new LocalStorage();
    storage.setOrCreate('storageSimpleProp', 121);
    try {
      if (!windowClass) {
        console.info('Failed to load the content. Cause: windowClass is null');
      }
      else {
        (windowClass as window.Window).loadContent('pages/page2', storage, (err: BusinessError) => {
          const errCode: number = err.code;
          if (errCode) {
            console.error('Failed to load the content. Cause:' + JSON.stringify(err));
            return;
          }
          console.info('Succeeded in loading the content.');
        });
      }
    } catch (exception) {
      console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
    }
  }
};

loadContent9+

loadContent(path: string, storage: LocalStorage): Promise&lt;void&gt;

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

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

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    let windowClass: window.Window = window.findWindow("test");
    let storage: LocalStorage = new LocalStorage();
    storage.setOrCreate('storageSimpleProp', 121);
    try {
      if (!windowClass) {
        console.info('Failed to load the content. Cause: windowClass is null');
      }
      else {
        let promise = (windowClass as window.Window).loadContent('pages/page2', storage);
        promise.then(() => {
          console.info('Succeeded in loading the content.');
        }).catch((err: BusinessError) => {
          console.error('Failed to load the content. Cause:' + JSON.stringify(err));
        });
      }
    } catch (exception) {
      console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
    }
  }
};

loadContentByName11+

loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void

为当前窗口加载与LocalStorage相关联的命名路由页面,使用callback异步回调。

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

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

参数:

参数名 类型 必填 说明
name string 命名路由页面的名称。
storage LocalStorage 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

// ets/entryability/EntryAbility.ets
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';
import * as Index from '../pages/Index'; // 导入命名路由页面

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
    let storage: LocalStorage = new LocalStorage();
    storage.setOrCreate('storageSimpleProp', 121);
    try {
      if (!windowClass) {
        console.info('Failed to load the content. Cause: windowClass is null');
      } else {
        (windowClass as window.Window).loadContentByName(Index.entryName, storage, (err: BusinessError) => {
          const errCode: number = err.code;
          if (errCode) {
            console.error('Failed to load the content. Cause:' + JSON.stringify(err));
            return;
          }
          console.info('Succeeded in loading the content.');
        });
      }
    } catch (exception) {
      console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
    }
  }
};
// ets/pages/Index.ets
export const entryName : string = 'Index';
@Entry({routeName: entryName, storage : LocalStorage.getShared()})
@Component
export struct Index {
  @State message: string = 'Hello World'
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
    }
    .height('100%')
  }
}

loadContentByName11+

loadContentByName(name: string, callback: AsyncCallback&lt;void&gt;): void

为当前窗口加载命名路由页面内容,使用callback异步回调。

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

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

参数:

参数名 类型 必填 说明
name string 命名路由页面的名称。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

// ets/entryability/EntryAbility.ets
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';
import * as Index from '../pages/Index'; // 导入命名路由页面

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
    try {
      if (!windowClass) {
        console.info('Failed to load the content. Cause: windowClass is null');
      } else {
        (windowClass as window.Window).loadContentByName(Index.entryName, (err: BusinessError) => {
          const errCode: number = err.code;
          if (errCode) {
            console.error('Failed to load the content. Cause:' + JSON.stringify(err));
            return;
          }
          console.info('Succeeded in loading the content.');
        });
      }
    } catch (exception) {
      console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
    }
  }
};
// ets/pages/Index.ets
export const entryName : string = 'Index';
@Entry({routeName: entryName})
@Component
export struct Index {
  @State message: string = 'Hello World'
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
    }
    .height('100%')
  }
}

loadContentByName11+

loadContentByName(name: string, storage?: LocalStorage): Promise&lt;void&gt;

为当前窗口加载与LocalStorage相关联的命名路由页面,使用Promise异步回调。

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

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

参数:

参数名 类型 必填 说明
name string 命名路由页面的名称。
storage LocalStorage 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

// ets/entryability/EntryAbility.ets
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';
import * as Index from '../pages/Index'; // 导入命名路由页面

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
    let storage: LocalStorage = new LocalStorage();
    storage.setOrCreate('storageSimpleProp', 121);
    try {
      if (!windowClass) {
        console.info('Failed to load the content. Cause: windowClass is null');
      } else {
        let promise = (windowClass as window.Window).loadContentByName(Index.entryName, storage);
        promise.then(() => {
          console.info('Succeeded in loading the content.');
        }).catch((err: BusinessError) => {
          console.error('Failed to load the content. Cause:' + JSON.stringify(err));
        });
      }
    } catch (exception) {
      console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
    }
  }
};
// ets/pages/Index.ets
export const entryName : string = 'Index';
@Entry({routeName: entryName, storage : LocalStorage.getShared()})
@Component
export struct Index {
  @State message: string = 'Hello World'
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
    }
    .height('100%')
  }
}

isWindowShowing9+

isWindowShowing(): boolean

判断当前窗口是否已显示。

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

返回值:

类型 说明
boolean 当前窗口是否已显示。true表示当前窗口已显示,false则表示当前窗口未显示。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

try {
  let windowClass: window.Window = window.findWindow("test");
  let data = windowClass.isWindowShowing();
  console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
} catch (exception) {
  console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(exception));
}

on(‘windowSizeChange’)7+

on(type: ‘windowSizeChange’, callback: Callback&lt;Size&gt;): void

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

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

参数:

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

示例:

try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.on('windowSizeChange', (data) => {
    console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data));
  });
} catch (exception) {
  console.error('Failed to enable the listener for window size changes. Cause: ' + JSON.stringify(exception));
}

off(‘windowSizeChange’)7+

off(type: ‘windowSizeChange’, callback?: Callback&lt;Size&gt;): void

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

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’windowSizeChange’,即窗口尺寸变化事件。
callback Callback&lt;Size&gt; 回调函数。返回当前的窗口尺寸。如果传入参数,则关闭该监听。如果未传入参数,则关闭窗口尺寸变化的监听。

示例:

try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.off('windowSizeChange');
} catch (exception) {
  console.error('Failed to disable the listener for window size changes. Cause: ' + JSON.stringify(exception));
}

on(‘avoidAreaChange’)9+

on(type: ‘avoidAreaChange’, callback: Callback&lt;{ type: AvoidAreaType, area: AvoidArea}&gt;): void

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

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’avoidAreaChange’,即系统规避区变化事件。
callback Callback&lt;{ type: AvoidAreaType, area: AvoidArea }&gt; 回调函数。返回当前规避区以及规避区类型。

示例:

try {
  let windowClass: window.Window = window.findWindow("test");
  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));
  });
} catch (exception) {
  console.error('Failed to enable the listener for system avoid area changes. Cause: ' + JSON.stringify(exception));
}

off(‘avoidAreaChange’)9+

off(type: ‘avoidAreaChange’, callback?: Callback&lt;{ type: AvoidAreaType, area: AvoidArea }&gt;): void

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

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’avoidAreaChange’,即系统规避区变化事件。
callback Callback&lt;{ type: AvoidAreaType, area: AvoidArea }&gt; 回调函数。返回当前规避区以及规避区类型。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有系统规避区变化的监听。

示例:

try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.off('avoidAreaChange');
} catch (exception) {
  console.error('Failed to disable the listener for system avoid area changes. Cause: ' + JSON.stringify(exception));
}

on(‘keyboardHeightChange’)7+

on(type: ‘keyboardHeightChange’, callback: Callback&lt;number&gt;): void

开启固定态输入法窗口软键盘高度变化的监听。从API version 10开始,改变输入法窗口为固定态或者悬浮态方法详细介绍请参见输入法服务

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’keyboardHeightChange’,即键盘高度变化事件。
callback Callback&lt;number&gt; 回调函数。返回当前的键盘高度,返回值为整数。

示例:

try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.on('keyboardHeightChange', (data) => {
    console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data));
  });
} catch (exception) {
  console.error('Failed to enable the listener for keyboard height changes. Cause: ' + JSON.stringify(exception));
}

off(‘keyboardHeightChange’)7+

off(type: ‘keyboardHeightChange’, callback?: Callback&lt;number&gt;): void

关闭固定态输入法窗口软键盘高度变化的监听。从API version 10开始,改变输入法窗口为固定态或者悬浮态方法详细介绍请参见输入法服务

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’keyboardHeightChange’,即键盘高度变化事件。
callback Callback&lt;number&gt; 回调函数。返回当前的键盘高度,返回值为整数。若传入参数,则关闭该监听。如果未传入参数,则关闭所有固定态输入法窗口软键盘高度变化的监听。

示例:

try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.off('keyboardHeightChange');
} catch (exception) {
  console.error('Failed to disable the listener for keyboard height changes. Cause: ' + JSON.stringify(exception));
}

on(‘touchOutside’)11+

on(type: ‘touchOutside’, callback: Callback&lt;void&gt;): void

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

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

参数:

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

示例:

try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.on('touchOutside', () => {
    console.info('touch outside');
  });
} catch (exception) {
  console.error('Failed to register callback. Cause: ' + JSON.stringify(exception));
}

off(‘touchOutside’)11+

off(type: ‘touchOutside’, callback?: Callback&lt;void&gt;): void

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

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’touchOutside’,即本窗口范围外的点击事件。
callback Callback&lt;void&gt; 回调函数。当点击事件发生在本窗口范围之外的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口区域范围外的点击事件的监听。

示例:

try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.off('touchOutside');
} catch (exception) {
  console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception));
}

on(‘screenshot’)9+

on(type: ‘screenshot’, callback: Callback&lt;void&gt;): void

开启截屏事件的监听。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’screenshot’,即截屏事件。
callback Callback&lt;void&gt; 回调函数。发生截屏事件时的回调。

示例:

try {
  let windowClass: window.Window = window.findWindow("test");
  windowClass.on('screenshot', () => {
    console.info('screenshot happened');
  });
} catch (exception) {
  console.error('Failed to register callback. Cause: ' + JSON.stringify(exception));
}

off(‘screenshot’)9+

off(type: ‘screenshot’, callback?: Callback&lt;void&gt;): void

关闭截屏事件的监听。

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’screenshot’,即截屏事件。
callback Callback&lt;void&gt; 回调函数。发生截屏事件时的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有截屏事件的监听。

示例:

let windowClass: window.Window = window.findWindow("test");
let callback = () => {
  console.info('screenshot happened');
};
try {
  windowClass.on('screenshot', callback);
} catch (exception) {
  console.error('Failed to register callback. Cause: ' + JSON.stringify(exception));
}
try {
  windowClass.off('screenshot', callback);
  // 如果通过on开启多个callback进行监听,同时关闭所有监听:
  windowClass.off('screenshot');
} catch (exception) {
  console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception));
}

on(‘dialogTargetTouch’)10+

on(type: ‘dialogTargetTouch’, callback: Callback&lt;void&gt;): void

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

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

参数:

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

示例:

let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.on('dialogTargetTouch', () => {
    console.info('touch dialog target');
  });
} catch (exception) {
  console.error('Failed to register callback. Cause: ' + JSON.stringify(exception));
}

off(‘dialogTargetTouch’)10+

off(type: ‘dialogTargetTouch’, callback?: Callback&lt;void&gt;): void

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

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’dialogTargetTouch’,即模态窗口目标窗口的点击事件。
callback Callback&lt;void&gt; 回调函数。当点击事件发生在模态窗口目标窗口的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有模态窗口目标窗口的点击事件的监听。

示例:

let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.off('dialogTargetTouch');
} catch (exception) {
  console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception));
}

on(‘windowEvent’)10+

on(type: ‘windowEvent’, callback: Callback&lt;WindowEventType&gt;): void

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

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’windowEvent’,即窗口生命周期变化事件。
callback Callback&lt;WindowEventType&gt; 回调函数。返回当前的窗口生命周期状态。

示例:

let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.on('windowEvent', (data) => {
    console.info('Window event happened. Event:' + JSON.stringify(data));
  });
} catch (exception) {
  console.error('Failed to register callback. Cause: ' + JSON.stringify(exception));
}

off(‘windowEvent’)10+

off(type: ‘windowEvent’, callback?: Callback&lt;WindowEventType &gt;): void

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

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’windowEvent’,即窗口生命周期变化事件。
callback Callback&lt;WindowEventType&gt; 回调函数。返回当前的窗口生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有窗口生命周期变化的监听。

示例:

let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.off('windowEvent');
} catch (exception) {
  console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception));
}

bindDialogTarget9+

bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback&lt;void&gt;, callback: AsyncCallback&lt;void&gt;): void

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

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

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

参数:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import rpc from '@ohos.rpc';
import { BusinessError } from '@ohos.base';

class MyDeathRecipient {
  onRemoteDied() {
    console.log('server died');
  }
}

class TestRemoteObject extends rpc.RemoteObject {
  constructor(descriptor: string) {
    super(descriptor);
  }

  addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
    return true;
  }

  removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
    return true;
  }

  isObjectDead(): boolean {
    return false;
  }
}

let token: TestRemoteObject = new TestRemoteObject('testObject');
let windowClass: window.Window = window.findWindow("test");
let config: window.Configuration = { name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG };
try {
  window.createWindow(config, (err: BusinessError, data) => {
    let errCode: number = err.code;
    if (errCode) {
      console.error('Failed to create the window. Cause: ' + JSON.stringify(err));
      return;
    }
    windowClass = data;
  });
  windowClass.bindDialogTarget(token, () => {
    console.info('Dialog Window Need Destroy.');
  }, (err: BusinessError) => {
    let errCode: number = err.code;
    if (errCode) {
      console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err));
      return;
    }
    console.info('Succeeded in binding dialog target.');
  });
} catch (exception) {
  console.error('Failed to bind dialog target. Cause:' + JSON.stringify(exception));
}

bindDialogTarget9+

bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback&lt;void&gt;): Promise&lt;void&gt;

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

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

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import rpc from '@ohos.rpc';
import { BusinessError } from '@ohos.base';

class MyDeathRecipient {
  onRemoteDied() {
    console.log('server died');
  }
}

class TestRemoteObject extends rpc.RemoteObject {
  constructor(descriptor: string) {
    super(descriptor);
  }

  addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
    return true;
  }

  removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
    return true;
  }

  isObjectDead(): boolean {
    return false;
  }
}

let token: TestRemoteObject = new TestRemoteObject('testObject');
let windowClass: window.Window = window.findWindow("test");
let config: window.Configuration = {
  name: "dialogWindow",
  windowType: window.WindowType.TYPE_DIALOG
};
try {
  window.createWindow(config, (err: BusinessError, data) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error('Failed to create the window. Cause: ' + JSON.stringify(err));
      return;
    }
    windowClass = data;
  });
  let promise = windowClass.bindDialogTarget(token, () => {
    console.info('Dialog Window Need Destroy.');
  });
  promise.then(() => {
    console.info('Succeeded in binding dialog target.');
  }).catch((err: BusinessError) => {
    console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to bind dialog target. Cause:' + JSON.stringify(exception));
}

bindDialogTarget9+

bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback&lt;void&gt;, callback: AsyncCallback&lt;void&gt;): void

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

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

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

参数:

参数名 类型 必填 说明
requestInfo dialogRequest.RequestInfo 目标窗口RequestInfo值。
deathCallback Callback&lt;void&gt; 模态窗口销毁监听。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import dialogRequest from '@ohos.app.ability.dialogRequest';
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';

export default class ServiceExtAbility extends ServiceExtensionAbility {
  onRequest(want: Want, startId: number) {
    console.info('onRequest');
    let windowClass: window.Window = window.findWindow("test");
    let config: window.Configuration = {
      name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG
    };
    try {
      window.createWindow(config, (err: BusinessError, data) => {
        let errCode: number = err.code;
        if (errCode) {
          console.error('Failed to create the window. Cause: ' + JSON.stringify(err));
          return;
        }
        windowClass = data;
      });
      let requestInfo = dialogRequest.getRequestInfo(want)
      windowClass.bindDialogTarget(requestInfo, () => {
        console.info('Dialog Window Need Destroy.');
      }, (err: BusinessError) => {
        let errCode: number = err.code;
        if (errCode) {
          console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err));
          return;
        }
        console.info('Succeeded in binding dialog target.');
      });
    } catch (err) {
      console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err))
    }
  }
}

bindDialogTarget9+

bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback&lt;void&gt;): Promise&lt;void&gt;

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

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

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

参数:

参数名 类型 必填 说明
requestInfo dialogRequest.RequestInfo 目标窗口RequestInfo值。
deathCallback Callback&lt;void&gt; 模态窗口销毁监听。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import dialogRequest from '@ohos.app.ability.dialogRequest';
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';

export default class ServiceExtAbility extends ServiceExtensionAbility {
  onRequest(want: Want, startId: number) {
    console.info('onRequest');
    let windowClass: window.Window = window.findWindow("test");
    let config: window.Configuration = {
      name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG
    };
    try {
      window.createWindow(config, (err: BusinessError, data) => {
        const errCode: number = err.code;
        if (errCode) {
          console.error('Failed to create the window. Cause: ' + JSON.stringify(err));
          return;
        }
        windowClass = data;
      });
      let requestInfo = dialogRequest.getRequestInfo(want)
      let promise = windowClass.bindDialogTarget(requestInfo, () => {
        console.info('Dialog Window Need Destroy.');
      });
      promise.then(() => {
        console.info('Succeeded in binding dialog target.');
      }).catch((err: BusinessError) => {
        console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err));
      });
    } catch (err) {
      console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err))
    }
  }
}

isWindowSupportWideGamut9+

isWindowSupportWideGamut(callback: AsyncCallback&lt;boolean&gt;): void

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

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

参数:

|参数名|类型|必填|说明| |——–|—————————-|–|——————————————————————————–| |callback|AsyncCallback&lt;boolean&gt;|是|回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。|

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.isWindowSupportWideGamut((err: BusinessError, data) => {
  const errCode: number = err.code;
  if (errCode) {
    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));
});

isWindowSupportWideGamut9+

isWindowSupportWideGamut(): Promise&lt;boolean&gt;

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

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

返回值:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.isWindowSupportWideGamut();
promise.then((data) => {
  console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error('Failed to check whether the window support WideGamut. Cause: ' + JSON.stringify(err));
});

setWindowColorSpace9+

setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback&lt;void&gt;): void

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

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

参数:

|参数名|类型|必填|说明| |———-|————————-|–|———–| |colorSpace|ColorSpace|是|设置色域模式。| |callback |AsyncCallback&lt;void&gt;|是|回调函数。 |

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err));
      return;
    }
    console.info('Succeeded in setting window colorspace.');
  });
} catch (exception) {
  console.error('Failed to set window colorspace. Cause:' + JSON.stringify(exception));
}

setWindowColorSpace9+

setWindowColorSpace(colorSpace:ColorSpace): Promise&lt;void&gt;

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

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
try {
  let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT);
  promise.then(() => {
    console.info('Succeeded in setting window colorspace.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set window colorspace. Cause:' + JSON.stringify(exception));
}

getWindowColorSpace9+

getWindowColorSpace(): ColorSpace

获取当前窗口色域模式。

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

返回值:

类型 说明
ColorSpace 当前色域模式。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

let colorSpace = windowClass.getWindowColorSpace();

setWindowBackgroundColor9+

setWindowBackgroundColor(color: string): void

设置窗口的背景色。Stage模型下,该接口需要在loadContent()setUIContent()调用生效后使用。

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

参数:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

let color: string = '#00ff33';
let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setWindowBackgroundColor(color);
} catch (exception) {
  console.error('Failed to set the background color. Cause: ' + JSON.stringify(exception));
}

setWindowBrightness9+

setWindowBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void

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

当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。

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

参数:

|参数名|类型|必填|说明 | |———-|————————-|–|——————————————-| |brightness|number |是|屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。| |callback |AsyncCallback&lt;void&gt;|是|回调函数。 |

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let brightness: number = 1;
let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setWindowBrightness(brightness, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err));
      return;
    }
    console.info('Succeeded in setting the brightness.');
  });
} catch (exception) {
  console.error('Failed to set the brightness. Cause: ' + JSON.stringify(exception));
}

setWindowBrightness9+

setWindowBrightness(brightness: number): Promise&lt;void&gt;

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

当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。

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

参数:

|参数名|类型|必填|说明 | |———-|——|–|—————————————-| |brightness|number|是|屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。|

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let brightness: number = 1;
try {
  let promise = windowClass.setWindowBrightness(brightness);
  promise.then(() => {
    console.info('Succeeded in setting the brightness.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set the brightness. Cause: ' + JSON.stringify(exception));
}

setWindowFocusable9+

setWindowFocusable(isFocusable: boolean, callback: AsyncCallback&lt;void&gt;): void

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

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

参数:

|参数名|类型|必填|说明| |———–|————————-|–|——————————————————-| |isFocusable|boolean |是|点击时是否支持切换焦点窗口。true表示支持;false表示不支持。| |callback |AsyncCallback&lt;void&gt;|是|回调函数。 |

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let isFocusable: boolean = true;
let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setWindowFocusable(isFocusable, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      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.');
  });
} catch (exception) {
  console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(exception));
}

setWindowFocusable9+

setWindowFocusable(isFocusable: boolean): Promise&lt;void&gt;

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

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

参数:

|参数名|类型|必填|说明| |———–|——-|–|——————————————————–| |isFocusable|boolean|是|点击时是否支持切换焦点窗口。true表示支持;false表示不支持。|

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let isFocusable: boolean = true;
let windowClass: window.Window = window.findWindow("test");
try {
  let promise = windowClass.setWindowFocusable(isFocusable);
  promise.then(() => {
    console.info('Succeeded in setting the window to be focusable.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(exception));
}

setWindowKeepScreenOn9+

setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback&lt;void&gt;): void

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

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

参数:

|参数名|类型|必填|说明| |————–|————————-|–|—————————————————-| |isKeepScreenOn|boolean |是|设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。| |callback |AsyncCallback&lt;void&gt;|是|回调函数。 |

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let isKeepScreenOn: boolean = true;
let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      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.');
  });
} catch (exception) {
  console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(exception));
}

setWindowKeepScreenOn9+

setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise&lt;void&gt;

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

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

参数:

|参数名|类型|必填|说明| |————–|——-|–|—————————————————| |isKeepScreenOn|boolean|是|设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。|

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let isKeepScreenOn: boolean = true;
let windowClass: window.Window = window.findWindow("test");
try {
  let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn);
  promise.then(() => {
    console.info('Succeeded in setting the screen to be always on.');
  }).catch((err: BusinessError) => {
    console.info('Failed to set the screen to be always on. Cause:  ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(exception));
}

setWakeUpScreen()9+

setWakeUpScreen(wakeUp: boolean): void

窗口唤醒屏幕。

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

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

参数:

参数名 类型 必填 说明
wakeUp boolean 是否设置唤醒屏幕。true表示唤醒;false表示不唤醒。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

let wakeUp: boolean = true;
let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setWakeUpScreen(wakeUp);
} catch (exception) {
  console.error('Failed to wake up the screen. Cause: ' + JSON.stringify(exception));
}

setWindowPrivacyMode9+

setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback&lt;void&gt;): void

设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。

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

需要权限: ohos.permission.PRIVACY_WINDOW

参数:

|参数名|类型|必填|说明| |————-|————————-|–|——————————————————| |isPrivacyMode|boolean |是|窗口是否为隐私模式。true表示模式开启;false表示模式关闭。| |callback |AsyncCallback&lt;void&gt;|是|回调函数。 |

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let isPrivacyMode: boolean = true;
let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      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.');
  });
} catch (exception) {
  console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception));
}

setWindowPrivacyMode9+

setWindowPrivacyMode(isPrivacyMode: boolean): Promise&lt;void&gt;

设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。

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

需要权限: ohos.permission.PRIVACY_WINDOW

参数:

|参数名|类型|必填|说明| |————-|——-|–|—————————————————–| |isPrivacyMode|boolean|是|窗口是否为隐私模式。true表示模式开启;false表示模式关闭。|

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';

let isPrivacyMode: boolean = true;
let windowClass: window.Window = window.findWindow("test");
try {
  let promise = windowClass.setWindowPrivacyMode(isPrivacyMode);
  promise.then(() => {
    console.info('Succeeded in setting the window to privacy mode.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception));
}

setSnapshotSkip9+

setSnapshotSkip(isSkip: boolean): void

截屏录屏是否忽略当前窗口。此接口一般用于禁止截屏/录屏的场景。

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

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

参数:

参数名 类型 必填 说明
isSkip boolean 截屏录屏是否忽略当前窗口,默认为false。
true表示忽略当前窗口,false表示不忽略当前窗口。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
let windowClass: window.Window = window.findWindow("test");
let isSkip: boolean = true;
try {
  windowClass.setSnapshotSkip(isSkip);
} catch (exception) {
  console.error('Failed to Skip. Cause: ' + JSON.stringify(exception));
}

setWindowTouchable9+

setWindowTouchable(isTouchable: boolean, callback: AsyncCallback&lt;void&gt;): void

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

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

参数:

|参数名|类型|必填|说明| |———–|————————-|–|———————————————–| |isTouchable|boolean |是|窗口是否为可触状态。true表示可触;false表示不可触。| |callback |AsyncCallback&lt;void&gt;|是|回调函数。 |

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let isTouchable = true;
let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setWindowTouchable(isTouchable, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      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.');
  });
} catch (exception) {
  console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(exception));
}

setWindowTouchable9+

setWindowTouchable(isTouchable: boolean): Promise&lt;void&gt;

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

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

参数:

|参数名|类型|必填|说明| |———–|——-|–|———————————————–| |isTouchable|boolean|是|窗口是否为可触状态。true表示可触;false表示不可触。|

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let isTouchable: boolean = true;
let windowClass: window.Window = window.findWindow("test");
try {
  let promise = windowClass.setWindowTouchable(isTouchable);
  promise.then(() => {
    console.info('Succeeded in setting the window to be touchable.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(exception));
}

setForbidSplitMove9+

setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback&lt;void&gt;): void

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

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

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

参数:

参数名 类型 必填 说明
isForbidSplitMove boolean 窗口在分屏模式下是否被禁止移动。true表示禁止;false表示不禁止。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let isForbidSplitMove: boolean = true;
let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setForbidSplitMove(isForbidSplitMove, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      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.');
  });
} catch (exception) {
  console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(exception));
}

setForbidSplitMove9+

setForbidSplitMove(isForbidSplitMove: boolean): Promise&lt;void&gt;

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

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

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import { BusinessError } from '@ohos.base';

let isForbidSplitMove: boolean = true;
let windowClass: window.Window = window.findWindow("test");
try {
  let promise = windowClass.setForbidSplitMove(isForbidSplitMove);
  promise.then(() => {
    console.info('Succeeded in forbidding window moving in split screen mode.');
  }).catch((err: BusinessError) => {
    console.error('Failed to forbid window moving in split screen mode. Cause: ' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(exception));
}

snapshot9+

snapshot(callback: AsyncCallback&lt;image.PixelMap&gt;): void

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

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

参数:

参数名 类型 必填 说明
callback AsyncCallback&lt;image.PixelMap&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';
import image from '@ohos.multimedia.image';

let windowClass: window.Window = window.findWindow("test");
windowClass.snapshot((err: BusinessError, pixelMap: image.PixelMap) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to snapshot window. Cause:' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
  pixelMap.release(); // PixelMap使用完后及时释放内存
});

snapshot9+

snapshot(): Promise&lt;image.PixelMap&gt;

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

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

返回值:

类型 说明
Promise&lt;image.PixelMap&gt; Promise对象。返回当前窗口截图。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.

示例:

import { BusinessError } from '@ohos.base';
import image from '@ohos.multimedia.image';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.snapshot();
promise.then((pixelMap: image.PixelMap) => {
  console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
  pixelMap.release(); // PixelMap使用完后及时释放内存
}).catch((err: BusinessError) => {
  console.error('Failed to snapshot window. Cause:' + JSON.stringify(err));
});

opacity9+

opacity(opacity: number): void

设置窗口不透明度。仅支持在自定义系统窗口的显示与隐藏动画中使用。

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

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

参数:

参数名 类型 必填 说明
opacity number 不透明度。该参数为浮点数,取值范围为[0.0, 1.0]。0.0表示完全透明,1.0表示完全不透明。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.opacity(0.5);
} catch (exception) {
  console.error('Failed to opacity. Cause: ' + JSON.stringify(exception));
}

scale9+

scale(scaleOptions: ScaleOptions): void

设置窗口缩放参数。仅支持在自定义系统窗口的显示与隐藏动画中使用。

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

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

参数:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

let windowClass: window.Window = window.findWindow("test");
let obj: window.ScaleOptions = {
  x: 2.0,
  y: 1.0,
  pivotX: 0.5,
  pivotY: 0.5
};
try {
  windowClass.scale(obj);
} catch (exception) {
  console.error('Failed to scale. Cause: ' + JSON.stringify(exception));
}

rotate9+

rotate(rotateOptions: RotateOptions): void

设置窗口旋转参数。仅支持在自定义系统窗口的显示与隐藏动画中使用。

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

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

参数:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

let windowClass: window.Window = window.findWindow("test");
let obj: window.RotateOptions = {
  x: 1.0,
  y: 1.0,
  z: 45.0,
  pivotX: 0.5,
  pivotY: 0.5
};
try {
  windowClass.rotate(obj);
} catch (exception) {
  console.error('Failed to rotate. Cause: ' + JSON.stringify(exception));
}

translate9+

translate(translateOptions: TranslateOptions): void

设置窗口平移参数。仅支持在自定义系统窗口的显示与隐藏动画中使用。

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

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

参数:

参数名 类型 必填 说明
translateOptions TranslateOptions 平移参数,单位为px。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

let windowClass: window.Window = window.findWindow("test");
let obj: window.TranslateOptions = {
  x: 100.0,
  y: 0.0,
  z: 0.0
};
try {
  windowClass.translate(obj);
} catch (exception) {
  console.error('Failed to translate. Cause: ' + JSON.stringify(exception));
}

getTransitionController9+

getTransitionController(): TransitionController

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

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

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

返回值:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
(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: BusinessError, data) => {
  const errCode: number = err.code;
  if (errCode) {
    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));
});

setBlur9+

setBlur(radius: number): void

设置窗口模糊。

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

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

参数:

参数名 类型 必填 说明
radius number 表示窗口模糊的半径值。该参数为浮点数,取值范围为[0, +∞),取值为0.0时表示关闭窗口模糊。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setBlur(4.0);
} catch (exception) {
  console.error('Failed to set blur. Cause: ' + JSON.stringify(exception));
}

setBackdropBlur9+

setBackdropBlur(radius: number): void

设置窗口背景模糊。

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

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

参数:

参数名 类型 必填 说明
radius number 表示窗口背景模糊的半径值。该参数为浮点数,取值范围为[0.0, +∞),取值为0.0表示关闭窗口背景模糊。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setBackdropBlur(4.0);
} catch (exception) {
  console.error('Failed to set backdrop blur. Cause: ' + JSON.stringify(exception));
}

setBackdropBlurStyle9+

setBackdropBlurStyle(blurStyle: BlurStyle): void

设置窗口背景模糊类型。

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

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

参数:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setBackdropBlurStyle(window.BlurStyle.THIN);
} catch (exception) {
  console.error('Failed to set backdrop blur style. Cause: ' + JSON.stringify(exception));
}

setShadow9+

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

设置窗口边缘阴影。

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

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

参数:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setShadow(4.0, '#FF00FF00', 2, 3);
} catch (exception) {
  console.error('Failed to set shadow. Cause: ' + JSON.stringify(exception));
}

setCornerRadius9+

setCornerRadius(cornerRadius: number): void

设置窗口圆角半径。

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

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

参数:

参数名 类型 必填 说明
radius number 表示窗口圆角的半径值。该参数为浮点数,取值范围为[0.0, +∞),取值为0.0时表示没有窗口圆角。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

let windowClass: window.Window = window.findWindow("test");
try {
  windowClass.setCornerRadius(4.0);
} catch (exception) {
  console.error('Failed to set corner radius. Cause: ' + JSON.stringify(exception));
}

raiseToAppTop10+

raiseToAppTop(callback: AsyncCallback&lt;void&gt;): void

提升应用子窗口到应用顶层。使用callback异步回调。

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

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

参数:

参数名 类型 必填 说明
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300004 Unauthorized operation.
1300009 The parent window is invalid.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.raiseToAppTop((err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to raise the window to app top. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in raising the window to app top.');
});

raiseToAppTop10+

raiseToAppTop(): Promise&lt;void&gt;

提升应用子窗口到应用顶层。使用Promise异步回调。

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

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300004 Unauthorized operation.
1300009 The parent window is invalid.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.raiseToAppTop();
promise.then(() => {
  console.info('Succeeded in raising the window to app top.');
}).catch((err: BusinessError) => {
  console.error('Failed to raise the window to app top. Cause: ' + JSON.stringify(err));
});

setAspectRatio10+

setAspectRatio(ratio: number): Promise&lt;void&gt;

设置窗口内容布局的比例,使用Promise异步回调。

仅应用主窗口支持此接口功能,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。

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

参数:

参数名 类型 必填 说明
ratio number 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,取值范围为(0.0, +∞)。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
try {
  let ratio = 1.0;
  let promise = windowClass.setAspectRatio(ratio);
  promise.then(() => {
    console.info('Succeeded in setting aspect ratio of window.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set the aspect ratio of window. Cause:' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set the aspect ratio of window. Cause: ' + JSON.stringify(exception));
}

setAspectRatio10+

setAspectRatio(ratio: number, callback: AsyncCallback&lt;void&gt;): void

设置窗口内容布局的比例,使用callback异步回调。

仅应用主窗口支持此接口功能,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。

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

参数:

参数名 类型 必填 说明
ratio number 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,取值范围为(0.0, +∞)。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
try {
  let ratio = 1.0;
  windowClass.setAspectRatio(ratio, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error('Failed to set the aspect ratio of window. Cause:' + JSON.stringify(err));
      return;
    }
    console.info('Succeeded in setting the aspect ratio of window.');
  });
} catch (exception) {
  console.error('Failed to set the aspect ratio of window. Cause: ' + JSON.stringify(exception));
}

resetAspectRatio10+

resetAspectRatio(): Promise&lt;void&gt;

取消设置窗口内容布局的比例,使用Promise异步回调。

仅应用主窗口支持此接口功能,调用后将清除持久化储存的比例信息。

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
try {
  let promise = windowClass.resetAspectRatio();
  promise.then(() => {
    console.info('Succeeded in resetting aspect ratio of window.');
  }).catch((err: BusinessError) => {
    console.error('Failed to reset the aspect ratio of window. Cause:' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to reset the aspect ratio of window. Cause: ' + JSON.stringify(exception));
}

resetAspectRatio10+

resetAspectRatio(callback: AsyncCallback&lt;void&gt;): void

取消设置窗口内容布局的比例,使用callback异步回调。

仅应用主窗口支持此接口功能,调用后将清除持久化储存的比例信息。

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

参数:

参数名 类型 必填 说明
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300004 Unauthorized operation.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
try {
    windowClass.resetAspectRatio((err: BusinessError) => {
        const errCode: number = err.code;
        if (errCode) {
            console.error('Failed to reset the aspect ratio of window. Cause:' + JSON.stringify(err));
            return;
        }
        console.info('Succeeded in resetting aspect ratio of window.');
    });
} catch (exception) {
    console.error('Failed to reset the aspect ratio of window. Cause: ' + JSON.stringify(exception));
}

setWaterMarkFlag10+

setWaterMarkFlag(enable: boolean): Promise&lt;void&gt;

为当前窗口添加或删除安全水印标志,使用Promise异步回调。

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

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

参数:

参数名 类型 必填 说明
enable boolean 是否对窗口添加标志位。true表示添加,false表示删除。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300008 The operation is on invalid display.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
try {
  let enable = true;
  let promise = windowClass.setWaterMarkFlag(enable);
  promise.then(() => {
    console.info('Succeeded in setting water mark flag of window.');
  }).catch((err: BusinessError) => {
    console.error('Failed to set water mark flag of window. Cause:' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set water mark flag of window. Cause: ' + JSON.stringify(exception));
}

setWaterMarkFlag10+

setWaterMarkFlag(enable: boolean, callback: AsyncCallback&lt;void&gt;): void

为当前窗口添加或删除安全水印标志,使用callback异步回调。

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

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

参数:

参数名 类型 必填 说明
enable boolean 是否对窗口添加标志位。true表示添加,false表示删除。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300008 The operation is on invalid display.

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
try {
  let enable: boolean = true;
  windowClass.setWaterMarkFlag(enable, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error('Failed to set water mark flag of window. Cause:' + JSON.stringify(err));
      return;
    }
    console.info('Succeeded in setting water mark flag of window.');
  });
} catch (exception) {
  console.error('Failed to set water mark flag of window. Cause: ' + JSON.stringify(exception));
}

raiseAboveTarget10+

raiseAboveTarget(windowId: number, callback: AsyncCallback&lt;void&gt;): void

将同一个主窗口下的子窗口提升到目标子窗口之上。使用callback异步回调。

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

系统能力: SystemCapability.Window.SessionManager

参数:

参数名 类型 必填 说明
windowId number 目标子窗口的id,通过getWindowProperties接口获取到properties后,再通过properties.id获取
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300004 Unauthorized operation.
1300009 The parent window is invalid.

示例:

// 将windowClass调整到targetWindow之上
let properties = targetWindow.getWindowProperties();
let targetId = properties.id;
let windowClass: window.Window = window.findWindow("test");
windowClass.raiseAboveTarget(targetId, (err) => {
    if (err.code) {
        console.error('Failed to raise the subWindow to target subWindow top. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Succeeded in raising the subWindow to target subWindow top.');
});

raiseAboveTarget10+

raiseAboveTarget(windowId: number): Promise&lt;void&gt;

将同一个主窗下的子窗口提升到目标子窗口之上。使用Promise异步回调。

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

系统能力: SystemCapability.Window.SessionManager

参数:

参数名 类型 必填 说明
windowId number 目标子窗口的id,通过getWindowProperties接口获取到properties后,再通过properties.id获取

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300004 Unauthorized operation.
1300009 The parent window is invalid.

示例:

// 将windowClass调整到targetWindow之上
let properties = targetWindow.getWindowProperties();
let targetId = properties.id;
let promise = windowClass.raiseAboveTarget(targetId);
promise.then(()=> {
    console.info('Succeeded in raising the subWindow to target subWindow top.');
}).catch((err)=>{
    console.error('Failed to raise the subWindow to target subWindow top. Cause: ' + JSON.stringify(err));
});

setRaiseByClickEnabled10+

setRaiseByClickEnabled(enable: boolean, callback: AsyncCallback&lt;void&gt;): void

禁止/使能子窗口点击抬升功能。使用callback异步回调。

通常来说,点击一个子窗口,会将该子窗口显示到最上方,如果设置为false,那么点击子窗口的时候,不会将该子窗口显示到最上方,而是保持不变。

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

系统能力: SystemCapability.Window.SessionManager

参数:

参数名 类型 必填 说明
enable boolean 设置子窗口点击抬升功能是否使能,true表示使能,false表示禁止。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300004 Unauthorized operation.
1300009 The parent window is invalid.

示例:

let enabled = false;
let windowClass: window.Window = window.findWindow("test");
windowClass.setRaiseByClickEnabled(enabled, (err) => {
    if (err.code) {
        console.error('Failed to disable the raise-by-click function. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Succeeded in disabling the raise-by-click function.');
});

setRaiseByClickEnabled10+

setRaiseByClickEnabled(enable: boolean): Promise&lt;void&gt;

禁止/使能子窗点击抬升功能。使用Promise异步回调。

通常来说,点击一个子窗口,会将该子窗口显示到最上方,如果设置为false,那么点击子窗口的时候,不会将该子窗口显示到最上方,而是保持不变。

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

系统能力: SystemCapability.Window.SessionManager

参数:

参数名 类型 必填 说明
enable boolean 设置子窗口点击抬升功能是否使能,true表示使能,false表示禁止。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300004 Unauthorized operation.
1300009 The parent window is invalid.

示例:

let enabled = false;
let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.setRaiseByClickEnabled(enabled);
promise.then(()=> {
    console.info('Succeeded in disabling the raise-by-click function.');
}).catch((err)=>{
    console.error('Failed to disable the raise-by-click function. Cause: ' + JSON.stringify(err));
});

minimize10+

minimize(callback: AsyncCallback&lt;void&gt;): void

最小化主窗口。使用callback异步回调。

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

系统能力: SystemCapability.Window.SessionManager

参数:

参数名 类型 必填 说明
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';

export default class EntryAbility extends UIAbility {
    onWindowStageCreate(windowStage) {
        // 为主窗口加载对应的目标页面。
        windowStage.loadContent("pages/page2", (err) => {
            if (err.code) {
                console.error('Failed to load the content. Cause:' + JSON.stringify(err));
                return;
            }
            console.info('Succeeded in loading the content.');
        });
        // 获取应用主窗口。
        let mainWindow = null;
        
        windowStage.getMainWindow((err, data) => {
            if (err.code) {
                console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
                return;
            }
            mainWindow = data;
            console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
            // 调用minimize接口。
            mainWindow.minimize((err) => {
                if (err.code) {
                    console.error('Failed to minimize the app main window. Cause: ' + JSON.stringify(err));
                    return;
                }
                console.info('Successfully minimized app main window.');
            });
        })
    }
};

minimize10+

minimize(): Promise&lt;void&gt;

最小化主窗口。使用Promise异步回调。

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

系统能力: SystemCapability.Window.SessionManager

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';

export default class EntryAbility extends UIAbility {
    onWindowStageCreate(windowStage) {
        // 为主窗口加载对应的目标页面。
        windowStage.loadContent("pages/page2", (err) => {
            if (err.code) {
                console.error('Failed to load the content. Cause:' + JSON.stringify(err));
                return;
            }
            console.info('Succeeded in loading the content.');
        });
        // 获取应用主窗口。
        let mainWindow = null;
        
        windowStage.getMainWindow((err, data) => {
            if (err.code) {
                console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
                return;
            }
            mainWindow = data;
            console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
            // 获取minimize接口的promise对象。
            let promise = mainWindow.minimize();
            promise.then(()=> {
                console.info('Successfully minimized app main window.');
            }).catch((err)=>{
                console.error('Failed to minimize the app main window. Cause: ' + JSON.stringify(err));
            });
        })
    }
};

setResizeByDragEnabled10+

setResizeByDragEnabled(enable: boolean, callback: AsyncCallback&lt;void&gt;): void

禁止/使能通过拖拽方式缩放主窗口的功能。使用callback异步回调。

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

系统能力: SystemCapability.Window.SessionManager

参数:

参数名 类型 必填 说明
enable boolean 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300004 Unauthorized operation.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';

export default class EntryAbility extends UIAbility {
    onWindowStageCreate(windowStage) {
        // 为主窗口加载对应的目标页面。
        windowStage.loadContent("pages/page2", (err) => {
            if (err.code) {
                console.error('Failed to load the content. Cause:' + JSON.stringify(err));
                return;
            }
            console.info('Succeeded in loading the content.');
        });
        // 获取应用主窗口。
        let mainWindow = null;
        
        windowStage.getMainWindow((err, data) => {
            if (err.code) {
                console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
                return;
            }
            mainWindow = data;
            console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));

            let enabled = false;
            // 调用setResizeByDragEnabled接口。
            mainWindow.setResizeByDragEnabled(enabled, (err) => {
                if (err.code) {
                    console.error('Failed to set the function of disabling the resize by dragg window. Cause: ' + JSON.stringify(err));
                    return;
                }
                console.info('Succeeded in setting the function of disabling the resize by dragg window.');
            });
        })
    }
};

setResizeByDragEnabled10+

setResizeByDragEnabled(enable: boolean): Promise&lt;void&gt;

禁止/使能通过拖拽方式缩放主窗口的功能。使用Promise异步回调。

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

系统能力: SystemCapability.Window.SessionManager

参数:

参数名 类型 必填 说明
enable boolean 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';

export default class EntryAbility extends UIAbility {
    onWindowStageCreate(windowStage) {
        // 为主窗口加载对应的目标页面。
        windowStage.loadContent("pages/page2", (err) => {
            if (err.code) {
                console.error('Failed to load the content. Cause:' + JSON.stringify(err));
                return;
            }
            console.info('Succeeded in loading the content.');
        });
        // 获取应用主窗口。
        let mainWindow = null;
        
        windowStage.getMainWindow((err, data) => {
            if (err.code) {
                console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
                return;
            }
            mainWindow = data;
            console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));

            let enabled = false;
            // 获取setResizeByDragEnabled接口的promise对象
            let promise = mainWindow.setResizeByDragEnabled(enabled);
            promise.then(()=> {
                console.info('Succeeded in setting the function of disabling the resize by dragg window.');
            }).catch((err)=>{
                console.error('Failed to set the function of disabling the resize by dragg window. Cause: ' + JSON.stringify(err));
            });
        })
    }
};

hideNonSystemFloatingWindows11+

hideNonSystemFloatingWindows(shouldHide: boolean, callback: AsyncCallback&lt;void&gt;): void

设置是否隐藏非系统级悬浮窗口。使用callback异步回调。

非系统级悬浮窗口是指非系统应用创建的悬浮窗口。默认情况下,一个系统应用主窗口可以与非系统级悬浮窗口共同显示,即该主窗口可以被上层的非系统级悬浮窗口遮挡,如果设置为true,则所有的非系统级悬浮窗口会被隐藏,此时该主窗口就不会被上层的非系统级悬浮窗口遮挡了。

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

系统能力: SystemCapability.Window.SessionManager

参数:

参数名 类型 必填 说明
shouldHide boolean 指示是否隐藏非系统级的悬浮窗口,true表示隐藏,false表示不隐藏。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300004 Unauthorized operation.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';

export default class EntryAbility extends UIAbility {
  onWindowStageCreate(windowStage: window.WindowStage) {
    // 加载主窗口对应的页面
    windowStage.loadContent('pages/Index', (err) => {
      if (err.code) {
        console.error('Failed to load the content. Cause:' + JSON.stringify(err));
        return;
      }
      console.info('Succeeded in loading the content.');
    });

    // 获取应用主窗口。
    let mainWindow = null;
    windowStage.getMainWindow((err, data) => {
      if (err.code) {
        console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
        return;
      }
      mainWindow = data;
      console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));

      let shouldHide = true;
      // 调用带callback参数的hideNonSystemFloatingWindows接口
      mainWindow.hideNonSystemFloatingWindows(shouldHide, (err) => {
        if (err.code) {
          console.error('Failed to hide the non-system floating windows. Cause: ' + JSON.stringify(err));
          return;
        }
        console.info('Succeeded in hiding the non-system floating windows.');
      });
    })
  }
}

hideNonSystemFloatingWindows11+

hideNonSystemFloatingWindows(shouldHide: boolean): Promise&lt;void&gt;

设置是否隐藏非系统级悬浮窗口。使用callback异步回调。

非系统级悬浮窗口是指非系统应用创建的悬浮窗口。默认情况下,一个系统应用主窗口可以与非系统级悬浮窗口共同显示,即该主窗口可以被上层的非系统级悬浮窗口遮挡,如果设置为true,则所有的非系统级悬浮窗口会被隐藏,此时该主窗口就不会被上层的非系统级悬浮窗口遮挡了。

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

系统能力: SystemCapability.Window.SessionManager

参数:

参数名 类型 必填 说明
shouldHide boolean 指示是否隐藏非系统级的悬浮窗口,true表示隐藏,false表示不隐藏。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.
1300004 Unauthorized operation.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';

export default class EntryAbility extends UIAbility {
  onWindowStageCreate(windowStage: window.WindowStage) {
    // 加载主窗口对应的页面
    windowStage.loadContent('pages/Index', (err) => {
      if (err.code) {
        console.error('Failed to load the content. Cause:' + JSON.stringify(err));
        return;
      }
      console.info('Succeeded in loading the content.');
    });

    // 获取应用主窗口。
    let mainWindow = null;
    windowStage.getMainWindow((err, data) => {
      if (err.code) {
        console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
        return;
      }
      mainWindow = data;
      console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));

      let shouldHide = true;
      // 调用hideNonSystemFloatingWindows接口,获取promise对象
      let promise = mainWindow.hideNonSystemFloatingWindows(shouldHide);
      promise.then(()=> {
        console.info('Succeeded in hiding the non-system floating windows.');
      }).catch((err)=>{
        console.error('Failed to hide the non-system floating windows. Cause: ' + JSON.stringify(err));
      });
    })
  }
}

show(deprecated)

show(callback: AsyncCallback&lt;void&gt;): void

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用showWindow()

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

参数:

参数名 类型 必填 说明
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.show((err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in showing the window.');
});

show(deprecated)

show(): Promise&lt;void&gt;

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用showWindow()

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.show();
promise.then(() => {
  console.info('Succeeded in showing the window.');
}).catch((err: BusinessError) => {
  console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
});

destroy(deprecated)

destroy(callback: AsyncCallback&lt;void&gt;): void

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用destroyWindow()

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

参数:

参数名 类型 必填 说明
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.destroy((err: BusinessError) => {
  const errCode: number = err.code;
  if (err.code) {
    console.error('Failed to destroy the window. Cause:' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in destroying the window.');
});

destroy(deprecated)

destroy(): Promise&lt;void&gt;

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用destroyWindow()

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.destroy();
promise.then(() => {
  console.info('Succeeded in destroying the window.');
}).catch((err: BusinessError) => {
  console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err));
});

moveTo(deprecated)

moveTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void

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

全屏模式窗口不支持该操作。

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用moveWindowTo()

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

参数:

参数名 类型 必填 说明
x number 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入。
y number 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.moveTo(300, 300, (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to move the window. Cause:' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in moving the window.');
});

moveTo(deprecated)

moveTo(x: number, y: number): Promise&lt;void&gt;

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

全屏模式窗口不支持该操作。

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用moveWindowTo()

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.moveTo(300, 300);
promise.then(() => {
  console.info('Succeeded in moving the window.');
}).catch((err: BusinessError) => {
  console.error('Failed to move the window. Cause: ' + JSON.stringify(err));
});

resetSize(deprecated)

resetSize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void

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

应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 2560],默认高度范围:[240, 2560],单位为vp。 应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准。

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

设置的宽度与高度受到此约束限制,规则: 若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。

全屏模式窗口不支持该操作。

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用resize()

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

参数:

参数名 类型 必填 说明
width number 目标窗口的宽度,单位为px,该参数仅支持整数输入。
height number 目标窗口的高度,单位为px,该参数仅支持整数输入。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.resetSize(500, 1000, (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to change the window size. Cause:' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in changing the window size.');
});

resetSize(deprecated)

resetSize(width: number, height: number): Promise&lt;void&gt;

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

应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 2560],默认高度范围:[240, 2560],单位为vp。 应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准。

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

设置的宽度与高度受到此约束限制,规则: 若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。

全屏模式窗口不支持该操作。

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用resize()

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

参数:

参数名 类型 必填 说明
width number 目标窗口的宽度,单位为px,该参数仅支持整数输入。
height number 目标窗口的高度,单位为px,该参数仅支持整数输入。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.resetSize(500, 1000);
promise.then(() => {
  console.info('Succeeded in changing the window size.');
}).catch((err: BusinessError) => {
  console.error('Failed to change the window size. Cause: ' + JSON.stringify(err));
});

setWindowType(deprecated)

setWindowType(type: WindowType, callback: AsyncCallback&lt;void&gt;): void

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

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

说明:

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

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

参数:

参数名 类型 必填 说明
type WindowType 窗口类型。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let type = window.WindowType.TYPE_APP;
windowClass.setWindowType(type, (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to set the window type. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in setting the window type.');
});

setWindowType(deprecated)

setWindowType(type: WindowType): Promise&lt;void&gt;

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

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

说明:

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

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let type = window.WindowType.TYPE_APP;
let promise = windowClass.setWindowType(type);
promise.then(() => {
  console.info('Succeeded in setting the window type.');
}).catch((err: BusinessError) => {
  console.error('Failed to set the window type. Cause: ' + JSON.stringify(err));
});

getProperties(deprecated)

getProperties(callback: AsyncCallback&lt;WindowProperties&gt;): void

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

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐使用getWindowProperties()

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

参数:

参数名 类型 必填 说明
callback AsyncCallback&lt;WindowProperties&gt; 回调函数。返回当前窗口属性。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.getProperties((err: BusinessError, data) => {
  const errCode: number = err.code;
  if (errCode) {
    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));
});

getProperties(deprecated)

getProperties(): Promise&lt;WindowProperties&gt;

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

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐使用getWindowProperties()

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

返回值:

类型 说明
Promise&lt;WindowProperties&gt; Promise对象。返回当前窗口属性。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.getProperties();
promise.then((data) => {
  console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err));
});

getAvoidArea(deprecated)

getAvoidArea(type: AvoidAreaType, callback: AsyncCallback&lt;AvoidArea&gt;): void

获取窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用getWindowAvoidArea()

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

参数:

参数名 类型 必填 说明
type AvoidAreaType 表示规避区类型。
callback AsyncCallback&lt;AvoidArea&gt; 回调函数。返回窗口内容规避区域。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let type = window.AvoidAreaType.TYPE_SYSTEM;
windowClass.getAvoidArea(type, (err: BusinessError, data) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to obtain the area. Cause:' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
});

getAvoidArea(deprecated)

getAvoidArea(type: AvoidAreaType): Promise&lt;AvoidArea&gt;

获取窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用getWindowAvoidArea()

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

参数:

参数名 类型 必填 说明
type AvoidAreaType 表示规避区类型。

返回值:

类型 说明
Promise&lt;AvoidArea&gt; Promise对象。返回窗口内容规避区域。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
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: BusinessError) => {
  console.error('Failed to obtain the area. Cause:' + JSON.stringify(err));
});

setFullScreen(deprecated)

setFullScreen(isFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void

设置窗口的布局是否为全屏布局,使用callback异步回调。 全屏布局是指窗口大小为全屏幕,状态栏与导航栏不显示。 非全屏布局是指状态栏与导航栏显示,窗口大小避让状态栏与导航栏位置。

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐联合使用setWindowSystemBarEnable()setWindowLayoutFullScreen()实现全屏。

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

参数:

参数名 类型 必填 说明
isFullScreen boolean 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let isFullScreen: boolean = true;
windowClass.setFullScreen(isFullScreen, (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in enabling the full-screen mode.');
});

setFullScreen(deprecated)

setFullScreen(isFullScreen: boolean): Promise&lt;void&gt;

设置窗口的布局是否为全屏布局,使用Promise异步回调。 全屏布局是指窗口大小为全屏幕,状态栏与导航栏不显示。 非全屏布局是指状态栏与导航栏显示,窗口大小避让状态栏与导航栏位置。

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐联合使用setWindowSystemBarEnable()setWindowLayoutFullScreen()实现全屏。

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

参数:

参数名 类型 必填 说明
isFullScreen boolean 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let isFullScreen: boolean = true;
let promise = windowClass.setFullScreen(isFullScreen);
promise.then(() => {
  console.info('Succeeded in enabling the full-screen mode.');
}).catch((err: BusinessError) => {
  console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
});

setLayoutFullScreen(deprecated)

setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void

设置窗口的布局是否为沉浸式布局,使用callback异步回调。 沉浸式布局是指布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 非沉浸式布局是指布局避让状态栏与导航栏,组件不会与其重叠。

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用setWindowLayoutFullScreen()

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

参数:

参数名 类型 必填 说明
isLayoutFullScreen boolean 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let isLayoutFullScreen: boolean = true;
windowClass.setLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    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.');
});

setLayoutFullScreen(deprecated)

setLayoutFullScreen(isLayoutFullScreen: boolean): Promise&lt;void&gt;

设置窗口的布局是否为沉浸式布局,使用Promise异步回调。 沉浸式布局是指布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 非沉浸式布局是指布局避让状态栏与导航栏,组件不会与其重叠。

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用setWindowLayoutFullScreen()

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

参数:

参数名 类型 必填 说明
isLayoutFullScreen boolean 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let isLayoutFullScreen: boolean = true;
let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen);
promise.then(() => {
  console.info('Succeeded in setting the window layout to full-screen mode.');
}).catch((err: BusinessError) => {
  console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
});

setSystemBarEnable(deprecated)

setSystemBarEnable(names: Array<‘status’|‘navigation’>, callback: AsyncCallback&lt;void&gt;): void

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用setWindowSystemBarEnable()

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

参数:

参数名 类型 必填 说明
names Array<‘status’|‘navigation’> 设置窗口全屏模式时状态栏和导航栏是否显示。
例如,需全部显示,该参数设置为[‘status’,&nbsp;‘navigation’];不设置,则默认不显示。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

// 此处以不显示导航栏、状态栏为例
import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let names: Array<'status'|'navigation'> = [];
windowClass.setSystemBarEnable(names, (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    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.');
});

setSystemBarEnable(deprecated)

setSystemBarEnable(names: Array<‘status’|‘navigation’>): Promise&lt;void&gt;

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用setWindowSystemBarEnable()

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

参数:

参数名 类型 必填 说明
names Array<‘status’|‘navigation’> 设置窗口全屏模式时状态栏和导航栏是否显示。
例如,需全部显示,该参数设置为[‘status’,&nbsp;‘navigation’];不设置,则默认不显示。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

// 此处以不显示导航栏、状态栏为例
import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let names: Array<'status'|'navigation'> = [];
let promise = windowClass.setSystemBarEnable(names);
promise.then(() => {
  console.info('Succeeded in setting the system bar to be invisible.');
}).catch((err: BusinessError) => {
  console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err));
});

setSystemBarProperties(deprecated)

setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback&lt;void&gt;): void

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

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐使用setWindowSystemBarProperties()

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

参数:

参数名 类型 必填 说明
SystemBarProperties SystemBarProperties 导航栏、状态栏的属性。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let SystemBarProperties: window.SystemBarProperties = {
  statusBarColor: '#ff00ff',
  navigationBarColor: '#00ff00',
  //以下两个属性从API Version8开始支持
  statusBarContentColor: '#ffffff',
  navigationBarContentColor: '#00ffff'
};
let windowClass: window.Window = window.findWindow("test");
windowClass.setSystemBarProperties(SystemBarProperties, (err) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in setting the system bar properties.');
});

setSystemBarProperties(deprecated)

setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise&lt;void&gt;

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

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐使用setWindowSystemBarProperties()

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let SystemBarProperties: window.SystemBarProperties = {
  statusBarColor: '#ff00ff',
  navigationBarColor: '#00ff00',
  //以下两个属性从API Version8开始支持
  statusBarContentColor: '#ffffff',
  navigationBarContentColor: '#00ffff'
};
let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.setSystemBarProperties(SystemBarProperties);
promise.then(() => {
  console.info('Succeeded in setting the system bar properties.');
}).catch((err: BusinessError) => {
  console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
});

loadContent(deprecated)

loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用setUIContent()

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

参数:

参数名 类型 必填 说明
path string 设置加载页面的路径。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.loadContent('pages/page2/page2', (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to load the content. Cause:' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in loading the content.');
});

loadContent(deprecated)

loadContent(path: string): Promise&lt;void&gt;

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用setUIContent()

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.loadContent('pages/page2/page2');
promise.then(() => {
  console.info('Succeeded in loading the content.');
}).catch((err: BusinessError) => {
  console.error('Failed to load the content. Cause: ' + JSON.stringify(err));
});

isShowing(deprecated)

isShowing(callback: AsyncCallback&lt;boolean&gt;): void

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用isWindowShowing()

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

参数:

参数名 类型 必填 说明
callback AsyncCallback&lt;boolean&gt; 回调函数。返回true表示当前窗口已显示,返回false表示当前窗口未显示。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.isShowing((err: BusinessError, data) => {
  const errCode: number = err.code;
  if (errCode) {
    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));
});

isShowing(deprecated)

isShowing(): Promise&lt;boolean&gt;

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用isWindowShowing()

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

返回值:

类型 说明
Promise&lt;boolean&gt; Promise对象。返回true表示当前窗口已显示,返回false表示当前窗口未显示。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.isShowing();
promise.then((data) => {
  console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(err));
});

on(‘systemAvoidAreaChange’)(deprecated)

on(type: ‘systemAvoidAreaChange’, callback: Callback&lt;AvoidArea&gt;): void

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用on(‘avoidAreaChange’)

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

参数:

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

示例:

let windowClass: window.Window = window.findWindow("test");
windowClass.on('systemAvoidAreaChange', (data) => {
  console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data));
});

off(‘systemAvoidAreaChange’)(deprecated)

off(type: ‘systemAvoidAreaChange’, callback?: Callback&lt;AvoidArea&gt;): void

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用off(‘avoidAreaChange’)

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’systemAvoidAreaChange’,即系统规避区变化事件。
callback Callback&lt;AvoidArea&gt; 回调函数。返回当前规避区。若传入参数,则关闭该监听。若未传入参数,则关闭所有系统规避区变化的监听。

示例:

let windowClass: window.Window = window.findWindow("test");
windowClass.off('systemAvoidAreaChange');

isSupportWideGamut(deprecated)

isSupportWideGamut(callback: AsyncCallback&lt;boolean&gt;): void

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

说明:

从 API version 8开始支持,从API version 9开始废弃,推荐使用isWindowSupportWideGamut()

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

参数:

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

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.isSupportWideGamut((err: BusinessError, data) => {
  const errCode: number = err.code;
  if (errCode) {
    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));
});

isSupportWideGamut(deprecated)

isSupportWideGamut(): Promise&lt;boolean&gt;

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

说明:

从 API version 8开始支持,从API version 9开始废弃,推荐使用isWindowSupportWideGamut()

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

返回值:

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

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.isSupportWideGamut();
promise.then((data) => {
  console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error('Failed to check whether the window support WideGamut. Cause: ' + JSON.stringify(err));
});

setColorSpace(deprecated)

setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback&lt;void&gt;): void

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

说明:

从 API version 8开始支持,从API version 9开始废弃,推荐使用setWindowColorSpace()

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

参数:

参数名 类型 必填 说明
colorSpace ColorSpace 设置色域模式。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in setting window colorspace.');
});

setColorSpace(deprecated)

setColorSpace(colorSpace:ColorSpace): Promise&lt;void&gt;

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

说明:

从 API version 8开始支持,从API version 9开始废弃,推荐使用setWindowColorSpace()

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT);
promise.then(() => {
  console.info('Succeeded in setting window colorspace.');
}).catch((err: BusinessError) => {
  console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err));
});

getColorSpace(deprecated)

getColorSpace(callback: AsyncCallback&lt;ColorSpace&gt;): void

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

说明:

从 API version 8开始支持,从API version 9开始废弃,推荐使用getWindowColorSpace()

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

参数:

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

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.getColorSpace((err: BusinessError, data) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to get window colorspace. Cause:' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data));
});

getColorSpace(deprecated)

getColorSpace(): Promise&lt;ColorSpace&gt;

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

说明:

从 API version 8开始支持,从API version 9开始废弃,推荐使用getWindowColorSpace()

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

返回值:

类型 说明
Promise&lt;ColorSpace&gt; Promise对象。返回当前色域模式。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.getColorSpace();
promise.then((data) => {
  console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data));
}).catch((err: BusinessError) => {
  console.error('Failed to get window colorspace. Cause: ' + JSON.stringify(err));
});

setBackgroundColor(deprecated)

setBackgroundColor(color: string, callback: AsyncCallback&lt;void&gt;): void

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

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐使用setWindowBackgroundColor()

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

参数:

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

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let color: string = '#00ff33';
windowClass.setBackgroundColor(color, (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to set the background color. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in setting the background color.');
});

setBackgroundColor(deprecated)

setBackgroundColor(color: string): Promise&lt;void&gt;

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

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐使用setWindowBackgroundColor()

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let color: string = '#00ff33';
let promise = windowClass.setBackgroundColor(color);
promise.then(() => {
  console.info('Succeeded in setting the background color.');
}).catch((err: BusinessError) => {
  console.error('Failed to set the background color. Cause: ' + JSON.stringify(err));
});

setBrightness(deprecated)

setBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void

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

当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐使用setWindowBrightness()

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

参数:

参数名 类型 必填 说明
brightness number 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let brightness: number = 1;
windowClass.setBrightness(brightness, (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in setting the brightness.');
});

setBrightness(deprecated)

setBrightness(brightness: number): Promise&lt;void&gt;

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

当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐使用setWindowBrightness()

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

参数:

参数名 类型 必填 说明
brightness number 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let brightness: number = 1;
let promise = windowClass.setBrightness(brightness);
promise.then(() => {
  console.info('Succeeded in setting the brightness.');
}).catch((err: BusinessError) => {
  console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err));
});

setDimBehind(deprecated)

setDimBehind(dimBehindValue: number, callback: AsyncCallback&lt;void&gt;): void

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

说明:

该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。

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

参数:

参数名 类型 必填 说明
dimBehindValue number 表示靠后的窗口的暗度值,取值范围为[0.0, 1.0],取1.0时表示最暗。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
windowClass.setDimBehind(0.5, (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Succeeded in setting the dimness.');
});

setDimBehind(deprecated)

setDimBehind(dimBehindValue: number): Promise&lt;void&gt;

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

说明:

该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.setDimBehind(0.5);
promise.then(() => {
  console.info('Succeeded in setting the dimness.');
}).catch((err: BusinessError) => {
  console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err));
});

setFocusable(deprecated)

setFocusable(isFocusable: boolean, callback: AsyncCallback&lt;void&gt;): void

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用setWindowFocusable()

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

参数:

参数名 类型 必填 说明
isFocusable boolean 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let isFocusable: boolean = true;
windowClass.setFocusable(isFocusable, (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    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.');
});

setFocusable(deprecated)

setFocusable(isFocusable: boolean): Promise&lt;void&gt;

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用setWindowFocusable()

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let isFocusable: boolean = true;
let promise = windowClass.setFocusable(isFocusable);
promise.then(() => {
  console.info('Succeeded in setting the window to be focusable.');
}).catch((err: BusinessError) => {
  console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err));
});

setKeepScreenOn(deprecated)

setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback&lt;void&gt;): void

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

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐使用setWindowKeepScreenOn()

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

参数:

参数名 类型 必填 说明
isKeepScreenOn boolean 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let isKeepScreenOn: boolean = true;
windowClass.setKeepScreenOn(isKeepScreenOn, (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    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.');
});

setKeepScreenOn(deprecated)

setKeepScreenOn(isKeepScreenOn: boolean): Promise&lt;void&gt;

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

说明:

从 API version 6开始支持,从API version 9开始废弃,推荐使用setWindowKeepScreenOn()

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

参数:

参数名 类型 必填 说明
isKeepScreenOn boolean 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let isKeepScreenOn: boolean = true;
let promise = windowClass.setKeepScreenOn(isKeepScreenOn);
promise.then(() => {
  console.info('Succeeded in setting the screen to be always on.');
}).catch((err: BusinessError) => {
  console.info('Failed to set the screen to be always on. Cause:  ' + JSON.stringify(err));
});

setOutsideTouchable(deprecated)

setOutsideTouchable(touchable: boolean, callback: AsyncCallback&lt;void&gt;): void

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

说明:

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

从 API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。

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

参数:

参数名 类型 必填 说明
touchable boolean 设置是否可点击。true表示可点击;false表示不可点击。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

if (!windowClass) {
  console.info('Failed to load the content. Cause: windowClass is null');
}
else {
  (windowClass as window.Window).setOutsideTouchable(true, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      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.');
  });
}

setOutsideTouchable(deprecated)

setOutsideTouchable(touchable: boolean): Promise&lt;void&gt;

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

说明:

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

从 API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。

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

参数:

参数名 类型 必填 说明
touchable boolean 设置是否可点击。true表示可点击;false表示不可点击。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

if (!windowClass) {
  console.info('Failed to load the content. Cause: windowClass is null');
}
else {
let promise = (windowClass as window.Window).setOutsideTouchable(true);
promise.then(() => {
  console.info('Succeeded in setting the area to be touchable.');
}).catch((err: BusinessError) => {
  console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err));
});
}

setPrivacyMode(deprecated)

setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback&lt;void&gt;): void

设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用setWindowPrivacyMode()

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

参数:

参数名 类型 必填 说明
isPrivacyMode boolean 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let isPrivacyMode: boolean = true;
windowClass.setPrivacyMode(isPrivacyMode, (err: BusinessError) => {
  const errCode: number = err.code;
  if (errCode) {
    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.');
});

setPrivacyMode(deprecated)

setPrivacyMode(isPrivacyMode: boolean): Promise&lt;void&gt;

设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用setWindowPrivacyMode()

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

参数:

参数名 类型 必填 说明
isPrivacyMode boolean 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let windowClass: window.Window = window.findWindow("test");
let isPrivacyMode: boolean = true;
let promise = windowClass.setPrivacyMode(isPrivacyMode);
promise.then(() => {
  console.info('Succeeded in setting the window to privacy mode.');
}).catch((err: BusinessError) => {
  console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err));
});

setTouchable(deprecated)

setTouchable(isTouchable: boolean, callback: AsyncCallback&lt;void&gt;): void

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用setWindowTouchable()

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

参数:

参数名 类型 必填 说明
isTouchable boolean 窗口是否为可触状态。true表示可触;false表示不可触。
callback AsyncCallback&lt;void&gt; 回调函数。

示例:

import { BusinessError } from '@ohos.base';

let isTouchable = true;
if (!windowClass) {
  console.info('Failed to load the content. Cause: windowClass is null');
}
else {
  (windowClass as window.Window).setTouchable(isTouchable, (err: BusinessError) => {
    const errCode: number = err.code;
    if (errCode) {
      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.');
  });
}

setTouchable(deprecated)

setTouchable(isTouchable: boolean): Promise&lt;void&gt;

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

说明:

从 API version 7开始支持,从API version 9开始废弃,推荐使用setWindowTouchable()

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

参数:

参数名 类型 必填 说明
isTouchable boolean 窗口是否为可触状态。true表示可触;false表示不可触。

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

let isTouchable = true;
let windowClass: window.Window = window.findWindow("test");
let promise = windowClass.setTouchable(isTouchable);
promise.then(() => {
  console.info('Succeeded in setting the window to be touchable.');
}).catch((err: BusinessError) => {
  console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err));
});

WindowStageEventType9+

WindowStage生命周期。

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

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

名称 说明
SHOWN 1 切到前台。
ACTIVE 2 获焦状态。
INACTIVE 3 失焦状态。
HIDDEN 4 切到后台。
RESUMED11+ 5 前台可交互状态。前台应用进入多任务为不可交互状态,继续返回前台时恢复可交互状态。
PAUSED11+ 6 前台不可交互状态。前台应用进入多任务为不可交互状态,继续返回前台时恢复可交互状态。

WindowStage9+

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

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

getMainWindow9+

getMainWindow(callback: AsyncCallback&lt;Window&gt;): void

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

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

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

参数:

参数名 类型 必填 说明
callback AsyncCallback&lt;Window&gt; 回调函数。返回当前WindowStage下的主窗口对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    let windowClass: window.Window = window.findWindow("test");
    windowStage.getMainWindow((err: BusinessError, data) => {
      const errCode: number = err.code;
      if (errCode) {
        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));
    });
  }
};

getMainWindow9+

getMainWindow(): Promise&lt;Window&gt;

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

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

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

返回值:

类型 说明
Promise&lt;Window&gt; Promise对象。返回当前WindowStage下的主窗口对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    let windowClass: window.Window = window.findWindow("test");
    let promise = windowStage.getMainWindow();
    promise.then((data) => {
      windowClass = data;
      console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
    }).catch((err: BusinessError) => {
      console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
    });
  }
};

getMainWindowSync9+

getMainWindowSync(): Window

获取该WindowStage实例下的主窗口。

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

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

返回值:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    try {
      let windowClass = windowStage.getMainWindowSync();
    } catch (exception) {
      console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(exception));
    }
  }
};

createSubWindow9+

createSubWindow(name: string, callback: AsyncCallback&lt;Window&gt;): void

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

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

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

参数:

参数名 类型 必填 说明
name string 子窗口的名字。
callback AsyncCallback&lt;Window&gt; 回调函数。返回当前WindowStage下的子窗口对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    let windowClass: window.Window = window.findWindow("test");
    try {
      windowStage.createSubWindow('mySubWindow', (err: BusinessError, data) => {
        const errCode: number = err.code;
        if (errCode) {
          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));
        if (!windowClass) {
          console.info('Failed to load the content. Cause: windowClass is null');
        }
        else {
          (windowClass as window.Window).resetSize(500, 1000);
        }
      });

    } catch (exception) {
      console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception));
    }
  }
};

createSubWindow9+

createSubWindow(name: string): Promise&lt;Window&gt;

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

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

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

参数:

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

返回值:

类型 说明
Promise&lt;Window&gt; Promise对象。返回当前WindowStage下的子窗口对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    let windowClass: window.Window = window.findWindow("test");
    try {
      let promise = windowStage.createSubWindow('mySubWindow');
      promise.then((data) => {
        windowClass = data;
        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
      }).catch((err: BusinessError) => {
        console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
      });
    } catch (exception) {
      console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception));
    }
  }
};

getSubWindow9+

getSubWindow(callback: AsyncCallback&lt;Array&lt;Window&gt;&gt;): void

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

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

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

参数:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    let windowClass: window.Window[] = [];
    windowStage.getSubWindow((err: BusinessError, data) => {
      const errCode: number = err.code;
      if (errCode) {
        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));
    });
  }
};

getSubWindow9+

getSubWindow(): Promise&lt;Array&lt;Window&gt;&gt;

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

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

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

返回值:

类型 说明
Promise&lt;Array&lt;Window&gt;&gt; Promise对象。返回当前WindowStage下的所有子窗口对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    let windowClass: window.Window[] = [];
    let promise = windowStage.getSubWindow();
    promise.then((data) => {
      windowClass = data;
      console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data));
    }).catch((err: BusinessError) => {
      console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err));
    })
  }
};

loadContent9+

loadContent(path: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void

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

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

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

参数:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';

export default class EntryAbility extends UIAbility {
  // ...

  storage: LocalStorage = new LocalStorage();

  onWindowStageCreate(windowStage: window.WindowStage) {
    this.storage.setOrCreate('storageSimpleProp', 121);
    console.log('onWindowStageCreate');
    try {
      windowStage.loadContent('pages/page2', this.storage, (err: BusinessError) => {
        const errCode: number = err.code;
        if (errCode) {
          console.error('Failed to load the content. Cause:' + JSON.stringify(err));
          return;
        }
        console.info('Succeeded in loading the content.');
      });
    } catch (exception) {
      console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
    }
  }
};

loadContent9+

loadContent(path: string, storage?: LocalStorage): Promise&lt;void&gt;

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

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

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

参数:

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

返回值:

类型 说明
Promise&lt;void&gt; 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';

export default class EntryAbility extends UIAbility {
  // ...

  storage: LocalStorage = new LocalStorage();

  onWindowStageCreate(windowStage: window.WindowStage) {
    this.storage.setOrCreate('storageSimpleProp', 121);
    console.log('onWindowStageCreate');
    try {
      let promise = windowStage.loadContent('pages/page2', this.storage);
      promise.then(() => {
        console.info('Succeeded in loading the content.');
      }).catch((err: BusinessError) => {
        console.error('Failed to load the content. Cause:' + JSON.stringify(err));
      });
    } catch (exception) {
      console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
    }
    ;
  }
};

loadContent9+

loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void

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

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

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

参数:

参数名 类型 必填 说明
path string 设置加载页面的路径。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    try {
      windowStage.loadContent('pages/page2', (err: BusinessError) => {
        const errCode: number = err.code;
        if (errCode) {
          console.error('Failed to load the content. Cause:' + JSON.stringify(err));
          return;
        }
        console.info('Succeeded in loading the content.');
      });
    } catch (exception) {
      console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
    }
  }
};

loadContentByName11+

loadContentByName(name: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void

为当前WindowStage加载与LocalStorage相关联的命名路由页面,使用callback异步回调。

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

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

参数:

参数名 类型 必填 说明
name string 命名路由页面的名称。
storage LocalStorage 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

// ets/entryability/EntryAbility.ets
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';
import * as Index from '../pages/Index'; // 导入命名路由页面

export default class EntryAbility extends UIAbility {
  // ...

  storage: LocalStorage = new LocalStorage();

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    this.storage.setOrCreate('storageSimpleProp', 121);
    try {
      windowStage.loadContentByName(Index.entryName, this.storage, (err: BusinessError) => {
        const errCode: number = err.code;
        if (errCode) {
          console.error('Failed to load the content. Cause:' + JSON.stringify(err));
          return;
        }
        console.info('Succeeded in loading the content.');
      });
    } catch (exception) {
      console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
    }
  }
};
// ets/pages/Index.ets
export const entryName : string = 'Index';
@Entry({routeName: entryName, storage : LocalStorage.getShared()})
@Component
export struct Index {
  @State message: string = 'Hello World'
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
    }
    .height('100%')
  }
}

loadContentByName11+

loadContentByName(name: string, callback: AsyncCallback&lt;void&gt;): void

为当前WindowStage加载命名路由页面,使用callback异步回调。

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

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

参数:

参数名 类型 必填 说明
name string 命名路由页面的名称。
callback AsyncCallback&lt;void&gt; 回调函数。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

// ets/entryability/EntryAbility.ets
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';
import * as Index from '../pages/Index'; // 导入命名路由页面

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    try {
      windowStage.loadContentByName(Index.entryName, (err: BusinessError) => {
        const errCode: number = err.code;
        if (errCode) {
          console.error('Failed to load the content. Cause:' + JSON.stringify(err));
          return;
        }
        console.info('Succeeded in loading the content.');
      });
    } catch (exception) {
      console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
    }
  }
};
// ets/pages/Index.ets
export const entryName : string = 'Index';
@Entry({routeName: entryName})
@Component
export struct Index {
  @State message: string = 'Hello World'
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
    }
    .height('100%')
  }
}

loadContentByName11+

loadContentByName(name: string, storage?: LocalStorage): Promise&lt;void&gt;;

为当前WindowStage加载命名路由页面,使用promise异步回调。

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

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

参数:

参数名 类型 必填 说明
name string 命名路由页面的名称。
storage LocalStorage 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300003 This window manager service works abnormally.

示例:

// ets/entryability/EntryAbility.ets
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';
import * as Index from '../pages/Index'; // 导入命名路由页面

export default class EntryAbility extends UIAbility {
  // ...

  storage: LocalStorage = new LocalStorage();

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    this.storage.setOrCreate('storageSimpleProp', 121);
    try {
      let promise = windowStage.loadContentByName(Index.entryName, this.storage);
      promise.then(() => {
        console.info('Succeeded in loading the content.');
      }).catch((err: BusinessError) => {
        console.error('Failed to load the content. Cause:' + JSON.stringify(err));
      });
    } catch (exception) {
      console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
    }
  }
};
// ets/pages/Index.ets
export const entryName : string = 'Index';
@Entry({routeName: entryName, storage : LocalStorage.getShared()})
@Component
export struct Index {
  @State message: string = 'Hello World'
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
    }
    .height('100%')
  }
}

on(‘windowStageEvent’)9+

on(eventType: ‘windowStageEvent’, callback: Callback&lt;WindowStageEventType&gt;): void

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

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

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

参数:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    try {
      windowStage.on('windowStageEvent', (data) => {
        console.info('Succeeded in enabling the listener for window stage event changes. Data: ' +
        JSON.stringify(data));
      });
    } catch (exception) {
      console.error('Failed to enable the listener for window stage event changes. Cause:' +
      JSON.stringify(exception));
    }
  }
};

off(‘windowStageEvent’)9+

off(eventType: ‘windowStageEvent’, callback?: Callback&lt;WindowStageEventType&gt;): void

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

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

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

参数:

参数名 类型 必填 说明
type string 监听事件,固定为’windowStageEvent’,即WindowStage生命周期变化事件。
callback Callback&lt;WindowStageEventType&gt; 回调函数。返回当前的WindowStage生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有WindowStage生命周期变化的监听。

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    try {
      windowStage.off('windowStageEvent');
    } catch (exception) {
      console.error('Failed to disable the listener for window stage event changes. Cause:' +
      JSON.stringify(exception));
    }
  }
};

disableWindowDecor()9+

disableWindowDecor(): void

禁止窗口装饰。

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

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

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('disableWindowDecor');
    windowStage.disableWindowDecor();
  }
};

setShowOnLockScreen()9+

setShowOnLockScreen(showOnLockScreen: boolean): void

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

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

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

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

参数:

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

错误码:

以下错误码的详细介绍请参见窗口错误码

错误码ID 错误信息
1300002 This window state is abnormal.
1300005 This window stage is abnormal.

示例:

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';

export default class EntryAbility extends UIAbility {
  // ...

  onWindowStageCreate(windowStage: window.WindowStage) {
    console.log('onWindowStageCreate');
    try {
      windowStage.setShowOnLockScreen(true);
    } catch (exception) {
      console.error('Failed to show on lockscreen. Cause:' + JSON.stringify(exception));
    }
  }
};

TransitionContext9+

属性转换的上下文信息。

属性

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

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

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

completeTransition9+

completeTransition(isCompleted: boolean): void

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

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

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

参数:

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

示例:

let windowClass: window.Window = window.findWindow("test");
(context: window.TransitionContext) => {
  let toWindow: window.Window = 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');
  }
  );
  try {
    context.completeTransition(true)
  } catch (exception) {
    console.info('toWindow translate fail. Cause: ' + JSON.stringify(exception));
  }
  console.info('complete transition end');
};

TransitionController9+

属性转换控制器。

animationForShown9+

animationForShown(context: TransitionContext): void

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

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

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

参数:

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

示例:

let windowClass: window.Window = window.findWindow("test");
(context : window.TransitionContext) => {
  let toWindow: window.Window = 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');
};

animationForHidden9+

animationForHidden(context: TransitionContext): void

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

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

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

参数:

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

示例:

let windowClass: window.Window = window.findWindow("test");
(context: window.TransitionContext) => {
  let toWindow: window.Window = 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');
};

你可能感兴趣的鸿蒙文章

harmony 鸿蒙接口

harmony 鸿蒙系统公共事件定义(待停用)

harmony 鸿蒙系统公共事件定义

harmony 鸿蒙开发说明

harmony 鸿蒙企业设备管理概述(仅对系统应用开放)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager模块)

harmony 鸿蒙@ohos.distributedBundle (分布式包管理)

harmony 鸿蒙@ohos.bundle (Bundle模块)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (企业设备管理扩展能力)

0  赞