在APP开发中发现状态栏是黑色,与设计图不符,按照如下修改即可
按如下路径找到文件src->main->ets->entryability->EntryAbility.ets
onWindowStageCreate(windowStage: window.WindowStage) {
//设置状态栏颜色
windowStage.getMainWindow((err,windowClass) => {
if(err.code){
console.log(JSON.stringify(err))
}
//设置沉浸式效果
windowClass.setWindowLayoutFullScreen(true,(error,data) => {
if(error.code == 0){
console.log("设置成功")
}else{
console.log("设置失败")
}
})
//将顶部状态栏的高度空出来
const statusBarHeight = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height
CommonConstants.STATUS_BAR_HEIGHT = statusBarHeight;
}
在之后的开发中,写UI时上方需要将statusBarHeight空出来,该值为px,开发中可使用px2vp()进行单位转换再使用