全屏沉浸:同时隐藏顶部状态栏与底部手势条
横屏游戏外壳下顶部状态栏与底部导航条都会遮挡/拦截 H5 内容点击。 setWindowSystemBarEnable 入参由 ['status'] 改为 [],两个系统栏均隐藏, 内容延伸至屏幕上下边缘。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
53fdd6d358
commit
a2758333cc
@@ -37,9 +37,8 @@ export default class EntryAbility extends UIAbility {
|
|||||||
// Main window is created, set main page for this ability
|
// Main window is created, set main page for this ability
|
||||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
||||||
|
|
||||||
// 隐藏底部系统手势条(导航条):横屏游戏外壳下其会遮挡并拦截 H5 底部点击。
|
// 全屏沉浸:隐藏顶部状态栏 + 底部导航条(手势条),二者均会遮挡/拦截 H5 内容点击。
|
||||||
// 保留顶部状态栏,避免给 H5 顶部内容引入新的避让遮挡。
|
this.hideSystemBars(windowStage);
|
||||||
this.hideNavigationBar(windowStage);
|
|
||||||
|
|
||||||
windowStage.loadContent('pages/Index', (err) => {
|
windowStage.loadContent('pages/Index', (err) => {
|
||||||
if (err.code) {
|
if (err.code) {
|
||||||
@@ -51,18 +50,18 @@ export default class EntryAbility extends UIAbility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 隐藏底部导航条(手势指示条),回收其占用空间给 H5 内容。
|
* 全屏沉浸:隐藏顶部状态栏与底部导航条(手势条),把整屏让给 H5 内容。
|
||||||
* setWindowSystemBarEnable 的入参是"需要显示"的系统栏集合:仅传 'status'
|
* setWindowSystemBarEnable 的入参是"需要显示"的系统栏集合:传空数组 []
|
||||||
* → 顶部状态栏保留、底部导航条隐藏。隐藏后避让区更新,内容自动延伸到屏幕底部。
|
* → 状态栏与导航条均隐藏。隐藏后避让区更新,内容自动延伸到屏幕上下边缘。
|
||||||
*/
|
*/
|
||||||
private hideNavigationBar(windowStage: window.WindowStage): void {
|
private hideSystemBars(windowStage: window.WindowStage): void {
|
||||||
try {
|
try {
|
||||||
const mainWin: window.Window = windowStage.getMainWindowSync();
|
const mainWin: window.Window = windowStage.getMainWindowSync();
|
||||||
mainWin.setWindowSystemBarEnable(['status']).catch((e: BusinessError) => {
|
mainWin.setWindowSystemBarEnable([]).catch((e: BusinessError) => {
|
||||||
hilog.error(DOMAIN, 'testTag', 'setWindowSystemBarEnable failed: %{public}s', JSON.stringify(e));
|
hilog.error(DOMAIN, 'testTag', 'setWindowSystemBarEnable failed: %{public}s', JSON.stringify(e));
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
hilog.error(DOMAIN, 'testTag', 'hideNavigationBar threw: %{public}s', JSON.stringify(e));
|
hilog.error(DOMAIN, 'testTag', 'hideSystemBars threw: %{public}s', JSON.stringify(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user