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() {}

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

HarmonyOS
2025-01-09 16:33:21
浏览
收藏 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')
  }
}
分享
微博
QQ
微信
回复
2025-01-09 18:52:03
相关问题
HarmonyOS CustomBuilder加载慢
374浏览 • 1回复 待解决
HarmonyOS Span属性设置失效
228浏览 • 1回复 待解决
HarmonyOS Navigation标题居中,背景设置
1512浏览 • 1回复 待解决
HarmonyOS relativeContainer设置guideLine属性
304浏览 • 1回复 待解决
HarmonyOS 属性字符如何设置
162浏览 • 1回复 待解决
HarmonyOS Navigation导航子页面别名设置
333浏览 • 1回复 待解决
HarmonyOS 组件设置属性无效果
815浏览 • 1回复 待解决
组件设置visibility属性回调
737浏览 • 2回复 待解决
如何动态设置组件属性
1090浏览 • 1回复 待解决