鸿蒙(HarmonyOS)项目方舟框架(ArkUI)之NavRouter组件

鸿蒙(HarmonyOS)项目方舟框架(ArkUI)之NavRouter组件

一、操作环境

操作系统: Windows 10 专业版、IDE:DevEco Studio 3.1、SDK:HarmonyOS 3.1+

二、NavRouter组件

导航组件,默认提供点击响应处理,不需要开发者自定义点击事件逻辑。

子组件

必须包含两个子组件,其中第二个子组件必须为NavDestination

接口

NavRouter()

事件
名称 功能描述
onStateChange(callback: (isActivated: boolean) => void) 组件激活状态切换时触发该回调。返回值isActivated为true时表示激活,为false时表示未激活。 说明: 开发者点击激活NavRouter,加载对应的NavDestination子组件时,回调onStateChange(true)。NavRouter对应的NavDestination子组件不再显示时,回调onStateChange(false)。

三、示例

代码
复制代码
// xxx.ets
@Entry
@Component
struct NavRouterExample {
  @State isActiveWLAN: boolean = false
  @State isActiveBluetooth: boolean = false

  build() {
    Column() {
      Navigation() {
        NavRouter() {
          Row() {
            Row().width(30).height(30).borderRadius(30).margin({ left: 3, right: 10 }).backgroundColor(Color.Pink)
            Text(`WLAN`)
              .fontSize(22)
              .fontWeight(500)
              .textAlign(TextAlign.Center)
          }
          .width('90%')
          .height(72)
          NavDestination() {
            Flex({ direction: FlexDirection.Row }) {
              Text('未找到可用WLAN').fontSize(30).padding({ left: 15 })
            }
          }.hideTitleBar(false).backgroundColor('#0c182431')
        }.backgroundColor(this.isActiveWLAN ? '#ccc' : '#fff')
        .borderRadius(24)
        .onStateChange((isActivated: boolean) => {
          this.isActiveWLAN = isActivated
        })

        NavRouter() {
          Row() {
            Row().width(30).height(30).borderRadius(30).margin({ left: 3, right: 10 }).backgroundColor(Color.Pink)
            Text(`蓝牙`)
              .fontSize(22)
              .fontWeight(500)
              .textAlign(TextAlign.Center)
          }
          .width('90%')
          .height(72)

          NavDestination() {
            Flex({ direction: FlexDirection.Row }) {
              Text('未找到可用蓝牙').fontSize(30).padding({ left: 15 })
            }
          }.hideTitleBar(false).backgroundColor('#0c182431')
        }.backgroundColor(this.isActiveBluetooth ? '#ccc' : '#fff')
        .borderRadius(24)
        .onStateChange((isActivated: boolean) => {
          this.isActiveBluetooth = isActivated
        })
      }
      .title('设置')
      .titleMode(NavigationTitleMode.Free)
      .mode(NavigationMode.Auto)
      .hideTitleBar(false)
      .hideToolBar(true)
    }.height('100%')
  }
}
图例

你有时间常去我家看看我在这里谢谢你啦...

我家地址:亚丁号

最后送大家一首诗:

山高路远坑深,

大军纵横驰奔,

谁敢横刀立马?

惟有点赞加关注大军。

相关推荐
鸿蒙程序媛12 分钟前
【知识汇总】PixelMap 和 ArrayBuffer 详解
harmonyos
程序猿追1 小时前
HarmonyOS 6.0 网络请求深度解析:从基础调用到生产级封装
网络·华为·harmonyos
互联网散修3 小时前
鸿蒙应用开发UI基础第三十四节:媒体查询核心解析 —— 响应式布局与工具类封装
ui·harmonyos·媒体查询
性感博主在线瞎搞3 小时前
【鸿蒙开发】OpenHarmony与HarmonyOS调用C/C++教程
华为·harmonyos·鸿蒙·鸿蒙系统·openharmony
大雷神4 小时前
HarmonyOS APP<玩转React>开源教程二十三:面试题库功能
harmonyos
程序猿追5 小时前
HarmonyOS 5.0 自定义组件与状态管理实战:用 RelationalStore 构建可复用的任务看板
华为·harmonyos
程序猿追5 小时前
HarmonyOS 6.0 实战:用 Native C++ NDK 开发一款本地计步器应用
c++·华为·harmonyos
程序猿追6 小时前
HarmonyOS 6.0 PC端蓝牙开发全攻略:从设备扫描到数据收发
华为·harmonyos
大雷神6 小时前
HarmonyOS APP<玩转React>开源教程二十四:错题本功能
react.js·面试·开源·harmonyos