HarmonyOS鸿蒙Next中可以实现这种自定义的导航栏效果吗

HarmonyOS鸿蒙Next中可以实现这种自定义的导航栏效果吗 现在导航栏组件写好了,但是不知道怎么应用,就是下面这个图里显示的 navbar 我认为他应该是有个 类似于 web vue 路由的哪个 Layout 布局吧,但是我看了文档找不到相关的 信息,求大佬指导一下 类似于这样的

cke_11323.png

cke_8527.png

cke_756.png


更多关于HarmonyOS鸿蒙Next中可以实现这种自定义的导航栏效果吗的实战教程也可以访问 https://www.itying.com/category-93-b0.html

6 回复

CSxiangce

@Entry
@ComponentV2
struct CSxiangce {
  @Local message: string = 'Hello World';
  private daohangqi:NavPathStack = new NavPathStack();
  private yuansuzu:string[] = ['壹','贰','叁','肆','伍','陆','柒','捌','玖','拾']

  build() {
    Stack(){
      Navigation(this.daohangqi){
        WaterFlow(){
          ForEach(this.yuansuzu, (i:string) => {
            ForEach(this.yuansuzu, (i:string) => {
              FlowItem(){
                Text(i)
                  .height('50')
                  .width('50')
                  .borderRadius(50)
                  .backgroundColor('#ff2f88ef')
                  .textAlign(TextAlign.Center)
              }
              .onClick(() => {
                this.daohangqi.pushDestinationByName('',{})
              })
            })
          })
        }
        .height("100%")
        .width('100%')
        .columnsTemplate('1fr 1fr 1fr 1fr')
        .rowsTemplate('1fr 1fr 1fr 1fr 1fr')
        .align(Alignment.Center)
        .rowsGap(50)
      }
      .height('100%')
      .width('100%')
      .navDestination(csXiangqing)

      Column(){
        Row(){
          Button('主页')
            .width(70)
            .height(50)

          Button('添加')
            .width(70)
            .height(50)

          Button('目/详')
            .width(70)
            .height(50)

        }
        .height(80)
        .margin({bottom:50})
        .width('80%')
        .borderRadius(50)
        .justifyContent(FlexAlign.SpaceAround)
        .backgroundColor('#ff709f79')
      }
      .height('100%')
      .width('100%')
      .justifyContent(FlexAlign.End)
      .hitTestBehavior(HitTestMode.Transparent)
    }
    .height('100%')
    .width('100%')
  }
}

@Builder
function csXiangqing(){
  xiangqingye()
}

@ComponentV2
struct xiangqingye{
  private daohangqi:NavPathStack = new NavPathStack();

  build() {
    NavDestination(){
      Column(){
        Text('这是详情页')
      }
      .height('100%')
      .width('100%')
    }
    .height('100%')
    .width('100%')
    .onReady((e:NavDestinationContext) => {
      if (e?.pathStack) {
        this.daohangqi = e.pathStack;
      }
    })
  }
}

效果截图

点击“首/详”按钮、列表元素,都可以跳转子页面。

更多关于HarmonyOS鸿蒙Next中可以实现这种自定义的导航栏效果吗的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


实现方式比较多。

第一种,利用TABS现有能力([https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-container-tabs#baroverlap10](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-container-tabs#baroverlap10)。第二种,隐藏tabs(或者使用swiper)页签栏,手搓一个页签栏,在stack容器叠加,然后通过tabscontroller(https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-container-tabs#tabscontroller)手动实现翻页效果。

还可以使用自定义页签。

当然,通过stack容器、scroll组件、scrollController控制器、数据展示容器,可以实现想要的大部分效果。组件参考([https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkui-declarative-comp](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkui-declarative-comp))

文档的需求比较复杂,看多了组件文档,自然就知道怎么实现了,直接给写好DEMO这种,估计很少人会发时间去做。因为这个需求没什么收益性。

首先感谢大佬回复,但是我还是有几点不太明白,期待回复

第一种先有的 tabs 做不到这种悬浮效果吧

第二种没看懂什么意思,现在已经把这个 自定义的 navbar 组件写好了,三个按钮三个事件直接绑定路由跳转事件可行吗

我还不明白的是如何做到 在 mainPage(root)视图里只引用这个 navbar 一次,而不是每个 page 都引入一遍这种该如何实现,

方便加个微信吗,想有偿请教这个问题,

很高兴您的认可,本来也不是专业人士,有偿就不需要了,如果真的需要,把需求详细描述下,看看有没有空时间做个DEMO,

在HarmonyOS鸿蒙Next中,可以通过自定义NavigationBar组件实现独特的导航栏效果。开发者可以利用ArkUI框架,结合Flex布局和Component组件,灵活设计导航栏的样式和交互逻辑。通过@State@Prop等装饰器,动态调整导航栏的状态和属性,满足个性化需求。此外,鸿蒙Next的AbilityPage机制支持导航栏与页面内容的无缝集成,确保用户体验的一致性。

回到顶部