HarmonyOS Navigation进入二级界面TabsController隐藏起来?

一级界面底下有三个Tab,需要在TabContent点击Button后,实现通过Navigation的push进入二级界面的时候,底下的Tabs隐藏起来,返回一级界面的时候,底下的Tabs显示出来。文档找不到相关的资料,是否TabsController和Navigation不适合组合起来?

阅读 453
1 个回答

需要Navigation 包在TabsController外面

@Entry
@Component
struct TabsExample {
  pageStack : NavPathStack = new NavPathStack();
  @State fontColor: string = '#182431'
  @State selectedFontColor: string = '#007DFF'
  @State currentIndex: number = 0
  private controller: TabsController = new TabsController()

  @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.pageStack){
      Column() {
        Tabs({ barPosition: BarPosition.End, index: this.currentIndex, controller: this.controller }) {
          TabContent() {
            Column(){
              Text("ddd")
                .width(50)
                .height(60)
                .onClick(()=>{
                  this.pageStack.pushPathByName("NextPage",null,true)
                })
            }.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("100%")
        .height("100%")
        .backgroundColor('#F1F3F5')
      }.width('100%')
    }.hideTitleBar(true)

  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进