往期鸿蒙全套实战精彩文章必看内容:
所谓全屏模式,就是让应用占满整个屏幕:
在鸿蒙开发中可以使用如下方式实现全屏模式:
let isLayoutFullScreen= true;
let windowClass = windowStage.getMainWindowSync()
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));
}
在全屏模式下,我们要注意规避顶部状态栏、刘海屏、底部工具栏等区域,获取规避区域尺寸的方法如下:
let type = window.AvoidAreaType.TYPE_SYSTEM;
try {
let avoidArea = windowClass.getWindowAvoidArea(type);
console.log('规避区域:' + JSON.stringify(avoidArea));
} catch (exception) {
console.error('Failed to obtain the area. Cause:' + JSON.stringify(exception));
}
规避区域:{"visible":true,"leftRect":{"left":0,"top":0,"width":0,"height":0},"topRect":{"left":0,"top":0,"width":1228,"height":108},"rightRect":{"left":0,"top":0,"width":0,"height":0},"bottomRect":{"left":0,"top":2570,"width":1228,"height":130}}
要注意此时获取到的尺寸单位为px,使用时需要转为vp单位或使用字符串形式。