使用getWindowDecorHeight获取标题栏三键按钮区域,同时页面使用padding避让该区域。
import { common } from '@kit.AbilityKit';
@Entry
@Component
struct DecorHeightDemo {
@State titleHeight: number = 0;
aboutToAppear(): void {
try {
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let windowStage = context.windowStage;
let windowClass = windowStage.getMainWindowSync();
// 获取标题栏高度
this.titleHeight = windowClass.getWindowDecorHeight();
windowClass.setWindowDecorVisible(false);
} catch (exception) {
console.error(`Failed to enable the listener for window title buttons area changes. Cause code: ${exception.code}, message: ${exception.message}`);
}
}
build() {
Column() {
Text('测试页面内容是否会被遮挡');
}
.width('100%')
.height('100%')
.alignItems(HorizontalAlign.End)
// 使用padding避让
.padding({ top: this.titleHeight });
}
}