0
点赞
收藏
分享

微信扫一扫

【Harmony OS】【ARK UI】js或ETS如何获取状态栏高度


 在Harmony OS项目怎么获取状态高度?
在开发中我们可以参考​​窗口​​的getAvoidArea和getTopWindow的api,分为“代码实现”,“运行效果”两个步骤进行实现

【Harmony OS】【ARK UI】js或ETS如何获取状态栏高度_json

【Harmony OS】【ARK UI】js或ETS如何获取状态栏高度_代码实现_02

  1. 代码实现
    全部代码如下

import window from '@ohos.window';
@Entry
@Component
struct Index {
@State statusBarHeight:number=-1
public click(){
window.getTopWindow((err, data) => {
var windowClass = data;
var type = window.AvoidAreaType.TYPE_SYSTEM;
windowClass.getAvoidArea(type, (err, data) => {
if (err) {
console.error('Failed to obtain the area. Cause:' + JSON.stringify(err));
return;
}
this. statusBarHeight = data.topRect.height;
console.log("statusBarHeight====>>>>"+this.statusBarHeight);
});
});
}
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('获取状态栏高度')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(this.click.bind(this))

Text('状态栏高度'+this.statusBarHeight)
.fontSize(50)
.margin(10)
.fontColor(Color.Red)
}
.width('100%')
.height('100%')
}
}

  1. 【Harmony OS】【ARK UI】js或ETS如何获取状态栏高度_状态栏高度_03

2.运行效果
效果如下

【Harmony OS】【ARK UI】js或ETS如何获取状态栏高度_json_04

欲了解更多更全技术文章,欢迎访问:https://developer.huawei.com/consumer/cn/forum/topic/0203803170703380031?fid=0102683795438680754?ha_source=zzh

举报

相关推荐

0 条评论