在HarmonyOS NEXT开发中NavDestination怎么添加导航右上角按钮?

在HarmonyOS NEXT开发中NavDestination怎么添加导航右上角按钮?

阅读 1.1k
1 个回答

目前NavDestination可以添加导航右上角按钮,可通过menus设置,具体可以参考:https://gitee.com/openharmony/docs/blob/master/zh-cn/applicat...

@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())) 
    }) 
  } 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进