HarmonyOS Navigation中title怎么居中显示?

如题:HarmonyOS Navigation中title怎么居中显示?

阅读 608
1 个回答

可以给自定义navigationtitle用row包裹并给与.width(‘100%’).justifyContent(FlexAlign.Center)属性,参考代码如下:

@Entry
@Component
struct Page {
  @State message: string = 'Hello World';

  build() {
    Navigation(){
      Row(){
        Column(){
          Text(this.message)
            .fontSize(  50)
            .fontWeight(FontWeight.Bold)
        }.width('100%')
      }.height('100%')
    }.title(this.navitionTitle)
    .titleMode(NavigationTitleMode.Mini)
    .hideBackButton(true)
    .menus(this.navigationMenus())
  }
  @Builder navitionTitle(){
    Row(){
      Text("购买记录")
        .fontWeight(FontWeight.Bold)
    }.width('100%').justifyContent(FlexAlign.Center)
  }
  @Builder navigationMenus(){
    Row(){
      Image($r('app.media.app_icon'))
        .width(24)
        .height(24)
        .margin({right:14,top:10})
    }
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进