HarmonyOS NavDestination组件自定义Title时自带返回按钮如何隐藏

使用NavDestination组件时,自带的返回按钮隐藏不掉

HarmonyOS
2024-12-25 08:34:01
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

NavDestination可以设置hideTitleBar(true)隐藏标题栏,再自定义一个text组件

DEMO如下:

import { window } from '@kit.ArkUI'

@Builder
export function titleBuilder(backIcon: Resource, title: string, pageInfos: NavPathStack) {
  Row() {
    Image(backIcon)
      .onClick(() => {
        pageInfos.pop()
      })
      .objectFit(ImageFit.Contain)
      .width('10%')
      .height('70%')
    Text(title)
  }
  .width('100%')
  .height('10%')
  .backgroundColor(Color.Orange)
}

@Component
export struct PageOneTmp {
  @Consume('pageInfos') pageInfos: NavPathStack;
  @State areaCodeSelectViewIsPresent: boolean = false

  build() {
    NavDestination() {
      Column() {
        titleBuilder($r('app.media.startIcon'), '返回', this.pageInfos)
      }
      .justifyContent(FlexAlign.Start)
      .width('100%')
      .height('100%')

    }
    .hideTitleBar(true)

  }
}

@Entry
@Component
struct Index {
  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack()
  @State topSafeHeight: number = 0

  @Builder
  PageMap(name: string) {
    if (name === 'pageOne') {
      PageOneTmp()
    }
  }

  build() {
    Navigation(this.pageInfos) {
      Column() {
        Button('pushPath')
          .onClick(() => {
            this.pageInfos.pushPath({ name: 'pageOne' })
          })
      }
    }
    .navDestination(this.PageMap)
  }
}
  • 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.
  • 62.
  • 63.
  • 64.
分享
微博
QQ
微信
回复
2024-12-25 10:28:38
相关问题
返回按钮是否可以自定义事件?
993浏览 • 1回复 待解决
HarmonyOS navdestination页面返回按钮问题
1679浏览 • 1回复 待解决
HarmonyOS NavDestination组件按钮
788浏览 • 1回复 待解决
HarmonyOS picker组件如何隐藏拍照按钮
788浏览 • 1回复 待解决
HarmonyOS NavDestinationtitle怎么居中
831浏览 • 1回复 待解决
HarmonyOS 定义自定义组件
1052浏览 • 1回复 待解决