新版的DevEco Studio(5.0)存在预览中屏幕上下各有一条空白
这是因为系统分为安全区域和非安全区域,安全区域是页面的显示区域不会和系统设置的非安全区域(比如状态栏、导航栏区域)重叠。
@Entry
@Component
struct Index {
build() {
Column(){
}
.width('100%')
.height('100%')
.backgroundColor(Color.Pink)
}
}
import { window } from '@kit.ArkUI';
在代码顶端引入以上代码后,于struct中填入
onPageShow(): void {
window.getLastWindow(getContext(this),(err,data)=>{
if(!err.code) {
data.setWindowLayoutFullScreen(true);
}
})
}
全部代码如下
import { window } from '@kit.ArkUI';
@Entry
@Component
struct Index {
onPageShow(): void {
window.getLastWindow(getContext(this),(err,data)=>{
if(!err.code) {
data.setWindowLayoutFullScreen(true);
}
})
}
build() {
Column(){
}
.width('100%')
.height('100%')
.backgroundColor(Color.Pink)
}
}
效果图: