HarmonyOS 是否有navigation示例

从广告页到登录页再到主页,主页有几个Tab页面,都是使用Navigation的示例。

HarmonyOS
2025-01-09 15:05:26
947浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

示例参考如下:

@Entry
@Component
struct Index {
  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack()
  isLogin: boolean = false;
  @State fontColor: string = '#182431'
  @State selectedFontColor: string = '#007DFF'
  @State currentIndex: number = 0
  private controller: TabsController = new TabsController()

  @Builder
  PagesMap(name: string) {
    if (name == 'Login') {
      Login()
    }
  }

  @Builder
  tabBuilder(index: number, name: string) {
    Column() {
      Text(name)
        .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
        .fontSize(16)
        .fontWeight(this.currentIndex === index ? 500 : 400)
        .lineHeight(22)
        .margin({ top: 17, bottom: 7 })
      Divider().strokeWidth(2).color('#007DFF').opacity(this.currentIndex === index ? 1 : 0)
    }.width('100%')
  }

  build() {
    Navigation(this.pageInfos) {
      Button('登录模块').width('80%').margin(2).onClick(() => {
        this.pageInfos.pushPathByName('Login', '');
      })
      NavRouter() {
        Button('页1').width('80%').margin(2)
        NavDestination() {
          Text("页1")
        }
      }

      NavRouter() {
        Button('页2').width('80%').margin(2)
        NavDestination() {
          Text("页2")
        }
      }

      NavRouter() {
        Button('页3').width('80%').margin(2)
        NavDestination() {
          Text("页3")
        }
      }

      Tabs({ barPosition: BarPosition.Start, index: this.currentIndex, controller: this.controller }) {
        TabContent() {
          Column().width('100%').height('100%').backgroundColor('#00CB87')
        }.tabBar(this.tabBuilder(0, 'green'))

        TabContent() {
          Column().width('100%').height('100%').backgroundColor('#007DFF')
        }.tabBar(this.tabBuilder(1, 'blue'))

        TabContent() {
          Column().width('100%').height('100%').backgroundColor('#FFBF00')
        }.tabBar(this.tabBuilder(2, 'yellow'))

        TabContent() {
          Column().width('100%').height('100%').backgroundColor('#E67C92')
        }.tabBar(this.tabBuilder(3, 'pink'))
      }
      .vertical(false)
      .barMode(BarMode.Fixed)
      .barWidth(360)
      .barHeight(56)
      .animationDuration(400)
      .onChange((index: number) => {
        this.currentIndex = index
      })
      .width(360)
      .height(296)
      .margin({ top: 52 })
      .backgroundColor('#F1F3F5')
    }.navDestination(this.PagesMap)
  }
}

@Component
struct Login {
  build() {
    NavDestination() {
      Navigation() {
        NavRouter() {
          Button('功能1').width('80%').margin(2)
          NavDestination() {
            Text("页1")
          }
        }

        NavRouter() {
          Button('功能2').width('80%').margin(2)
          NavDestination() {
            Text("页2")
          }
        }

        NavRouter() {
          Button('功能3').width('80%').margin(2)
          NavDestination() {
            Text("页3")
          }
        }
      }
    }
  }
}
  • 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.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-navigation-V5

分享
微博
QQ
微信
回复
2025-01-09 18:35:04


相关问题
HarmonyOS 是否区号选择示例
574浏览 • 1回复 待解决
HarmonyOS 是否图片滑块验证示例
723浏览 • 1回复 待解决
HarmonyOS 是否个人信息页示例
722浏览 • 1回复 待解决
证书锁定功能示例哪些?
1426浏览 • 1回复 待解决
HarmonyOS 输入框的dialog示例
747浏览 • 1回复 待解决
HarmonyOS RN是否支持CodePush与Navigation
806浏览 • 1回复 待解决
HarmonyOS navigation单例模式吗
960浏览 • 1回复 待解决
屏幕自动旋转的示例哪些?
1037浏览 • 1回复 待解决