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

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

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())
  }
}
  • 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.
分享
微博
QQ
微信
回复
2025-01-09 17:55:46
相关问题
HarmonyOS Navigationtitle怎么居中显示
841浏览 • 1回复 待解决
Navigation如何自定义立体转场动画?
307浏览 • 1回复 待解决
HarmonyOS 怎么自定义TabTabbar
716浏览 • 1回复 待解决
HarmonyOS 如何动态设置导航栏title标题
628浏览 • 1回复 待解决
HarmonyOS 怎么自定义装饰器
743浏览 • 1回复 待解决