HarmonyOS Navigation的toolbarConfiguration属性怎么设置customBuilder

@State TooTmp: ToolbarItem = {
  'value': "func", 'icon': "./image/ic_public_highlights.svg", 'action': () => {
    // this.pageInfos.pushPath({ name: "NavDestinationTitle" + '99999' })
    this.pageInfos.pushPathByName('Page1', 1);
  }
}
  .toolbarConfiguration([this.TooTmp, this.TooTmp,this.customToolbarBuilder()])

@Builder customToolbarBuilder() {}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

toolbarConfiguration前两个使用ToolbarItem,后面使用customBuilder这种写法有报错。

HarmonyOS
2025-01-09 16:33:21
586浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

有关toolbarConfiguration的使用,可以参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-navigation-V5#toolbarconfiguration10

参考示例如下:

class ActionFn {
  onclick: Function = () => {
  }
}

@Entry
@Component
struct NavigationExample {
  @State TooTmp: ToolbarItem = {
    'value': "func", 'icon': "./image/ic_public_highlights.svg", 'action': () => {
    }
  }
  private arr: number[] = [1, 2, 3];
  testOnClick = (params: string) => {
    console.log('Test' + params)
  }

  @Builder
  test(action: ActionFn) {
    Column() {
      Text('Test').onClick(() => {
        action.onclick('Test')
      })
    }
  }

  build() {
    Column() {
      Navigation() {
        List({ space: 12 }) {
          ForEach(this.arr, (item: string) => {
            ListItem() {
              NavRouter() {
                Text("NavRouter" + item)
                  .width("100%")
                  .height(72)
                  .backgroundColor('#FFFFFF')
                  .borderRadius(24)
                  .fontSize(16)
                  .fontWeight(500)
                  .textAlign(TextAlign.Center)
                NavDestination() {
                  Text("NavDestinationContent" + item)
                }
                .title("NavDestinationTitle" + item)
              }
            }
          }, (item: string): string => item)
        }
        .width("90%")
        .margin({ top: 12 })
      }
      .title("主标题")
      .mode(NavigationMode.Split)
      .toolbarConfiguration(this.test({ onclick: this.testOnClick }))
    }
    .height('100%')
    .width('100%')
    .backgroundColor('#F1F3F5')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
分享
微博
QQ
微信
回复
2025-01-09 18:52:03


相关问题
HarmonyOS CustomBuilder加载慢
700浏览 • 1回复 待解决
HarmonyOS Span属性设置失效
565浏览 • 1回复 待解决
HarmonyOS 属性字符如何设置
446浏览 • 1回复 待解决
HarmonyOS relativeContainer设置guideLine属性
653浏览 • 1回复 待解决
HarmonyOS Navigation标题居中,背景设置
1962浏览 • 1回复 待解决
HarmonyOS 组件设置属性无效果
1141浏览 • 1回复 待解决
HarmonyOS Navigation导航子页面别名设置
839浏览 • 1回复 待解决
组件设置visibility属性回调
1043浏览 • 2回复 待解决
如何动态设置组件属性
1445浏览 • 1回复 待解决