当前位置: 首页 > news >正文

鸿蒙开发接口图形图像:【@ohos.window (窗口)】

窗口

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

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

  • [Window]:当前窗口实例,窗口管理器管理的基本单元。
  • [WindowStage]:窗口管理器。管理各个基本窗口单元。
说明:
开发前请熟悉鸿蒙开发指导文档: gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md点击或者复制转到。
本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import window from '@ohos.window';

WindowType7+

窗口类型枚举。

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

名称说明
TYPE_APP0表示应用子窗口。此接口仅可在FA模型下使用。
TYPE_SYSTEM_ALERT1表示系统告警窗口。此接口仅可在Stage模型下使用。

AvoidAreaType7+

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

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

名称说明
TYPE_SYSTEM0表示系统默认区域。
TYPE_CUTOUT1表示刘海屏区域。

WindowMode7+

窗口模式枚举。

此接口为系统接口,三方应用不支持调用。

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

名称说明
UNDEFINED1表示APP未定义窗口模式。
FULLSCREEN2表示APP全屏模式。
PRIMARY3表示APP分屏多窗口主要模式。
SECONDARY4表示APP分屏多窗口次要模式。
FLOATING5表示APP自由悬浮形式窗口模式。

WindowLayoutMode9+

窗口布局模式枚举。

此接口为系统接口,三方应用不支持调用。

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

名称说明
WINDOW_LAYOUT_MODE_CASCADE0表示使用层叠布局模式。
WINDOW_LAYOUT_MODE_TILE1表示使用平铺布局模式。

SystemBarProperties

状态栏、导航栏的属性。

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

名称参数类型可读可写说明
statusBarColorstring状态栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如#00FF00#FF00FF00
isStatusBarLightIcon7+boolean状态栏图标是否为高亮状态。
statusBarContentColor8+string状态栏文字颜色。
navigationBarColorstring导航栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如#00FF00#FF00FF00
isNavigationBarLightIcon7+boolean导航栏图标是否为高亮状态。
navigationBarContentColor8+string导航栏文字颜色。

SystemBarRegionTint8+

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

此接口为系统接口,三方应用不支持调用。

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

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

SystemBarTintState8+

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

此接口为系统接口,三方应用不支持调用。

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

名称参数类型可读可写说明
displayIdnumber当前物理屏幕id。
regionTintArray<[SystemBarRegionTint]>当前已改变的所有系统栏信息。

Rect7+

窗口矩形区域。

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

名称参数类型可读可写说明
leftnumber矩形区域的左边界。
topnumber矩形区域的上边界。
widthnumber矩形区域的宽度。
heightnumber矩形区域的高度。

AvoidArea7+

窗口内容规避区域。

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

名称参数类型可读可写说明
leftRect[Rect]屏幕左侧的矩形区。
topRect[Rect]屏幕顶部的矩形区。
rightRect[Rect]屏幕右侧的矩形区。
bottomRect[Rect]屏幕底部的矩形区。

Size7+

窗口大小。

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

名称参数类型可读可写说明
widthnumber窗口宽度。
heightnumber窗口高度。

WindowProperties

窗口属性。

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

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

ColorSpace8+

色域模式。

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

名称默认值说明
DEFAULT0默认色域模式。
WIDE_GAMUT1广色域模式。

window.create7+

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

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

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

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

参数:

参数名类型必填说明
idstring窗口id。
type[WindowType]窗口类型。
callbackAsyncCallback<[Window]>回调函数。返回当前创建的子窗口对象。

示例:

var windowClass = null;let promise = window.create("first", window.WindowType.TYPE_APP);promise.then((data)=> {windowClass = data;console.info('SubWindow created. Data: ' + JSON.stringify(data));}).catch((err)=>{console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err));});

window.create7+

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

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

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

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

参数:

参数名类型必填说明
idstring窗口id。
type[WindowType]窗口类型。

返回值:

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

示例:

var windowClass = null;
let promise = window.create("first", window.WindowType.TYPE_APP);
promise.then((data)=> {windowClass = data;console.info('SubWindow created. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err));
});

window.create8+

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

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

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

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

参数:

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

示例:

var windowClass = null;window.create(this.context, "alertWindow", window.WindowType.TYPE_SYSTEM_ALERT, (err, data) => {if (err.code) {console.error('Failed to create the Window. Cause: ' + JSON.stringify(err));return;}windowClass = data;console.info('Window created. Data: ' + JSON.stringify(data));windowClass.resetSize(500, 1000);
});

window.create8+

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

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

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

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

参数:

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

返回值:

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

示例:

var windowClass = null;
let promise = window.create(this.context, "alertWindow", window.WindowType.TYPE_SYSTEM_ALERT);
promise.then((data)=> {windowClass = data;console.info('Window created. Data:' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to create the Window. Cause:' + JSON.stringify(err));
});

window.find7+

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

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

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

参数:

参数名类型必填说明
idstring窗口id。
callbackAsyncCallback<[Window]>回调函数。返回当前查找到的窗口对象。

示例:

var windowClass = null;window.find("alertWindow", (err, data) => {if (err.code) {console.error('Failed to find the Window. Cause: ' + JSON.stringify(err));return;}windowClass = data;console.info('window found. Data: ' + JSON.stringify(data));
});

window.find7+

find(id: string): Promise<Window>

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

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

参数:

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

返回值:

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

示例:

var windowClass = null;
let promise = window.find("alertWindow");
promise.then((data)=> {windowClass = data;console.info('window found. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to find the Window. Cause: ' + JSON.stringify(err));
});

window.getTopWindow

getTopWindow(callback: AsyncCallback<Window>): void

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

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

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

参数:

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

示例:

var windowClass = null;
window.getTopWindow((err, data) => {if (err.code) {console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));return;}windowClass = data;console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
});

window.getTopWindow

getTopWindow(): Promise<Window>

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

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

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

返回值:

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

示例:

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

window.getTopWindow8+

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

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

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

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

参数:

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

示例:

var windowClass = null;
window.getTopWindow(this.context, (err, data) => {if (err.code) {console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));return;}windowClass = data;console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
});

window.getTopWindow8+

getTopWindow(ctx: Context): Promise<Window>

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

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

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

参数:

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

返回值:

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

示例:

var windowClass = null;
let promise = window.getTopWindow(this.context);
promise.then((data)=> {windowClass = data;console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
})

window.minimizeAll9+

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

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

此接口为系统接口,三方应用不支持调用。

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

参数:

参数名类型必填说明
idnumber显示设备[Display]的ID号
callbackAsyncCallback<void>回调信息。

示例:

import display from '@ohos.display'
import window from '@ohos.window'var displayClass = null;
display.getDefaultDisplay((err, data) => {if(err.code) {return;}displayClass = data;window.minimizeAll(displayClass.id, (err, data) => {if(err.code) {console.error('Failed to minimize all window. Cause: ' + JSON.stringify(err));return;}console.info('Succeeded in minimizing all window.');});
});

window.minimizeAll9+

minimizeAll(id: number): Promise<void>

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

此接口为系统接口,三方应用不支持调用。

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

参数:

参数名类型必填说明
idnumber显示设备[Display]的ID号

返回值:

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

示例:

import display from '@ohos.display'
import window from '@ohos.window'var displayClass = null;
display.getDefaultDisplay((err, data) => {if(err.code) {return;}displayClass = data;let promise = window.minimizeAll(displayClass.id);promise.then((data)=> {console.info('Succeeded in minimizing all window.');}).catch((err)=>{console.error('Failed to minimize all window. Cause: ' + JSON.stringify(err));})
});

window.toggleShownStateForAllAppWindows9+

toggleShownStateForAllAppWindows(callback: AsyncCallback<void>): void

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

此接口为系统接口,三方应用不支持调用。

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

参数:

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

示例:

window.toggleShownStateForAllAppWindows((err, data) => {if (err.code) {console.error('Failed to toggle shown state for all app windows. Cause: ' + JSON.stringify(err));return;}console.info('Succeeded in toggling shown state for all app windows.');
})

window.toggleShownStateForAllAppWindows9+

toggleShownStateForAllAppWindows(): Promise<void>

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

此接口为系统接口,三方应用不支持调用。

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

返回值:

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

示例:

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

window.setWindowLayoutMode9+

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

设置窗口布局模式。

此接口为系统接口,三方应用不支持调用。

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

参数:

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

示例:

window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE, (data) => {console.info('Succeeded in setting window layout mode. Data: ' + JSON.stringify(data));
});

window.setWindowLayoutMode9+

setWindowLayoutMode(mode: WindowLayoutMode): Promise<void>

设置窗口布局模式。

此接口为系统接口,三方应用不支持调用。

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

参数:

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

返回值:

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

示例:

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

on('systemBarTintChange')8+

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

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

此接口为系统接口,三方应用不支持调用。

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

参数:

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

示例:

window.on('systemBarTintChange', (data) => {console.info('Succeeded in enabling the listener for systemBarTint changes. Data: ' + JSON.stringify(data));
});

off('systemBarTintChange')8+

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

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

此接口为系统接口,三方应用不支持调用。

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

参数:

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

示例:

window.off('systemBarTintChange');

Window

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

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

hide7+

hide (callback: AsyncCallback<void>): void

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

此接口为系统接口,三方应用不支持调用。

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

参数:

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

示例:

windowClass.hide((err, data) => {if (err.code) {console.error('Failed to hide the window. Cause: ' + JSON.stringify(err));return;}console.info('window hidden. data: ' + JSON.stringify(data));
})

hide7+

hide(): Promise<void>

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

此接口为系统接口,三方应用不支持调用。

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

返回值:

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

示例:

let promise = windowClass.hide();
promise.then((data)=> {console.info('window hidden. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to hide the window. Cause: ' + JSON.stringify(err));
})

show7+

show(callback: AsyncCallback<void>): void

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

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

参数:

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

示例:

windowClass.show((err, data) => {if (err.code) {console.error('Failed to show the window. Cause: ' + JSON.stringify(err));return;}console.info('Succeeded in showing the window. Data: ' + JSON.stringify(data));
})

show7+

show(): Promise<void>

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

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

返回值:

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

示例:

let promise = windowClass.show();
promise.then((data)=> {console.info('Succeeded in showing the window. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
})

destroy7+

destroy(callback: AsyncCallback<void>): void

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

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

参数:

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

示例:

windowClass.destroy((err, data) => {if (err.code) {console.error('Failed to destroy the window. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in destroying the window. Data: ' + JSON.stringify(data));
})

destroy7+

destroy(): Promise<void>

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

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

返回值:

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

示例:

let promise = windowClass.destroy();
promise.then((data)=> {console.info('Succeeded in destroying the window. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err));
})

moveTo7+

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

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

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

参数:

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

示例:

windowClass.moveTo(300, 300, (err, data)=>{if (err.code) {console.error('Failed to move the window. Cause:' + JSON.stringify(err));return;}console.info('Window moved. Data: ' + JSON.stringify(data));});

moveTo7+

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

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

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

参数:

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

返回值:

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

示例:

let promise = windowClass.moveTo(300, 300);
promise.then((data)=> {console.info('Window moved. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to move the window. Cause: ' + JSON.stringify(err));
})

resetSize7+

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

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

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

参数:

参数名类型必填说明
widthnumber目标窗口的宽度,单位为px。
heightnumber目标窗口的高度,单位为px。
callbackAsyncCallback<void>回调函数。

示例:

windowClass.resetSize(500, 1000, (err, data) => {if (err.code) {console.error('Failed to change the window size. Cause:' + JSON.stringify(err));return;}console.info('Window size changed. Data: ' + JSON.stringify(data));
});

resetSize7+

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

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

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

参数:

参数名类型必填说明
widthnumber目标窗口的宽度,单位为px。
heightnumber目标窗口的高度,单位为px。

返回值:

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

示例:

let promise = windowClass.resetSize(500, 1000);
promise.then((data)=> {console.info('Window size changed. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to change the window size. Cause: ' + JSON.stringify(err));
});

setWindowType7+

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

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

此接口为系统接口,三方应用不支持调用。

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

参数:

参数名类型必填说明
type[WindowType]窗口类型。
callbackAsyncCallback<void>回调函数。

示例:

var type = window.WindowType.TYPE_APP;
windowClass.setWindowType(type, (err, data) => {if (err.code) {console.error('Failed to set the window type. Cause: ' + JSON.stringify(err));return;}console.info('Succeeded in setting the window type. Data: ' + JSON.stringify(data));
});

setWindowType7+

setWindowType(type: WindowType): Promise<void>

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

此接口为系统接口,三方应用不支持调用。

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

参数:

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

返回值:

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

示例:

var type = window.WindowType.TYPE_APP;
let promise = windowClass.setWindowType(type);
promise.then((data)=> {console.info('Succeeded in setting the window type. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to set the window type. Cause: ' + JSON.stringify(err));
});

getProperties

getProperties(callback: AsyncCallback<WindowProperties>): void

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

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

参数:

参数名类型必填说明
callbackAsyncCallback<[WindowProperties]>回调函数。返回当前窗口属性。

示例:

windowClass.getProperties((err, data) => {if (err.code) {console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err));return;}console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data));
});

getProperties

getProperties(): Promise<WindowProperties>

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

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

返回值:

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

示例:

let promise = windowClass.getProperties();
promise.then((data)=> {console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err));
});

getAvoidArea7+

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

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

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

参数:

参数名类型必填说明
type[AvoidAreaType]表示规避区类型。type为TYPE_SYSTEM,表示系统默认区域。type为TYPE_CUTOUT,表示刘海屏区域。
callbackAsyncCallback<[AvoidArea]>回调函数。返回窗口内容规避区域。

示例:

var type = window.AvoidAreaType.TYPE_SYSTEM;
windowClass.getAvoidArea(type, (err, data) => {if (err.code) {console.error('Failed to obtain the area. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
});

getAvoidArea7+

getAvoidArea(type: AvoidAreaType): Promise<AvoidArea>

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

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

参数:

参数名类型必填说明
type[AvoidAreaType]表示规避区类型。type为TYPE_SYSTEM,表示系统默认区域。type为TYPE_CUTOUT,表示刘海屏区域。

返回值:

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

示例:

let promise = windowClass.getAvoidArea();
promise.then((data)=> {console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to obtain the area. Cause:' + JSON.stringify(err));
});

setFullScreen

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

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

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

参数:

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

示例:

var isFullScreen = true;
windowClass.setFullScreen(isFullScreen, (err, data) => {if (err.code) {console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));return;}console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data));
});

setFullScreen

setFullScreen(isFullScreen: boolean): Promise<void>

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

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

参数:

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

返回值:

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

示例:

var isFullScreen = true;
let promise = windowClass.setFullScreen(isFullScreen);
promise.then((data)=> {console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
});

setLayoutFullScreen7+

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

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

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

参数:

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

示例:

var isLayoutFullScreen= true;
windowClass.setLayoutFullScreen(isLayoutFullScreen, (err, data) => {if (err.code) {console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in setting the window layout to full-screen mode. Data: ' + JSON.stringify(data));
});

setLayoutFullScreen7+

setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void>

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

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

参数:

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

返回值:

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

示例:

var isLayoutFullScreen = true;
let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen);
promise.then((data)=> {console.info('Succeeded in setting the window layout to full-screen mode. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
});

setSystemBarEnable7+

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

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

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

参数:

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

示例:

var names = ["status", "navigation"];
windowClass.setSystemBarEnable(names, (err, data) => {if (err.code) {console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in setting the system bar to be visible. Data: ' + JSON.stringify(data));
});

setSystemBarEnable7+

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

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

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

参数:

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

返回值:

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

示例:

var names = ["status", "navigation"];
let promise = windowClass.setSystemBarEnable(names);
promise.then((data)=> {console.info('Succeeded in setting the system bar to be visible. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err));
});

setSystemBarProperties

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

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

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

参数:

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

示例:

var SystemBarProperties={statusBarColor: '#ff00ff',navigationBarColor: '#00ff00',//以下两个属性从API Version7开始支持isStatusBarLightIcon: true,isNavigationBarLightIcon:false,//以下两个属性从API Version8开始支持statusBarContentColor:'#ffffff',navigationBarContentColor:'#00ffff'
};
windowClass.setSystemBarProperties(SystemBarProperties, (err, data) => {if (err.code) {console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));return;}console.info('Succeeded in setting the system bar properties. Data: ' + JSON.stringify(data));
});

setSystemBarProperties

setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void>

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

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

参数:

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

返回值:

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

示例:

var SystemBarProperties={statusBarColor: '#ff00ff',navigationBarColor: '#00ff00',//以下两个属性从API Version7开始支持isStatusBarLightIcon: true,isNavigationBarLightIcon:false,//以下两个属性从API Version8开始支持statusBarContentColor:'#ffffff',navigationBarContentColor:'#00ffff'
};
let promise = windowClass.setSystemBarProperties(SystemBarProperties);
promise.then((data)=> {console.info('Succeeded in setting the system bar properties. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
});

loadContent7+

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

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

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

参数:

参数名类型必填说明
pathstring设置加载页面的路径。
callbackAsyncCallback<void>回调函数。

示例:

windowClass.loadContent("pages/page2/page2", (err, data) => {if (err.code) {console.error('Failed to load the content. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
});

loadContent7+

loadContent(path: string): Promise<void>

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

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

参数:

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

返回值:

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

示例:

let promise = windowClass.loadContent("pages/page2/page2");
promise.then((data)=> {console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to load the content. Cause: ' + JSON.stringify(err));
});

loadContent9+

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

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

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

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

参数:

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

示例:

class myAbility extends Ability {storage : LocalStorage  onWindowStageCreate(windowStage) {this.storage = new LocalStorage();this.storage.setOrCreate("storageSimpleProp",121);console.log('onWindowStageCreate');windowStage.loadContent("pages/page2",this.storage,(err, data) => {if (err.code) {console.error('Failed to load the content. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));});}
}

loadContent9+

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

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

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

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

参数:

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

返回值:

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

示例:

class myAbility extends Ability {storage : LocalStorage onWindowStageCreate(windowStage) {this.storage = new LocalStorage();this.storage.setOrCreate("storageSimpleProp",121);console.log('onWindowStageCreate');var windowClass = null;let promise = windowStage.loadContent("pages/page2",this.storage);promise.then((data)=> {windowClass = data;console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));}).catch((err)=>{console.error('Failed to load the content. Cause:' + JSON.stringify(err));})}
}

isShowing7+

isShowing(callback: AsyncCallback<boolean>): void

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

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

参数:

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

示例:

windowClass.isShowing((err, data) => {if (err.code) {console.error('Failed to check whether the window is showing. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
});

isShowing7+

isShowing(): Promise<boolean>

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

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

返回值:

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

示例:

let promise = windowClass.isShowing();
promise.then((data)=> {console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(err));
});

on('windowSizeChange')7+

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

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

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

参数:

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

示例:

windowClass.on('windowSizeChange', (data) => {console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data));
});

off('windowSizeChange')7+

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

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

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

参数:

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

示例:

windowClass.off('windowSizeChange');

on('systemAvoidAreaChange')7+

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

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

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

参数:

参数名类型必填说明
typestring监听事件,固定为'systemAvoidAreaChange',即系统窗口规避区变化事件。
callbackCallback<[AvoidArea]>回调函数。返回当前的窗口规避区。

示例:

windowClass.on('systemAvoidAreaChange', (data) => {console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data));
});

off('systemAvoidAreaChange')7+

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

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

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

参数:

参数名类型必填说明
typestring监听事件,固定为'systemAvoidAreaChange',即系统窗口规避区变化事件。
callbackCallback<[AvoidArea]>回调函数。返回当前的窗口规避区。

示例:

windowClass.off('systemAvoidAreaChange');

on('keyboardHeightChange')7+

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

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

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

参数:

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

示例:

windowClass.on('keyboardHeightChange', (data) => {console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data));
});

off('keyboardHeightChange')7+

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

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

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

参数:

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

示例:

windowClass.off('keyboardHeightChange');

isSupportWideGamut8+

isSupportWideGamut(callback: AsyncCallback<boolean>): void

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

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

参数:

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

示例:

windowClass.isSupportWideGamut((err, data) => {if (err.code) {console.error('Failed to check whether the window support WideGamut. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data));
})

isSupportWideGamut8+

isSupportWideGamut(): Promise<boolean>

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

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

返回值:

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

示例:

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

setColorSpace8+

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

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

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

参数:

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

示例:

windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err, data) => {if (err.code) {console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in setting window colorspace. Data: ' + JSON.stringify(data));
})

setColorSpace8+

setColorSpace(colorSpace:ColorSpace): Promise<void>

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

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

参数:

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

返回值:

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

示例:

let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT);
promise.then((data)=> {console.info('Succeeded in setting window colorspace. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err));
});

getColorSpace8+

getColorSpace(callback: AsyncCallback<ColorSpace>): void

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

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

参数:

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

示例:

windowClass.getColorSpace((err, data) => {if (err.code) {console.error('Failed to get window colorspace. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data));
})

getColorSpace8+

getColorSpace(): Promise<ColorSpace>

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

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

返回值:

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

示例:

let promise = windowClass.getColorSpace();
promise.then((data)=> {console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to get window colorspace. Cause: ' + JSON.stringify(err));
});

setBackgroundColor

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

设置窗口的背景色,使用callback异步回调。

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

参数:

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

示例:

var color = '#00ff33';
windowClass.setBackgroundColor(color, (err, data) => {if (err.code) {console.error('Failed to set the background color. Cause: ' + JSON.stringify(err));return;}console.info('Succeeded in setting the background color. Data: ' + JSON.stringify(data));
});

setBackgroundColor

setBackgroundColor(color: string): Promise<void>

设置窗口的背景色,使用Promise异步回调。

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

参数:

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

返回值:

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

示例:

var color = '#00ff33';
let promise = windowClass.setBackgroundColor(color);
promise.then((data)=> {console.info('Succeeded in setting the background color. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to set the background color. Cause: ' + JSON.stringify(err));
});

setBrightness

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

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

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

参数:

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

示例:

var brightness = 1;
windowClass.setBrightness(brightness, (err, data) => {if (err.code) {console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err));return;}console.info('Succeeded in setting the brightness. Data: ' + JSON.stringify(data));
});

setBrightness

setBrightness(brightness: number): Promise<void>

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

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

参数:

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

返回值:

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

示例:

var brightness = 1;
let promise = windowClass.setBrightness(brightness);
promise.then((data)=> {console.info('Succeeded in setting the brightness. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err));
});

setDimBehind(deprecated)

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

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

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

从 API version 7开始支持。

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

参数:

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

示例:

windowClass.setDimBehind(0.5, (err, data) => {if (err.code) {console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err));return;}console.info('Succeeded in setting the dimness. Data:' + JSON.stringify(data));
});

setDimBehind(deprecated)

setDimBehind(dimBehindValue: number): Promise<void>

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

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

从 API version 7开始支持。

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

参数:

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

返回值:

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

示例:

let promise = windowClass.setDimBehind(0.5);
promise.then((data)=> {console.info('Succeeded in setting the dimness. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err));
});

setFocusable7+

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

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

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

参数:

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

示例:

var isFocusable= true;
windowClass.setFocusable(isFocusable, (err, data) => {if (err.code) {console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in setting the window to be focusable. Data: ' + JSON.stringify(data));
});

setFocusable7+

setFocusable(isFocusable: boolean): Promise<void>

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

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

参数:

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

返回值:

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

示例:

var isFocusable= true;
let promise = windowClass.setFocusable(isFocusable);
promise.then((data)=> {console.info('Succeeded in setting the window to be focusable. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err));
});

setKeepScreenOn

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

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

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

参数:

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

示例:

var isKeepScreenOn = true;
windowClass.setKeepScreenOn(isKeepScreenOn, (err, data) => {if (err.code) {console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err));return;}console.info('Succeeded in setting the screen to be always on. Data: ' + JSON.stringify(data));
});

setKeepScreenOn

setKeepScreenOn(isKeepScreenOn: boolean): Promise<void>

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

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

参数:

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

返回值:

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

示例:

var isKeepScreenOn = true;
let promise = windowClass.setKeepScreenOn(isKeepScreenOn);
promise.then((data) => {console.info('Succeeded in setting the screen to be always on. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.info('Failed to set the screen to be always on. Cause:  ' + JSON.stringify(err)); 
});

setOutsideTouchable(deprecated)

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

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

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

从 API version 7开始支持。

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

参数:

参数名类型必填说明
touchableboolean设置是否可点击。
callbackAsyncCallback<void>回调函数。

示例:

windowClass.setOutsideTouchable(true, (err, data) => {if (err.code) {console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err));return;}console.info('Succeeded in setting the area to be touchable. Data: ' + JSON.stringify(data));
})

setOutsideTouchable(deprecated)

setOutsideTouchable(touchable: boolean): Promise<void>

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

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

从 API version 7开始支持。

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

参数:

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

返回值:

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

示例:

let promise = windowClass.setOutsideTouchable(true);
promise.then((data)=> {console.info('Succeeded in setting the area to be touchable. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err));
});

setPrivacyMode7+

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

设置窗口是否为隐私模式,使用callback异步回调。

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

参数:

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

示例:

var isPrivacyMode = true;
windowClass.setPrivacyMode(isPrivacyMode, (err, data) => {if (err.code) {console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in setting the window to privacy mode. Data:' + JSON.stringify(data));});

setPrivacyMode7+

setPrivacyMode(isPrivacyMode: boolean): Promise<void>

设置窗口是否为隐私模式,使用Promise异步回调。

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

参数:

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

返回值:

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

示例:

var isPrivacyMode = true;
let promise = windowClass.setPrivacyMode(isPrivacyMode);
promise.then((data)=> {console.info('Succeeded in setting the window to privacy mode. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err));
});

setTouchable7+

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

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

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

参数:

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

示例:

var isTouchable = true;
windowClass.setTouchable(isTouchable, (err, data) => {if (err.code) {console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in setting the window to be touchable. Data:' + JSON.stringify(data));});

setTouchable7+

setTouchable(isTouchable: boolean): Promise<void>

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

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

参数:

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

返回值:

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

示例:

var isTouchable = true;
let promise = windowClass.setTouchable(isTouchable);
promise.then((data)=> {console.info('Succeeded in setting the window to be touchable. Data: ' + JSON.stringify(data));
}).catch((err)=>{console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err));
});

WindowStageEventType9+

WindowStage生命周期。

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

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

名称默认值说明
FOREGROUND1切到前台。
ACTIVE2获焦状态。
INACTIVE3失焦状态。
BACKGROUND4切到后台。

WindowStage9+

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

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

getMainWindow9+

getMainWindow(callback: AsyncCallback<Window>): void

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

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

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

参数:

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

示例:

import Ability from '@ohos.application.Ability';
class myAbility extends Ability {onWindowStageCreate(windowStage) {console.log('onWindowStageCreate');var windowClass = null;windowStage.getMainWindow((err, data) => {if (err.code) {console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));return;}windowClass = data;console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));});}
}

getMainWindow9+

getMainWindow(): Promise<Window>

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

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

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

返回值:

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

示例:

import Ability from '@ohos.application.Ability';
class myAbility extends Ability {onWindowStageCreate(windowStage) {console.log('onWindowStageCreate');var windowClass = null;let promise = windowStage.getMainWindow();promise.then((data)=> {windowClass = data;console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));}).catch((err)=>{console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));});}
}

createSubWindow9+

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

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

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

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

参数:

参数名类型必填说明
nameString子窗口的名字。
callbackAsyncCallback<[Window]>回调函数。返回当前WindowStage下的子窗口对象。

示例:

import Ability from '@ohos.application.Ability';
class myAbility extends Ability {onWindowStageCreate(windowStage) {console.log('onWindowStageCreate');var windowClass = null;windowStage.createSubWindow("mySubWindow", (err, data) => {if (err.code) {console.error('Failed to create sub window. Cause: ' + JSON.stringify(err));return;}windowClass = data;console.info('Succeeded in create sub window. Data: ' + JSON.stringify(data));windowClass.resetSize(500, 1000);});}
}

createSubWindow9+

createSubWindow(name: string): Promise<Window>

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

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

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

参数:

参数名类型必填说明
nameString子窗口的名字。

返回值:

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

示例:

import Ability from '@ohos.application.Ability';
class myAbility extends Ability {onWindowStageCreate(windowStage) {console.log('onWindowStageCreate');var windowClass = null;let promise = windowStage.createSubWindow("mySubWindow");promise.then((data)=> {windowClass = data;console.info('Succeeded in create sub window. Data: ' + JSON.stringify(data));}).catch((err)=>{console.error('Failed to create sub window. Cause: ' + JSON.stringify(err));})}
}

getSubWindow9+

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

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

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

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

参数:

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

示例:

import Ability from '@ohos.application.Ability';
class myAbility extends Ability {onWindowStageCreate(windowStage) {console.log('onWindowStageCreate');var windowClass = null;windowStage.getSubWindow((err, data) => {if (err.code) {console.error('Failed to obtain the sub window. Cause: ' + JSON.stringify(err));return;}windowClass = data;console.info('Succeeded in obtaining the sub window. Data: ' + JSON.stringify(data));});}
}

getSubWindow9+

getSubWindow(): Promise<Array<Window>>

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

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

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

返回值:

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

示例:

import Ability from '@ohos.application.Ability';
class myAbility extends Ability {onWindowStageCreate(windowStage) {console.log('onWindowStageCreate');var windowClass = null;let promise = windowStage.getSubWindow();promise.then((data)=> {windowClass = data;console.info('Succeeded in obtaining the sub window. Data: ' + JSON.stringify(data));}).catch((err)=>{console.error('Failed to obtain the sub window. Cause: ' + JSON.stringify(err));})}
}

loadContent9+

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

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

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

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

参数:

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

示例:

import Ability from '@ohos.application.Ability';
class myAbility extends Ability {storage : LocalStorage  onWindowStageCreate(windowStage) {this.storage = new LocalStorage();this.storage.setOrCreate("storageSimpleProp",121);console.log('onWindowStageCreate');windowStage.loadContent("pages/page2",this.storage,(err, data) => {if (err.code) {console.error('Failed to load the content. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));});}
}

loadContent9+

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

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

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

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

参数:

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

返回值:

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

示例:

import Ability from '@ohos.application.Ability';
class myAbility extends Ability {storage : LocalStorage onWindowStageCreate(windowStage) {this.storage = new LocalStorage();this.storage.setOrCreate("storageSimpleProp",121);console.log('onWindowStageCreate');var windowClass = null;let promise = windowStage.loadContent("pages/page2",this.storage);promise.then((data)=> {windowClass = data;console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));}).catch((err)=>{console.error('Failed to load the content. Cause:' + JSON.stringify(err));})}
}

loadContent9+

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

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

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

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

参数:

参数名类型必填说明
pathstring设置加载页面的路径。
callbackAsyncCallback<void>回调函数。

示例:

import Ability from '@ohos.application.Ability';
class myAbility extends Ability {onWindowStageCreate(windowStage) {console.log('onWindowStageCreate');windowStage.loadContent("pages/page2", (err, data) => {if (err.code) {console.error('Failed to load the content. Cause:' + JSON.stringify(err));return;}console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));});}
}

on('windowStageEvent')9+

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

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

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

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

参数:

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

示例:

import Ability from '@ohos.application.Ability';
class myAbility extends Ability {onWindowStageCreate(windowStage) {console.log('onWindowStageCreate');windowStage.on('windowStageEvent', (data) => {console.info('Succeeded in enabling the listener for window stage event changes. Data: ' + JSON.stringify(data));});}
}

off('windowStageEvent')9+

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

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

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

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

参数:

参数名类型必填说明 HarmonyOS与OpenHarmony鸿蒙文档籽料:mau123789是v直接拿
typestring监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。
callbackCallback<[WindowStageEventType]>回调函数。返回当前的WindowStage生命周期状态。

鸿蒙文档.png


示例:

import Ability from '@ohos.application.Ability';
class myAbility extends Ability {onWindowStageCreate(windowStage) {console.log('onWindowStageCreate');windowStage.off('windowStageEvent');}
}

到这里我们就基本上学完了这个知识点,当然如果说要真正参与到鸿蒙的开发当中,要学的还有很多。大家可以看看下面这个鸿蒙入门到实战的学习技术路线图:

 而随着鸿蒙的火热,现阶段已有许多Android、前端等开发者看中其未来趋势;想从网上查阅学习,但搜索到的鸿蒙资料都是七零八碎的,对此为了避免大家在学习过程中浪费过多时间,特地根据鸿蒙官方发布文档结合华为内部人员的分享,经过反复修改整理得出:

整套鸿蒙(HarmonyOS NEXT)学习手册(共计1236页)与鸿蒙(HarmonyOS NEXT开发入门&实战教学视频(200集+)发放给大家。

内容包含了:(ArkTS、ArkUI、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、鸿蒙南向开发、鸿蒙项目实战)等技术知识点。帮助大家在学习鸿蒙路上少走弯路!下面点击↓↓↓拿

废话不多说,接下来好好看下这份资料。

《鸿蒙 (HarmonyOS NEXT)开发基础到实战手册》

OpenHarmony北向、南向开发环境搭建

鸿蒙开发基础》

  1. ArkTS语言

  2. 安装DevEco Studio

  3. 运用你的第一个ArkTS应用

  4. ArkUI声明式UI开发

  5. .……

《鸿蒙开发进阶》

  1. Stage模型入门

  2. 网络管理

  3. 数据管理

  4. 电话服务

  5. 分布式应用开发

  6. 通知与窗口管理

  7. 多媒体技术

  8. 安全技能

  9. 任务管理

  10. WebGL

  11. 国际化开发

  12. 应用测试

  13. DFX面向未来设计

  14. 鸿蒙系统移植和裁剪定制

  15. ……

《鸿蒙开发实战》

  1. ArkTS实践

  2. UIAbility应用

  3. 网络案例

  4. ……

《鸿蒙 (HarmonyOS NEXT)开发入门&实战教学视频》  

↑↑↑点击即可

相关文章:

鸿蒙开发接口图形图像:【@ohos.window (窗口)】

窗口 窗口提供管理窗口的一些基础能力&#xff0c;包括对当前窗口的创建、销毁、各属性设置&#xff0c;以及对各窗口间的管理调度。 该模块提供以下窗口相关的常用功能&#xff1a; [Window]&#xff1a;当前窗口实例&#xff0c;窗口管理器管理的基本单元。[WindowStage]&…...

LLM 基准测试的深入指南

随着越来越多的 LLM 可用,对于组织和用户来说,快速浏览不断增长的环境并确定哪些模型最适合他们的需求至关重要。实现这一目标的最可靠方法之一是了解基准分数。 考虑到这一点,本指南深入探讨了 LLM 基准的概念、最常见的基准是什么以及它们需要什么,以及仅依赖基准作为模…...

深入理解Redis事务、事务异常、乐观锁、管道

Redis事务与MySQL事务 不一样。原子性&#xff1a;MySQL有Undo Log机制&#xff0c;支持强原子性&#xff0c;和回滚。Redis只能保证事务内指令可以不被干扰的在同一批次执行&#xff0c;且没有机制保证全部成功则提交&#xff0c;部分失败则回滚。隔离性&#xff1a;MySQL的隔…...

17、Spring系列-SpringMVC-请求源码流程

前言 Spring官网的MVC模块介绍&#xff1a; Spring Web MVC是基于Servlet API构建的原始Web框架&#xff0c;从一开始就已包含在Spring框架中。正式名称“ Spring Web MVC”来自其源模块的名称&#xff08;spring-webmvc&#xff09;&#xff0c;但它通常被称为“ Spring MVC…...

对简单工厂模式、工厂方法模式、抽象工厂模式的简单理解

简单工厂模式 三部分组成 抽象类一些抽象类的具体实现类工厂类 把创建对象的任务交给一个工厂类来实现&#xff0c;对业务进行封装。 优点&#xff1a;实现了任务分离&#xff0c;客户端不用关心业务的具体实现&#xff0c;交由工厂来“生产”。 缺点&#xff1a;违背开闭原…...

PostgreSQL常用插件

PostgreSQL 拥有许多常用插件&#xff0c;这些插件可以大大增强其功能和性能。以下是一些常用的 PostgreSQL 插件&#xff1a; 性能监控和优化 pg_stat_statements 1.提供对所有 SQL 语句执行情况的统计信息。对调优和监控非常有用。 2.安装和使用&#xff1a; pg_stat_k…...

mysql表字段超过多少影响性能 mysql表多少效率会下降

一直有传言说&#xff0c;MySQL 表的数据只要超过 2000 万行&#xff0c;其性能就会下降。而本文作者用实验分析证明&#xff1a;至少在 2023 年&#xff0c;这已不再是 MySQL 表的有效软限制。 传言 互联网上有一则传言说&#xff0c;我们应该避免单个 MySQL 表中的数据超过 …...

Vue进阶之Vue无代码可视化项目(一)

Vue无代码可视化项目 项目搭建初始步骤拓展:工程项目从0-1项目规范化package.jsoncpell.jsoncustom-words.txtts-eslint规则.eslintrc.cjsgit钩子检查有没有问题type-checkspellchecklint:stylehusky操作安装pre-commitpnpm的commit规范package.json:commitlint.config.cjs安装…...

初识C++ · 模拟实现list

目录 前言 1 push_back pop_back 2 迭代器类 2.1 ! 2.2 -- 2.3 * 3 Print_List 4 有关自定义类型 5 有关const迭代器 6 拷贝构造 赋值 析构 Insert erase 前言 有了string&#xff0c;vector的基础&#xff0c;我们模拟实现list还是比较容易的&#xff0c;这里同…...

电商运营-2024年6月1日

作为一名电商运营&#xff0c;针对淘工厂平台&#xff0c;需要具备以下核心技能和素质&#xff1a; 核心技能 新店入驻与产品管理 熟练掌握淘工厂平台的新店入驻流程&#xff0c;包括资质准备、资料提交、审核跟进等。精通产品上架技巧&#xff0c;确保产品信息准确、图片清晰…...

Go跨平台编译

1.编译windows平台运行程序 # windows env GOOSwindows GOARCHamd64 go build main.go2.编译linux平台运行程序 # linux env GOOSlinux GOARCHamd64 go build main.go 3.编译macos平台运行程序 # macos env GOOSdarwin GOARCHamd64 go build main.go 编译结果:...

生产计划排产,制定每小时计划产量(“查表法”SQL计算)

根据日生产计划产量排产&#xff0c;制定每2小时理论计划生产产量。 每2小时计划产量 每2小时工作时间&#xff08;秒&#xff09;/生产计划节拍&#xff08;秒&#xff09;。 假设&#xff0c;生产计划节拍 &#xff1a; 25.0(秒)/台 工厂以每天8点00分钟作为当日工作日的…...

视频汇聚管理安防监控平台EasyCVR程序报错“create jwtSecret del server class:0xf98b6040”的原因排查与解决

国标GB28181协议EasyCVR安防视频监控平台可以提供实时远程视频监控、视频录像、录像回放与存储、告警、语音对讲、云台控制、平台级联、磁盘阵列存储、视频集中存储、云存储等丰富的视频能力&#xff0c;平台支持7*24小时实时高清视频监控&#xff0c;能同时播放多路监控视频流…...

头歌页面置换算法第2关:计算OPT算法缺页率

2 任务:OPT算法 2.1 任务描述 设计OPT页面置换算法模拟程序:从键盘输入访问串。计算OPT算法在不同内存页框数时的缺页数和缺页率。要求程序模拟驻留集变化过程,即能模拟页框装入与释放过程。 2.2任务要求 输入串长度作为总页框数目,补充程序完成OPT算法。 2.3算法思路 OPT算…...

vscode怎么拷贝插件到另一台电脑

说明 vscode插件默认存放在 C:\Users\用户名\.vscode 目录下的 extensions 文件夹中 方法 拷贝 C:\Users\用户名\.vscode 目录下的 extensions 文件夹到另一台电脑的C:\Users\用户名\.vscode 目录下 C:\Users\用户名\.vscode...

网络协议分析

网络协议分析 网络协议分析概述用IP实现异构网络互联网络协议的分层TCP/IP的分层模型协议分析协议分析应用协议分析任务 常见网络协议PPP协议报文选项IPCP认证协议PAP安全缺陷认证协议CHAPPPPoE协议流程 地址解析协议ARPARP的思想和步骤ARP报文格式及封装 移动IP移动IP的工作机…...

GAMIT目录配置

1打开home&#xff0c;显示隐藏文件&#xff0c;CTRH 2修改目录 #set gamitpath gamitpath/opt/gamit10.7 export PATH$PATH:${gamitpath}/com/:${gamitpath}/gamit/bin:${gamitpath}/kf/bin HELP_DIR${gamitpath}/help export HELP_DIR #set GMT path gmtpath/usr/lib/gmt P…...

基于JSP的九宫格日志网站

你好呀&#xff0c;我是学长猫哥&#xff01;如果有需求可以文末加我。 开发语言&#xff1a;Java 数据库&#xff1a;MySQL 技术&#xff1a;JSP技术 工具&#xff1a;浏览器/服务器&#xff08;B/S&#xff09;结构 系统展示 首页 管理员功能模块 用户功能模块 摘要 本…...

C#中结构struct能否继承于一个类class,类class能否继承于一个struct

C#中结构struct能否继承于一个类class&#xff0c;类class能否继承于一个struct 答案是&#xff1a;都不能。 第一种情行&#xff0c;尝试结构继承类 报错&#xff1a;接口列表中的类型"XX"不是接口interface。 一般来说&#xff0c;都是结构只能实现接口&#x…...

【Vulhub】Fastjson 1.2.24_rce复现

文章目录 一&#xff0c;Fastjson是什么&#xff1f;二&#xff0c;fastjson漏洞原理三&#xff0c;判断是否有fastjson反序列化四&#xff0c;复现Fastjson 1.2.24_rce(vulhub)环境配置1.判断是否存在Fastjson反序列化2.反弹shell3.启动RMI服务器4.构造恶意POST请求 一&#x…...

【iconv】UTF-8字符串转换为UTF-16字符串

使用<iconv.h>来进行字符串编码的转换 #include <iconv.h> #include <iostream> #include <string.h> #include <unistd.h> #include <memory> #include <fcntl.h>// 需要链接iconv库// iconv -l 命令可列出所有支持的格式 // exam…...

AI技术的未来展望:重塑人类社会的智能革命

一、引言 随着技术的飞速发展&#xff0c;人工智能&#xff08;AI&#xff09;已经不再是科幻小说中的概念&#xff0c;而是成为了我们生活中不可或缺的一部分。从简单的智能助手到复杂的自动化生产线&#xff0c;AI技术正在以前所未有的速度改变着世界。本文将对AI技术的未来…...

掘金AI 商战宝典-系统班:2024掘金AIGC课程(30节视频课)

课程目录 1-第一讲学会向Al提问&#xff1a;万能提问公式_1.mp4 2-第二讲用AI写视频脚本_1.mp4 3-第三讲用AI写视频口播文案_1.mp4 4-第四讲用AI自动做视频&#xff08;上&#xff09;_1.mp4 5-第五讲用AI自动做视频&#xff08;中&#xff09;_1.mp4 6-第六讲用AI自动做视…...

C# WinForm —— 26 ImageList 介绍

1. 简介 图片集合&#xff0c;用于存储图像的资源&#xff0c;并在关联控件中显示出来 可以通过 索引、键名 访问每张图片 没有事件 2. 属性 属性解释(Name)控件ID&#xff0c;在代码里引用的时候会用到,一般以 imgList 开头ClolorDepth用于呈现图像的颜色数&#xff0c;默…...

Vue:现代前端开发的首选框架-【声明周期钩子详解】

引言 Vue.js 是一个流行的前端框架&#xff0c;它通过组件化的开发方式&#xff0c;让开发者能够构建出高效且可维护的应用程序。在Vue中&#xff0c;生命周期钩子&#xff08;Lifecycle Hooks&#xff09;是理解组件行为的关键概念。本文将深入探讨Vue生命周期钩子&#xff0…...

【因果推断python】8_线性回归模型2

目录 回归理论 非随机数据的回归 回归理论 我不打算深入研究线性回归是如何构建和估计的。然而&#xff0c;一点点理论将有助于解释它在因果推断中的力量。首先&#xff0c;回归解决了理论上的最佳线性预测问题。令 是一个参数向量&#xff1a; 线性回归找到最小化均方误差 (…...

MySQL目录和文件

MySQL目录和文件 bin目录 存储一些mysql脚本比如mysqld、mysqld-self等等&#xff0c;用于执行mysql一些操作 数据目录 show variables like datadir;--查看数据目录位置每一个数据库都有一个和数据库名相同的文件夹&#xff1b;MySQL5.7开始每创建一个表&#xff0c;在Innod…...

0基础学习Elasticsearch-Quick start

文章目录 1 背景2 前言3 快速部署ES4 快速部署Kibana5 发送请求给ES5.1 打开Kibana控制台5.2 通过REST API发送请求5.3 通过curl发送请求5.4 添加数据5.4.1 添加单个document5.4.2 添加多个document 5.5 搜索数据5.5.1 搜索所有documents5.5.2 match查询 6 总结 1 背景 因电商项…...

Centos给普通用户添加sudo命令权限

打开sudoers文件 sudo visudo 修改sudoers文件 找到root ALL(ALL) ALL这一行&#xff0c;即如下图标出红线的一行 在此行下新增如下内容: lbs为用给予sudo执行权限的用户名 # 执行sudo命令&#xff0c;需要输入命令 lbs ALL(ALL) ALL 或 # 执行sudo命令&#xff0c;…...

编写备份MySQL 脚本

目录 环境准备 增量备份 增量备份和差异备份 完整代码如下 测试脚本是否正常 星期天运行脚本&#xff08;完全备份&#xff09; 星期一运备份脚本&#xff08;增量备份&#xff09; 星期二备份数据&#xff08;其他天--增量备份&#xff09; 星期三备份数据&#xff08;差异备…...

C语言中的数据类型转换:隐式类型转换与显示类型转换

一. 简介 本文简单学习一下&#xff0c;C语言中的数据类型转换。重点学习一下隐式类型转换。 二. C语言中的数据类型转换&#xff1a;隐式类型转换与显示类型转换 类型转换&#xff08;TypeCasting&#xff09;&#xff1a;在C语言中是将一种数据类型值转换为另一种数据类型…...

Android 安卓通过bindService ServiceConnection 没有响应的问题

bindService 失败且 ServiceConnection 没有响应可能由多种原因造成。以下是一些可能的原因和相应的解决方法&#xff1a; Service未正确声明或注册&#xff1a; 如果Service没有在AndroidManifest.xml文件中正确声明或注册&#xff0c;bindService将会失败。解决方法&#xf…...

python切片(彻底解除对切片的曲解)

sequence[start:stop:step] **start: **step为正时默认为0,step为负时默认为-1 stop:_ step为正时默认为结尾结束,step为负时默认为开始位置_ ss=“abcdefg” 以该字符串举例,ss[start:stop:step]的意思是将字符串ss从start开始截取(包括start),截取到stop(不包括sto…...

Java—— StringBuilder 和 StringBuffer

1.介绍 由于String的不可更改特性&#xff0c;为了方便字符串的修改&#xff0c;Java中又提供了StringBuilder和Stringbuffer类&#xff0c;这两个类大部分功能是相同的&#xff0c;以下为常用方法&#xff1a; public static void main(String[] args) {StringBuilder sb1 n…...

vs2019 c++20 规范 STL库中关于时间的模板

在学习线程的时候&#xff0c;一些函数会让线程等待或睡眠一段时间。函数形参是时间单位&#xff0c;那么在 c 中是如何记录和表示时间的呢&#xff1f;以下给出模板简图&#xff1a; 谢谢...

激光焊接机作为一种高效、精密的焊接设备

激光焊接机是一种用于材料加工时激光焊接的机器&#xff0c;以下是对其的详细介绍&#xff1a; 1. 定义与别称&#xff1a; 激光焊接机&#xff0c;又常称为激光焊机、镭射焊机&#xff0c;是材料加工激光焊接时用的机器。 2. 工作原理&#xff1a; 激光焊接是利用高能量…...

vite为什么速度快

原因 vite快的原因是因为 vite在开发环境中是使用的 esbuild&#xff0c;esbuild 是 go 写的&#xff0c;go 编译型语言、多线程&#xff0c;nodejs 解释型语言、单线程&#xff0c;并且 vite 使用了原生 esm 导入的&#xff0c;所以快一点&#xff0c;当然&#xff0c;这也…...

Java网络编程(下)

White graces&#xff1a;个人主页 &#x1f649;专栏推荐:Java入门知识&#x1f649; &#x1f649; 内容推荐:Java网络编程&#x1f649; &#x1f439;今日诗词:姑苏城外寒山寺&#xff0c;夜半钟声到客船&#x1f439; ⛳️点赞 ☀️收藏⭐️关注&#x1f4ac;卑微小博主…...

APISIX的安装与测试(springboot服务测试)

安装&#xff1a; 1.1安装依赖&#xff1a; curl https://raw.githubusercontent.com/apache/apisix/master/utils/install-dependencies.sh -sL | bash -1.2 安装 OpenResty yum-config-manager --add-repo https://openresty.org/package/centos/openresty.reposudo yum i…...

AI技术:探索未来智能的无限可能

随着科技的飞速发展&#xff0c;人工智能&#xff08;AI&#xff09;技术已经成为我们这个时代最引人瞩目的科技力量。从简单的自动化任务到复杂的决策支持系统&#xff0c;AI技术正在以前所未有的速度改变着我们的世界。本文将深入探讨AI技术的定义、发展历程、当前应用、面临…...

npm install 出错,按照版本不匹配解决

一、现象 npm install npm WARN config global --global, --local are deprecated. Use --locationglobal instead. npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: panshi-main-web0.1.0 npm ERR! Found…...

【第1章】SpringBoot实战篇之注册接口

文章目录 前言一、代码部分1. User2.UserMapper13. UserSerivce4. UserController15. Result 二、测试1.注册2.再次注册 总结 前言 下面介绍用户注册接口。 一、代码部分 1. User package org.example.springboot3.bigevent.entity;import com.baomidou.mybatisplus.annotat…...

代码随想录-Day25

216.组合总和III 找出所有相加之和为 n 的 k 个数的组合&#xff0c;且满足下列条件&#xff1a; 只使用数字1到9 每个数字 最多使用一次 返回 所有可能的有效组合的列表 。该列表不能包含相同的组合两次&#xff0c;组合可以以任何顺序返回。 示例 1: 输入: k 3, n 7 输…...

JavaWeb_SpringBootWeb基础

先通过一个小练习简单了解以下SpringBootWeb。 小练习&#xff1a; 需求&#xff1a;使用SpringBoot开发一个Web应用&#xff0c;浏览器发起请求/hello后&#xff0c;给浏览器返回字符串"Hello World~"。 步骤&#xff1a; 1.创建SpringBoot项目&#xff0c;勾选We…...

Stable Diffusion生成图片的参数查看与抹除方法

前几天分享了几张Stable Diffusion生成的艺术二维码&#xff0c;有同学反映不知道怎么查看图片的参数信息&#xff0c;还有的同学问怎么保护自己的图片生成参数不会泄露&#xff0c;这篇文章就来专门分享如何查看和抹除图片的参数。 查看图片的生成参数 1、打开Stable Diffus…...

Linux下多线程的相关概念

&#x1f916;个人主页&#xff1a;晚风相伴-CSDN博客 &#x1f496;如果觉得内容对你有帮助的话&#xff0c;还请给博主一键三连&#xff08;点赞&#x1f49c;、收藏&#x1f9e1;、关注&#x1f49a;&#xff09;吧 &#x1f64f;如果内容有误或者有写的不好的地方的话&…...

在java java.util.Date 已知逝去时间怎么求年月日

在java中&#xff0c;可以使用java.util.Date类来获取年、月和日。以下是一种方法&#xff1a; 首先创建一个java.util.Date对象&#xff0c;表示逝去的时间。 Date pastDate new Date(逝去的时间的毫秒数);然后使用java.util.Calendar类来获取年、月和日。 Calendar calen…...

LeetCode 2928.给小朋友们分糖果 I:Java提交的运行时间超过了61%的用户

【LetMeFly】2928.给小朋友们分糖果 I&#xff1a;Java提交的运行时间超过了61%的用户 力扣题目链接&#xff1a;https://leetcode.cn/problems/distribute-candies-among-children-i/ 给你两个正整数 n 和 limit 。 请你将 n 颗糖果分给 3 位小朋友&#xff0c;确保没有任何…...

【typescript/flatbuffer】在websocket中使用flatbuffer

目录 说在前面场景fbs服务器代码前端typescript代码问题 说在前面 操作系统&#xff1a;Windows11node版本&#xff1a;v18.19.0typescript flatbuffer版本&#xff1a;24.3.25 场景 服务器(本文为golanggin)与前端通信时使用flatbuffer进行序列化与反序列化通信协议为websock…...

构建一个文字冒险游戏:Python 编程实战

在本文中&#xff0c;我们将探索如何使用 Python 创建一个简单的文字冒险游戏。通过这个项目&#xff0c;你将了解到基础的编程技术&#xff0c;包括条件语句、函数和基本的用户输入处理&#xff0c;同时也能体会到文本游戏的魅力和设计的挑战。 项目概述 文字冒险游戏是一种…...