HarmonyOS NavDestination怎么添加导航右上角按钮

HarmonyOS
2024-12-18 15:07:14
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

目前NavDestination可以添加导航右上角按钮,可通过menus设置,具体可以参考:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/arkui-ts/ts-basic-components-navigation.md#%E7%A4%BA%E4%BE%8B2

@Entry
@Component
struct Index {
  pathStack: NavPathStack = new NavPathStack()

  private menuItems: Array<NavigationMenuItem> = [
    {
      value: "1",
      icon: 'resources/base/media/startIcon.png',
    },
    {
      value: "2",
      icon: 'resources/base/media/startIcon.png',
      isEnabled: false,
    },
    {
      value: "3",
      icon: 'resources/base/media/startIcon.png',
      isEnabled: true,
    }
  ]

  build() {
    NavDestination() {
      Column() {
        Button('pushPathByName', { stateEffect: true, type: ButtonType.Capsule })
          .width('80%')
          .height(40)
          .margin(20)
          .onClick(() => {
            this.pathStack.pushPathByName('pageOne', null)
          })
      }.width('100%').height('100%')
    }.title('pageTwo')
    .menus(this.menuItems)
    .onBackPressed(() => {
      this.pathStack.pop()
      return true
    })
    .onReady((context: NavDestinationContext) => {
      this.pathStack = context.pathStack;
      console.log("current page config info is " + JSON.stringify(context.getConfigInRouteMap()))
    })
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-18 17:06:49
相关问题
HarmonyOS PUSH推送右上角红点问题
710浏览 • 2回复 待解决
元服务右上角的胶囊区域
403浏览 • 1回复 待解决
HarmonyOS NavDestination组件加按钮
801浏览 • 1回复 待解决
HarmonyOS navdestination页面返回按钮问题
1734浏览 • 1回复 待解决
如何给按钮添加图片?
6666浏览 • 4回复 待解决
HarmonyOS NavDestination的title怎么居中
854浏览 • 1回复 待解决