HarmonyOS Navigation中的title怎么通过CustomBuilder自定义标题呢

title(value: ResourceStr | CustomBuilder | NavigationCommonTitle | NavigationCustomTitle, options?: NavigationTitleOptions) 

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-navigation-V5

HarmonyOS
2025-01-09 14:46:07
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Excelsior_abit

可以参考下面的demo来自定义标题:

import { NavRouterDemo } from './NavRouterDemo';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';
  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack()
  @Builder
  PageMap(name: string) {
    if (name === "NavRouterDemo") {
      NavRouterDemo()
    }
  }
  @Builder
  title(){
    Image($r('app.media.startIcon'))
      .width('50vp')
  }

  build() {
    Navigation(this.pageInfos){
      RelativeContainer() {
        Text(this.message)
          .id('HelloWorld')
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .alignRules({
            center: { anchor: '__container__', align: VerticalAlign.Center },
            middle: { anchor: '__container__', align: HorizontalAlign.Center }
          })
          .onClick(() => {
            this.pageInfos.pushPathByName('NavRouterDemo',null)
          })
      }
      .height('100%')
      .width('100%')
    }
    .navDestination(this.PageMap)
    .title(this.title())
  }
}
分享
微博
QQ
微信
回复
2025-01-09 17:55:46
相关问题
HarmonyOS Navigationtitle怎么居中显示
370浏览 • 1回复 待解决
HarmonyOS 怎么自定义TabTabbar
329浏览 • 1回复 待解决
HarmonyOS 如何动态设置导航栏title标题
180浏览 • 1回复 待解决
HarmonyOS 怎么自定义装饰器
333浏览 • 1回复 待解决