鸿蒙5.0开发实战:全屏模式

12 篇文章 0 订阅
12 篇文章 0 订阅

往期鸿蒙全套实战精彩文章必看内容:


所谓全屏模式,就是让应用占满整个屏幕:

图片

在鸿蒙开发中可以使用如下方式实现全屏模式:

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单位或使用字符串形式。

 

  • 10
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值