智能客服
你问我答,随时在线为你解决问题
应用元服务在设备上打开时,右上角胶囊(menuBar)与应用组件重叠遮挡。

应用未使用Navigation容器组件自动避让系统UI,也未使用getBarRect获取menuBar相对窗口的布局信息,手动使用padding避让元服务的右上角胶囊(menuBar)区域,导致遮挡了页面组件。
- import { AtomicServiceBar } from '@kit.ArkUI';
-
- @Entry
- @Component
- struct BarRectDemo {
- private message: string = 'Hello World';
- @State rect: number = 0;
-
- build() {
- Column() {
- Text(this.message)
- .id('HelloWorld')
- .fontSize($r('app.float.page_text_font_size'))
- .fontWeight(FontWeight.Bold)
- .alignRules({
- center: { anchor: '__container__', align: VerticalAlign.Center },
- middle: { anchor: '__container__', align: HorizontalAlign.Center }
- });
- }
- .width('100%')
- .justifyContent(FlexAlign.End)
- .alignItems(HorizontalAlign.End)
- .padding({ top: this.rect });
- }
-
- onPageShow() {
- setTimeout(() => {
- let uiContext: UIContext = this.getUIContext();
- let currentBar: Nullable<AtomicServiceBar> = uiContext.getAtomicServiceBar();
- if (currentBar !== undefined) {
- this.rect = currentBar.getBarRect().height;
- }
- }, 0); // 延迟确保渲染完成
- }
- }