49.HarmonyOS鸿蒙系统 App(ArkUI)Tab导航组件的使用

HarmonyOS鸿蒙系统 App(ArkUI)Tab导航组件的使用

图片显示

Row()
{
  Image($r('app.media.leaf')).height(100).width(100)
  Image($r('app.media.icon')).height(100).width(100)
}

 

左侧导航 

 

import prompt from '@ohos.prompt';
import promptAction from '@ohos.promptAction';
@Entry
@Component
struct Index {
  @State message: string = 'Hello World'
  @State handlePopup: boolean = false
  build() {
   // Tabs() { //默认顶部导航
     // Tabs({ barPosition: BarPosition.End }) { //设置底部导航
    Tabs({ barPosition: BarPosition.Start }) { //设置顶部部导航
      TabContent() {
        Column()
        {

          Row()
          {
            Image($r('app.media.leaf')).height(100).width(100)
            Image($r('app.media.icon')).height(100).width(100)
          }
          Row(){
            Text('工号:')
            TextInput({text:'tintel10699487'}).backgroundColor(Color.Yellow)

          }
          Row(){
            Button('确定')

          }
          Row(){
            Text('首页的内容').fontSize(30)
            Button('查看')
          }
          Row(){
            Text('首页的内容2').fontSize(30)
            Button('查看2')
          }
        }

      }
      .tabBar('首页').backgroundColor(Color.Green)

      TabContent() {
        Column()
        {
          Row()
          {
            Text('这里是推荐的内容').fontSize(30)
          }
          Row()
          {
            Text('这里是推荐的内容2').fontSize(30)
          }
          Row()
          {
            Text('这里是推荐的内容3').fontSize(30)
          }
          Row()
          {
            Text('这里是推荐的内容4').fontSize(30)
          }
          Row()
          {
            Text('这里是推荐的内容5').fontSize(30)
          }
        }


      }
      .tabBar('推荐')
      .backgroundColor(Color.Yellow)

      TabContent() {
        Text('发现的内容').fontSize(30)

      }
      .tabBar('发现')

      TabContent() {
        Column(){
          Row()
          {
            Text('姓名:').fontSize(30).fontColor(Color.White)
            TextInput({text:"书书航"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Text('职业:').fontSize(30).fontColor(Color.White)
            TextInput({text:"工程师"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Text('爱好:').fontSize(30).fontColor(Color.White)
            TextInput({text:"音乐"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Text('户籍:').fontSize(30).fontColor(Color.White)
            TextInput({text:"CHN"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Text('地区:').fontSize(30).fontColor(Color.White)
            TextInput({text:"SHH"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Button('编辑').fontSize(30).fontColor(Color.White)
            Button('确认').fontSize(30).fontColor(Color.White)
          }
        }


      }
      .tabBar("我的")
        .backgroundColor(Color.Blue)

    }.vertical(true)
  }
}

 

Tabs组件的页面的组成包含了两个部分,分别是TabContent和TabBar。TabContent是内容页,TabBar是导航页签栏,页面结构如下图所示,根据不同的导航类型,布局会有区别,可以分为底部导航、顶部的导航、侧边的导航,其导航栏分别位于底部、顶部和侧边。

图1 Tabs组件布局示意图

说明

  • TabContent组件不支持设置通用宽度属性,其宽度默认撑满Tabs父组件。
  • TabContent组件不支持设置通用高度属性,其高度由Tabs父组件高度与TabBar组件高度决定。

Tabs使用花括号包裹TabContent,如图2,其中TabContent显示相应的内容页。

图2 Tabs与TabContent使用

每一个TabContent对应的内容需要有一个页签,可以通过TabContent的tabBar属性进行配置。在如下TabContent组件上设置属性tabBar,可以设置其对应页签中的内容,tabBar作为内容的页签。


  
  1. TabContent() {
  2. Text('首页的内容').fontSize(30)
  3. }
  4. .tabBar('首页')

设置多个内容时,需在Tabs内按照顺序放置。


  
  1. Tabs() {
  2. TabContent() {
  3. Text('首页的内容').fontSize(30)
  4. }
  5. .tabBar('首页')
  6. TabContent() {
  7. Text('推荐的内容').fontSize(30)
  8. }
  9. .tabBar('推荐')
  10. TabContent() {
  11. Text('发现的内容').fontSize(30)
  12. }
  13. .tabBar('发现')
  14. TabContent() {
  15. Text('我的内容').fontSize(30)
  16. }
  17. .tabBar("我的")
  18. }

 

顶部导航:

设置:Tabs({ barPosition: BarPosition.Start }) { //设置顶部部导航
设置:}.vertical(false)

import prompt from '@ohos.prompt';
import promptAction from '@ohos.promptAction';
@Entry
@Component
struct Index {
  @State message: string = 'Hello World'
  @State handlePopup: boolean = false
  build() {
   // Tabs() { //默认顶部导航
     // Tabs({ barPosition: BarPosition.End }) { //设置底部导航
    Tabs({ barPosition: BarPosition.Start }) { //设置顶部部导航
      TabContent() {
        Column()
        {

          Row()
          {
            Image($r('app.media.leaf')).height(100).width(100)
            Image($r('app.media.icon')).height(100).width(100)
          }
          Row(){
            Text('工号:')
            TextInput({text:'tintel10699487'}).backgroundColor(Color.Yellow)

          }
          Row(){
            Button('确定')

          }
          Row(){
            Text('首页的内容').fontSize(30)
            Button('查看')
          }
          Row(){
            Text('首页的内容2').fontSize(30)
            Button('查看2')
          }
        }

      }
      .tabBar('首页').backgroundColor(Color.Green)

      TabContent() {
        Column()
        {
          Row()
          {
            Text('这里是推荐的内容').fontSize(30)
          }
          Row()
          {
            Text('这里是推荐的内容2').fontSize(30)
          }
          Row()
          {
            Text('这里是推荐的内容3').fontSize(30)
          }
          Row()
          {
            Text('这里是推荐的内容4').fontSize(30)
          }
          Row()
          {
            Text('这里是推荐的内容5').fontSize(30)
          }
        }


      }
      .tabBar('推荐')
      .backgroundColor(Color.Yellow)

      TabContent() {
        Text('发现的内容').fontSize(30)

      }
      .tabBar('发现')

      TabContent() {
        Column(){
          Row()
          {
            Text('姓名:').fontSize(30).fontColor(Color.White)
            TextInput({text:"书书航"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Text('职业:').fontSize(30).fontColor(Color.White)
            TextInput({text:"工程师"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Text('爱好:').fontSize(30).fontColor(Color.White)
            TextInput({text:"音乐"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Text('户籍:').fontSize(30).fontColor(Color.White)
            TextInput({text:"CHN"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Text('地区:').fontSize(30).fontColor(Color.White)
            TextInput({text:"SHH"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Button('编辑').fontSize(30).fontColor(Color.White)
            Button('确认').fontSize(30).fontColor(Color.White)
          }
        }


      }
      .tabBar("我的")
        .backgroundColor(Color.Blue)

    }.vertical(false)
  }
}

 

 

底部导航:

设置:Tabs({ barPosition: BarPosition.End}) { //设置底部导航
设置:}.vertical(false)

 

 

import prompt from '@ohos.prompt';
import promptAction from '@ohos.promptAction';
@Entry
@Component
struct Index {
  @State message: string = 'Hello World'
  @State handlePopup: boolean = false
  build() {
   // Tabs() { //默认顶部导航
      Tabs({ barPosition: BarPosition.End }) { //设置底部导航
    //Tabs({ barPosition: BarPosition.Start }) { //设置顶部部导航
      TabContent() {
        Column()
        {

          Row()
          {
            Image($r('app.media.leaf')).height(100).width(100)
            Image($r('app.media.icon')).height(100).width(100)
          }
          Row(){
            Text('工号:')
            TextInput({text:'tintel10699487'}).backgroundColor(Color.Yellow)

          }
          Row(){
            Button('确定')

          }
          Row(){
            Text('首页的内容').fontSize(30)
            Button('查看')
          }
          Row(){
            Text('首页的内容2').fontSize(30)
            Button('查看2')
          }
        }

      }
      .tabBar('首页').backgroundColor(Color.Green)

      TabContent() {
        Column()
        {
          Row()
          {
            Text('这里是推荐的内容').fontSize(30)
          }
          Row()
          {
            Text('这里是推荐的内容2').fontSize(30)
          }
          Row()
          {
            Text('这里是推荐的内容3').fontSize(30)
          }
          Row()
          {
            Text('这里是推荐的内容4').fontSize(30)
          }
          Row()
          {
            Text('这里是推荐的内容5').fontSize(30)
          }
        }


      }
      .tabBar('推荐')
      .backgroundColor(Color.Yellow)

      TabContent() {
        Text('发现的内容').fontSize(30)

      }
      .tabBar('发现')

      TabContent() {
        Column(){
          Row()
          {
            Text('姓名:').fontSize(30).fontColor(Color.White)
            TextInput({text:"书书航"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Text('职业:').fontSize(30).fontColor(Color.White)
            TextInput({text:"工程师"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Text('爱好:').fontSize(30).fontColor(Color.White)
            TextInput({text:"音乐"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Text('户籍:').fontSize(30).fontColor(Color.White)
            TextInput({text:"CHN"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Text('地区:').fontSize(30).fontColor(Color.White)
            TextInput({text:"SHH"}).fontSize(30).fontColor(Color.Green)
          }
          Row()
          {
            Button('编辑').fontSize(30).fontColor(Color.White)
            Button('确认').fontSize(30).fontColor(Color.White)
          }
        }


      }
      .tabBar("我的")
        .backgroundColor(Color.Blue)

    }.vertical(false)
  }
}

 

相关推荐

  1. Harmonyos系统列表组件和video组件使用

    2024-04-21 19:26:02       70 阅读
  2. 鸿蒙(HarmonyOS)应用开发——http使用

    2024-04-21 19:26:02       65 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-21 19:26:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-21 19:26:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-21 19:26:02       87 阅读
  4. Python语言-面向对象

    2024-04-21 19:26:02       96 阅读

热门阅读

  1. Git恢复至某一个提交的状态

    2024-04-21 19:26:02       35 阅读
  2. 【大模型系列】目录

    2024-04-21 19:26:02       36 阅读
  3. GoLang核心知识点

    2024-04-21 19:26:02       37 阅读
  4. Angular自定义异步表单验证

    2024-04-21 19:26:02       33 阅读
  5. Scala之面向对象 Day -3

    2024-04-21 19:26:02       45 阅读
  6. 134. 加油站

    2024-04-21 19:26:02       31 阅读
  7. 【设计模式】享元模式

    2024-04-21 19:26:02       41 阅读
  8. 批量控制教程-Ansible管理windows

    2024-04-21 19:26:02       42 阅读
  9. 【Ansible】02

    2024-04-21 19:26:02       35 阅读
  10. linux的工具tcptrace的输出信息的解释和介绍

    2024-04-21 19:26:02       38 阅读