全局检索setWindowLayoutFullScreen,应用通过setWindowLayoutFullScreen配置了全屏模式,且未设置padding避让导航栏和状态栏。
@Entry
@Component
struct WebComponent {
aboutToAppear(): void {
let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
window.getLastWindow(context).then((lastWindow) => {
lastWindow.setWindowLayoutFullScreen(true); // 设置全屏
});
}
build() {
Column() {
// 页面内容
}
// 未设置padding避让导航栏和状态栏
}
} 在开启全屏模式后,通过padding避让状态栏和导航栏。
import { TipsDialog, window } from '@kit.ArkUI';
import { common } from '@kit.AbilityKit';
@Entry
@Component
struct AvoidArea {
dialogController: CustomDialogController = new CustomDialogController({
builder: TipsDialog({
content: '是否确认无误',
primaryButton: {
value: '取消',
action: () => {
this.dialogController.close();
},
},
secondaryButton: {
value: '确定',
role: ButtonRole.ERROR,
action: () => {
this.dialogController.close();
}
}
}),
});
@State statusHeight: number = 0;
@State navigationHeight: number = 0;
aboutToAppear(): void {
let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
window.getLastWindow(context).then((lastWindow) => {
lastWindow.setWindowLayoutFullScreen(true); // 设置全屏
this.statusHeight = lastWindow.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height; // 获取状态栏高度
this.navigationHeight =
lastWindow.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height; // 获取导航栏高度
});
}
build() {
Column() {
TextInput({ placeholder: '请输入内容' })
.width('80%')
.height(40)
.borderRadius('50%')
.margin({ bottom: 350 });
Button('确认')
.height(30)
.width(90)
.borderRadius('50%')
.backgroundColor('#0A59F7')
.margin({ bottom: 2 })
.onClick(() => {
this.dialogController.open();
});
}
.height('100%')
.width('100%')
.justifyContent(FlexAlign.End)
.padding({ top: this.statusHeight + 'px', bottom: this.navigationHeight + 'px' }); // 设置padding避让导航栏和状态栏
}
} 效果图如下:
