应用底部导航实现,有人知道处理方案吗?

应用底部导航实现

HarmonyOS
2024-05-26 14:32:57
1390浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
e_leaner

核心代码

@Entry 
@Component 
struct Index { 
 @State message: string = 'Hello World'; 
 @State selectTabIndex: number = 3; 
 @State test: string[] = ["1", "2", "4", "4", "5", "6", "7", "8", "9", "9", "9",] 
 @State tabs: string[] = ["直播日历", "城市专享优惠", "发布会", "非常会玩机", "精选推荐", "特色门店百家游"] 
 listScroller: Scroller = new Scroller() 
 tabsController: TabsController = new TabsController() 
​ 
 build() { 
   Column() { 
     Tabs({ index: this.selectTabIndex, barPosition: BarPosition.Start, controller: this.tabsController }) { 
       ForEach(this.tabs, (item: string, index) => { 
         TabContent() { 
           Text(item) 
        } 
        .height(0) 
        .layoutWeight(1) 
        .tabBar(this.buildTab(item, index)) 
      }, (item: string, index: number) => item + index) 
    } 
    .height(0) 
    .barHeight(200) 
    .layoutWeight(1) 
    .fadingEdge(false) 
    .barMode(BarMode.Scrollable) 
    .onChange(index => { 
       this.selectTabIndex = index; 
    }) 
  } 
  .height('100%') 
  .width('100%') 
  .backgroundColor(0xf0fff0) 
} 
​ 
 @Builder 
 buildTab(title: ResourceStr, targetIndex: number) { 
   Column() { 
     Text(title) 
      .fontColor(this.selectTabIndex === targetIndex ? $r('sys.color.ohos_id_color_subtab_text_on') : $r('sys.color.ohos_id_color_subtab_text_off')) 
      .padding({ top: 10, bottom: 10 }) 
      .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) 
      .fontSize($r('sys.float.ohos_id_text_size_body1')) 
  } 
  .margin({ 
     left: 10, 
     right: 10 
  }) 
​ 
  .justifyContent(FlexAlign.Center) 
  .borderWidth({ bottom: 10, left: 0, right: 0, top: 0 }) 
  .borderColor(this.selectTabIndex === targetIndex ? $r('sys.color.ohos_id_color_subtab_text_on') : Color.Transparent) 
  .onClick((e => { 
     this.tabsController.changeIndex(targetIndex); 
  })) 
} 
}
  • 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.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.

实现效果

注明适配的版本信息

  • IDE:DevEco Studio 4.0.3.600
  • SDK:HarmoneyOS 4.0.10.11
分享
微博
QQ
微信
回复
2024-05-27 19:44:28


相关问题
导航栏如何适配,有人知道?
2544浏览 • 0回复 待解决
SnapShot定位,有人知道怎么处理
2056浏览 • 1回复 待解决
List局部刷新,有人知道怎么处理
1955浏览 • 1回复 待解决
如何实现振动,有人知道
2023浏览 • 2回复 待解决
如何对网络图片处理有人知道
894浏览 • 1回复 待解决
如何实现图片预览,有人知道
1441浏览 • 1回复 待解决
如何实现翻页功能,有人知道
2802浏览 • 1回复 待解决
有人知道如何实现图文混排
1679浏览 • 1回复 待解决
如何实现镂空效果,有人知道?
1081浏览 • 1回复 待解决
应用动态导入的场景,有人知道
1015浏览 • 1回复 待解决
如何实现http长连接,有人知道
2425浏览 • 1回复 待解决
弧形进度条实现有人知道方法
1270浏览 • 1回复 待解决
HarmonyOS 底部导航条沉浸式方案
972浏览 • 1回复 待解决
热重载该如何实现有人知道
1358浏览 • 1回复 待解决
应用商店更新机制有人知道
2841浏览 • 1回复 待解决
如何实现防截屏功能,有人知道
2718浏览 • 1回复 待解决
有人知道关于页demo
1480浏览 • 1回复 待解决
实现扫码的库有哪些 ,有人知道
1899浏览 • 1回复 待解决
有人知道JS menu如何隐藏
5392浏览 • 1回复 待解决