1 个回答

可以自定义tabbar,参考此demo:

@Entry
@Component
struct TabsPage {
  @State tabArray: Array<string> = ['首页', '推荐', '发现', '我的']
  @State focusIndex: number = 0
  private controller: TabsController = new TabsController()

  build() {
    Stack() {
      //Tab content
      Tabs({ controller: this.controller }) {
        ForEach(this.tabArray, (item: number, index: number) => {
          TabContent() {
            Text(item + '的内容')
              .width(500)
              .fontSize(30)
              .textAlign(TextAlign.Start)
          }
          .backgroundColor(Color.Blue)
        })
      }
      .barHeight(0)
      .animationDuration(100)
      .onChange((index: number) => {
        this.focusIndex = index
      })

      //tab bar
      Row() {
        ForEach(this.tabArray, (item: string, index: number) => {
          Text(item)
            .fontSize(18)
            .fontColor(this.focusIndex === index ? '#007dff' : Color.Black)
            .height(60)
            .textAlign(TextAlign.Center)
            .onClick(() => {
              this.controller.changeIndex(index)
              this.focusIndex = index
            })
        })
      }
      .position({left:0,bottom:50})
      .width('100%')
      .height(50)
      .backgroundColor(Color.Red)
    }
    .width('100%')
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进