在實際生產中,進場遇到需要關閉導航欄和狀態欄的需求,現分享解決辦法:
開發環境
OpenHarmony 5.0.0r
代碼分析
思路: launcher本身可以關閉 導航欄(實際是 公共事件,發送消息給systemUI來實控制)
systemUI中product\default\navigationBar\src\main\ets\viewmodel\NavigationBarViewModel.ts 中
private windowSwitches(navigationBarStatusValue: string): void {this.isDisplay = navigationBarStatusValue == '1' ? true : false;if (!this.isDisplay || !this.mNavigationBarComponentData.isEnable) {//For gesture navigation scenarios//Systemui hides the navigation bar,and then notifies the launcher that it can start moving down the dock bar.WindowManager.hideWindow(WindowType.STATUS_BAR).then(() => {//關狀態欄}).catch((err) => {Log.showError(TAG, `${NAVIGATIONBAR_HIDE_EVENT} Publish catch err: ${JSON.stringify(err)}`);});WindowManager.hideWindow(WindowType.NAVIGATION_BAR).then(() => {//關導航欄}).catch((err) => {Log.showError(TAG, `${NAVIGATIONBAR_HIDE_EVENT} Publish catch err: ${JSON.stringify(err)}`);});} else {WindowManager.showWindow(WindowType.STATUS_BAR).then(() => {//開狀態欄}).catch((err) => {});WindowManager.showWindow(WindowType.NAVIGATION_BAR).then(() => {//開導航欄}).catch((err) => {});}}