HarmonyOS Navigation无法正确显示

视图层为Tabs-TabContent-Navigation。Tabs里循环创建5个TabContent,然后每个TabContent里就是一个导航控制器Navigation,但是导航栏掉下来了一半。

HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
shlp

参考示例:

EntryAbility.ets:

import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
  }

  onDestroy(): void {
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
  }

  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) => {
      if (err.code) {
        hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
        return;
      }
      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
    });

    let windowClass: window.Window = windowStage.getMainWindowSync();
    // 1. 设置窗口全屏
    let isLayoutFullScreen = true;
    windowClass.setWindowLayoutFullScreen(isLayoutFullScreen)
      .then(() => {
        console.info('Succeeded in setting the window layout to full-screen mode.');
      })
      .catch((err: BusinessError) => {
        console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
      });
  }
  onWindowStageDestroy(): void {
    // Main window is destroyed, release UI related resources
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
  }
  onForeground(): void {
    // Ability has brought to foreground
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
  }
  onBackground(): void {
    // Ability has back to background
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
  }
}

Index.ets:

@Entry
@Component
struct Index {
  private tabBarItemList: string[] = ["首页", "门店", "工单", "资产", "我的"]
  @State private currentIndex: number = 0;
  @Builder
  private buildNavigationTitle(item: string) {
    Column() {
      Text(item)
        .fontSize(16)
        .fontWeight(FontWeight.Regular)
        .fontColor(Color.Red)
    }
    .height("100%")
    .width("100%")
    .backgroundColor(Color.Orange)
    .align(Alignment.Center)
    .justifyContent(FlexAlign.Center)
  }

  @Builder
  private buildTabBarItem(item: string, index: number) {
    Text(item)
      .fontSize(12)
      .fontWeight(FontWeight.Regular)
      .fontColor(index === this.currentIndex ? "#0A59F7" : "#7F7F7F")
  }

  build() {
    Tabs({
      barPosition: BarPosition.End,
      index: this.currentIndex
    }) {
      ForEach(
        this.tabBarItemList,
        (item: string, index: number) => {
          TabContent() {
            Navigation() {
              Column() {
                Text(item).fontSize(30)
              }
              .height("100%")
              .width("100%")
              .backgroundColor(Color.Green)
              .justifyContent(FlexAlign.Start)
            }
            .title(this.buildNavigationTitle(item))
            .backgroundColor(Color.Red)
          }
          .width("100%")
          .height("100%")
          .backgroundColor(Color.Yellow)
          .tabBar(this.buildTabBarItem(item, index))
        }
      )
    }
    .onChange((index: number) => {
      this.currentIndex = index;
    })
    .scrollable(false)
    .animationDuration(0)
    .barBackgroundColor("#F1F3F5")
    .divider({
      strokeWidth: 0.5,
    })
  }
}

需要给给navigation设置:

Navigation() {}
.titleMode(NavigationTitleMode.Mini)
.hideBackButton(true)
分享
微博
QQ
微信
回复
2天前
相关问题
HarmonyOS 无法正确生成
0浏览 • 1回复 待解决
HarmonyOSNavigation显示dialog问题
491浏览 • 1回复 待解决
HarmonyOS Navigation中title怎么居中显示
28浏览 • 1回复 待解决
HarmonyOS heif图片无法显示
13浏览 • 1回复 待解决
Fluttertoast无法HarmonyOS显示
19浏览 • 1回复 待解决
HarmonyOS px2vp在模拟器上无法正确转换
539浏览 • 1回复 待解决
HarmonyOS TextArea显示无法自动聚焦
60浏览 • 1回复 待解决
HarmonyOS 跨module调用组件,无法显示
340浏览 • 1回复 待解决
HarmonyOS webview加载页面无法显示
708浏览 • 1回复 待解决
来电横幅通知头像无法显示
1811浏览 • 1回复 待解决
HarmonyOS Image组件无法显示网络图片
1126浏览 • 1回复 待解决