窗口提供管理窗口的一些基礎(chǔ)能力,包括對當前窗口的創(chuàng)建、銷毀、各屬性設(shè)置,以及對各窗口間的管理調(diào)度。
該模塊提供以下窗口相關(guān)的常用功能:
本模塊首批接口從API version 6開始支持。后續(xù)版本的新增接口,采用上角標單獨標記接口的起始版本。
窗口類型枚舉。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
名稱 | 值 | 說明 |
---|---|---|
TYPE_APP | 0 | 表示應用子窗口。 模型約束: 此接口僅可在FA模型下使用。 |
TYPE_SYSTEM_ALERT | 1 | 表示系統(tǒng)告警窗口。 |
TYPE_FLOAT9+ | 8 | 表示懸浮窗。 模型約束: 此接口僅可在Stage模型下使用。 需要權(quán)限: ohos.permission.SYSTEM_FLOAT_WINDOW |
創(chuàng)建子窗口時的參數(shù)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 窗口名字。 |
windowType | 是 | 窗口類型。 | |
ctx | 否 | 當前應用上下文信息。不設(shè)置,則默認為空。 FA模型下不需要使用該參數(shù),即可創(chuàng)建子窗口。 Stage模型下需要使用該參數(shù),用于創(chuàng)建系統(tǒng)窗口。 | |
displayId | number | 否 | 當前物理屏幕id。不設(shè)置,則默認為-1。 |
parentId | number | 否 | 父窗口id。不設(shè)置,則默認為-1。 |
窗口內(nèi)容需要規(guī)避區(qū)域的類型枚舉。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
名稱 | 值 | 說明 |
---|---|---|
TYPE_SYSTEM | 0 | 表示系統(tǒng)默認區(qū)域。一般包括狀態(tài)欄、導航欄,各設(shè)備系統(tǒng)定義可能不同。 |
TYPE_CUTOUT | 1 | 表示劉海屏區(qū)域。 |
TYPE_SYSTEM_GESTURE9+ | 2 | 表示手勢區(qū)域。 |
TYPE_KEYBOARD9+ | 3 | 表示軟鍵盤區(qū)域。 |
狀態(tài)欄、導航欄的屬性。
當前HarmonyOS設(shè)備均不支持此接口,此接口在被setWindowSystemBarProperties()接口調(diào)用時將返回801錯誤碼。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
statusBarColor | string | 否 | 狀態(tài)欄背景顏色,為十六進制RGB或ARGB顏色,不區(qū)分大小寫,例如#00FF00或#FF00FF00。默認值:#0x66000000。 |
isStatusBarLightIcon7+ | boolean | 否 | 狀態(tài)欄圖標是否為高亮狀態(tài)。true表示高亮;false表示不高亮。默認值:false。 |
statusBarContentColor8+ | string | 否 | 狀態(tài)欄文字顏色。當設(shè)置此屬性后, isStatusBarLightIcon屬性設(shè)置無效。默認值:0xE5FFFFFF。 |
navigationBarColor | string | 否 | 導航欄背景顏色,為十六進制RGB或ARGB顏色,不區(qū)分大小寫,例如#00FF00或#FF00FF00。默認值:#0x66000000。 |
isNavigationBarLightIcon7+ | boolean | 否 | 導航欄圖標是否為高亮狀態(tài)。true表示高亮;false表示不高亮。默認值:false。 |
navigationBarContentColor8+ | string | 否 | 導航欄文字顏色。當設(shè)置此屬性后, isNavigationBarLightIcon屬性設(shè)置無效。默認值:#0xE5FFFFFF。 |
窗口顯示方向類型枚舉。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
名稱 | 值 | 說明 |
---|---|---|
UNSPECIFIED | 0 | 表示未定義方向模式,由系統(tǒng)判定。 |
PORTRAIT | 1 | 表示豎屏顯示模式。 |
LANDSCAPE | 2 | 表示橫屏顯示模式。 |
PORTRAIT_INVERTED | 3 | 表示反向豎屏顯示模式。 |
LANDSCAPE_INVERTED | 4 | 表示反向橫屏顯示模式。 |
AUTO_ROTATION | 5 | 表示傳感器自動旋轉(zhuǎn)模式。 |
AUTO_ROTATION_PORTRAIT | 6 | 表示傳感器自動豎向旋轉(zhuǎn)模式。 |
AUTO_ROTATION_LANDSCAPE | 7 | 表示傳感器自動橫向旋轉(zhuǎn)模式。 |
AUTO_ROTATION_RESTRICTED | 8 | 表示受開關(guān)控制的自動旋轉(zhuǎn)模式。 |
AUTO_ROTATION_PORTRAIT_RESTRICTED | 9 | 表示受開關(guān)控制的自動豎向旋轉(zhuǎn)模式。 |
AUTO_ROTATION_LANDSCAPE_RESTRICTED | 10 | 表述受開關(guān)控制的自動橫向旋轉(zhuǎn)模式。 |
LOCKED | 11 | 表示鎖定模式。 |
窗口矩形區(qū)域。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
left | number | 是 | 是 | 矩形區(qū)域的左邊界,單位為px。 |
top | number | 是 | 是 | 矩形區(qū)域的上邊界,單位為px。 |
width | number | 是 | 是 | 矩形區(qū)域的寬度,單位為px。 |
height | number | 是 | 是 | 矩形區(qū)域的高度,單位為px。 |
窗口大小。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
width | number | 是 | 是 | 窗口寬度,單位為px。 |
height | number | 是 | 是 | 窗口高度,單位為px。 |
窗口屬性。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
windowRect7+ | 是 | 是 | 窗口尺寸。 | |
type7+ | 是 | 是 | 窗口類型。 | |
isFullScreen | boolean | 是 | 是 | 是否全屏,默認為false。true表示全屏;false表示非全屏。 |
isLayoutFullScreen7+ | boolean | 是 | 是 | 窗口是否為沉浸式,默認為false。true表示沉浸式;false表示非沉浸式。 |
focusable7+ | boolean | 是 | 否 | 窗口是否可聚焦,默認為true。true表示可聚焦;false表示不可聚焦。 |
touchable7+ | boolean | 是 | 否 | 窗口是否可觸摸,默認為true。true表示可觸摸;false表示不可觸摸。 |
brightness | number | 是 | 是 | 屏幕亮度, 可設(shè)置的亮度范圍為0~1,其中1表示最大亮度值。如果窗口沒有設(shè)置亮度值,表示亮度跟隨系統(tǒng),此時獲取到的亮度值為-1。 |
dimBehindValue(deprecated) | number | 是 | 是 | 靠后窗口的暗度值,取值范圍為0~1,1表示最暗。 - 說明: 從API version 9開始廢棄。 - 從 API version 7開始支持。 |
isKeepScreenOn | boolean | 是 | 是 | 屏幕是否常亮,默認為false。true表示常亮;false表示不常亮。 |
isPrivacyMode7+ | boolean | 是 | 是 | 隱私模式,默認為false。true表示模式開啟;false表示模式關(guān)閉。 |
isRoundCorner(deprecated) | boolean | 是 | 是 | 窗口是否為圓角。默認為false。true表示圓角;false表示非圓角。 - 說明: 從API version 9開始廢棄。 - 從 API version 7開始支持。 |
isTransparent7+ | boolean | 是 | 是 | 窗口是否透明。默認為false。true表示透明;false表示不透明。 |
id9+ | number | 是 | 否 | 窗口ID,默認值為0.0。 |
色域模式。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
名稱 | 值 | 說明 |
---|---|---|
DEFAULT | 0 | 默認SRGB色域模式。 |
WIDE_GAMUT | 1 | 廣色域模式。 |
createWindow(config: Configuration, callback: AsyncCallback<Window>): void
創(chuàng)建子窗口,使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
config | 是 | 創(chuàng)建窗口時的參數(shù)。 | |
callback | AsyncCallback<Window> | 是 | 回調(diào)函數(shù)。返回當前創(chuàng)建的窗口對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300001 | Repeated operation. |
1300006 | This window context is abnormal. |
示例:
- let windowClass = null;
- let config = {name: "alertWindow", windowType: window.WindowType.TYPE_SYSTEM_ALERT, ctx: this.context};
- try {
- window.createWindow(config, (err, data) => {
- if (err.code) {
- console.error('Failed to create the window. Cause: ' + JSON.stringify(err));
- return;
- }
- windowClass = data;
- console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data));
- windowClass.resize(500, 1000);
- });
- } catch (exception) {
- console.error('Failed to create the window. Cause: ' + JSON.stringify(exception));
- }
createWindow(config: Configuration): Promise<Window>
創(chuàng)建子窗口,使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
config | 是 | 創(chuàng)建窗口時的參數(shù)。 |
返回值:
類型 | 說明 |
---|---|
Promise<Window> | Promise對象。返回當前創(chuàng)建的窗口對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300001 | Repeated operation. |
1300006 | This window context is abnormal. |
示例:
- let windowClass = null;
- let config = {name: "alertWindow", windowType: window.WindowType.TYPE_SYSTEM_ALERT, ctx: this.context};
- try {
- let promise = window.createWindow(config);
- promise.then((data)=> {
- windowClass = data;
- console.info('Succeeded in creating the window. Data:' + JSON.stringify(data));
- }).catch((err)=>{
- console.error('Failed to create the Window. Cause:' + JSON.stringify(err));
- });
- } catch (exception) {
- console.error('Failed to create the window. Cause: ' + JSON.stringify(exception));
- }
findWindow(name: string): Window
查找name所對應的窗口。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 窗口id。 |
返回值:
類型 | 說明 |
---|---|
當前查找的窗口對象。 |
示例:
- let windowClass = null;
- try {
- windowClass = window.findWindow('alertWindow');
- } catch (exception) {
- console.error('Failed to find the Window. Cause: ' + JSON.stringify(exception));
- }
getLastWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void
獲取當前應用內(nèi)最上層的子窗口,若無應用子窗口,則返回應用主窗口,使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
ctx | 是 | 當前應用上下文信息。 | |
callback | AsyncCallback<Window> | 是 | 回調(diào)函數(shù)。返回當前應用內(nèi)最后顯示的窗口對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300006 | This window context is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- import window from '@ohos.window';
- class myAbility extends UIAbility {
- // ...
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = undefined;
- try {
- window.getLastWindow(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));
- });
- } catch (exception) {
- console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception));
- }
- }
- }
getLastWindow(ctx: BaseContext): Promise<Window>
獲取當前應用內(nèi)最上層的子窗口,若無應用子窗口,則返回應用主窗口,使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
ctx | 是 | 當前應用上下文信息。 |
返回值:
類型 | 說明 |
---|---|
Promise<Window> | Promise對象。返回當前應用內(nèi)最后顯示的窗口對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300006 | This window context is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- import window from '@ohos.window';
- class myAbility extends UIAbility {
- // ...
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = undefined;
- try {
- let promise = window.getLastWindow(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));
- });
- } catch (exception) {
- console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception));
- }
- };
- }
create(id: string, type: WindowType, callback: AsyncCallback<Window>): void
創(chuàng)建子窗口,使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用createWindow()。
模型約束: 此接口僅可在FA模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
id | string | 是 | 窗口id。 |
type | 是 | 窗口類型。 | |
callback | AsyncCallback<Window> | 是 | 回調(diào)函數(shù)。返回當前創(chuàng)建的子窗口對象。 |
示例:
- let windowClass = null;
- window.create('first', window.WindowType.TYPE_APP,(err,data) => {
- if(err.code){
- console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err));
- return;
- }
- windowClass = data;
- console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data));
- });
create(id: string, type: WindowType): Promise<Window>
創(chuàng)建子窗口,使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用createWindow()。
模型約束: 此接口僅可在FA模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
id | string | 是 | 窗口id。 |
type | 是 | 窗口類型。 |
返回值:
類型 | 說明 |
---|---|
Promise<Window> | Promise對象。返回當前創(chuàng)建的子窗口對象。 |
示例:
- let windowClass = null;
- let promise = window.create('first', window.WindowType.TYPE_APP);
- promise.then((data)=> {
- windowClass = data;
- console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data));
- }).catch((err)=>{
- console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err));
- });
create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback<Window>): void
創(chuàng)建子窗口,使用callback異步回調(diào)。
當前此接口僅可在FA模型下使用。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用createWindow()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
ctx | 是 | 當前應用上下文信息。 | |
id | string | 是 | 窗口id。 |
type | 是 | 窗口類型。 | |
callback | AsyncCallback<Window> | 是 | 回調(diào)函數(shù)。返回當前創(chuàng)建的子窗口對象。 |
示例:
- let windowClass = null;
- window.create(this.context, 'alertWindow', window.WindowType.TYPE_SYSTEM_ALERT, (err, data) => {
- if (err.code) {
- console.error('Failed to create the window. Cause: ' + JSON.stringify(err));
- return;
- }
- windowClass = data;
- console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data));
- windowClass.resetSize(500, 1000);
- });
create(ctx: BaseContext, id: string, type: WindowType): Promise<Window>
創(chuàng)建子窗口,使用Promise異步回調(diào)。
當前此接口僅可在FA模型下使用。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用createWindow()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
ctx | 是 | 當前應用上下文信息。 | |
id | string | 是 | 窗口id。 |
type | 是 | 窗口類型。 |
返回值:
類型 | 說明 |
---|---|
Promise<Window> | Promise對象。返回當前創(chuàng)建的子窗口對象。 |
示例:
- let windowClass = null;
- let promise = window.create(this.context, 'alertWindow', window.WindowType.TYPE_SYSTEM_ALERT);
- promise.then((data)=> {
- windowClass = data;
- console.info('Succeeded in creating the window. Data:' + JSON.stringify(data));
- }).catch((err)=>{
- console.error('Failed to create the Window. Cause:' + JSON.stringify(err));
- });
find(id: string, callback: AsyncCallback<Window>): void
查找id所對應的窗口,使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用findWindow()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
id | string | 是 | 窗口id。 |
callback | AsyncCallback<Window> | 是 | 回調(diào)函數(shù)。返回當前查找到的窗口對象。 |
示例:
- let windowClass = null;
- window.find('alertWindow', (err, data) => {
- if (err.code) {
- console.error('Failed to find the Window. Cause: ' + JSON.stringify(err));
- return;
- }
- windowClass = data;
- console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data));
- });
find(id: string): Promise<Window>
查找id所對應的窗口,使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用findWindow()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
id | string | 是 | 窗口id。 |
返回值:
類型 | 說明 |
---|---|
Promise<Window> | Promise對象。返回當前查找的窗口對象。 |
示例:
- let windowClass = null;
- let promise = window.find('alertWindow');
- promise.then((data)=> {
- windowClass = data;
- console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data));
- }).catch((err)=>{
- console.error('Failed to find the Window. Cause: ' + JSON.stringify(err));
- });
getTopWindow(callback: AsyncCallback<Window>): void
獲取當前應用內(nèi)最后顯示的窗口,使用callback異步回調(diào)。
從 API version 6開始支持,從API version 9開始廢棄,推薦使用getLastWindow()。
模型約束: 此接口僅可在FA模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<Window> | 是 | 回調(diào)函數(shù)。返回當前應用內(nèi)最后顯示的窗口對象。 |
示例:
- let windowClass = null;
- window.getTopWindow((err, data) => {
- if (err.code) {
- console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
- return;
- }
- windowClass = data;
- console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
- });
getTopWindow(): Promise<Window>
獲取當前應用內(nèi)最后顯示的窗口,使用Promise異步回調(diào)。
從 API version 6開始支持,從API version 9開始廢棄,推薦使用getLastWindow()。
模型約束: 此接口僅可在FA模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
類型 | 說明 |
---|---|
Promise<Window> | Promise對象。返回當前應用內(nèi)最后顯示的窗口對象。 |
示例:
- let windowClass = null;
- let promise = window.getTopWindow();
- promise.then((data)=> {
- windowClass = data;
- console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
- }).catch((err)=>{
- console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
- });
getTopWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void
獲取當前應用內(nèi)最后顯示的窗口,使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄,推薦使用getLastWindow()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
ctx | 是 | 當前應用上下文信息。 | |
callback | AsyncCallback<Window> | 是 | 回調(diào)函數(shù)。返回當前應用內(nèi)最后顯示的窗口對象。 |
示例:
- let windowClass = null;
- window.getTopWindow(this.context, (err, data) => {
- if (err.code) {
- console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
- return;
- }
- windowClass = data;
- console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
- });
getTopWindow(ctx: BaseContext): Promise<Window>
獲取當前應用內(nèi)最后顯示的窗口,使用Promise異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄,推薦使用getLastWindow()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
ctx | 是 | 當前應用上下文信息。 |
返回值:
類型 | 說明 |
---|---|
Promise<Window> | Promise對象。返回當前應用內(nèi)最后顯示的窗口對象。 |
示例:
- let windowClass = null;
- let promise = window.getTopWindow(this.context);
- promise.then((data)=> {
- windowClass = data;
- console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
- }).catch((err)=>{
- console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
- });
當前窗口實例,窗口管理器管理的基本單元。
下列API示例中都需先使用getLastWindow()、createWindow()、findWindow()中的任一方法獲取到Window實例,再通過此實例調(diào)用對應方法。
showWindow(callback: AsyncCallback<void>): void
顯示當前窗口,使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- windowClass.showWindow((err) => {
- if (err.code) {
- console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in showing the window.');
- });
showWindow(): Promise<void>
顯示當前窗口,使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- let promise = windowClass.showWindow();
- promise.then(()=> {
- console.info('Succeeded in showing the window.');
- }).catch((err)=>{
- console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
- });
destroyWindow(callback: AsyncCallback<void>): void
銷毀當前窗口,使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- windowClass.destroyWindow((err) => {
- if (err.code) {
- console.error('Failed to destroy the window. Cause:' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in destroying the window.');
- });
destroyWindow(): Promise<void>
銷毀當前窗口,使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let promise = windowClass.destroyWindow();
- promise.then(()=> {
- console.info('Succeeded in destroying the window.');
- }).catch((err)=>{
- console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err));
- });
moveWindowTo(x: number, y: number, callback: AsyncCallback<void>): void
移動窗口位置,使用callback異步回調(diào)。
全屏模式窗口不支持該操作。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
x | number | 是 | 窗口在x軸方向移動的值,值為正表示右移,單位為px。 |
y | number | 是 | 窗口在y軸方向移動的值,值為正表示下移,單位為px。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- try {
- windowClass.moveWindowTo(300, 300, (err)=>{
- if (err.code) {
- 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));
- }
moveWindowTo(x: number, y: number): Promise<void>
移動窗口位置,使用Promise異步回調(diào)。
全屏模式窗口不支持該操作。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
x | number | 是 | 窗口在x軸方向移動的值,值為正表示右移,單位為px。 |
y | number | 是 | 窗口在y軸方向移動的值,值為正表示下移,單位為px。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- try {
- let promise = windowClass.moveWindowTo(300, 300);
- promise.then(()=> {
- console.info('Succeeded in moving the window.');
- }).catch((err)=>{
- console.error('Failed to move the window. Cause: ' + JSON.stringify(err));
- });
- } catch (exception) {
- console.error('Failed to move the window. Cause:' + JSON.stringify(exception));
- }
resize(width: number, height: number, callback: AsyncCallback<void>): void
改變當前窗口大小,使用callback異步回調(diào)。
應用主窗口與子窗口存在大小限制,寬度范圍:[320, 2560],高度范圍:[240, 2560],單位為vp。
系統(tǒng)窗口存在大小限制,寬度范圍:[0, 2560],高度范圍:[0, 2560],單位為vp。
設(shè)置的寬度與高度受到此約束限制,規(guī)則: 若所設(shè)置的窗口寬/高尺寸小于窗口最小寬/高限值,則窗口最小寬/高限值生效; 若所設(shè)置的窗口寬/高尺寸大于窗口最大寬/高限值,則窗口最大寬/高限值生效。
全屏模式窗口不支持該操作。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
width | number | 是 | 目標窗口的寬度,單位為px。 |
height | number | 是 | 目標窗口的高度,單位為px。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- try {
- windowClass.resize(500, 1000, (err) => {
- if (err.code) {
- 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));
- }
resize(width: number, height: number): Promise<void>
改變當前窗口大小,使用Promise異步回調(diào)。
應用主窗口與子窗口存在大小限制,寬度范圍:[320, 2560],高度范圍:[240, 2560],單位為vp。
系統(tǒng)窗口存在大小限制,寬度范圍:[0, 2560],高度范圍:[0, 2560],單位為vp。
設(shè)置的寬度與高度受到此約束限制,規(guī)則: 若所設(shè)置的窗口寬/高尺寸小于窗口最小寬/高限值,則窗口最小寬/高限值生效; 若所設(shè)置的窗口寬/高尺寸大于窗口最大寬/高限值,則窗口最大寬/高限值生效。
全屏模式窗口不支持該操作。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
width | number | 是 | 目標窗口的寬度,單位為px。 |
height | number | 是 | 目標窗口的高度,單位為px。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- try {
- let promise = windowClass.resize(500, 1000);
- promise.then(()=> {
- console.info('Succeeded in changing the window size.');
- }).catch((err)=>{
- 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));
- }
getWindowProperties(): WindowProperties
獲取當前窗口的屬性,返回WindowProperties。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
類型 | 說明 |
---|---|
當前窗口屬性。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- try {
- let properties = windowClass.getWindowProperties();
- } catch (exception) {
- console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(exception));
- }
getWindowAvoidArea(type: AvoidAreaType): AvoidArea
獲取窗口內(nèi)容規(guī)避的區(qū)域;如系統(tǒng)欄區(qū)域、劉海屏區(qū)域、手勢區(qū)域、軟鍵盤區(qū)域等與窗口內(nèi)容重疊時,需要窗口內(nèi)容避讓的區(qū)域。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | 是 | 表示規(guī)避區(qū)類型。 |
返回值:
類型 | 說明 |
---|---|
窗口內(nèi)容規(guī)避區(qū)域。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- let type = window.AvoidAreaType.TYPE_SYSTEM;
- try {
- let avoidArea = windowClass.getWindowAvoidArea(type);
- } catch (exception) {
- console.error('Failed to obtain the area. Cause:' + JSON.stringify(exception));
- }
setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void
設(shè)置窗口的布局是否為全屏顯示狀態(tài),使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isLayoutFullScreen | boolean | 是 | 窗口的布局是否為全屏顯示狀態(tài)(該全屏狀態(tài)下狀態(tài)欄、導航欄仍然顯示)。true表示全屏顯示;false表示非全屏顯示。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let isLayoutFullScreen= true;
- try {
- windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err) => {
- 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.');
- });
- } catch (exception) {
- console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception));
- }
setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void>
設(shè)置窗口的布局是否為全屏顯示狀態(tài),使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isLayoutFullScreen | boolean | 是 | 窗口的布局是否為全屏顯示狀態(tài)(該全屏狀態(tài)下狀態(tài)欄、導航欄仍然顯示)。true表示全屏顯示;false表示非全屏顯示。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let isLayoutFullScreen = true;
- try {
- let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen);
- promise.then(()=> {
- console.info('Succeeded in setting the window layout to full-screen mode.');
- }).catch((err)=>{
- 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));
- }
setWindowSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void
設(shè)置導航欄、狀態(tài)欄的可見模式,使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
names | Array<'status'|'navigation'> | 是 | 設(shè)置狀態(tài)欄和導航欄是否顯示。 例如,需全部顯示,該參數(shù)設(shè)置為['status', 'navigation'];不設(shè)置,則默認不顯示。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- // 此處以不顯示導航欄、狀態(tài)欄為例
- let names = [];
- try {
- windowClass.setWindowSystemBarEnable(names, (err) => {
- if (err.code) {
- console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in setting the system bar to be invisible.');
- });
- } catch (exception) {
- console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception));
- }
setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void>
設(shè)置導航欄、狀態(tài)欄的可見模式,使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
names | Array<'status'|'navigation'> | 是 | 設(shè)置狀態(tài)欄和導航欄是否顯示。 例如,需全部顯示,該參數(shù)設(shè)置為['status', 'navigation'];不設(shè)置,則默認不顯示。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- // 此處以不顯示導航欄、狀態(tài)欄為例
- let names = [];
- try {
- let promise = windowClass.setWindowSystemBarEnable(names);
- promise.then(()=> {
- console.info('Succeeded in setting the system bar to be invisible.');
- }).catch((err)=>{
- 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));
- }
setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void
設(shè)置窗口內(nèi)導航欄、狀態(tài)欄的屬性,使用callback異步回調(diào)。
當前HarmonyOS設(shè)備均不支持此接口,應用調(diào)用此接口將返回801錯誤碼。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
SystemBarProperties | 是 | 導航欄、狀態(tài)欄的屬性。 | |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let SystemBarProperties = {
- statusBarColor: '#ff00ff',
- navigationBarColor: '#00ff00',
- //以下兩個屬性從API Version8開始支持
- statusBarContentColor:'#ffffff',
- navigationBarContentColor:'#00ffff'
- };
- try {
- windowClass.setWindowSystemBarProperties(SystemBarProperties, (err) => {
- 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.');
- });
- } catch (exception) {
- console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(exception));
- }
setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void>
設(shè)置窗口內(nèi)導航欄、狀態(tài)欄的屬性,使用Promise異步回調(diào)。
當前HarmonyOS設(shè)備均不支持此接口,應用調(diào)用此接口將返回801錯誤碼。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
SystemBarProperties | 是 | 導航欄、狀態(tài)欄的屬性。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let SystemBarProperties = {
- statusBarColor: '#ff00ff',
- navigationBarColor: '#00ff00',
- //以下兩個屬性從API Version8開始支持
- statusBarContentColor:'#ffffff',
- navigationBarContentColor:'#00ffff'
- };
- try {
- let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties);
- promise.then(()=> {
- console.info('Succeeded in setting the system bar properties.');
- }).catch((err)=>{
- 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));
- }
setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void
設(shè)置窗口的顯示方向?qū)傩裕褂胏allback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
Orientation | 是 | 窗口顯示方向的屬性。 | |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- let orientation = window.Orientation.AUTO_ROTATION;
- try {
- windowClass.setPreferredOrientation(orientation, (err) => {
- if (err.code) {
- 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));
- }
setPreferredOrientation(orientation: Orientation): Promise<void>
設(shè)置窗口的顯示方向?qū)傩裕褂肞romise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
Orientation | 是 | 窗口顯示方向的屬性。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- let orientation = window.Orientation.AUTO_ROTATION;
- try {
- let promise = windowClass.setPreferredOrientation(orientation);
- promise.then(()=> {
- console.info('Succeeded in setting the window orientation.');
- }).catch((err)=>{
- 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));
- }
setUIContent(path: string, callback: AsyncCallback<void>): void
為當前窗口加載具體頁面內(nèi)容,使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 要加載到窗口中的頁面內(nèi)容的路徑,Stage模型下該路徑需添加到工程的main_pages.json文件中,F(xiàn)A模型下該路徑需添加到工程的config.json文件中。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- try {
- windowClass.setUIContent('pages/page2/page2', (err) => {
- if (err.code) {
- 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));
- }
setUIContent(path: string): Promise<void>
為當前窗口加載具體頁面內(nèi)容,使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 要加載到窗口中的頁面內(nèi)容的路徑,Stage模型下該路徑需添加到工程的main_pages.json文件中,F(xiàn)A模型下該路徑需添加到工程的config.json文件中。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- try {
- let promise = windowClass.setUIContent('pages/page2/page2');
- promise.then(()=> {
- console.info('Succeeded in loading the content.');
- }).catch((err)=>{
- console.error('Failed to load the content. Cause: ' + JSON.stringify(err));
- });
- } catch (exception) {
- console.error('Failed to load the content. Cause: ' + JSON.stringify(exception));
- }
loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void
為當前窗口加載與LocalStorage相關(guān)聯(lián)的具體頁面內(nèi)容,使用callback異步回調(diào)。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 要加載到窗口中的頁面內(nèi)容的路徑,該路徑需添加到工程的main_pages.json文件中。 |
storage | 是 | 存儲單元,為應用程序范圍內(nèi)的可變狀態(tài)屬性和非可變狀態(tài)屬性提供存儲。 | |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let storage = new LocalStorage();
- storage.setOrCreate('storageSimpleProp',121);
- console.log('onWindowStageCreate');
- try {
- windowClass.loadContent('pages/page2', storage, (err) => {
- if (err.code) {
- 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));
- }
loadContent(path: string, storage: LocalStorage): Promise<void>
為當前窗口加載與LocalStorage相關(guān)聯(lián)的具體頁面內(nèi)容,使用Promise異步回調(diào)。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 要加載到窗口中的頁面內(nèi)容的路徑,該路徑需添加到工程的main_pages.json文件中。 |
storage | 是 | 存儲單元,為應用程序范圍內(nèi)的可變狀態(tài)屬性和非可變狀態(tài)屬性提供存儲。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let storage = new LocalStorage();
- storage.setOrCreate('storageSimpleProp',121);
- console.log('onWindowStageCreate');
- try {
- let promise = windowClass.loadContent('pages/page2', storage);
- promise.then(() => {
- console.info('Succeeded in loading the content.');
- }).catch((err) => {
- console.error('Failed to load the content. Cause:' + JSON.stringify(err));
- });
- } catch (exception) {
- console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
- }
isWindowShowing(): boolean
判斷當前窗口是否已顯示。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
類型 | 說明 |
---|---|
boolean | 當前窗口是否已顯示。true表示當前窗口已顯示,false則表示當前窗口未顯示。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- try {
- 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(type: 'windowSizeChange', callback: Callback<Size>): void
開啟窗口尺寸變化的監(jiān)聽。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 監(jiān)聽事件,固定為'windowSizeChange',即窗口尺寸變化事件。 |
callback | Callback<Size> | 是 | 回調(diào)函數(shù)。返回當前的窗口尺寸。 |
示例:
- try {
- 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(type: 'windowSizeChange', callback?: Callback<Size>): void
關(guān)閉窗口尺寸變化的監(jiān)聽。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 監(jiān)聽事件,固定為'windowSizeChange',即窗口尺寸變化事件。 |
callback | Callback<Size> | 否 | 回調(diào)函數(shù)。返回當前的窗口尺寸。 |
示例:
- try {
- windowClass.off('windowSizeChange');
- } catch (exception) {
- console.error('Failed to disable the listener for window size changes. Cause: ' + JSON.stringify(exception));
- }
on(type: 'avoidAreaChange', callback: Callback<{type: AvoidAreaType, area: AvoidArea}>): void
開啟系統(tǒng)規(guī)避區(qū)變化的監(jiān)聽。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 監(jiān)聽事件,固定為'avoidAreaChange',即系統(tǒng)規(guī)避區(qū)變化事件。 |
callback | Callback<{type: AvoidAreaType, area: AvoidArea}> | 是 | 回調(diào)函數(shù)。返回當前規(guī)避區(qū)以及規(guī)避區(qū)類型。 |
示例:
- try {
- 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(type: 'avoidAreaChange', callback?: Callback<{type: AvoidAreaType, area: AvoidArea}>): void
關(guān)閉系統(tǒng)規(guī)避區(qū)變化的監(jiān)聽。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 監(jiān)聽事件,固定為'avoidAreaChange',即系統(tǒng)規(guī)避區(qū)變化事件。 |
callback | Callback<{type: AvoidAreaType, area: AvoidArea}> | 否 | 回調(diào)函數(shù)。返回當前規(guī)避區(qū)以及規(guī)避區(qū)類型。 |
示例:
- try {
- windowClass.off('avoidAreaChange');
- } catch (exception) {
- console.error('Failed to disable the listener for system avoid area changes. Cause: ' + JSON.stringify(exception));
- }
on(type: 'keyboardHeightChange', callback: Callback<number>): void
開啟鍵盤高度變化的監(jiān)聽。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 監(jiān)聽事件,固定為'keyboardHeightChange',即鍵盤高度變化事件。 |
callback | Callback<number> | 是 | 回調(diào)函數(shù)。返回當前的鍵盤高度。 |
示例:
- try {
- 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(type: 'keyboardHeightChange', callback?: Callback<number>): void
關(guān)閉鍵盤高度變化的監(jiān)聽。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 監(jiān)聽事件,固定為'keyboardHeightChange',即鍵盤高度變化事件。 |
callback | Callback<number> | 否 | 回調(diào)函數(shù)。返回當前的鍵盤高度。 |
示例:
- try {
- windowClass.off('keyboardHeightChange');
- } catch (exception) {
- console.error('Failed to disable the listener for keyboard height changes. Cause: ' + JSON.stringify(exception));
- }
on(type: 'screenshot', callback: Callback<void>): void
開啟截屏事件的監(jiān)聽。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 監(jiān)聽事件,固定為'screenshot',即截屏事件。 |
callback | Callback<void> | 是 | 回調(diào)函數(shù)。發(fā)生截屏事件時的回調(diào)。 |
示例:
- try {
- windowClass.on('screenshot', () => {
- console.info('screenshot happened');
- });
- } catch (exception) {
- console.error('Failed to register callback. Cause: ' + JSON.stringify(exception));
- }
off(type: 'screenshot', callback?: Callback<void>): void
關(guān)閉截屏事件的監(jiān)聽。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 監(jiān)聽事件,固定為'screenshot',即截屏事件。 |
callback | Callback<void> | 否 | 回調(diào)函數(shù)。發(fā)生截屏事件時的回調(diào)。 |
示例:
- 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進行監(jiān)聽,同時關(guān)閉所有監(jiān)聽:
- windowClass.off('screenshot');
- } catch (exception) {
- console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception));
- }
isWindowSupportWideGamut(callback: AsyncCallback<boolean>): void
判斷當前窗口是否支持廣色域模式,使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。返回true表示當前窗口支持廣色域模式,返回false表示當前窗口不支持廣色域模式。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- windowClass.isWindowSupportWideGamut((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));
- });
isWindowSupportWideGamut(): Promise<boolean>
判斷當前窗口是否支持廣色域模式,使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示當前窗口支持廣色域模式,返回false表示當前窗口不支持廣色域模式。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- let promise = windowClass.isWindowSupportWideGamut();
- 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));
- });
setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void
設(shè)置當前窗口為廣色域模式或默認色域模式,使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
colorSpace | 是 | 設(shè)置色域模式。 | |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- try {
- windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err) => {
- if (err.code) {
- 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));
- }
setWindowColorSpace(colorSpace:ColorSpace): Promise<void>
設(shè)置當前窗口為廣色域模式或默認色域模式,使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
colorSpace | 是 | 設(shè)置色域模式。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- try {
- let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT);
- promise.then(()=> {
- console.info('Succeeded in setting window colorspace.');
- }).catch((err)=>{
- console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err));
- });
- } catch (exception) {
- console.error('Failed to set window colorspace. Cause:' + JSON.stringify(exception));
- }
getWindowColorSpace(): ColorSpace
獲取當前窗口色域模式。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
類型 | 說明 |
---|---|
當前色域模式。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- let colorSpace = windowClass.getWindowColorSpace();
setWindowBackgroundColor(color: string): void
設(shè)置窗口的背景色。Stage模型下,該接口需要在loadContent或setUIContent之后使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
color | string | 是 | 需要設(shè)置的背景色,為十六進制RGB或ARGB顏色,不區(qū)分大小寫,例如#00FF00或#FF00FF00。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- let color = '#00ff33';
- try {
- windowClass.setWindowBackgroundColor(color);
- } catch (exception) {
- console.error('Failed to set the background color. Cause: ' + JSON.stringify(exception));
- }
setWindowBrightness(brightness: number, callback: AsyncCallback<void>): void
設(shè)置屏幕亮度值,使用callback異步回調(diào)。
當前屏幕亮度規(guī)格:窗口設(shè)置屏幕亮度生效時,控制中心不可以調(diào)整系統(tǒng)屏幕亮度,窗口恢復默認系統(tǒng)亮度之后,控制中心可以調(diào)整系統(tǒng)屏幕亮度。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
brightness | number | 是 | 屏幕亮度值,值為0-1之間。1表示最亮。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let brightness = 1;
- try {
- windowClass.setWindowBrightness(brightness, (err) => {
- if (err.code) {
- 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));
- }
setWindowBrightness(brightness: number): Promise<void>
設(shè)置屏幕亮度值,使用Promise異步回調(diào)。
當前屏幕亮度規(guī)格:窗口設(shè)置屏幕亮度生效時,控制中心不可以調(diào)整系統(tǒng)屏幕亮度,窗口恢復默認系統(tǒng)亮度之后,控制中心可以調(diào)整系統(tǒng)屏幕亮度。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
brightness | number | 是 | 屏幕亮度值,值為0-1之間。1表示最亮。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let brightness = 1;
- try {
- let promise = windowClass.setWindowBrightness(brightness);
- promise.then(()=> {
- console.info('Succeeded in setting the brightness.');
- }).catch((err)=>{
- console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err));
- });
- } catch (exception) {
- console.error('Failed to set the brightness. Cause: ' + JSON.stringify(exception));
- }
setWindowFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void
設(shè)置點擊時是否支持切換焦點窗口,使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isFocusable | boolean | 是 | 點擊時是否支持切換焦點窗口。true表示支持;false表示不支持。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let isFocusable = true;
- try {
- windowClass.setWindowFocusable(isFocusable, (err) => {
- 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.');
- });
- } catch (exception) {
- console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(exception));
- }
setWindowFocusable(isFocusable: boolean): Promise<void>
設(shè)置點擊時是否支持切換焦點窗口,使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isFocusable | boolean | 是 | 點擊時是否支持切換焦點窗口。true表示支持;false表示不支持。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let isFocusable = true;
- try {
- let promise = windowClass.setWindowFocusable(isFocusable);
- promise.then(()=> {
- console.info('Succeeded in setting the window to be focusable.');
- }).catch((err)=>{
- 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));
- }
setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void
設(shè)置屏幕是否為常亮狀態(tài),使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isKeepScreenOn | boolean | 是 | 設(shè)置屏幕是否為常亮狀態(tài)。true表示常亮;false表示不常亮。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let isKeepScreenOn = true;
- try {
- windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err) => {
- 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.');
- });
- } catch (exception) {
- console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(exception));
- }
setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise<void>
設(shè)置屏幕是否為常亮狀態(tài),使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isKeepScreenOn | boolean | 是 | 設(shè)置屏幕是否為常亮狀態(tài)。true表示常亮;false表示不常亮。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let isKeepScreenOn = true;
- try {
- let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn);
- promise.then(() => {
- console.info('Succeeded in setting the screen to be always on.');
- }).catch((err)=>{
- 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));
- }
setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void
設(shè)置窗口是否為隱私模式,使用callback異步回調(diào)。設(shè)置為隱私模式的窗口,窗口內(nèi)容將無法被截屏或錄屏。此接口可用于禁止截屏/錄屏的場景。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
需要權(quán)限: ohos.permission.PRIVACY_WINDOW
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isPrivacyMode | boolean | 是 | 窗口是否為隱私模式。true表示模式開啟;false表示模式關(guān)閉。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- let isPrivacyMode = true;
- try {
- windowClass.setWindowPrivacyMode(isPrivacyMode, (err) => {
- 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.');
- });
- } catch (exception) {
- console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception));
- }
setWindowPrivacyMode(isPrivacyMode: boolean): Promise<void>
設(shè)置窗口是否為隱私模式,使用Promise異步回調(diào)。設(shè)置為隱私模式的窗口,窗口內(nèi)容將無法被截屏或錄屏。此接口可用于禁止截屏/錄屏的場景。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
需要權(quán)限: ohos.permission.PRIVACY_WINDOW
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isPrivacyMode | boolean | 是 | 窗口是否為隱私模式。true表示模式開啟;false表示模式關(guān)閉。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- let isPrivacyMode = true;
- try {
- let promise = windowClass.setWindowPrivacyMode(isPrivacyMode);
- promise.then(()=> {
- console.info('Succeeded in setting the window to privacy mode.');
- }).catch((err)=>{
- 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));
- }
setWindowTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void
設(shè)置窗口是否為可觸狀態(tài),使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isTouchable | boolean | 是 | 窗口是否為可觸狀態(tài)。true表示可觸;false表示不可觸。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let isTouchable = true;
- try {
- windowClass.setWindowTouchable(isTouchable, (err) => {
- 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.');
- });
- } catch (exception) {
- console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(exception));
- }
setWindowTouchable(isTouchable: boolean): Promise<void>
設(shè)置窗口是否為可觸狀態(tài),使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isTouchable | boolean | 是 | 窗口是否為可觸狀態(tài)。true表示可觸;false表示不可觸。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
- let isTouchable = true;
- try {
- let promise = windowClass.setWindowTouchable(isTouchable);
- promise.then(()=> {
- console.info('Succeeded in setting the window to be touchable.');
- }).catch((err)=>{
- 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));
- }
snapshot(callback: AsyncCallback<image.PixelMap>): void
獲取窗口截圖,使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<image.PixelMap> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- windowClass.snapshot((err, pixelMap) => {
- if (err.code) {
- console.error('Failed to snapshot window. Cause:' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
- pixelMap.release(); // PixelMap使用完后及時釋放內(nèi)存
- });
snapshot(): Promise<image.PixelMap>
獲取窗口截圖,使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
類型 | 說明 |
---|---|
Promise<image.PixelMap> | Promise對象。返回當前窗口截圖。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
- let promise = windowClass.snapshot();
- promise.then((pixelMap)=> {
- console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber());
- pixelMap.release(); // PixelMap使用完后及時釋放內(nèi)存
- }).catch((err)=>{
- console.error('Failed to snapshot window. Cause:' + JSON.stringify(err));
- });
show(callback: AsyncCallback<void>): void
顯示當前窗口,使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用showWindow()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- windowClass.show((err) => {
- if (err.code) {
- console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in showing the window.');
- });
show(): Promise<void>
顯示當前窗口,使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用showWindow()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let promise = windowClass.show();
- promise.then(()=> {
- console.info('Succeeded in showing the window.');
- }).catch((err)=>{
- console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
- });
destroy(callback: AsyncCallback<void>): void
銷毀當前窗口,使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用destroyWindow()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- windowClass.destroy((err) => {
- if (err.code) {
- console.error('Failed to destroy the window. Cause:' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in destroying the window.');
- });
destroy(): Promise<void>
銷毀當前窗口,使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用destroyWindow()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let promise = windowClass.destroy();
- promise.then(()=> {
- console.info('Succeeded in destroying the window.');
- }).catch((err)=>{
- console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err));
- });
moveTo(x: number, y: number, callback: AsyncCallback<void>): void
移動窗口位置,使用callback異步回調(diào)。
全屏模式窗口不支持該操作。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用moveWindowTo()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
x | number | 是 | 窗口在x軸方向移動的值,值為正表示右移,單位為px。 |
y | number | 是 | 窗口在y軸方向移動的值,值為正表示下移,單位為px。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- windowClass.moveTo(300, 300, (err)=>{
- if (err.code) {
- console.error('Failed to move the window. Cause:' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in moving the window.');
- });
moveTo(x: number, y: number): Promise<void>
移動窗口位置,使用Promise異步回調(diào)。
全屏模式窗口不支持該操作。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用moveWindowTo()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
x | number | 是 | 窗口在x軸方向移動的值,值為正表示右移,單位為px。 |
y | number | 是 | 窗口在y軸方向移動的值,值為正表示下移,單位為px。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let promise = windowClass.moveTo(300, 300);
- promise.then(()=> {
- console.info('Succeeded in moving the window.');
- }).catch((err)=>{
- console.error('Failed to move the window. Cause: ' + JSON.stringify(err));
- });
resetSize(width: number, height: number, callback: AsyncCallback<void>): void
改變當前窗口大小,使用callback異步回調(diào)。
應用主窗口與子窗口存在大小限制,寬度范圍:[320, 2560],高度范圍:[240, 2560],單位為vp。
系統(tǒng)窗口存在大小限制,寬度范圍:[0, 2560],高度范圍:[0, 2560],單位為vp。
設(shè)置的寬度與高度受到此約束限制,規(guī)則: 若所設(shè)置的窗口寬/高尺寸小于窗口最小寬/高限值,則窗口最小寬/高限值生效; 若所設(shè)置的窗口寬/高尺寸大于窗口最大寬/高限值,則窗口最大寬/高限值生效。
全屏模式窗口不支持該操作。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用resize()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
width | number | 是 | 目標窗口的寬度,單位為px。 |
height | number | 是 | 目標窗口的高度,單位為px。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- windowClass.resetSize(500, 1000, (err) => {
- if (err.code) {
- console.error('Failed to change the window size. Cause:' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in changing the window size.');
- });
resetSize(width: number, height: number): Promise<void>
改變當前窗口大小,使用Promise異步回調(diào)。
應用主窗口與子窗口存在大小限制,寬度范圍:[320, 2560],高度范圍:[240, 2560],單位為vp。
系統(tǒng)窗口存在大小限制,寬度范圍:[0, 2560],高度范圍:[0, 2560],單位為vp。
設(shè)置的寬度與高度受到此約束限制,規(guī)則: 若所設(shè)置的窗口寬/高尺寸小于窗口最小寬/高限值,則窗口最小寬/高限值生效; 若所設(shè)置的窗口寬/高尺寸大于窗口最大寬/高限值,則窗口最大寬/高限值生效。
全屏模式窗口不支持該操作。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用resize()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
width | number | 是 | 目標窗口的寬度,單位為px。 |
height | number | 是 | 目標窗口的高度,單位為px。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let promise = windowClass.resetSize(500, 1000);
- promise.then(()=> {
- console.info('Succeeded in changing the window size.');
- }).catch((err)=>{
- console.error('Failed to change the window size. Cause: ' + JSON.stringify(err));
- });
getProperties(callback: AsyncCallback<WindowProperties>): void
獲取當前窗口的屬性,使用callback異步回調(diào),返回WindowProperties。
從 API version 6開始支持,從API version 9開始廢棄,推薦使用getWindowProperties()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<WindowProperties> | 是 | 回調(diào)函數(shù)。返回當前窗口屬性。 |
示例:
- 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(): Promise<WindowProperties>
獲取當前窗口的屬性,使用Promise異步回調(diào),返回WindowProperties。
從 API version 6開始支持,從API version 9開始廢棄,推薦使用getWindowProperties()。
系統(tǒng)能力: 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));
- });
getAvoidArea(type: AvoidAreaType, callback: AsyncCallback<AvoidArea>): void
獲取窗口內(nèi)容規(guī)避的區(qū)域;如系統(tǒng)欄區(qū)域、劉海屏區(qū)域、手勢區(qū)域、軟鍵盤區(qū)域等與窗口內(nèi)容重疊時,需要窗口內(nèi)容避讓的區(qū)域。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用getWindowAvoidArea()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | 是 | 表示規(guī)避區(qū)類型。 | |
callback | AsyncCallback<AvoidArea> | 是 | 回調(diào)函數(shù)。返回窗口內(nèi)容規(guī)避區(qū)域。 |
示例:
- let type = window.AvoidAreaType.TYPE_SYSTEM;
- windowClass.getAvoidArea(type, (err, data) => {
- if (err.code) {
- console.error('Failed to obtain the area. Cause:' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
- });
getAvoidArea(type: AvoidAreaType): Promise<AvoidArea>
獲取窗口內(nèi)容規(guī)避的區(qū)域;如系統(tǒng)欄區(qū)域、劉海屏區(qū)域、手勢區(qū)域、軟鍵盤區(qū)域等與窗口內(nèi)容重疊時,需要窗口內(nèi)容避讓的區(qū)域。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用getWindowAvoidArea()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | 是 | 表示規(guī)避區(qū)類型。 |
返回值:
類型 | 說明 |
---|---|
Promise<AvoidArea> | Promise對象。返回窗口內(nèi)容規(guī)避區(qū)域。 |
示例:
- let type = window.AvoidAreaType.TYPE_SYSTEM;
- let promise = windowClass.getAvoidArea(type);
- promise.then((data)=> {
- console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
- }).catch((err)=>{
- console.error('Failed to obtain the area. Cause:' + JSON.stringify(err));
- });
setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void
設(shè)置是否為全屏狀態(tài),使用callback異步回調(diào)。
從 API version 6開始支持,從API version 9開始廢棄,推薦聯(lián)合使用setWindowSystemBarEnable()和setWindowLayoutFullScreen()實現(xiàn)全屏。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isFullScreen | boolean | 是 | 是否設(shè)為全屏狀態(tài)(該全屏狀態(tài)隱藏狀態(tài)欄導航欄)。true表示全屏;false表示非全屏。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- let isFullScreen = true;
- windowClass.setFullScreen(isFullScreen, (err) => {
- 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.');
- });
setFullScreen(isFullScreen: boolean): Promise<void>
設(shè)置是否為全屏狀態(tài),使用Promise異步回調(diào)。
從 API version 6開始支持,從API version 9開始廢棄,推薦聯(lián)合使用setWindowSystemBarEnable()和setWindowLayoutFullScreen()實現(xiàn)全屏。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isFullScreen | boolean | 是 | 是否設(shè)為全屏狀態(tài)(該全屏狀態(tài)隱藏狀態(tài)欄導航欄)。true表示全屏;false表示非全屏。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let isFullScreen = true;
- let promise = windowClass.setFullScreen(isFullScreen);
- promise.then(()=> {
- console.info('Succeeded in enabling the full-screen mode.');
- }).catch((err)=>{
- console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
- });
setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void
設(shè)置窗口的布局是否為全屏顯示狀態(tài),使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用setWindowLayoutFullScreen()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isLayoutFullScreen | boolean | 是 | 窗口的布局是否為全屏顯示狀態(tài)(該全屏狀態(tài)下狀態(tài)欄、導航欄仍然顯示)。true表示全屏;false表示非全屏。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- let isLayoutFullScreen= true;
- windowClass.setLayoutFullScreen(isLayoutFullScreen, (err) => {
- 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.');
- });
setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void>
設(shè)置窗口的布局是否為全屏顯示狀態(tài),使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用setWindowLayoutFullScreen()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isLayoutFullScreen | boolean | 是 | 窗口的布局是否為全屏顯示狀態(tài)(該全屏狀態(tài)下狀態(tài)欄、導航欄仍然顯示)。true表示全屏;false表示非全屏。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let isLayoutFullScreen = true;
- let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen);
- promise.then(()=> {
- console.info('Succeeded in setting the window layout to full-screen mode.');
- }).catch((err)=>{
- console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
- });
setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void
設(shè)置導航欄、狀態(tài)欄的可見模式,使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用setWindowSystemBarEnable()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
names | Array<'status'|'navigation'> | 是 | 設(shè)置狀態(tài)欄和導航欄是否顯示。 例如,需全部顯示,該參數(shù)設(shè)置為['status', 'navigation'];不設(shè)置,則默認不顯示。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- // 此處以不顯示導航欄、狀態(tài)欄為例
- let names = [];
- windowClass.setSystemBarEnable(names, (err) => {
- if (err.code) {
- console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in setting the system bar to be invisible.');
- });
setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void>
設(shè)置導航欄、狀態(tài)欄的可見模式,使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用setWindowSystemBarEnable()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
names | Array<'status'|'navigation'> | 是 | 設(shè)置狀態(tài)欄和導航欄是否顯示。 例如,需全部顯示,該參數(shù)設(shè)置為['status', 'navigation'];不設(shè)置,則默認不顯示。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- // 此處以不顯示導航欄、狀態(tài)欄為例
- let names = [];
- let promise = windowClass.setSystemBarEnable(names);
- promise.then(()=> {
- console.info('Succeeded in setting the system bar to be invisible.');
- }).catch((err)=>{
- console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err));
- });
setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void
設(shè)置窗口內(nèi)導航欄、狀態(tài)欄的屬性,使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
SystemBarProperties | 是 | 導航欄、狀態(tài)欄的屬性。 | |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- let SystemBarProperties={
- statusBarColor: '#ff00ff',
- navigationBarColor: '#00ff00',
- //以下兩個屬性從API Version8開始支持
- statusBarContentColor:'#ffffff',
- navigationBarContentColor:'#00ffff'
- };
- windowClass.setSystemBarProperties(SystemBarProperties, (err) => {
- 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.');
- });
setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void>
設(shè)置窗口內(nèi)導航欄、狀態(tài)欄的屬性,使用Promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
SystemBarProperties | 是 | 導航欄、狀態(tài)欄的屬性。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let SystemBarProperties={
- statusBarColor: '#ff00ff',
- navigationBarColor: '#00ff00',
- //以下兩個屬性從API Version8開始支持
- statusBarContentColor:'#ffffff',
- navigationBarContentColor:'#00ffff'
- };
- let promise = windowClass.setSystemBarProperties(SystemBarProperties);
- promise.then(()=> {
- console.info('Succeeded in setting the system bar properties.');
- }).catch((err)=>{
- console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
- });
loadContent(path: string, callback: AsyncCallback<void>): void
為當前窗口加載具體頁面內(nèi)容,使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用setUIContent()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 要加載到窗口中的頁面內(nèi)容的路徑,Stage模型下該路徑需添加到工程的main_pages.json文件中,F(xiàn)A模型下該路徑需添加到工程的config.json文件中。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- windowClass.loadContent('pages/page2/page2', (err) => {
- if (err.code) {
- console.error('Failed to load the content. Cause:' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in loading the content.');
- });
loadContent(path: string): Promise<void>
為當前窗口加載具體頁面內(nèi)容,使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用setUIContent()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 要加載到窗口中的頁面內(nèi)容的路徑,Stage模型下該路徑需添加到工程的main_pages.json文件中,F(xiàn)A模型下該路徑需添加到工程的config.json文件中。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let promise = windowClass.loadContent('pages/page2/page2');
- promise.then(()=> {
- console.info('Succeeded in loading the content.');
- }).catch((err)=>{
- console.error('Failed to load the content. Cause: ' + JSON.stringify(err));
- });
isShowing(callback: AsyncCallback<boolean>): void
判斷當前窗口是否已顯示,使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用isWindowShowing()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。返回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));
- });
isShowing(): Promise<boolean>
判斷當前窗口是否已顯示,使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用isWindowShowing()。
系統(tǒng)能力: 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(type: 'systemAvoidAreaChange', callback: Callback<AvoidArea>): void
開啟系統(tǒng)規(guī)避區(qū)變化的監(jiān)聽。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用on('avoidAreaChange')。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 監(jiān)聽事件,固定為'systemAvoidAreaChange',即系統(tǒng)規(guī)避區(qū)變化事件。 |
callback | Callback<AvoidArea> | 是 | 回調(diào)函數(shù)。返回當前規(guī)避區(qū)。 |
示例:
- windowClass.on('systemAvoidAreaChange', (data) => {
- console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data));
- });
off(type: 'systemAvoidAreaChange', callback?: Callback<AvoidArea>): void
關(guān)閉系統(tǒng)規(guī)避區(qū)變化的監(jiān)聽。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用off('avoidAreaChange')。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 監(jiān)聽事件,固定為'systemAvoidAreaChange',即系統(tǒng)規(guī)避區(qū)變化事件。 |
callback | Callback<AvoidArea> | 否 | 回調(diào)函數(shù)。返回當前規(guī)避區(qū)。 |
示例:
- windowClass.off('systemAvoidAreaChange');
isSupportWideGamut(callback: AsyncCallback<boolean>): void
判斷當前窗口是否支持廣色域模式,使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄,推薦使用isWindowSupportWideGamut()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。返回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));
- });
isSupportWideGamut(): Promise<boolean>
判斷當前窗口是否支持廣色域模式,使用Promise異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄,推薦使用isWindowSupportWideGamut()。
系統(tǒng)能力: 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));
- });
setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void
設(shè)置當前窗口為廣色域模式或默認色域模式,使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄,推薦使用setWindowColorSpace()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
colorSpace | 是 | 設(shè)置色域模式。 | |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err) => {
- if (err.code) {
- console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in setting window colorspace.');
- });
setColorSpace(colorSpace:ColorSpace): Promise<void>
設(shè)置當前窗口為廣色域模式或默認色域模式,使用Promise異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄,推薦使用setWindowColorSpace()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
colorSpace | 是 | 設(shè)置色域模式。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT);
- promise.then(()=> {
- console.info('Succeeded in setting window colorspace.');
- }).catch((err)=>{
- console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err));
- });
getColorSpace(callback: AsyncCallback<ColorSpace>): void
獲取當前窗口色域模式,使用callback異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄,推薦使用getWindowColorSpace()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<ColorSpace> | 是 | 回調(diào)函數(shù)。當獲取成功,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));
- });
getColorSpace(): Promise<ColorSpace>
獲取當前窗口色域模式,使用Promise異步回調(diào)。
從 API version 8開始支持,從API version 9開始廢棄,推薦使用getWindowColorSpace()。
系統(tǒng)能力: 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(color: string, callback: AsyncCallback<void>): void
設(shè)置窗口的背景色,使用callback異步回調(diào)。Stage模型下,該接口需要在loadContent或setUIContent之后使用。
從 API version 6開始支持,從API version 9開始廢棄,推薦使用setWindowBackgroundColor()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
color | string | 是 | 需要設(shè)置的背景色,為十六進制RGB或ARGB顏色,不區(qū)分大小寫,例如#00FF00或#FF00FF00。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- let color = '#00ff33';
- windowClass.setBackgroundColor(color, (err) => {
- if (err.code) {
- console.error('Failed to set the background color. Cause: ' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in setting the background color.');
- });
setBackgroundColor(color: string): Promise<void>
設(shè)置窗口的背景色,使用Promise異步回調(diào)。Stage模型下,該接口需要在loadContent或setUIContent之后使用。
從 API version 6開始支持,從API version 9開始廢棄,推薦使用setWindowBackgroundColor()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
color | string | 是 | 需要設(shè)置的背景色,為十六進制RGB或ARGB顏色,不區(qū)分大小寫,例如#00FF00或#FF00FF00。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let color = '#00ff33';
- let promise = windowClass.setBackgroundColor(color);
- promise.then(()=> {
- console.info('Succeeded in setting the background color.');
- }).catch((err)=>{
- console.error('Failed to set the background color. Cause: ' + JSON.stringify(err));
- });
setBrightness(brightness: number, callback: AsyncCallback<void>): void
設(shè)置屏幕亮度值,使用callback異步回調(diào)。
當前屏幕亮度規(guī)格:窗口設(shè)置屏幕亮度生效時,控制中心不可以調(diào)整系統(tǒng)屏幕亮度,窗口恢復默認系統(tǒng)亮度之后,控制中心可以調(diào)整系統(tǒng)屏幕亮度。
從 API version 6開始支持,從API version 9開始廢棄,推薦使用setWindowBrightness()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
brightness | number | 是 | 屏幕亮度值,值為0-1之間。1表示最亮。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- let brightness = 1;
- windowClass.setBrightness(brightness, (err) => {
- if (err.code) {
- console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in setting the brightness.');
- });
setBrightness(brightness: number): Promise<void>
設(shè)置屏幕亮度值,使用Promise異步回調(diào)。
當前屏幕亮度規(guī)格:窗口設(shè)置屏幕亮度生效時,控制中心不可以調(diào)整系統(tǒng)屏幕亮度,窗口恢復默認系統(tǒng)亮度之后,控制中心可以調(diào)整系統(tǒng)屏幕亮度。
從 API version 6開始支持,從API version 9開始廢棄,推薦使用setWindowBrightness()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
brightness | number | 是 | 屏幕亮度值,值為0-1之間。1表示最亮。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let brightness = 1;
- let promise = windowClass.setBrightness(brightness);
- promise.then(()=> {
- console.info('Succeeded in setting the brightness.');
- }).catch((err)=>{
- console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err));
- });
setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void
窗口疊加時,設(shè)備有子窗口的情況下設(shè)置靠后的窗口的暗度值,使用callback異步回調(diào)。
該接口不支持使用。從 API version 7開始支持,從API version 9開始廢棄。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范圍為0-1,1表示最暗。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- windowClass.setDimBehind(0.5, (err) => {
- if (err.code) {
- console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in setting the dimness.');
- });
setDimBehind(dimBehindValue: number): Promise<void>
窗口疊加時,設(shè)備有子窗口的情況下設(shè)置靠后的窗口的暗度值,使用Promise異步回調(diào)。
該接口不支持使用。從 API version 7開始支持,從API version 9開始廢棄。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范圍為0-1,1表示最暗。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let promise = windowClass.setDimBehind(0.5);
- promise.then(()=> {
- console.info('Succeeded in setting the dimness.');
- }).catch((err)=>{
- console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err));
- });
setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void
設(shè)置點擊時是否支持切換焦點窗口,使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用setWindowFocusable()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isFocusable | boolean | 是 | 點擊時是否支持切換焦點窗口。true表示支持;false表示不支持。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- let isFocusable= true;
- windowClass.setFocusable(isFocusable, (err) => {
- 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.');
- });
setFocusable(isFocusable: boolean): Promise<void>
設(shè)置點擊時是否支持切換焦點窗口,使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用setWindowFocusable()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isFocusable | boolean | 是 | 點擊時是否支持切換焦點窗口。true表示支持;false表示不支持。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let isFocusable= true;
- let promise = windowClass.setFocusable(isFocusable);
- promise.then(()=> {
- console.info('Succeeded in setting the window to be focusable.');
- }).catch((err)=>{
- console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err));
- });
setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void
設(shè)置屏幕是否為常亮狀態(tài),使用callback異步回調(diào)。
從 API version 6開始支持,從API version 9開始廢棄,推薦使用setWindowKeepScreenOn()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isKeepScreenOn | boolean | 是 | 設(shè)置屏幕是否為常亮狀態(tài)。true表示常亮;false表示不常亮。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- let isKeepScreenOn = true;
- windowClass.setKeepScreenOn(isKeepScreenOn, (err) => {
- 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.');
- });
setKeepScreenOn(isKeepScreenOn: boolean): Promise<void>
設(shè)置屏幕是否為常亮狀態(tài),使用Promise異步回調(diào)。
從 API version 6開始支持,從API version 9開始廢棄,推薦使用setWindowKeepScreenOn()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isKeepScreenOn | boolean | 是 | 設(shè)置屏幕是否為常亮狀態(tài)。true表示常亮;false表示不常亮。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let isKeepScreenOn = true;
- let promise = windowClass.setKeepScreenOn(isKeepScreenOn);
- promise.then(() => {
- console.info('Succeeded in setting the screen to be always on.');
- }).catch((err)=>{
- console.info('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err));
- });
setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void
設(shè)置是否允許可點擊子窗口之外的區(qū)域,使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。
從 API version 9開始,系統(tǒng)默認允許點擊子窗口之外的區(qū)域,此接口不再支持使用,也不再提供替代接口。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
touchable | boolean | 是 | 設(shè)置是否可點擊。true表示可點擊;false表示不可點擊。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- windowClass.setOutsideTouchable(true, (err) => {
- 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.');
- });
setOutsideTouchable(touchable: boolean): Promise<void>
設(shè)置是否允許可點擊子窗口之外的區(qū)域,使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄。
從 API version 9開始,系統(tǒng)默認允許點擊子窗口之外的區(qū)域,此接口不再支持使用,也不再提供替代接口。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
touchable | boolean | 是 | 設(shè)置是否可點擊。true表示可點擊;false表示不可點擊。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let promise = windowClass.setOutsideTouchable(true);
- promise.then(()=> {
- console.info('Succeeded in setting the area to be touchable.');
- }).catch((err)=>{
- console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err));
- });
setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void
設(shè)置窗口是否為隱私模式,使用callback異步回調(diào)。設(shè)置為隱私模式的窗口,窗口內(nèi)容將無法被截屏或錄屏。此接口可用于禁止截屏/錄屏的場景。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用setWindowPrivacyMode()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isPrivacyMode | boolean | 是 | 窗口是否為隱私模式。true表示模式開啟;false表示模式關(guān)閉。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- let isPrivacyMode = true;
- windowClass.setPrivacyMode(isPrivacyMode, (err) => {
- 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.');
- });
setPrivacyMode(isPrivacyMode: boolean): Promise<void>
設(shè)置窗口是否為隱私模式,使用Promise異步回調(diào)。設(shè)置為隱私模式的窗口,窗口內(nèi)容將無法被截屏或錄屏。此接口可用于禁止截屏/錄屏的場景。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用setWindowPrivacyMode()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isPrivacyMode | boolean | 是 | 窗口是否為隱私模式。true表示模式開啟;false表示模式關(guān)閉。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let isPrivacyMode = true;
- let promise = windowClass.setPrivacyMode(isPrivacyMode);
- promise.then(()=> {
- console.info('Succeeded in setting the window to privacy mode.');
- }).catch((err)=>{
- console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err));
- });
setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void
設(shè)置窗口是否為可觸狀態(tài),使用callback異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用setWindowTouchable()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isTouchable | boolean | 是 | 窗口是否為可觸狀態(tài)。true表示可觸;false表示不可觸。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
示例:
- let isTouchable = true;
- windowClass.setTouchable(isTouchable, (err) => {
- 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.');
- });
setTouchable(isTouchable: boolean): Promise<void>
設(shè)置窗口是否為可觸狀態(tài),使用Promise異步回調(diào)。
從 API version 7開始支持,從API version 9開始廢棄,推薦使用setWindowTouchable()。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
isTouchable | boolean | 是 | 窗口是否為可觸狀態(tài)。true表示可觸;false表示不可觸。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- let isTouchable = true;
- let promise = windowClass.setTouchable(isTouchable);
- promise.then(()=> {
- console.info('Succeeded in setting the window to be touchable.');
- }).catch((err)=>{
- console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err));
- });
WindowStage生命周期。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
名稱 | 值 | 說明 |
---|---|---|
SHOWN | 1 | 切到前臺。 |
ACTIVE | 2 | 獲焦狀態(tài)。 |
INACTIVE | 3 | 失焦狀態(tài)。 |
HIDDEN | 4 | 切到后臺。 |
窗口管理器。管理各個基本窗口單元,即Window實例。
下列API示例中都需在onWindowStageCreate()函數(shù)中使用WindowStage的實例調(diào)用對應方法。
getMainWindow(callback: AsyncCallback<Window>): void
獲取該WindowStage實例下的主窗口,使用callback異步回調(diào)。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<Window> | 是 | 回調(diào)函數(shù)。返回當前WindowStage下的主窗口對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300005 | This window stage is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- class myAbility extends UIAbility {
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = null;
- windowStage.getMainWindow((err, data) => {
- if (err.code) {
- console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
- return;
- }
- windowClass = data;
- console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
- });
- }
- };
getMainWindow(): Promise<Window>
獲取該WindowStage實例下的主窗口,使用Promise異步回調(diào)。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
類型 | 說明 |
---|---|
Promise<Window> | Promise對象。返回當前WindowStage下的主窗口對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300005 | This window stage is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- class myAbility extends UIAbility {
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = null;
- let promise = windowStage.getMainWindow();
- promise.then((data) => {
- windowClass = data;
- console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
- }).catch((err) => {
- console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
- });
- }
- };
getMainWindowSync(): Window
獲取該WindowStage實例下的主窗口。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
類型 | 說明 |
---|---|
返回當前WindowStage下的主窗口對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300005 | This window stage is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- class myAbility extends UIAbility {
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- try {
- let windowClass = windowStage.getMainWindowSync();
- } catch (exception) {
- console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(exception));
- };
- }
- };
createSubWindow(name: string, callback: AsyncCallback<Window>): void
創(chuàng)建該WindowStage實例下的子窗口,使用callback異步回調(diào)。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 子窗口的名字。 |
callback | AsyncCallback<Window> | 是 | 回調(diào)函數(shù)。返回當前WindowStage下的子窗口對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300005 | This window stage is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- class myAbility extends UIAbility {
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = null;
- try {
- windowStage.createSubWindow('mySubWindow', (err, data) => {
- if (err.code) {
- console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
- return;
- }
- windowClass = data;
- console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
- windowClass.resize(500, 1000);
- });
- } catch (exception) {
- console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception));
- };
- }
- };
createSubWindow(name: string): Promise<Window>
創(chuàng)建該WindowStage實例下的子窗口,使用Promise異步回調(diào)。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
name | string | 是 | 子窗口的名字。 |
返回值:
類型 | 說明 |
---|---|
Promise<Window> | Promise對象。返回當前WindowStage下的子窗口對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300005 | This window stage is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- class myAbility extends UIAbility {
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = null;
- try {
- let promise = windowStage.createSubWindow('mySubWindow');
- promise.then((data) => {
- windowClass = data;
- console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
- }).catch((err) => {
- console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
- });
- } catch (exception) {
- console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception));
- };
- }
- };
getSubWindow(callback: AsyncCallback<Array<Window>>): void
獲取該WindowStage實例下的所有子窗口,使用callback異步回調(diào)。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<Array<Window>> | 是 | 回調(diào)函數(shù)。返回當前WindowStage下的所有子窗口對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300005 | This window stage is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- class myAbility extends UIAbility {
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = null;
- windowStage.getSubWindow((err, data) => {
- if (err.code) {
- console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err));
- return;
- }
- windowClass = data;
- console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data));
- });
- }
- };
getSubWindow(): Promise<Array<Window>>
獲取該WindowStage實例下的所有子窗口,使用Promise異步回調(diào)。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
類型 | 說明 |
---|---|
Promise<Array<Window>> | Promise對象。返回當前WindowStage下的所有子窗口對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300005 | This window stage is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- class myAbility extends UIAbility {
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = null;
- let promise = windowStage.getSubWindow();
- promise.then((data) => {
- windowClass = data;
- console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data));
- }).catch((err) => {
- console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err));
- })
- }
- };
loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void
為當前WindowStage的主窗口加載與LocalStorage相關(guān)聯(lián)的具體頁面內(nèi)容,使用callback異步回調(diào)。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 要加載到窗口中的頁面內(nèi)容的路徑,該路徑需添加到工程的main_pages.json文件中。 |
storage | 是 | 存儲單元,為應用程序范圍內(nèi)的可變狀態(tài)屬性和非可變狀態(tài)屬性提供存儲。 | |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300005 | This window stage is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- class myAbility extends UIAbility {
- storage : LocalStorage
- onWindowStageCreate(windowStage) {
- this.storage = new LocalStorage();
- this.storage.setOrCreate('storageSimpleProp',121);
- console.log('onWindowStageCreate');
- try {
- windowStage.loadContent('pages/page2',this.storage,(err) => {
- if (err.code) {
- 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));
- };
- }
- };
loadContent(path: string, storage?: LocalStorage): Promise<void>
為當前WindowStage的主窗口加載與LocalStorage相關(guān)聯(lián)的具體頁面內(nèi)容,使用Promise異步回調(diào)。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 要加載到窗口中的頁面內(nèi)容的路徑,該路徑需添加到工程的main_pages.json文件中。 |
storage | 否 | 存儲單元,為應用程序范圍內(nèi)的可變狀態(tài)屬性和非可變狀態(tài)屬性提供存儲。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300005 | This window stage is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- class myAbility extends UIAbility {
- storage : LocalStorage
- onWindowStageCreate(windowStage) {
- this.storage = new LocalStorage();
- 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) => {
- console.error('Failed to load the content. Cause:' + JSON.stringify(err));
- });
- } catch (exception) {
- console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
- };
- }
- };
loadContent(path: string, callback: AsyncCallback<void>): void
為當前WindowStage的主窗口加載具體頁面內(nèi)容,使用callback異步回調(diào)。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 要加載到窗口中的頁面內(nèi)容的路徑,該路徑需添加到工程的main_pages.json文件中。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300005 | This window stage is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- class myAbility extends UIAbility {
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- try {
- 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.');
- });
- } catch (exception) {
- console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
- };
- }
- };
on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void
開啟WindowStage生命周期變化的監(jiān)聽。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 監(jiān)聽事件,固定為'windowStageEvent',即WindowStage生命周期變化事件。 |
callback | Callback<WindowStageEventType> | 是 | 回調(diào)函數(shù)。返回當前的WindowStage生命周期狀態(tài)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300005 | This window stage is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- class myAbility extends UIAbility {
- onWindowStageCreate(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(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType>): void
關(guān)閉WindowStage生命周期變化的監(jiān)聽。
模型約束: 此接口僅可在Stage模型下使用。
系統(tǒng)能力: SystemCapability.WindowManager.WindowManager.Core
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 監(jiān)聽事件,固定為'windowStageEvent',即WindowStage生命周期變化事件。 |
callback | Callback<WindowStageEventType> | 否 | 回調(diào)函數(shù)。返回當前的WindowStage生命周期狀態(tài)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見窗口錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
1300002 | This window state is abnormal. |
1300005 | This window stage is abnormal. |
示例:
- import UIAbility from '@ohos.app.ability.UIAbility';
- class myAbility extends UIAbility {
- onWindowStageCreate(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));
- };
- }
更多建議: