开始学习鸿蒙,自己写个项目,app开发中,经常会需要隐藏顶部导航栏,在网上没找到资料,去翻看鸿蒙开发文档,找到了解决方法
项目我使用的Stage模型
1. 找到自动生成入口文件EntryAbility.ets 文件中,类继承的UIAbility
2. 在onWindowStageCreate方法里写以下代码
设置setWindowLayoutFullScreen方法和setWindowSystemBarEnable
onWindowStageCreate(windowStage: window.WindowStage)
let names = []
try { windowStage.getMainWindowSync().setWindowLayoutFullScreen(true,(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.'); }) windowStage.getMainWindowSync().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)); }
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
标签:ArkTS,console,状态栏,err,Failed,stringify,HarmonyOS,JSON,Cause From: https://www.cnblogs.com/timipaul/p/17717976.html