一、體驗(yàn)窗口沉浸式能力說(shuō)明
在看視頻、玩游戲等場(chǎng)景下,用戶往往希望隱藏狀態(tài)欄、導(dǎo)航欄等不必要的系統(tǒng)窗口,從而獲得更佳的沉浸式體驗(yàn)。此時(shí)可以借助窗口沉浸式能力(窗口沉浸式能力都是針對(duì)應(yīng)用主窗口而言的),達(dá)到預(yù)期效果。
二、開(kāi)發(fā)步驟
1.獲取應(yīng)用主窗口。
通過(guò)getMainWindow接口獲取應(yīng)用主窗口。
2.實(shí)現(xiàn)沉浸式效果。
調(diào)用setWindowSystemBarEnable接口,設(shè)置導(dǎo)航欄、狀態(tài)欄不顯示,從而達(dá)到沉浸式效果。
3.加載顯示沉浸式窗口的具體內(nèi)容。
通過(guò)loadContent接口加載沉浸式窗口的具體內(nèi)容。
import UIAbility from '@ohos.app.ability.UIAbility';
export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
// 1.獲取應(yīng)用主窗口。
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));
// 2.實(shí)現(xiàn)沉浸式效果:設(shè)置導(dǎo)航欄、狀態(tài)欄不顯示。
let names = [];
windowClass.setWindowSystemBarEnable(names, (err) = > {
if (err.code) {
console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the system bar to be visible.');
});
})
// 3.為沉浸式窗口加載對(duì)應(yīng)的目標(biāo)頁(yè)面。
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.');
});
}
};
審核編輯 黃宇
-
模型
+關(guān)注
關(guān)注
1文章
3521瀏覽量
50421 -
鴻蒙
+關(guān)注
關(guān)注
60文章
2620瀏覽量
44052 -
鴻蒙OS
+關(guān)注
關(guān)注
0文章
191瀏覽量
4992
發(fā)布評(píng)論請(qǐng)先 登錄
鴻蒙應(yīng)用/元服務(wù)開(kāi)發(fā)-窗口(Stage模型)設(shè)置應(yīng)用主窗口
鴻蒙應(yīng)用/元服務(wù)開(kāi)發(fā)-窗口(Stage模型)體驗(yàn)窗口沉浸式能力
KaihongOS操作系統(tǒng)FA模型與Stage模型介紹
Stage模型深入解讀
鴻蒙原生應(yīng)用/元服務(wù)開(kāi)發(fā)-Stage模型能力接口(一)
鴻蒙原生應(yīng)用/元服務(wù)開(kāi)發(fā)-Stage模型能力接口(二)
鴻蒙原生應(yīng)用/元服務(wù)開(kāi)發(fā)-Stage模型能力接口(四)
鴻蒙原生應(yīng)用/元服務(wù)開(kāi)發(fā)-Stage模型能力接口(五)
鴻蒙原生應(yīng)用/元服務(wù)開(kāi)發(fā)-Stage模型能力接口(六)
鴻蒙原生應(yīng)用/元服務(wù)開(kāi)發(fā)-Stage模型能力接口(七)
鴻蒙原生應(yīng)用/元服務(wù)開(kāi)發(fā)-Stage模型能力接口(八)
Stage模型深入解讀
鴻蒙OS元服務(wù)開(kāi)發(fā):【(Stage模型)設(shè)置應(yīng)用主窗口】

評(píng)論