HarmonyOS tab切换demo

app首页底部tab切换 demo

HarmonyOS tab切换demo -鸿蒙开发者社区

HarmonyOS
2024-12-26 13:15:57
602浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

tab切换可使用tabs组件来实现,以下是demo:

@Entry
@Component
struct Index {
  @State cIndex:number=0
  build() {
    Tabs(){
      TabContent(){
        Text('tab0')
      }.tabBar(this.tbar(0))
      TabContent(){
        Text('tab1')
      }.tabBar(this.tbar(1))
      TabContent(){
        Text('tab2')
      }.tabBar(this.tbar(2))
      TabContent(){
        Text('tab3')
      }.tabBar(this.tbar(3))
    }.onChange((index:number)=>{
      this.cIndex=index
    })
  }
  @Builder tbar(index:number){
    Text("tab")
      .fontColor(this.cIndex==index?Color.Red:Color.Black)
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-26 16:24:03


相关问题
HarmonyOS Tab导航demo
635浏览 • 1回复 待解决
Tab控件切换问题有哪些?
1183浏览 • 1回复 待解决
Tab组件内嵌web view左右滑动切换问题
1083浏览 • 1回复 待解决
请问一下tab按钮组切换效果
1659浏览 • 1回复 待解决