实战15-状态栏高度问题

async onWindowStageCreate(windowStage: window.WindowStage): Promise<void> { // 3.为沉浸式窗口加载对应的目标页面。 windowStage.loadContent("pages/Index", (err) => { if (err.code) { console.error('Failed to load the content. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in loading the content.'); }); //1.设置全屏 //应用窗口对象 const windowClass = await windowStage.getMainWindow() //设置全屏 windowClass.setWindowLayoutFullScreen(true) //获取状态栏高度 const avoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM) //单位是px const topHeight = avoidArea.topRect.height; //将状态高度存储起来 AppStorage.setOrCreate('topHeight', px2vp(topHeight)) const prop = windowClass.getWindowProperties() hilog.info(0x0000, 'atguigu', JSON.stringify(prop)) }

修改EntryAbility.ets的  

onWindowStageCreate方法修改为 async 返回参数Promise<void>

 存储起来状态栏高度 在需要使用的地方取出

AppStorage.setOrCreate('topHeight', px2vp(topHeight))

取出方法:

@StorageProp('topHeight') topHeight: number = 0
例如:height(211 - 36 + this.topHeight) 

注:模拟器运行和预览完全不一样,需要使用模拟器去查看效果。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值