这是应用了[沉浸式的特性],其中状态栏和导航条,在沉浸式布局下称为避让区,避让区之外的区域称为安全区,在默认情况下,开发者的组件被布局在安全区内。
如果希望将页面布局应用到全屏窗口,可以采用如下两种方式: 方法一:可以使用 expandSafeArea 扩展安全区域属性进行调整。
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
build() {
RelativeContainer() {
Text(this.message)
}
.height('100%')
.width('100%')
.backgroundColor('#008800')
.expandSafeArea([SafeAreaType.SYSTEM]) ///将布局改为全屏
}
}
方法二:可以调用 setWindowLayoutFullScreen () 接口设置窗口为全屏。
onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err) => {
…..
});
windowStage.getMainWindow((err, data) => {
if (!err.code) {
data.setWindowLayoutFullScreen(true) ///将布局改为全屏
}
});
}